mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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.
This commit is contained in:
1 parent
1f8dc1651d
commit
b5994e4d9e
10 files changed
+100
-98
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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<String, String> getConfigOverrides() {
|
||||
return Map.of(
|
||||
"floci.services.dsql.mock", "false",
|
||||
"floci.services.iam.enforcement-enabled", "true");
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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";
|
||||
|
||||
+2
-15
@@ -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<String, String> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
|
||||
+2
-13
@@ -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<String, String> 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);
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>The overrides, and who relies on them:
|
||||
* <ul>
|
||||
* <li>{@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.</li>
|
||||
* <li>{@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.</li>
|
||||
* <li>{@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.</li>
|
||||
* <li>{@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.</li>
|
||||
* <li>{@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.</li>
|
||||
* <li>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.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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<String, String> getConfigOverrides() {
|
||||
Map<String, String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.</li>
|
||||
* <li>{@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.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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.
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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<String, String> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>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<String, String> getConfigOverrides() {
|
||||
return Map.of(
|
||||
"floci.services.iam.enforcement-enabled", "true",
|
||||
"floci.services.iam.partner-permission-boundaries-path",
|
||||
"src/test/resources/partner-permission-boundaries.json");
|
||||
}
|
||||
}
|
||||
@@ -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<String, String> getConfigOverrides() {
|
||||
Map<String, String> overrides = new HashMap<>(enforcementOverrides());
|
||||
overrides.put("floci.services.rds.mock", "true");
|
||||
overrides.put("floci.services.docdb.mock", "true");
|
||||
return overrides;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user