fix(s3vectors): address vector buckets and indexes by ARN (#8669)

S3 Vectors calls that name a vector bucket now take its vectorBucketName or its vectorBucketArn, and calls that name an index take vectorBucketName with indexName, or indexArn. GetVectorBucket, DeleteVectorBucket, ListIndexes, CreateIndex, GetIndex, DeleteIndex, PutVectors, GetVectors, DeleteVectors and QueryVectors used to answer NotFoundException for a request by ARN. A request that gives neither form, or both, or mixes indexArn with the names, gets AWS's ValidationException message. A bucket or index ARN of another partition or Region than the request's is refused with a ValidationException, and one of another account with AccessDeniedException (403), in these calls, ListVectors and the bucket policy calls alike. CreateVectorBucket and CreateIndex refuse a blank name or one with a slash, which no call could reach.
This commit is contained in:
mrfelek authored and GitHub committed 2026-11-17 05:52:13 -04:00
1 parent c2401d7e06
commit b2f550e6be
6 files changed
+467 -65

No files matched your search

@@ -0,0 +1,247 @@
package io.floci.aws.services.s3vectors;
import io.floci.aws.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.List;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
/**
* Every S3 Vectors call that names a vector bucket takes its {@code vectorBucketName} or its {@code vectorBucketArn},
* and every call that names an index takes its bucket's name and its {@code indexName}, or its {@code indexArn}, as
* AWS does. A request that gives neither, or mixes them, is refused with the message AWS gives (measured on AWS).
*/
@QuarkusTest
class S3VectorsArnAddressingIntegrationTest {
private static final String BUCKET_CHOICE = "Must specify either vectorBucketName or vectorBucketArn but not both";
private static final String INDEX_CHOICE = "Must specify either indexArn or both vectorBucketName and indexName";
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
void aVectorBucketIsReadListedAndDeletedByItsArn() {
String bucket = bucketName();
String arn = post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200)
.extract().path("vectorBucketArn");
post("/GetVectorBucket", byBucketArn(arn)).statusCode(200)
.body("vectorBucket.vectorBucketName", equalTo(bucket))
.body("vectorBucket.vectorBucketArn", equalTo(arn));
post("/CreateIndex", "{\"vectorBucketArn\":\"" + arn + "\",\"indexName\":\"events\",\"dataType\":\"float32\","
+ "\"dimension\":2,\"distanceMetric\":\"cosine\"}").statusCode(200)
.body("indexArn", equalTo(arn + "/index/events"));
post("/ListIndexes", byBucketArn(arn)).statusCode(200)
.body("indexes.indexName", equalTo(List.of("events")));
post("/DeleteIndex", "{\"indexArn\":\"" + arn + "/index/events\"}").statusCode(200);
post("/DeleteVectorBucket", byBucketArn(arn)).statusCode(200);
post("/GetVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(404)
.body("__type", equalTo("NotFoundException"));
}
@Test
void anIndexIsReadAndItsVectorsWrittenQueriedAndDeletedByItsArn() {
String bucket = bucketName();
post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200);
String index = post("/CreateIndex", "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"events\","
+ "\"dataType\":\"float32\",\"dimension\":2,\"distanceMetric\":\"cosine\"}").statusCode(200)
.extract().path("indexArn");
try {
post("/GetIndex", byIndexArn(index)).statusCode(200)
.body("index.indexName", equalTo("events"))
.body("index.vectorBucketName", equalTo(bucket));
post("/PutVectors", "{\"indexArn\":\"" + index + "\",\"vectors\":[{\"key\":\"v1\","
+ "\"data\":{\"float32\":[1.0,0.0]}}]}").statusCode(200);
post("/GetVectors", "{\"indexArn\":\"" + index + "\",\"keys\":[\"v1\"]}").statusCode(200)
.body("vectors.key", equalTo(List.of("v1")));
post("/QueryVectors", "{\"indexArn\":\"" + index + "\",\"topK\":1,"
+ "\"queryVector\":{\"float32\":[1.0,0.0]}}").statusCode(200)
.body("vectors", hasSize(1))
.body("distanceMetric", equalTo("cosine"));
post("/DeleteVectors", "{\"indexArn\":\"" + index + "\",\"keys\":[\"v1\"]}").statusCode(200);
post("/GetVectors", "{\"indexArn\":\"" + index + "\",\"keys\":[\"v1\"]}").statusCode(200)
.body("vectors", hasSize(0));
} finally {
post("/DeleteIndex", "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"events\"}").statusCode(200);
post("/DeleteVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200);
}
}
@ParameterizedTest
@ValueSource(strings = {"/GetVectorBucket", "/DeleteVectorBucket", "/ListIndexes", "/CreateIndex"})
void aBucketCallGivingNeitherOrBothIsRefused(String path) {
String bucket = bucketName();
String arn = "arn:aws:s3vectors:us-east-1:000000000000:bucket/" + bucket;
refused(post(path, "{}"), BUCKET_CHOICE);
refused(post(path, "{\"vectorBucketName\":\"" + bucket + "\",\"vectorBucketArn\":\"" + arn + "\"}"),
BUCKET_CHOICE);
}
@ParameterizedTest
@ValueSource(strings = {"/GetIndex", "/DeleteIndex", "/PutVectors", "/GetVectors", "/DeleteVectors", "/QueryVectors",
"/ListVectors"})
void anIndexCallGivingNeitherOrMixingThemIsRefused(String path) {
String bucket = bucketName();
String index = "arn:aws:s3vectors:us-east-1:000000000000:bucket/" + bucket + "/index/events";
refused(post(path, "{\"keys\":[\"v1\"]}"), INDEX_CHOICE);
refused(post(path, "{\"vectorBucketName\":\"" + bucket + "\",\"keys\":[\"v1\"]}"), INDEX_CHOICE);
refused(post(path, "{\"indexName\":\"events\",\"indexArn\":\"" + index + "\",\"keys\":[\"v1\"]}"),
INDEX_CHOICE);
}
/** An index ARN is checked as a bucket ARN is: it names a Region and an account, of the Region's partition. */
@ParameterizedTest
@ValueSource(strings = {"arn:aws:s3vectors:us-east-1::bucket/vectors/index/events",
"arn:aws-cn:s3vectors:us-east-1:000000000000:bucket/vectors/index/events"})
void aMalformedIndexArnIsRefused(String arn) {
refused(post("/GetIndex", byIndexArn(arn)), "Invalid S3 Vectors ARN: " + arn);
refused(post("/ListVectors", byIndexArn(arn)), "Invalid S3 Vectors ARN: " + arn);
}
/**
* 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.
*/
@Test
void aBucketAndAnIndexAreReachedByTheNamesAndArnsTheyWereGiven() {
String bucket = "Arn_" + UUID.randomUUID().toString().substring(0, 8);
String arn = post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200)
.extract().path("vectorBucketArn");
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);
} finally {
post("/DeleteIndex", "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"My_Index\"}");
post("/DeleteVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200);
}
}
/**
* An ARN of another account is refused with an AccessDeniedException that carries no message, as S3 Vectors does
* (measured on AWS), even when the caller has a bucket and an index of those names.
*/
@Test
void anArnOfAnotherAccountIsRefused() {
String bucket = bucketName();
post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200);
post("/CreateIndex", "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"events\","
+ "\"dataType\":\"float32\",\"dimension\":2,\"distanceMetric\":\"cosine\"}").statusCode(200);
String other = "arn:aws:s3vectors:us-east-1:111122223333:bucket/" + bucket;
try {
for (ValidatableResponse response : List.of(post("/GetVectorBucket", byBucketArn(other)),
post("/ListIndexes", byBucketArn(other)), post("/GetIndex", byIndexArn(other + "/index/events")))) {
response.statusCode(403).body("__type", equalTo("AccessDeniedException")).body("message", equalTo(""));
}
} finally {
post("/DeleteIndex", "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"events\"}").statusCode(200);
post("/DeleteVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200);
}
}
/**
* 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.
*/
@Test
void aBucketNameNoCallCouldReachIsRefusedOnCreate() {
refused(post("/CreateVectorBucket", "{\"vectorBucketName\":\"\"}"), "1 validation error detected. "
+ "Value with length 0 at '/vectorBucketName' failed to satisfy constraint: "
+ "Member must have length between 3 and 63, inclusive");
for (String name : List.of("a/b", " ", bucketName() + "/index/events")) {
refused(post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + name + "\"}"), "Invalid vector bucket name");
post("/ListVectorBuckets", "{}").statusCode(200).body("vectorBuckets.vectorBucketName", not(hasItem(name)));
}
}
/**
* An index name no call could reach the index by is refused before the bucket is looked for, as S3 Vectors does
* (measured on AWS for a slash), and nothing is left that would keep its bucket from being deleted.
*/
@Test
void anIndexNameNoCallCouldReachIsRefusedOnCreate() {
refused(post("/CreateIndex", index(bucketName(), "a/b")), "Invalid index name");
String bucket = bucketName();
post("/CreateVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200);
try {
refused(post("/CreateIndex", index(bucket, "a/b")), "Invalid index name");
refused(post("/CreateIndex", index(bucket, " ")), "Invalid index name");
refused(post("/CreateIndex", index(bucket, "")), "1 validation error detected. "
+ "Value with length 0 at '/indexName' failed to satisfy constraint: "
+ "Member must have length between 3 and 63, inclusive");
post("/ListIndexes", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200)
.body("indexes", hasSize(0));
} finally {
post("/DeleteVectorBucket", "{\"vectorBucketName\":\"" + bucket + "\"}").statusCode(200);
}
}
/**
* An ARN of another Region than the request's, or of another partition, is refused as S3 Vectors refuses it
* (measured on AWS), by calls of each kind that take one (bucket, index, ListVectors and policy), the partition
* checked first.
*/
@ParameterizedTest
@ValueSource(strings = {"/GetVectorBucket", "/DeleteVectorBucket", "/ListIndexes", "/GetIndex", "/DeleteIndex",
"/ListVectors", "/GetVectorBucketPolicy"})
void anArnOfAnotherRegionOrPartitionIsRefused(String path) {
boolean byIndex = List.of("/GetIndex", "/DeleteIndex", "/ListVectors").contains(path);
String bucket = bucketName();
String west = "arn:aws:s3vectors:us-west-2:000000000000:bucket/" + bucket;
String china = "arn:aws-cn:s3vectors:cn-north-1:000000000000:bucket/" + bucket;
refused(post(path, byIndex ? byIndexArn(west + "/index/events") : byBucketArn(west)),
"Unexpected value for ARN region component");
refused(post(path, byIndex ? byIndexArn(china + "/index/events") : byBucketArn(china)),
"Unexpected value for ARN partition component");
}
private static String index(String bucket, String index) {
return "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"" + index + "\",\"dataType\":\"float32\","
+ "\"dimension\":2,\"distanceMetric\":\"cosine\"}";
}
private static String bucketName() {
return "arn-" + UUID.randomUUID().toString().substring(0, 8);
}
private static String byBucketArn(String arn) {
return "{\"vectorBucketArn\":\"" + arn + "\"}";
}
private static String byIndexArn(String arn) {
return "{\"indexArn\":\"" + arn + "\"}";
}
private static ValidatableResponse post(String path, String body) {
return given().contentType("application/json").body(body).when().post(path).then();
}
private static void refused(ValidatableResponse response, String message) {
response.statusCode(400).body("__type", equalTo("ValidationException")).body("message", equalTo(message));
}
}
@@ -653,7 +653,7 @@ class S3VectorsIntegrationTest {
@Test
@Order(18)
void listVectorsByIndexArnResolvesTheArnsOwnRegionNotTheRequestRegion() {
void listVectorsByIndexArnIsRefusedOutsideTheRequestsRegion() {
String bucketName = "cross-region-vector-bucket";
String indexName = "cross-region-idx";
String otherRegionAuth = "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-west-2/s3vectors/aws4_request";
@@ -705,9 +705,8 @@ class S3VectorsIntegrationTest {
.then()
.statusCode(200);
// No Authorization header here, so this request resolves to the default region — not
// us-west-2. The lookup must still succeed because it honors the region encoded in the
// ARN itself, not the region the ListVectors request happens to be signed for.
// No Authorization header here, so this request resolves to the default region, not us-west-2. S3 Vectors
// refuses an ARN of another Region than the request's (measured on AWS).
given()
.contentType(JSON_CONTENT_TYPE)
.body("""
@@ -715,6 +714,20 @@ class S3VectorsIntegrationTest {
""".formatted(indexArn))
.when()
.post("/ListVectors")
.then()
.statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("Unexpected value for ARN region component"));
// Signed for the ARN's Region, it lists the index's vectors.
given()
.contentType(JSON_CONTENT_TYPE)
.header("Authorization", otherRegionAuth)
.body("""
{ "indexArn": "%s" }
""".formatted(indexArn))
.when()
.post("/ListVectors")
.then()
.statusCode(200)
.body("vectors", hasSize(1))
@@ -167,28 +167,40 @@ class S3VectorsServiceTest {
service.deleteVectorBucketPolicy("bucket", null, REGION);
}
/**
* The policy calls take a bucket ARN of the request's Region and refuse one of another Region or partition, as S3
* Vectors does (measured on AWS), leaving that bucket's policy alone.
*/
@Test
void vectorBucketPolicyByArnResolvesTheArnsOwnRegion() {
void vectorBucketPolicyByArnIsTakenOnlyInTheRequestsRegion() {
VectorBucket westBucket = service.createVectorBucket("west-bucket", null, "us-west-2");
String policy = "{\"Version\":\"2012-10-17\",\"Statement\":[]}";
String westArn = westBucket.getVectorBucketArn();
service.putVectorBucketPolicy(null, westBucket.getVectorBucketArn(), policy, REGION);
assertEquals(policy, service.getVectorBucketPolicy(null, westBucket.getVectorBucketArn(), REGION));
assertEquals(policy, service.getVectorBucketPolicy("west-bucket", null, "us-west-2"));
for (Runnable call : List.<Runnable>of(() -> service.putVectorBucketPolicy(null, westArn, policy, REGION),
() -> service.getVectorBucketPolicy(null, westArn, REGION),
() -> service.deleteVectorBucketPolicy(null, westArn, REGION))) {
AwsException refused = assertThrows(AwsException.class, call::run);
assertEquals("ValidationException", refused.getErrorCode());
assertEquals("Unexpected value for ARN region component", refused.getMessage());
}
assertEquals("NotFoundException", assertThrows(AwsException.class,
() -> service.getVectorBucketPolicy("west-bucket", null, "us-west-2")).getErrorCode());
service.deleteVectorBucketPolicy(null, westBucket.getVectorBucketArn(), REGION);
AwsException notFound = assertThrows(AwsException.class,
() -> service.getVectorBucketPolicy("west-bucket", null, "us-west-2"));
assertEquals("NotFoundException", notFound.getErrorCode());
service.putVectorBucketPolicy(null, westArn, policy, "us-west-2");
assertEquals(policy, service.getVectorBucketPolicy(null, westArn, "us-west-2"));
// Custom region in a non-commercial deployment stays in the deployment's partition.
// A custom Region of a non-commercial deployment is in the deployment's partition: its ARN is taken in that
// Region, and a commercial Region's ARN is of another partition.
S3VectorsService chinaService = new S3VectorsService(inMemoryFactory(),
new RegionResolver("cn-north-1", "000000000000"),
Clock.fixed(CREATION_TIME, ZoneOffset.UTC));
VectorBucket customRegionBucket = chinaService.createVectorBucket("custom-bucket", null, "custom-region-1");
assertTrue(customRegionBucket.getVectorBucketArn().startsWith("arn:aws-cn:s3vectors:custom-region-1:"));
chinaService.putVectorBucketPolicy(null, customRegionBucket.getVectorBucketArn(), policy, "cn-north-1");
chinaService.putVectorBucketPolicy(null, customRegionBucket.getVectorBucketArn(), policy, "custom-region-1");
assertEquals(policy, chinaService.getVectorBucketPolicy("custom-bucket", null, "custom-region-1"));
assertEquals("Unexpected value for ARN partition component", assertThrows(AwsException.class,
() -> chinaService.getVectorBucketPolicy(null, westArn, "cn-north-1")).getMessage());
}
@Test
@@ -198,16 +210,20 @@ class S3VectorsServiceTest {
String validPolicy = "{\"Version\":\"2012-10-17\",\"Statement\":[]}";
service.putVectorBucketPolicy("bucket", null, validPolicy, REGION);
// Missing bucket or foreign-account ARN returns NotFoundException (404) and leaves local bucket untouched.
String foreignAccountArn = "arn:aws:s3vectors:us-east-1:111122223333:bucket/bucket";
// A missing bucket returns NotFoundException (404), and another account's ARN AccessDeniedException (403), as
// S3 Vectors answers it (measured on AWS); either leaves the local bucket untouched.
for (Runnable action : List.<Runnable>of(
() -> service.putVectorBucketPolicy("missing", null, validPolicy, REGION),
() -> service.getVectorBucketPolicy("missing", null, REGION),
() -> service.deleteVectorBucketPolicy("missing", null, REGION),
() -> service.deleteVectorBucketPolicy("missing", null, REGION))) {
assertRejected("NotFoundException", 404, validPolicy, action);
}
String foreignAccountArn = "arn:aws:s3vectors:us-east-1:111122223333:bucket/bucket";
for (Runnable action : List.<Runnable>of(
() -> service.putVectorBucketPolicy(null, foreignAccountArn, "{\"Statement\":[]}", REGION),
() -> service.getVectorBucketPolicy(null, foreignAccountArn, REGION),
() -> service.deleteVectorBucketPolicy(null, foreignAccountArn, REGION))) {
assertRejected("NotFoundException", 404, validPolicy, action);
assertRejected("AccessDeniedException", 403, validPolicy, action);
}
// Neither, both, or invalid bucket names return ValidationException (400).