fix(s3vectors): check create names by S3 Vectors' naming rules and answer its not-found messages (#8966)

This commit is contained in:
mrfelek authored and GitHub committed 2026-11-19 07:25:11 -04:00
1 parent 5f38401fdd
commit 3316d46df3
7 files changed
+190 -51

No files matched your search

@@ -220,7 +220,7 @@ class S3VectorsCfnProvisionerTest {
}
@ParameterizedTest
@ValueSource(strings = {"", " ", "\t", "Uppercase", "under_score", "dot.name", "ab", "-bucket", "bucket-",
@ValueSource(strings = {"", " ", "\t", "Uppercase", "under_score", "dot..name", "ab", "-bucket", "bucket-",
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl"})
void invalidBucketNamesAreRejectedForBothSelectors(String name) throws Exception {
for (String selector : List.of("VectorBucketName", "VectorBucketArn")) {
@@ -234,6 +234,28 @@ class S3VectorsCfnProvisionerTest {
verifyNoInteractions(service);
}
/**
* An index may name, by name or by ARN, a bucket an older Floci took under a name the create rules now reserve;
* a bucket the stack creates under such a name is refused.
*/
@Test
void anIndexReachesABucketStoredUnderAReservedName() throws Exception {
stubCreates();
for (String selector : List.of("VectorBucketName", "VectorBucketArn")) {
ObjectNode props = indexProps();
props.remove("VectorBucketArn");
props.put(selector, "VectorBucketName".equals(selector) ? "sthree-logs"
: BUCKET_ARN.replace("my-bucket", "sthree-logs"));
provisioner.provision(resource("Index"), props, context(null));
}
verify(service, times(2)).createIndex(eq("sthree-logs"), eq("my-index"), eq(3), eq("float32"), eq("cosine"),
anyList(), any(), anyMap(), eq(REGION));
AwsException refused = assertThrows(AwsException.class, () -> provisioner.provision(resource("VectorBucket"),
props("{\"VectorBucketName\":\"sthree-logs\"}"), context(null)));
assertEquals("ValidationError", refused.getErrorCode());
}
@Test
void blankExplicitResourceNamesAreRejected() throws Exception {
for (String name : List.of("", " ")) {
@@ -116,29 +116,52 @@ class S3VectorsArnAddressingIntegrationTest {
}
/**
* CreateVectorBucket and CreateIndex take a name without checking it, so what they make stays reachable by that
* name and by the ARN they gave it.
* CreateVectorBucket and CreateIndex refuse a name outside S3 Vectors' naming rules, which are the same for both,
* with "Invalid vector bucket name" or "Invalid index name", as it does (measured on AWS). The index name is
* checked before its bucket is looked for.
*/
@ParameterizedTest
@ValueSource(strings = {"Arn-name", "arn_name", "-arn-name", "arn-name-", ".arn-name", "arn-name.", "arn..name",
"arn.-name", "arn-.name", "192.168.5.4", "sthree-arn-name", "arn-name-s3alias", "arn-name--x-s3"})
void aNameOutsideTheNamingRulesIsRefusedOnCreate(String name) {
refused(post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + name + "\"}"), "Invalid vector bucket name");
refused(post("/CreateIndex", index(bucketName(), name)), "Invalid index name");
post("/ListVectorBuckets", "{}").statusCode(200).body("vectorBuckets.vectorBucketName", not(hasItem(name)));
}
/** A name of fewer than 3 or more than 63 characters gets the length message first (measured on AWS). */
@ParameterizedTest
@ValueSource(ints = {2, 64})
void aNameOfAnotherLengthIsRefusedOnCreate(int length) {
String name = "a".repeat(length);
String limit = " failed to satisfy constraint: Member must have length between 3 and 63, inclusive";
refused(post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + name + "\"}"),
"1 validation error detected. Value with length " + length + " at '/vectorBucketName'" + limit);
refused(post("/CreateIndex", index(bucketName(), name)),
"1 validation error detected. Value with length " + length + " at '/indexName'" + limit);
}
/**
* Names the rules take, though their documentation lists only letters, numbers and hyphens for a bucket: dots
* between labels, hyphens running together, labels of numbers only, and S3's reserved prefix {@code xn--}
* (measured on AWS).
*/
@Test
void aBucketAndAnIndexAreReachedByTheNamesAndArnsTheyWereGiven() {
String bucket = "Arn_" + UUID.randomUUID().toString().substring(0, 8);
String arn = post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200)
.extract().path("vectorBucketArn");
void aNameOfDottedLabelsIsTakenOnCreate() {
String id = UUID.randomUUID().toString().substring(0, 8);
List<String> names = List.of("arn." + id + ".v2", "ar--n-" + id, "123." + id, "xn--arn-" + id);
try {
String index = post("/CreateIndex", "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"My_Index\","
+ "\"dataType\":\"float32\",\"dimension\":2,\"distanceMetric\":\"cosine\"}").statusCode(200)
.extract().path("indexArn");
post("/GetVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200)
.body("vectorBucket.vectorBucketName", equalTo(bucket));
post("/ListIndexes", byBucketArn(arn)).statusCode(200)
.body("indexes.indexName", equalTo(List.of("My_Index")));
post("/GetIndex", byIndexArn(index)).statusCode(200)
.body("index.indexName", equalTo("My_Index"));
post("/DeleteIndex", byIndexArn(index)).statusCode(200);
for (String name : names) {
post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + name + "\"}").statusCode(200);
}
post("/CreateIndex", index(names.getFirst(), "1.2.3")).statusCode(200);
post("/ListIndexes", "{\"vectorBucketName\":\"" + names.getFirst() + "\"}").statusCode(200)
.body("indexes.indexName", equalTo(List.of("1.2.3")));
} finally {
post("/DeleteIndex", "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"My_Index\"}");
post("/DeleteVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200);
post("/DeleteIndex", "{\"vectorBucketName\":\"" + names.getFirst() + "\",\"indexName\":\"1.2.3\"}");
for (String name : names) {
post("/DeleteVectorBucket", "{\"vectorBucketName\":\"" + name + "\"}");
}
}
}
@@ -166,7 +189,7 @@ class S3VectorsArnAddressingIntegrationTest {
/**
* A name no call could reach the bucket by, blank or with a slash, is refused on create, as S3 Vectors refuses it
* (measured on AWS), the length first. A bucket of a name AWS refuses otherwise is still made: see above.
* (measured on AWS), the length first.
*/
@Test
void aBucketNameNoCallCouldReachIsRefusedOnCreate() {
@@ -452,7 +452,7 @@ class S3VectorsIntegrationTest {
.then()
.statusCode(200);
// Verify index is gone
// Verify index is gone, with S3 Vectors' message (measured on AWS)
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
@@ -464,7 +464,9 @@ class S3VectorsIntegrationTest {
.when()
.post("/GetIndex")
.then()
.statusCode(404);
.statusCode(404)
.body("__type", equalTo("NotFoundException"))
.body("message", equalTo("The specified index could not be found"));
}
@Test
@@ -482,7 +484,7 @@ class S3VectorsIntegrationTest {
.then()
.statusCode(200);
// Verify bucket is gone
// Verify bucket is gone, with S3 Vectors' message (measured on AWS)
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
@@ -493,7 +495,9 @@ class S3VectorsIntegrationTest {
.when()
.post("/GetVectorBucket")
.then()
.statusCode(404);
.statusCode(404)
.body("__type", equalTo("NotFoundException"))
.body("message", equalTo("The specified vector bucket could not be found"));
}
// Self-contained: each test below creates its own bucket/index so it doesn't depend on the
@@ -86,6 +86,57 @@ class S3VectorsServiceTest {
assertEquals(Set.of(REGION + "::legacy"), raw.keys());
}
/**
* A bucket and an index an older Floci stored under names S3 Vectors' rules refuse, which the create calls now
* refuse too, stay reachable by those names and by their ARNs in the calls that read a name as given.
*/
@Test
void aBucketAndAnIndexStoredUnderNamesTheRulesRefuseStayReachable() {
String bucketArn = "arn:aws:s3vectors:us-east-1:000000000000:bucket/Legacy_Bucket";
VectorBucket legacy = new VectorBucket("Legacy_Bucket", bucketArn, Map.of("sseType", "AES256"));
legacy.setCreationTime(CREATION_TIME);
legacy.getIndexes().put("My_Index",
new VectorIndex("My_Index", bucketArn + "/index/My_Index", "Legacy_Bucket", 2, "float32", "cosine"));
S3VectorsService upgraded = storing(legacy);
assertEquals(new S3VectorsService.ResolvedBucket("Legacy_Bucket", REGION, null),
upgraded.bucketTarget("Legacy_Bucket", null, REGION));
assertEquals(new S3VectorsService.ResolvedBucket("Legacy_Bucket", REGION, "000000000000"),
upgraded.bucketTarget(null, bucketArn, REGION));
assertEquals(new S3VectorsService.ResolvedIndex("Legacy_Bucket", "My_Index", REGION),
upgraded.resolveIndexTarget(null, null, bucketArn + "/index/My_Index", REGION));
assertEquals("My_Index", upgraded.getIndex("Legacy_Bucket", "My_Index", REGION).getIndexName());
assertEquals(List.of("My_Index"), upgraded.listIndexes("Legacy_Bucket", REGION).stream()
.map(VectorIndex::getIndexName).toList());
}
/**
* A bucket an older Floci took under a name the create rules now reserve keeps its policy calls, by name and by
* ARN: they check only that the bucket's name is one of dot-joined labels, as before.
*/
@Test
void aBucketStoredUnderAReservedNameKeepsItsPolicyCalls() {
String bucketArn = "arn:aws:s3vectors:us-east-1:000000000000:bucket/sthree-logs";
VectorBucket legacy = new VectorBucket("sthree-logs", bucketArn, Map.of("sseType", "AES256"));
legacy.setCreationTime(CREATION_TIME);
S3VectorsService upgraded = storing(legacy);
String policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"Read\",\"Effect\":\"Allow\"}]}";
upgraded.putVectorBucketPolicy("sthree-logs", null, policy, REGION);
assertEquals(policy, upgraded.getVectorBucketPolicy(null, bucketArn, REGION));
upgraded.deleteVectorBucketPolicy(null, bucketArn, REGION);
assertEquals("NotFoundException", assertThrows(AwsException.class,
() -> upgraded.getVectorBucketPolicy("sthree-logs", null, REGION)).getErrorCode());
}
/** A service over a store holding {@code bucket}, as an older Floci stored it. */
private static S3VectorsService storing(VectorBucket bucket) {
AccountAwareStorageBackend<VectorBucket> stored = AccountAwareStorageBackend.inMemory("000000000000");
stored.put(REGION + "::" + bucket.getVectorBucketName(), bucket);
return new S3VectorsService(new InMemoryStorageFactory("000000000000").withStore("s3vectors.json", stored),
new RegionResolver(REGION, "000000000000"), Clock.fixed(CREATION_TIME, ZoneOffset.UTC));
}
@Test
void persistsCreationTimesConfigurationAndCreationTags() throws Exception {
Map<String, String> encryption = Map.of("sseType", "aws:kms", "kmsKeyArn", "key");