From b5994e4d9ee2286100c6dda73f185d32fb154aca Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Wed, 18 Nov 2026 09:00:56 -0400 Subject: [PATCH] test: fold four IAM-enforced one-off profiles into two shared ones (#8859) RdsIamEnforcementProfile becomes IamEnforcedServiceSettingsProfile and takes the classes of DsqlEnforcementProfile, of the nested IamEnforcementProfile of LambdaExecutionRoleDockerIntegrationTest and of the GlobalNamespaceIamOnlyProfile of S3PresignedPostBucketPolicyAccountContextIntegrationTest. Each adds one service setting, and no other class there calls the service it changes. The Lambda class's fixed port 4587 becomes a free port chosen when the profile loads. PartnerPermissionBoundaryEnforcementProfile folds into IamEnforcementProfile: the partner registration only reaches a delegation request filed as the partner account, which no other class there files. IamEnforcementProfile's joining rule now asks that settings be inert both ways, as the other shared profiles do. --- .../DsqlClusterPolicyIntegrationTest.java | 3 +- .../services/dsql/DsqlEnforcementProfile.java | 18 ----- ...oleBoundaryEnforcementIntegrationTest.java | 4 +- ...bdaExecutionRoleDockerIntegrationTest.java | 17 +---- .../rds/RdsResourceIamIntegrationTest.java | 4 +- ...etPolicyAccountContextIntegrationTest.java | 15 +--- .../IamEnforcedServiceSettingsProfile.java | 73 +++++++++++++++++++ .../aws/testing/IamEnforcementProfile.java | 24 ++++-- ...rPermissionBoundaryEnforcementProfile.java | 25 ------- .../aws/testing/RdsIamEnforcementProfile.java | 15 ---- 10 files changed, 100 insertions(+), 98 deletions(-) delete mode 100644 src/test/java/io/floci/aws/services/dsql/DsqlEnforcementProfile.java create mode 100644 src/test/java/io/floci/aws/testing/IamEnforcedServiceSettingsProfile.java delete mode 100644 src/test/java/io/floci/aws/testing/PartnerPermissionBoundaryEnforcementProfile.java delete mode 100644 src/test/java/io/floci/aws/testing/RdsIamEnforcementProfile.java diff --git a/src/test/java/io/floci/aws/services/dsql/DsqlClusterPolicyIntegrationTest.java b/src/test/java/io/floci/aws/services/dsql/DsqlClusterPolicyIntegrationTest.java index de32e7a2ba..5a40f5bac8 100644 --- a/src/test/java/io/floci/aws/services/dsql/DsqlClusterPolicyIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/dsql/DsqlClusterPolicyIntegrationTest.java @@ -3,6 +3,7 @@ package io.floci.aws.services.dsql; import com.github.dockerjava.api.DockerClient; import io.floci.aws.services.dsql.dataplane.DsqlEndpoint; import io.floci.aws.testing.EnforcementFixtures; +import io.floci.aws.testing.IamEnforcedServiceSettingsProfile; import io.floci.aws.testing.PartitionCleanup; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; @@ -40,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * the decision to the caller's own policies. */ @QuarkusTest -@TestProfile(DsqlEnforcementProfile.class) +@TestProfile(IamEnforcedServiceSettingsProfile.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) @Tag("docker") class DsqlClusterPolicyIntegrationTest { diff --git a/src/test/java/io/floci/aws/services/dsql/DsqlEnforcementProfile.java b/src/test/java/io/floci/aws/services/dsql/DsqlEnforcementProfile.java deleted file mode 100644 index 69d9a9d0ed..0000000000 --- a/src/test/java/io/floci/aws/services/dsql/DsqlEnforcementProfile.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.floci.aws.services.dsql; - -import io.quarkus.test.junit.QuarkusTestProfile; - -import java.util.Map; - -/** - * Clusters with a real database in Docker, served on an ephemeral port, with IAM enforcement on, - * for what a cluster's policy decides on connect. - */ -public final class DsqlEnforcementProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.services.dsql.mock", "false", - "floci.services.iam.enforcement-enabled", "true"); - } -} diff --git a/src/test/java/io/floci/aws/services/iam/DelegationRoleBoundaryEnforcementIntegrationTest.java b/src/test/java/io/floci/aws/services/iam/DelegationRoleBoundaryEnforcementIntegrationTest.java index 317a1d8f98..1a664cf2c0 100644 --- a/src/test/java/io/floci/aws/services/iam/DelegationRoleBoundaryEnforcementIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/iam/DelegationRoleBoundaryEnforcementIntegrationTest.java @@ -1,7 +1,7 @@ package io.floci.aws.services.iam; import io.floci.aws.core.common.RequestScopes; -import io.floci.aws.testing.PartnerPermissionBoundaryEnforcementProfile; +import io.floci.aws.testing.IamEnforcementProfile; import io.floci.aws.testutil.S3RequestSigner; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; @@ -30,7 +30,7 @@ import static org.hamcrest.Matchers.equalTo; * so the approver's own policy is what authorizes the write and what the condition is read against. */ @QuarkusTest -@TestProfile(PartnerPermissionBoundaryEnforcementProfile.class) +@TestProfile(IamEnforcementProfile.class) class DelegationRoleBoundaryEnforcementIntegrationTest { private static final String CUSTOMER = "222233334444"; diff --git a/src/test/java/io/floci/aws/services/lambda/LambdaExecutionRoleDockerIntegrationTest.java b/src/test/java/io/floci/aws/services/lambda/LambdaExecutionRoleDockerIntegrationTest.java index 46b16a0b87..9e31ab87be 100644 --- a/src/test/java/io/floci/aws/services/lambda/LambdaExecutionRoleDockerIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/lambda/LambdaExecutionRoleDockerIntegrationTest.java @@ -2,9 +2,9 @@ package io.floci.aws.services.lambda; import com.github.dockerjava.api.DockerClient; import io.floci.aws.services.iam.IamService; +import io.floci.aws.testing.IamEnforcedServiceSettingsProfile; import io.floci.aws.testing.LambdaCodeFixtures; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; import io.restassured.response.Response; import jakarta.inject.Inject; @@ -12,7 +12,6 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.Map; import java.util.UUID; import static io.floci.aws.testing.IamTestPolicies.EMPTY_POLICY_DOCUMENT; @@ -22,7 +21,7 @@ import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertNull; @QuarkusTest -@TestProfile(LambdaExecutionRoleDockerIntegrationTest.IamEnforcementProfile.class) +@TestProfile(IamEnforcedServiceSettingsProfile.class) class LambdaExecutionRoleDockerIntegrationTest { private static final String BASE_PATH = "/2015-03-31"; @@ -152,16 +151,4 @@ class LambdaExecutionRoleDockerIntegrationTest { return false; } } - - public static final class IamEnforcementProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.services.iam.enforcement-enabled", "true", - "floci.services.lambda.ephemeral", "true", - "quarkus.http.test-port", "4587", - "floci.port", "4587", - "floci.base-url", "http://localhost:4587"); - } - } } diff --git a/src/test/java/io/floci/aws/services/rds/RdsResourceIamIntegrationTest.java b/src/test/java/io/floci/aws/services/rds/RdsResourceIamIntegrationTest.java index 6b45be55c0..33841e52b5 100644 --- a/src/test/java/io/floci/aws/services/rds/RdsResourceIamIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/rds/RdsResourceIamIntegrationTest.java @@ -4,8 +4,8 @@ import io.floci.aws.core.common.AwsRegions; import io.floci.aws.services.ec2.Ec2Service; import io.floci.aws.testing.AwsTestClients; import io.floci.aws.testing.EnforcementFixtures; +import io.floci.aws.testing.IamEnforcedServiceSettingsProfile; import io.floci.aws.testing.PartitionCleanup; -import io.floci.aws.testing.RdsIamEnforcementProfile; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; import io.restassured.RestAssured; @@ -27,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @QuarkusTest -@TestProfile(RdsIamEnforcementProfile.class) +@TestProfile(IamEnforcedServiceSettingsProfile.class) class RdsResourceIamIntegrationTest { private static final String ACCOUNT = "000000000000"; diff --git a/src/test/java/io/floci/aws/services/s3/S3PresignedPostBucketPolicyAccountContextIntegrationTest.java b/src/test/java/io/floci/aws/services/s3/S3PresignedPostBucketPolicyAccountContextIntegrationTest.java index fdabc985ab..ec87d39cee 100644 --- a/src/test/java/io/floci/aws/services/s3/S3PresignedPostBucketPolicyAccountContextIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/s3/S3PresignedPostBucketPolicyAccountContextIntegrationTest.java @@ -1,8 +1,8 @@ package io.floci.aws.services.s3; import io.floci.aws.core.common.IamEnforcementFilter; +import io.floci.aws.testing.IamEnforcedServiceSettingsProfile; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; import org.junit.jupiter.api.Test; @@ -10,7 +10,6 @@ import java.nio.charset.StandardCharsets; import java.time.Instant; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import java.util.Map; import java.util.UUID; import static io.restassured.RestAssured.given; @@ -31,7 +30,7 @@ import static org.hamcrest.Matchers.equalTo; * scoping. */ @QuarkusTest -@TestProfile(S3PresignedPostBucketPolicyAccountContextIntegrationTest.GlobalNamespaceIamOnlyProfile.class) +@TestProfile(IamEnforcedServiceSettingsProfile.class) class S3PresignedPostBucketPolicyAccountContextIntegrationTest { private static final String REGION = "us-east-1"; @@ -40,16 +39,6 @@ class S3PresignedPostBucketPolicyAccountContextIntegrationTest { private static final DateTimeFormatter AMZ_DATE_FMT = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneOffset.UTC); - public static final class GlobalNamespaceIamOnlyProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.services.iam.enforcement-enabled", "true", - "floci.services.s3.enforce-auth", "false", - "floci.services.s3.global-bucket-namespace", "true"); - } - } - @Test void presignedPostSucceedsForNonDefaultAccountBucketAndSignerWhenOnlyBucketPolicyAllows() { String suffix = UUID.randomUUID().toString().substring(0, 8); diff --git a/src/test/java/io/floci/aws/testing/IamEnforcedServiceSettingsProfile.java b/src/test/java/io/floci/aws/testing/IamEnforcedServiceSettingsProfile.java new file mode 100644 index 0000000000..7fe3091757 --- /dev/null +++ b/src/test/java/io/floci/aws/testing/IamEnforcedServiceSettingsProfile.java @@ -0,0 +1,73 @@ +package io.floci.aws.testing; + +import io.floci.aws.testutil.FreePorts; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.HashMap; +import java.util.Map; + +/** + * IAM and SCP enforcement, with service settings that each reach only the class relying on them, + * for IAM classes whose own settings would reach the classes on {@link IamEnforcementProfile}. + * Quarkus builds the application once per distinct profile class, and keeps every one it built for + * the rest of the test JVM, so they share this one rather than each declaring their own. + * + *

The overrides, and who relies on them: + *

    + *
  • {@link IamEnforcementProfile#enforcementOverrides()} evaluates every request against the + * caller's IAM policies, and caps a member account by the SCPs its organization attaches. Every + * class here asserts a decision IAM enforcement makes. None creates an organization, so the SCP + * lookup finds no ceiling for any account they use.
  • + *
  • {@code floci.services.rds.mock=true} and {@code floci.services.docdb.mock=true} keep RDS and + * DocumentDB from starting database containers. {@code RdsResourceIamIntegrationTest} relies on + * them.
  • + *
  • {@code floci.services.dsql.mock=false} backs each DSQL cluster with a real database in + * Docker, so a connection is let through or refused as the cluster's policy decides. + * {@code DsqlClusterPolicyIntegrationTest} relies on it.
  • + *
  • {@code floci.services.lambda.ephemeral=true} removes a function's container once its + * invocation ends, rather than keeping it warm. {@code LambdaExecutionRoleDockerIntegrationTest} + * relies on it.
  • + *
  • {@code floci.services.s3.global-bucket-namespace=true} resolves a bucket name across + * accounts, so finding the bucket does not depend on the ambient account. + * {@code S3PresignedPostBucketPolicyAccountContextIntegrationTest} relies on it.
  • + *
  • The HTTP port, {@code floci.port} and {@code floci.base-url} name one free port, chosen once + * when the class loads, so a Lambda container calls back to the port the application listens on. + * {@code LambdaExecutionRoleDockerIntegrationTest} relies on it. The other classes send to the + * port RestAssured or the test-port setting reports, which is the same one.
  • + *
+ * + *

Each service setting is inert for the other classes: none of them calls RDS, DocumentDB, DSQL + * or Lambda, and the only S3 call outside the S3 class is the function's ListBuckets in + * {@code LambdaExecutionRoleDockerIntegrationTest}, which its execution role denies whichever way + * bucket names resolve. + * + *

A class joins if every setting here is either one it relies on or one that never reaches its + * requests, and if any setting it adds never reaches the requests of a class already here. + */ +public class IamEnforcedServiceSettingsProfile extends IamEnforcementProfile { + + private static final int TEST_PORT = freePort(); + + @Override + public Map getConfigOverrides() { + Map overrides = new HashMap<>(enforcementOverrides()); + overrides.put("floci.services.rds.mock", "true"); + overrides.put("floci.services.docdb.mock", "true"); + overrides.put("floci.services.dsql.mock", "false"); + overrides.put("floci.services.lambda.ephemeral", "true"); + overrides.put("floci.services.s3.global-bucket-namespace", "true"); + overrides.put("quarkus.http.test-port", String.valueOf(TEST_PORT)); + overrides.put("floci.port", String.valueOf(TEST_PORT)); + overrides.put("floci.base-url", "http://localhost:" + TEST_PORT); + return overrides; + } + + private static int freePort() { + try { + return FreePorts.anyInterfacePort(); + } catch (IOException e) { + throw new UncheckedIOException("No free port for the IAM-enforced service settings test application", e); + } + } +} diff --git a/src/test/java/io/floci/aws/testing/IamEnforcementProfile.java b/src/test/java/io/floci/aws/testing/IamEnforcementProfile.java index f1d46ed812..b877fc2c30 100644 --- a/src/test/java/io/floci/aws/testing/IamEnforcementProfile.java +++ b/src/test/java/io/floci/aws/testing/IamEnforcementProfile.java @@ -33,6 +33,11 @@ import java.util.Map; * exercise the RDS paths they share unmocked. {@code DocDbClusterSnapshotIntegrationTest}, * {@code DocDbLegacyRecordArnIntegrationTest}, {@code DocDbRegionScopedIdentifierIntegrationTest} * and {@code DocDbTagConcurrencyTest} rely on it. + *

  • {@code floci.services.iam.partner-permission-boundaries-path} names + * {@code src/test/resources/partner-permission-boundaries.json}, which registers one permissions + * boundary for the delegation partner account {@code 000000000001}. + * {@code DelegationRoleBoundaryEnforcementIntegrationTest} relies on it, to see the condition key a + * delegated role write publishes.
  • * * *

    SCP enforcement is inert for every other class. An SCP only applies to a member account of an @@ -41,15 +46,18 @@ import java.util.Map; * account of its own and removing it as it ends, so the SCP lookup finds no ceiling for any account * the others use and their decisions are the ones IAM enforcement alone makes. * - *

    The region and DocumentDB settings are inert for the other classes: no other class here sends a - * region no partition publishes, and none calls DocumentDB. The DocumentDB classes sign every request - * with the {@code test} root stand-in, or call the service directly, and never act as a role, so - * IAM enforcement passes them through. + *

    The region, DocumentDB and partner settings are inert for the other classes: no other class + * here sends a region no partition publishes, none calls DocumentDB, and none files a delegation + * request as the partner account, the only request the registration reaches. The DocumentDB + * classes sign every request with the {@code test} root stand-in, or call the service directly, and + * never act as a role, so IAM enforcement passes them through. * *

    A class joins if it tests what IAM enforcement decides, or if it signs every request as the - * {@code test} root stand-in without a role and no other class here calls the service its own - * setting changes. An unsigned request is refused here. A profile that extends this one starts from - * {@link #enforcementOverrides()}, so the other classes' settings stay with them. + * {@code test} root stand-in without a role, and in either case if every other setting here is + * either one it relies on or one that never reaches its requests, and any setting it adds never + * reaches the requests of a class already here. An unsigned request is refused here. A profile that + * extends this one starts from {@link #enforcementOverrides()}, so the other classes' settings stay + * with them. */ public class IamEnforcementProfile implements QuarkusTestProfile { @@ -58,6 +66,8 @@ public class IamEnforcementProfile implements QuarkusTestProfile { Map overrides = new HashMap<>(enforcementOverrides()); overrides.put("floci.partitions.allow-unknown-regions", "true"); overrides.put("floci.services.docdb.mock", "true"); + overrides.put("floci.services.iam.partner-permission-boundaries-path", + "src/test/resources/partner-permission-boundaries.json"); return overrides; } diff --git a/src/test/java/io/floci/aws/testing/PartnerPermissionBoundaryEnforcementProfile.java b/src/test/java/io/floci/aws/testing/PartnerPermissionBoundaryEnforcementProfile.java deleted file mode 100644 index 1b1f6f8b79..0000000000 --- a/src/test/java/io/floci/aws/testing/PartnerPermissionBoundaryEnforcementProfile.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.floci.aws.testing; - -import io.quarkus.test.junit.QuarkusTestProfile; - -import java.util.Map; - -/** - * A deployment that enforces IAM policies and has registered permissions boundaries for a - * delegation partner, which is what it takes to see the condition key a delegated role write - * publishes: without enforcement nothing reads it, and without a registration there is no cap to - * publish. - * - *

    Both overrides are inert for every class that does not ask for this profile, and - * {@link PartnerPermissionBoundaryProfile} covers the cases that need the registration alone. - */ -public class PartnerPermissionBoundaryEnforcementProfile implements QuarkusTestProfile { - - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.services.iam.enforcement-enabled", "true", - "floci.services.iam.partner-permission-boundaries-path", - "src/test/resources/partner-permission-boundaries.json"); - } -} diff --git a/src/test/java/io/floci/aws/testing/RdsIamEnforcementProfile.java b/src/test/java/io/floci/aws/testing/RdsIamEnforcementProfile.java deleted file mode 100644 index 1ea953c46c..0000000000 --- a/src/test/java/io/floci/aws/testing/RdsIamEnforcementProfile.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.floci.aws.testing; - -import java.util.HashMap; -import java.util.Map; - -/** Real control-plane authorization with only the database container runtime mocked. */ -public class RdsIamEnforcementProfile extends IamEnforcementProfile { - @Override - public Map getConfigOverrides() { - Map overrides = new HashMap<>(enforcementOverrides()); - overrides.put("floci.services.rds.mock", "true"); - overrides.put("floci.services.docdb.mock", "true"); - return overrides; - } -}