fix(s3vectors): check S3 Vectors requests under IAM enforcement (#8518)

Under IAM enforcement no S3 Vectors request was checked: its model was
not among the vendored REST routes and the s3vectors namespace's request
resources were not read, so every call went through. regen_rest_routes.py
now vendors its routes and the request-resources and tag-on-create
generators read the namespace, so a vector bucket call is checked on the
bucket its vectorBucketName or vectorBucketArn names, an index or vector
call on the index its bucket and indexName or its indexArn names, and
ListVectorBuckets on *. Nothing in IAM is written by hand for it.

The IAM tests of REST services (CloudFront, EMR Serverless, S3 Tables,
S3 Vectors) sign and send their requests through one shared
SignedRestRequests helper.
This commit is contained in:
mrfelek authored and GitHub committed 2026-11-15 19:59:56 -04:00
1 parent b0a4cc41cb
commit cf4e1101a9
12 files changed
+252 -60

No files matched your search

@@ -2,20 +2,19 @@ package io.floci.aws.services.cloudfront;
import io.floci.aws.testing.SignedIamEnforcementProfile;
import io.floci.aws.testing.SignedIamUsers;
import io.floci.aws.testing.SignedRestRequests;
import io.floci.aws.testutil.AwsRequestSigner;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static io.floci.aws.testing.SignedRestRequests.denied;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
@@ -139,18 +138,6 @@ class CloudFrontIamIntegrationTest {
private Response send(AwsRequestSigner signer, String method, String path, String body, Map<String, String> headers)
throws Exception {
URI uri = endpoint.resolve(path);
byte[] bytes = body == null ? new byte[0] : body.getBytes(StandardCharsets.UTF_8);
// The signer signs the extra headers but returns only its own, so the request carries both.
RequestSpecification request = given().urlEncodingEnabled(false).headers(headers)
.headers(signer.headersFor(method, uri, headers, bytes));
if (body != null) {
request = request.contentType("application/xml").body(bytes);
}
return request.request(method, uri);
}
private static void denied(Response response, String action) {
response.then().statusCode(403).body(containsString("not authorized to perform: " + action));
return SignedRestRequests.send(endpoint, signer, method, path, body, "application/xml", headers);
}
}
@@ -2,20 +2,18 @@ package io.floci.aws.services.emrserverless;
import io.floci.aws.testing.SignedIamEnforcementProfile;
import io.floci.aws.testing.SignedIamUsers;
import io.floci.aws.testing.SignedRestRequests;
import io.floci.aws.testutil.AwsRequestSigner;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static io.floci.aws.testing.SignedRestRequests.denied;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
@@ -124,17 +122,6 @@ class EmrServerlessIamIntegrationTest {
}
private Response send(AwsRequestSigner signer, String method, String path, String body) throws Exception {
URI uri = endpoint.resolve(path);
byte[] bytes = body == null ? new byte[0] : body.getBytes(StandardCharsets.UTF_8);
RequestSpecification request = given().urlEncodingEnabled(false)
.headers(signer.headersFor(method, uri, Map.of(), bytes));
if (body != null) {
request = request.contentType("application/json").body(bytes);
}
return request.request(method, uri);
}
private static void denied(Response response, String action) {
response.then().statusCode(403).body(containsString("not authorized to perform: " + action));
return SignedRestRequests.send(endpoint, signer, method, path, body, "application/json");
}
}
@@ -3,12 +3,12 @@ package io.floci.aws.services.s3tables;
import io.floci.aws.testing.AwsTestClients;
import io.floci.aws.testing.SignedIamEnforcementProfile;
import io.floci.aws.testing.SignedIamUsers;
import io.floci.aws.testing.SignedRestRequests;
import io.floci.aws.testutil.AwsRequestSigner;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3tables.S3TablesClient;
@@ -18,10 +18,9 @@ import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static io.floci.aws.testing.SignedRestRequests.denied;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
@@ -294,17 +293,6 @@ class S3TablesIamIntegrationTest {
}
private Response send(AwsRequestSigner signer, String method, String path, String body) throws Exception {
URI uri = endpoint.resolve(path);
byte[] bytes = body == null ? new byte[0] : body.getBytes(StandardCharsets.UTF_8);
RequestSpecification request = given().urlEncodingEnabled(false)
.headers(signer.headersFor(method, uri, Map.of(), bytes));
if (body != null) {
request = request.contentType("application/json").body(bytes);
}
return request.request(method, uri);
}
private static void denied(Response response, String action) {
response.then().statusCode(403).body(containsString("not authorized to perform: " + action));
return SignedRestRequests.send(endpoint, signer, method, path, body, "application/json");
}
}
@@ -0,0 +1,130 @@
package io.floci.aws.services.s3vectors;
import io.floci.aws.testing.SignedIamEnforcementProfile;
import io.floci.aws.testing.SignedIamUsers;
import io.floci.aws.testing.SignedRestRequests;
import io.floci.aws.testutil.AwsRequestSigner;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.response.Response;
import org.junit.jupiter.api.Test;
import java.net.URI;
import java.util.UUID;
import static io.floci.aws.testing.SignedRestRequests.denied;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
/**
* S3 Vectors requests are checked against the caller's policies through its generated routes: a vector bucket call
* on the bucket its {@code vectorBucketName} or {@code vectorBucketArn} names, and an index or vector call on the
* index its bucket and {@code indexName}, or its {@code indexArn}, name.
*/
@QuarkusTest
@TestProfile(SignedIamEnforcementProfile.class)
class S3VectorsIamIntegrationTest {
private final AwsRequestSigner admin = AwsRequestSigner.signedAs("test", "test", "s3vectors");
@TestHTTPResource("/")
URI endpoint;
@Test
void callerWithoutPermissionsIsRefusedBeforeAVectorBucketIsCreated() throws Exception {
String name = "iam-none-" + UUID.randomUUID().toString().substring(0, 8);
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3v-iam-")) {
denied(send(user.signer("s3vectors"), "/CreateVectorBucket", "{\"vectorBucketName\":\"" + name + "\"}"),
"s3vectors:CreateVectorBucket");
denied(send(user.signer("s3vectors"), "/ListVectorBuckets", "{}"), "s3vectors:ListVectorBuckets");
}
send(admin, "/ListVectorBuckets", "{}").then().statusCode(200).body(not(containsString(name)));
}
@Test
void aBucketScopedAllowReadsThatBucketByNameOrArnAndRefusesAnother() throws Exception {
String allowed = bucketName();
String other = bucketName();
String allowedArn = createBucket(allowed);
createBucket(other);
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3v-iam-", "access",
allow("[\"s3vectors:GetVectorBucket\",\"s3vectors:GetVectorBucketPolicy\"]", allowedArn))) {
send(user.signer("s3vectors"), "/GetVectorBucket", bucket(allowed)).then().statusCode(200)
.body("vectorBucket.vectorBucketArn", equalTo(allowedArn));
denied(send(user.signer("s3vectors"), "/GetVectorBucket", bucket(other)), "s3vectors:GetVectorBucket");
denied(send(user.signer("s3vectors"), "/DeleteVectorBucket", bucket(allowed)),
"s3vectors:DeleteVectorBucket");
// By its ARN: the call is checked on the bucket the ARN names, and passes the check to answer that
// the bucket has no policy.
send(user.signer("s3vectors"), "/GetVectorBucketPolicy", "{\"vectorBucketArn\":\"" + allowedArn + "\"}")
.then().statusCode(404).body("__type", equalTo("NotFoundException"));
denied(send(user.signer("s3vectors"), "/GetVectorBucketPolicy",
"{\"vectorBucketArn\":\"" + allowedArn.replace(allowed, other) + "\"}"),
"s3vectors:GetVectorBucketPolicy");
} finally {
deleteBucket(allowed);
deleteBucket(other);
}
}
@Test
void anIndexScopedAllowReadsThatIndexByNameOrArnAndRefusesAnother() throws Exception {
String name = bucketName();
createBucket(name);
String events = createIndex(name, "events");
String orders = createIndex(name, "orders");
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3v-iam-", "access",
allow("[\"s3vectors:GetIndex\",\"s3vectors:ListVectors\"]", events))) {
send(user.signer("s3vectors"), "/GetIndex", index(name, "events")).then().statusCode(200)
.body("index.indexArn", equalTo(events));
denied(send(user.signer("s3vectors"), "/GetIndex", index(name, "orders")), "s3vectors:GetIndex");
denied(send(user.signer("s3vectors"), "/DeleteIndex", index(name, "events")), "s3vectors:DeleteIndex");
send(user.signer("s3vectors"), "/ListVectors", "{\"indexArn\":\"" + events + "\"}").then()
.statusCode(200);
denied(send(user.signer("s3vectors"), "/ListVectors", "{\"indexArn\":\"" + orders + "\"}"),
"s3vectors:ListVectors");
} finally {
send(admin, "/DeleteIndex", index(name, "events")).then().statusCode(200);
send(admin, "/DeleteIndex", index(name, "orders")).then().statusCode(200);
deleteBucket(name);
}
}
private static String bucketName() {
return "iam-" + UUID.randomUUID().toString().substring(0, 8);
}
private static String bucket(String name) {
return "{\"vectorBucketName\":\"" + name + "\"}";
}
private static String index(String bucket, String index) {
return "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"" + index + "\"}";
}
private static String allow(String actions, String resource) {
return "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":" + actions
+ ",\"Resource\":\"" + resource + "\"}]}";
}
private String createBucket(String name) throws Exception {
return send(admin, "/CreateVectorBucket", bucket(name)).then().statusCode(200)
.extract().path("vectorBucketArn");
}
private String createIndex(String bucket, String index) throws Exception {
return send(admin, "/CreateIndex", "{\"vectorBucketName\":\"" + bucket + "\",\"indexName\":\"" + index
+ "\",\"dataType\":\"float32\",\"dimension\":2,\"distanceMetric\":\"cosine\"}").then()
.statusCode(200).extract().path("indexArn");
}
private void deleteBucket(String name) throws Exception {
send(admin, "/DeleteVectorBucket", bucket(name)).then().statusCode(200);
}
private Response send(AwsRequestSigner signer, String path, String body) throws Exception {
return SignedRestRequests.send(endpoint, signer, "POST", path, body, "application/json");
}
}
@@ -0,0 +1,47 @@
package io.floci.aws.testing;
import io.floci.aws.testutil.AwsRequestSigner;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
/**
* REST requests signed as a caller and sent to the test's Floci, and the answer IAM gives one whose caller lacks the
* permission, for the IAM tests of a REST service, whose requests are checked on the routes its model gives.
*/
public final class SignedRestRequests {
private SignedRestRequests() {
}
/** Sends {@code body}, none when null, as {@code contentType} to {@code path} under {@code endpoint}. */
public static Response send(URI endpoint, AwsRequestSigner signer, String method, String path, String body,
String contentType) throws Exception {
return send(endpoint, signer, method, path, body, contentType, Map.of());
}
/** As above; with {@code headers} signed and sent beside the signer's own. */
public static Response send(URI endpoint, AwsRequestSigner signer, String method, String path, String body,
String contentType, Map<String, String> headers) throws Exception {
URI uri = endpoint.resolve(path);
byte[] bytes = body == null ? new byte[0] : body.getBytes(StandardCharsets.UTF_8);
// The signer signs the extra headers but returns only its own, so the request carries both.
RequestSpecification request = given().urlEncodingEnabled(false).headers(headers)
.headers(signer.headersFor(method, uri, headers, bytes));
if (body != null) {
request = request.contentType(contentType).body(bytes);
}
return request.request(method, uri);
}
/** IAM refused the request with a 403 naming the action the caller lacks. */
public static void denied(Response response, String action) {
response.then().statusCode(403).body(containsString("not authorized to perform: " + action));
}
}