test(iam): fold the SCP and presigned POST enforcement profiles into the shared ones (#5725)

ScpEnforcementLeaveOrganizationIntegrationTest declared a profile that turned on IAM and SCP enforcement, and DynamoDbTransactionPolicyBoundaryIntegrationTest shared it. Both now use IamEnforcementProfile, which gains SCP enforcement. The flag is inert for that profile's other 45 classes. An SCP applies only to a member account of an organization whose root has SCPs enabled, the management account is exempt, as the Organizations user guide says, and none of those classes creates an organization. For an account outside one, the SCP lookup returns no ceiling, so the IAM enforcement filter and the Step Functions Lambda task authorizer, its only callers, decide exactly as before.

S3PresignedPostAuthEnforcementIntegrationTest declared S3 and IAM enforcement on its own; #4249 kept it apart from S3IamEnforcementProfile only because that profile also turns on the global bucket namespace. The namespace changes how a bucket name resolves for a caller in another account, and every bucket the class creates is reached only from the account that owns it, so it moves onto the shared profile.

Both shared profiles' javadoc now lists each override, the classes that rely on it, found by running each profile's classes with that override off, and why it is inert for the rest. The assumption each retired profile encoded moves into the javadoc of the classes that used it.

Sharing an application means each class has to delete what it creates. ScpEnforcementLeaveOrganizationIntegrationTest left its organization, OU, SCP and member account behind under the default account 000000000000. It now registers each removal with PartitionCleanup as it creates them, so DeleteOrganization runs last, once the OU and the member are gone, as it requires. S3PresignedPostAuthEnforcementIntegrationTest creates its five IAM users through EnforcementFixtures.createUser, which replaces a private copy of it and removes each user with its key and policies after the test. It registers removeBucket for the buckets three of its tests create, and removes the bucket its ordered tests share in a final cleanup test, the way the ordered Lambda suites do. With S3 auth enforcement on, S3 verifies every header signature, so the fixed Authorization header removeBucket sends is refused there; it gains an overload that signs each request with S3RequestSigner instead, sharing the existing body.

Part of #4542.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-15 22:14:28 -05:00
1 parent b58d181a30
commit 007744b925
6 files changed
+160 -78

No files matched your search

@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.iam;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.testing.IamEnforcementProfile;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.common.http.TestHTTPResource;
@@ -30,8 +31,16 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertAll;
/**
* The boundaries of IAM authorization for DynamoDB transaction items: the caller's account and
* region, foreign ARNs, session policies, service control policies and request shape checks.
*
* <p>{@code scpDeniesUnderlyingItemActionForMemberRootAndUser} relies on the SCP enforcement that
* {@link IamEnforcementProfile} turns on next to IAM enforcement, and removes the organization it
* creates once it ends.
*/
@QuarkusTest
@TestProfile(ScpEnforcementLeaveOrganizationIntegrationTest.ScpEnforcementProfile.class)
@TestProfile(IamEnforcementProfile.class)
class DynamoDbTransactionPolicyBoundaryIntegrationTest {
@RegisterExtension
@@ -1,15 +1,18 @@
package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.testing.IamEnforcementProfile;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.restassured.config.EncoderConfig;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.util.Map;
import java.net.URI;
import java.util.UUID;
import static io.restassured.RestAssured.config;
@@ -26,9 +29,13 @@ import static org.hamcrest.Matchers.containsString;
* stop the member from leaving. This test drives the full Organizations control plane over HTTP
* (management sets up org + OU + deny-SCP + member) and asserts that the member's
* {@code LeaveOrganization} is denied with 403 while a non-denied action still succeeds.</p>
*
* <p>SCP enforcement comes from {@link IamEnforcementProfile}, which this class shares with the
* other IAM enforcement tests, so it removes the organization, OU, SCP and member account it
* builds once the test ends.</p>
*/
@QuarkusTest
@TestProfile(ScpEnforcementLeaveOrganizationIntegrationTest.ScpEnforcementProfile.class)
@TestProfile(IamEnforcementProfile.class)
class ScpEnforcementLeaveOrganizationIntegrationTest {
private static final String MGMT = "000000000000";
@@ -38,12 +45,19 @@ class ScpEnforcementLeaveOrganizationIntegrationTest {
{"Sid":"DenyLeaveOrg","Effect":"Deny",
"Action":"organizations:LeaveOrganization","Resource":"*"}]}""";
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
@TestHTTPResource
URI endpoint;
@Test
void scpDeniesMemberLeaveOrganizationButAllowsOtherActions() {
String suffix = UUID.randomUUID().toString().substring(0, 8);
// --- management sets up the organization -----------------------------------------------
org(MGMT, "CreateOrganization", "{\"FeatureSet\":\"ALL\"}").then().statusCode(200);
cleanup.register(() -> org(MGMT, "DeleteOrganization", "{}").then().statusCode(200));
// A new root has no policy types enabled; SCPs only participate once EnablePolicyType
// turns them on. FullAWSAccess is already attached, so enabling them denies nothing alone.
@@ -57,19 +71,28 @@ class ScpEnforcementLeaveOrganizationIntegrationTest {
+ "\"Description\":\"deny leave org\",\"Content\":"
+ jsonString(DENY_LEAVE_ORG_SCP) + "}").asString())
.getString("Policy.PolicySummary.Id");
cleanup.register(() -> org(MGMT, "DeletePolicy", "{\"PolicyId\":\"" + policyId + "\"}")
.then().statusCode(200));
String ouId = JsonPath.from(org(MGMT, "CreateOrganizationalUnit",
"{\"ParentId\":\"" + rootId + "\",\"Name\":\"Denied-" + suffix + "\"}").asString())
.getString("OrganizationalUnit.Id");
cleanup.register(() -> org(MGMT, "DeleteOrganizationalUnit",
"{\"OrganizationalUnitId\":\"" + ouId + "\"}").then().statusCode(200));
org(MGMT, "AttachPolicy",
"{\"PolicyId\":\"" + policyId + "\",\"TargetId\":\"" + ouId + "\"}")
.then().statusCode(200);
cleanup.register(() -> org(MGMT, "DetachPolicy",
"{\"PolicyId\":\"" + policyId + "\",\"TargetId\":\"" + ouId + "\"}")
.then().statusCode(200));
// CreateAccount is synchronous in floci: the account id is present on the returned status.
String memberId = JsonPath.from(org(MGMT, "CreateAccount",
"{\"AccountName\":\"member-" + suffix + "\",\"Email\":\"member-" + suffix + "@floci.test\"}")
.asString()).getString("CreateAccountStatus.AccountId");
cleanup.register(() -> org(MGMT, "RemoveAccountFromOrganization",
"{\"AccountId\":\"" + memberId + "\"}").then().statusCode(200));
org(MGMT, "MoveAccount",
"{\"AccountId\":\"" + memberId + "\",\"SourceParentId\":\"" + rootId
@@ -103,8 +126,9 @@ class ScpEnforcementLeaveOrganizationIntegrationTest {
.body(containsString("AccessDeniedException"));
}
private static Response org(String account, String action, String body) {
private Response org(String account, String action, String body) {
return given()
.port(endpoint.getPort())
.config(config().encoderConfig(EncoderConfig.encoderConfig()
.encodeContentTypeAs("application/x-amz-json-1.1", ContentType.JSON)))
.header("Authorization", auth(account))
@@ -136,13 +160,4 @@ class ScpEnforcementLeaveOrganizationIntegrationTest {
}
return sb.append('"').toString();
}
public static final class ScpEnforcementProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
"floci.services.iam.enforcement-enabled", "true",
"floci.services.organizations.scp-enforcement-enabled", "true");
}
}
}
@@ -1,23 +1,29 @@
package io.github.hectorvent.floci.services.s3;
import io.github.hectorvent.floci.testing.EnforcementFixtures.UserCredentials;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.github.hectorvent.floci.testing.S3IamEnforcementProfile;
import io.github.hectorvent.floci.testutil.S3RequestSigner;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.RegisterExtension;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Base64;
import java.util.Map;
import static io.github.hectorvent.floci.testing.EnforcementFixtures.createUser;
import static io.github.hectorvent.floci.testing.EnforcementFixtures.removeBucket;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
@@ -26,27 +32,27 @@ import static org.hamcrest.Matchers.notNullValue;
* Regression coverage for presigned POST (browser-form multipart upload) rejecting fabricated
* or absent credentials once {@code floci.services.s3.enforce-auth} is enabled: see the fix in
* {@code S3Controller#validatePresignedPostAuth}.
*
* <p>It runs on {@link S3IamEnforcementProfile}, whose global bucket namespace is inert here: every
* bucket the class creates is reached only from the account that owns it.
*/
@QuarkusTest
@TestProfile(S3PresignedPostAuthEnforcementIntegrationTest.S3AuthProfile.class)
@TestProfile(S3IamEnforcementProfile.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class S3PresignedPostAuthEnforcementIntegrationTest {
public static final class S3AuthProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
"floci.services.s3.enforce-auth", "true",
"floci.services.iam.enforcement-enabled", "true");
}
}
private static final String BUCKET = "presigned-post-auth-bucket";
private static final String LEGACY_ACCESS_KEY_ID = "test";
private static final String LEGACY_SECRET_KEY = "test";
// Matches the "20260101" date embedded in every credential scope built by this test class.
private static final String AMZ_DATE = "20260101T000000Z";
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
@TestHTTPResource
URI endpoint;
@Test
@Order(1)
void createBucket() {
@@ -339,9 +345,9 @@ class S3PresignedPostAuthEnforcementIntegrationTest {
void rejectsGenuineSignatureWhenIdentityPolicyDeniesPutObject() {
String key = "uploads/iam-denied.txt";
String userName = "presigned-post-denied-user";
String[] credentials = createUserAndAccessKey(userName);
String accessKeyId = credentials[0];
String secretKey = credentials[1];
UserCredentials credentials = createUser(cleanup, endpoint.getPort(), IAM_ROOT_AUTH, userName);
String accessKeyId = credentials.accessKeyId();
String secretKey = credentials.secretAccessKey();
putUserPolicy(userName, "DenyPutObject", """
{"Version":"2012-10-17","Statement":[
{"Effect":"Deny","Action":"s3:PutObject","Resource":"*"}
@@ -373,9 +379,9 @@ class S3PresignedPostAuthEnforcementIntegrationTest {
String key = "uploads/iam-allowed.txt";
String fileContent = "uploaded by a permitted IAM user";
String userName = "presigned-post-allowed-user";
String[] credentials = createUserAndAccessKey(userName);
String accessKeyId = credentials[0];
String secretKey = credentials[1];
UserCredentials credentials = createUser(cleanup, endpoint.getPort(), IAM_ROOT_AUTH, userName);
String accessKeyId = credentials.accessKeyId();
String secretKey = credentials.secretAccessKey();
putUserPolicy(userName, "AllowPutObject", """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"s3:PutObject","Resource":"arn:aws:s3:::%1$s/*"}
@@ -407,9 +413,9 @@ class S3PresignedPostAuthEnforcementIntegrationTest {
String key = "uploads/bucket-policy-only.txt";
String fileContent = "uploaded under a bucket-policy-only grant";
String userName = "presigned-post-bucket-policy-user";
String[] credentials = createUserAndAccessKey(userName);
String accessKeyId = credentials[0];
String secretKey = credentials[1];
UserCredentials credentials = createUser(cleanup, endpoint.getPort(), IAM_ROOT_AUTH, userName);
String accessKeyId = credentials.accessKeyId();
String secretKey = credentials.secretAccessKey();
createBucket(bucket);
putBucketPolicy(bucket, """
@@ -446,9 +452,9 @@ class S3PresignedPostAuthEnforcementIntegrationTest {
String bucket = "presigned-post-bucket-policy-deny-bucket";
String key = "uploads/bucket-policy-denied.txt";
String userName = "presigned-post-bucket-policy-denied-user";
String[] credentials = createUserAndAccessKey(userName);
String accessKeyId = credentials[0];
String secretKey = credentials[1];
UserCredentials credentials = createUser(cleanup, endpoint.getPort(), IAM_ROOT_AUTH, userName);
String accessKeyId = credentials.accessKeyId();
String secretKey = credentials.secretAccessKey();
putUserPolicy(userName, "AllowPutObject", """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"s3:PutObject","Resource":"*"}
@@ -497,9 +503,9 @@ class S3PresignedPostAuthEnforcementIntegrationTest {
String bucket = "presigned-post-tag-condition-bucket";
String key = "uploads/tag-condition.txt";
String userName = "presigned-post-tag-condition-user";
String[] credentials = createUserAndAccessKey(userName);
String accessKeyId = credentials[0];
String secretKey = credentials[1];
UserCredentials credentials = createUser(cleanup, endpoint.getPort(), IAM_ROOT_AUTH, userName);
String accessKeyId = credentials.accessKeyId();
String secretKey = credentials.secretAccessKey();
createBucket(bucket);
putBucketPolicy(bucket, """
@@ -532,7 +538,18 @@ class S3PresignedPostAuthEnforcementIntegrationTest {
.body("Error.Code", equalTo("AccessDenied"));
}
private static void createBucket(String bucket) {
/** Removes {@link #BUCKET}, which the tests from {@code createBucket} on share, with the objects they uploaded. */
@Test
@Order(99)
void cleanup_removeTheSharedBucket() {
removeBucket(endpoint.getPort(), S3RequestSigner.signedAs(LEGACY_ACCESS_KEY_ID, LEGACY_SECRET_KEY),
BUCKET);
}
/** Creates {@code bucket} as the account root, having first registered its removal. */
private void createBucket(String bucket) {
cleanup.register(() -> removeBucket(endpoint.getPort(),
S3RequestSigner.signedAs(LEGACY_ACCESS_KEY_ID, LEGACY_SECRET_KEY), bucket));
given()
.filter(S3RequestSigner.signedAs(LEGACY_ACCESS_KEY_ID, LEGACY_SECRET_KEY))
.when()
@@ -556,33 +573,6 @@ class S3PresignedPostAuthEnforcementIntegrationTest {
"AWS4-HMAC-SHA256 Credential=" + LEGACY_ACCESS_KEY_ID + "/20260101/us-east-1/iam/aws4_request"
+ ", SignedHeaders=host, Signature=abc";
/** Returns {accessKeyId, secretAccessKey} for a freshly created IAM user. */
private static String[] createUserAndAccessKey(String userName) {
given()
.formParam("Action", "CreateUser")
.formParam("UserName", userName)
.header("Authorization", IAM_ROOT_AUTH)
.when()
.post("/")
.then()
.statusCode(200);
io.restassured.response.ExtractableResponse<io.restassured.response.Response> response = given()
.formParam("Action", "CreateAccessKey")
.formParam("UserName", userName)
.header("Authorization", IAM_ROOT_AUTH)
.when()
.post("/")
.then()
.statusCode(200)
.extract();
return new String[] {
response.path("CreateAccessKeyResponse.CreateAccessKeyResult.AccessKey.AccessKeyId"),
response.path("CreateAccessKeyResponse.CreateAccessKeyResult.AccessKey.SecretAccessKey")
};
}
private static void putUserPolicy(String userName, String policyName, String policyDocument) {
given()
.formParam("Action", "PutUserPolicy")
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.testing;
import io.restassured.filter.Filter;
import io.restassured.path.xml.XmlPath;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
@@ -8,6 +9,7 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import static io.restassured.RestAssured.given;
@@ -221,13 +223,29 @@ public final class EnforcementFixtures {
* delete object versions, and delete the bucket
*/
public static void removeBucket(int port, String authorization, String bucket) {
if (s3(port, authorization).when().head("/" + bucket)
removeBucket(() -> s3(port, authorization), bucket);
}
/**
* {@link #removeBucket(int, String, String)} under a profile that turns on
* {@code floci.services.s3.enforce-auth}, where S3 verifies every header signature and a
* fixed {@code Authorization} header is refused. Each request is signed by {@code signer}.
*
* @param signer a request signer, such as {@code S3RequestSigner}, for an identity allowed to
* list bucket versions, delete object versions, and delete the bucket
*/
public static void removeBucket(int port, Filter signer, String bucket) {
removeBucket(() -> given().port(port).filter(signer), bucket);
}
private static void removeBucket(Supplier<RequestSpecification> s3, String bucket) {
if (s3.get().when().head("/" + bucket)
.then().extract().statusCode() == 404) {
return;
}
List<ObjectVersion> previousPage = List.of();
while (true) {
XmlPath listing = s3(port, authorization).queryParam("versions", "")
XmlPath listing = s3.get().queryParam("versions", "")
.queryParam("max-keys", 10)
.when().get("/" + bucket)
.then().statusCode(200).extract().xmlPath();
@@ -243,14 +261,14 @@ public final class EnforcementFixtures {
for (ObjectVersion version : page) {
String encodedKey = URLEncoder.encode(version.key(), StandardCharsets.UTF_8)
.replace("+", "%20").replace("%2F", "/");
s3(port, authorization).urlEncodingEnabled(false)
s3.get().urlEncodingEnabled(false)
.queryParam("versionId", version.versionId())
.when().delete("/" + bucket + "/" + encodedKey)
.then().statusCode(204);
}
previousPage = page;
}
s3(port, authorization).when().delete("/" + bucket).then().statusCode(204);
s3.get().when().delete("/" + bucket).then().statusCode(204);
}
/**
@@ -5,14 +5,34 @@ import io.quarkus.test.junit.QuarkusTestProfile;
import java.util.Map;
/**
* Turns IAM enforcement on, and nothing else. Quarkus restarts and re-augments the application
* once per distinct profile class, so the classes that need only this override share this one
* rather than each declaring an identical nested profile.
* IAM policy enforcement, with service control policy enforcement next to it, for the classes
* that test what an IAM identity may do. Quarkus builds the application once per distinct
* profile class, so they share this one rather than each declaring their own.
*
* <p>The overrides, and who relies on them:
* <ul>
* <li>{@code floci.services.iam.enforcement-enabled=true} evaluates every request against the
* caller's IAM policies. Every class here asserts a decision it makes, except
* {@code EnforcementFixturesIntegrationTest} and {@code StsPresignedIdentityIntegrationTest},
* which pass with it off.</li>
* <li>{@code floci.services.organizations.scp-enforcement-enabled=true} caps a member account's
* permissions with the SCPs its organization attaches.
* {@code ScpEnforcementLeaveOrganizationIntegrationTest} and
* {@code DynamoDbTransactionPolicyBoundaryIntegrationTest} rely on it: each creates an
* organization, enables SCPs on its root and attaches a deny that reaches a member account.</li>
* </ul>
*
* <p>SCP enforcement is inert for every other class. An SCP only applies to a member account of an
* organization whose root has SCPs enabled, and the management account is exempt, as in AWS. No
* other class creates an organization, so the SCP lookup finds no ceiling for any account they use
* and the decision is the one IAM enforcement alone makes.
*/
public class IamEnforcementProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of("floci.services.iam.enforcement-enabled", "true");
return Map.of(
"floci.services.iam.enforcement-enabled", "true",
"floci.services.organizations.scp-enforcement-enabled", "true");
}
}
@@ -6,7 +6,37 @@ import java.util.Map;
/**
* S3 auth enforcement, IAM enforcement and the global bucket namespace together, for the classes
* that need all three. {@link S3EnforceAuthProfile} covers the narrower case.
* that need all three. {@link S3EnforceAuthProfile} covers the narrower case. Quarkus builds the
* application once per distinct profile class, so they share this one rather than each declaring
* their own.
*
* <p>The overrides, and who relies on them:
* <ul>
* <li>{@code floci.services.s3.enforce-auth=true} makes S3 verify every signature and run its own
* access checks, bucket policies among them, beside IAM's.
* {@code S3BucketPolicyEnforcementIntegrationTest},
* {@code S3CopyObjectSourcePermissionIntegrationTest},
* {@code S3DeleteObjectsSignedIamEnforcementIntegrationTest} and
* {@code S3PresignedPostAuthEnforcementIntegrationTest} rely on it.</li>
* <li>{@code floci.services.iam.enforcement-enabled=true} evaluates every request against the
* caller's IAM policies. Every class relies on it except
* {@code ResourcePolicyPrincipalTypeEnforcementIntegrationTest}, whose cross-account caller
* S3's own bucket policy check refuses as well.</li>
* <li>{@code floci.services.s3.global-bucket-namespace=true} resolves a bucket name in the
* account that owns it, whoever calls.
* {@code ResourcePolicyPrincipalTypeEnforcementIntegrationTest},
* {@code S3BucketPolicyEnforcementIntegrationTest},
* {@code S3CopyObjectSourcePermissionIntegrationTest} and
* {@code S3DeleteObjectsSignedIamEnforcementIntegrationTest} call another account's bucket, and
* {@code StsIssuedSessionEnforcementIntegrationTest} reads one anonymously, which Floci serves as
* the default account.</li>
* </ul>
*
* <p>Each override is inert for the classes it does not name, which pass with it off. S3 auth
* enforcement only adds refusals, and every refusal those classes assert comes from IAM as well.
* {@code GeneratedPreSignedUrlAuthEnforcementIntegrationTest} and
* {@code S3PresignedPostAuthEnforcementIntegrationTest} reach each bucket only from the account
* that owns it, so the namespace never comes into play for them.
*/
public class S3IamEnforcementProfile implements QuarkusTestProfile {