test: share the Pod Identity profiles and the AppSync IAM profiles (#8858)

The two EKS Pod Identity Docker classes each declared a profile named Profile
with the same webhook, TLS and port settings. Only the agent class's turned EKS
mocking off, which never reaches the other class: it stores its cluster and
add-on through the services directly. They now share EksPodIdentityProfile.

AppSyncHttpDataSourceSidecarIntegrationTest and
EventBridgeAppSyncSidecarIntegrationTest each declared an EnforcedSidecars
profile, the sidecar namespace and port with IAM enforcement, the first with
signature validation as well. AwsIamHttpDataSourceIntegrationTest declared the
same two switches without the sidecar settings, which never reach it: it starts
no container and sends to the port the application listens on. The three now
share SidecarIamEnforcementProfile. The EventBridge class creates and deletes
its stack through a signed CloudFormation client rather than a hand-written
Authorization header, which signature validation would refuse.
Its cleanup now holds the SDK clients in a try-with-resources, so each closes
whatever the stack and IAM cleanup throws.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-18 09:00:51 -04:00
1 parent 3dce88baed
commit 1f8dc1651d
7 files changed
+131 -96

No files matched your search

@@ -6,6 +6,7 @@ import io.floci.aws.testing.AppSyncHttpTestPolicies;
import io.floci.aws.testing.AwsTestClients;
import io.floci.aws.testing.RestAssuredJsonUtils;
import io.floci.aws.testing.SidecarContainersProfile;
import io.floci.aws.testing.SidecarIamEnforcementProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
@@ -23,7 +24,6 @@ import software.amazon.awssdk.services.cloudformation.CloudFormationClient;
import software.amazon.awssdk.services.cloudformation.model.CloudFormationException;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@@ -36,23 +36,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/** SDK management, real GraphQL/Node sidecars, resolver callbacks and signed local AWS requests. */
@QuarkusTest
@TestProfile(AppSyncHttpDataSourceSidecarIntegrationTest.EnforcedSidecars.class)
@TestProfile(SidecarIamEnforcementProfile.class)
class AppSyncHttpDataSourceSidecarIntegrationTest {
private static final String ACCOUNT = "000000000000";
private static final String REGION = "us-east-1";
private static final String TARGET_REGION = "us-west-2";
public static class EnforcedSidecars extends SidecarContainersProfile {
@Override
public Map<String, String> getConfigOverrides() {
Map<String, String> overrides = new HashMap<>(containerOverrides());
overrides.put("floci.services.iam.enforcement-enabled", "true");
overrides.put("floci.auth.validate-signatures", "true");
return overrides;
}
}
@Inject
IamService iam;
@@ -8,9 +8,9 @@ import io.floci.aws.services.iam.IamService;
import io.floci.aws.services.scheduler.SchedulerService;
import io.floci.aws.services.stepfunctions.StepFunctionsService;
import io.floci.aws.testing.AppSyncHttpTestPolicies;
import io.floci.aws.testing.SidecarIamEnforcementProfile;
import io.floci.aws.testutil.AwsRequestSigner;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.test.junit.mockito.InjectSpy;
import io.restassured.RestAssured;
@@ -42,7 +42,7 @@ import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.verify;
@QuarkusTest
@TestProfile(AwsIamHttpDataSourceIntegrationTest.EnforcedSignatures.class)
@TestProfile(SidecarIamEnforcementProfile.class)
class AwsIamHttpDataSourceIntegrationTest {
private static final String ACCOUNT = "724600001234";
@@ -50,13 +50,6 @@ class AwsIamHttpDataSourceIntegrationTest {
private static final String TARGET_REGION = "us-west-2";
private static final String API_ARN = "arn:aws:appsync:" + API_REGION + ":" + ACCOUNT + ":apis/example";
public static class EnforcedSignatures implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of("floci.services.iam.enforcement-enabled", "true", "floci.auth.validate-signatures", "true");
}
}
@Inject
AppSyncDataSourceInvokers invokers;
@InjectSpy
@@ -10,9 +10,9 @@ import io.floci.aws.services.eks.model.CreatePodIdentityAssociationRequest;
import io.floci.aws.services.eks.model.OidcIdentity;
import io.floci.aws.services.iam.IamService;
import io.floci.aws.testing.DockerAvailability;
import io.floci.aws.testing.EksPodIdentityProfile;
import io.floci.aws.testing.EksTestNode;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
@@ -43,28 +43,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* after a Floci restart answers again only while the add-on is stored.
*
* <p>The cluster is started through {@link EksClusterManager} directly, on the webhook and TLS
* settings the Pod Identity forward needs, so this class keeps a profile of its own rather than
* {@code RdsMockProfile}, which the other real-cluster classes share. The add-on is created and deleted through the EKS API, as a client would.
* settings the Pod Identity forward needs, which {@link EksPodIdentityProfile} holds, rather than on
* {@code RdsMockProfile}, which the other real-cluster classes share. The add-on is created and
* deleted through the EKS API, as a client would.
*/
@QuarkusTest
@TestProfile(EksPodIdentityAgentDockerIntegrationTest.Profile.class)
@TestProfile(EksPodIdentityProfile.class)
class EksPodIdentityAgentDockerIntegrationTest {
public static final class Profile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
"floci.services.eks.mock", "false",
"floci.services.eks.pod-identity-webhook", "true",
"floci.tls.enabled", "true",
"floci.tls.aws-https-port", "0",
"quarkus.http.test-port", "4510",
"quarkus.http.test-ssl-port", "4511",
"floci.port", "4595",
"floci.base-url", "http://localhost:4595");
}
}
private static final Logger LOG = Logger.getLogger(EksPodIdentityAgentDockerIntegrationTest.class);
private static final String ACCOUNT = "000000000000";
private static final String POD = "pod-identity-client";
@@ -16,8 +16,8 @@ import io.floci.aws.services.eks.model.CreatePodIdentityAssociationRequest;
import io.floci.aws.services.eks.model.OidcIdentity;
import io.floci.aws.services.iam.IamService;
import io.floci.aws.testing.DockerAvailability;
import io.floci.aws.testing.EksPodIdentityProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
@@ -28,7 +28,6 @@ import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -36,23 +35,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@QuarkusTest
@TestProfile(EksPodIdentityDockerIntegrationTest.Profile.class)
@TestProfile(EksPodIdentityProfile.class)
class EksPodIdentityDockerIntegrationTest {
public static final class Profile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
"floci.services.eks.pod-identity-webhook", "true",
"floci.tls.enabled", "true",
"floci.tls.aws-https-port", "0",
"quarkus.http.test-port", "4510",
"quarkus.http.test-ssl-port", "4511",
"floci.port", "4595",
"floci.base-url", "http://localhost:4595");
}
}
private static final Logger LOG = Logger.getLogger(EksPodIdentityDockerIntegrationTest.class);
private static final String TEST_IMAGE = "alpine:3.21";
@@ -7,8 +7,8 @@ import io.floci.aws.services.appsync.GraphqlSidecarClient;
import io.floci.aws.services.iam.IamService;
import io.floci.aws.testing.AwsTestClients;
import io.floci.aws.testing.CfnStackWaits;
import io.floci.aws.testing.RestAssuredJsonUtils;
import io.floci.aws.testing.SidecarContainersProfile;
import io.floci.aws.testing.SidecarIamEnforcementProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
@@ -17,6 +17,7 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.cloudformation.CloudFormationClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
@@ -27,14 +28,12 @@ import software.amazon.awssdk.services.eventbridge.model.Target;
import software.amazon.awssdk.services.sqs.SqsClient;
import software.amazon.awssdk.services.sqs.model.Message;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static io.floci.aws.services.eventbridge.EventBridgeAppSyncFixtures.policy;
import static io.floci.aws.services.eventbridge.EventBridgeAppSyncFixtures.trust;
import static io.floci.aws.testing.CfnRequests.cfn;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -42,26 +41,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/** Real SDK delivery through a CFN rule, GraphQL sidecar, resolver callback and DynamoDB. */
@QuarkusTest
@TestProfile(EventBridgeAppSyncSidecarIntegrationTest.EnforcedSidecars.class)
@TestProfile(SidecarIamEnforcementProfile.class)
class EventBridgeAppSyncSidecarIntegrationTest {
private static final String ACCOUNT = "000000000000";
private static final String REGION = "us-west-2";
private static final String AUTH = "AWS4-HMAC-SHA256 Credential=test/20261104/" + REGION + "/cloudformation/aws4_request";
private static final String OPERATION = "mutation Publish($id: ID!) { publish(id: $id) { id caller } }";
private static final String SCHEMA = "type Message { id: ID! caller: String } type Query { unused: String } "
+ "type Mutation { publish(id: ID!): Message }";
private static final ObjectMapper MAPPER = new ObjectMapper();
public static class EnforcedSidecars extends SidecarContainersProfile {
@Override
public Map<String, String> getConfigOverrides() {
Map<String, String> overrides = new HashMap<>(containerOverrides());
overrides.put("floci.services.iam.enforcement-enabled", "true");
return overrides;
}
}
@Inject
IamService iam;
@Inject
@@ -75,12 +64,12 @@ class EventBridgeAppSyncSidecarIntegrationTest {
private EventBridgeClient events;
private DynamoDbClient dynamo;
private SqsClient sqs;
private CloudFormationClient cloudFormation;
private boolean stackCreated;
@BeforeAll
static void requireSidecar() {
SidecarContainersProfile.requireDockerAndImage("floci.services.appsync.graphql-image");
RestAssuredJsonUtils.configureAwsContentTypes();
}
@BeforeEach
@@ -95,6 +84,7 @@ class EventBridgeAppSyncSidecarIntegrationTest {
events = AwsTestClients.create(EventBridgeClient.builder(), "test", Region.of(REGION));
dynamo = AwsTestClients.create(DynamoDbClient.builder(), "test", Region.of(REGION));
sqs = AwsTestClients.create(SqsClient.builder(), "test", Region.of(REGION));
cloudFormation = AwsTestClients.create(CloudFormationClient.builder(), "test", Region.of(REGION));
RequestScopes.runAs(ACCOUNT, REGION, () -> {
iam.createRole(targetRoleName, "/", trust("events", "arn:aws:events:" + REGION + ":" + ACCOUNT + ":rule/" + rule, ACCOUNT),
null, 3600, Map.of());
@@ -114,36 +104,38 @@ class EventBridgeAppSyncSidecarIntegrationTest {
target.putObject("AppSyncParameters").put("GraphQLOperation", OPERATION);
target.putObject("InputTransformer").putObject("InputPathsMap").put("id", "$.detail.id");
((ObjectNode) target.path("InputTransformer")).put("InputTemplate", "{\"id\":<id>}");
cfn("CreateStack", stack).header("Authorization", AUTH).formParam("TemplateBody", MAPPER.writeValueAsString(template))
.formParam("Parameters.member.1.ParameterKey", "RuleName").formParam("Parameters.member.1.ParameterValue", rule)
.formParam("Parameters.member.2.ParameterKey", "TableName").formParam("Parameters.member.2.ParameterValue", table)
.formParam("Parameters.member.3.ParameterKey", "TargetRole").formParam("Parameters.member.3.ParameterValue", roleArn(targetRoleName))
.formParam("Parameters.member.4.ParameterKey", "DataRole").formParam("Parameters.member.4.ParameterValue", roleArn(dataRoleName))
.when().post("/").then().statusCode(200);
String templateBody = MAPPER.writeValueAsString(template);
cloudFormation.createStack(request -> request.stackName(stack).templateBody(templateBody).parameters(
parameter -> parameter.parameterKey("RuleName").parameterValue(rule),
parameter -> parameter.parameterKey("TableName").parameterValue(table),
parameter -> parameter.parameterKey("TargetRole").parameterValue(roleArn(targetRoleName)),
parameter -> parameter.parameterKey("DataRole").parameterValue(roleArn(dataRoleName))));
stackCreated = true;
CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stack, AUTH);
assertEquals("CREATE_COMPLETE", state.status(), state.reason());
CfnStackWaits.awaitStatus(cloudFormation, stack, "CREATE_COMPLETE");
}
@AfterEach
void cleanUp() {
try {
if (stackCreated) {
cfn("DeleteStack", stack).header("Authorization", AUTH).post("/").then().statusCode(200);
CfnStackWaits.awaitStackDeleted(stack, AUTH);
// The clients close whatever the cleanup throws, each even if another fails to close.
EventBridgeClient eventsClient = events;
DynamoDbClient dynamoClient = dynamo;
SqsClient sqsClient = sqs;
CloudFormationClient cloudFormationClient = cloudFormation;
try (eventsClient; dynamoClient; sqsClient; cloudFormationClient) {
try {
if (stackCreated) {
CfnStackWaits.deleteStack(cloudFormationClient, stack);
}
} finally {
if (targetRoleName != null) {
RequestScopes.runAs(ACCOUNT, REGION, () -> {
iam.deleteRolePolicy(targetRoleName, "invoke");
iam.deleteRole(targetRoleName);
iam.deleteRolePolicy(dataRoleName, "invoke");
iam.deleteRole(dataRoleName);
});
}
}
} finally {
if (targetRoleName != null) {
RequestScopes.runAs(ACCOUNT, REGION, () -> {
iam.deleteRolePolicy(targetRoleName, "invoke");
iam.deleteRole(targetRoleName);
iam.deleteRolePolicy(dataRoleName, "invoke");
iam.deleteRole(dataRoleName);
});
}
if (events != null) { events.close(); }
if (dynamo != null) { dynamo.close(); }
if (sqs != null) { sqs.close(); }
}
}
@@ -0,0 +1,46 @@
package io.floci.aws.testing;
import io.quarkus.test.junit.QuarkusTestProfile;
import java.util.Map;
/**
* The webhook and TLS settings the EKS Pod Identity forward needs, for the classes that ask the
* Pod Identity address for credentials from inside a container. 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>{@code floci.services.eks.pod-identity-webhook=true}, TLS on with no AWS HTTPS port of its
* own, the test ports 4510 and 4511, and {@code floci.port} 4595 with the base URL on it, are what
* the Pod Identity forward reads. {@code EksPodIdentityDockerIntegrationTest} and
* {@code EksPodIdentityAgentDockerIntegrationTest} rely on them, and the second checks that the
* forward targets port 4595.</li>
* <li>{@code floci.services.eks.mock=false} runs EKS clusters for real.
* {@code EksPodIdentityAgentDockerIntegrationTest} starts a k3s node and relies on it.</li>
* </ul>
*
* <p>{@code floci.services.eks.mock} never reaches {@code EksPodIdentityDockerIntegrationTest}: it
* stores its cluster record and add-on through the services directly, never through CreateCluster,
* and nothing it stores is persisted for a boot to restore, so EKS never starts or stops a cluster
* for it.
*
* <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 EksPodIdentityProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
"floci.services.eks.mock", "false",
"floci.services.eks.pod-identity-webhook", "true",
"floci.tls.enabled", "true",
"floci.tls.aws-https-port", "0",
"quarkus.http.test-port", "4510",
"quarkus.http.test-ssl-port", "4511",
"floci.port", "4595",
"floci.base-url", "http://localhost:4595");
}
}
@@ -0,0 +1,43 @@
package io.floci.aws.testing;
import java.util.HashMap;
import java.util.Map;
/**
* IAM enforcement and signature validation on, over the sidecar containers' namespace and port, for
* the classes that check what a role may do when AppSync or EventBridge acts as it. 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 SidecarContainersProfile#containerOverrides()} names the containers and points a
* launched container's callbacks at the port the application listens on.
* {@code AppSyncHttpDataSourceSidecarIntegrationTest} and
* {@code EventBridgeAppSyncSidecarIntegrationTest} run the GraphQL sidecar and rely on it.</li>
* <li>{@code floci.services.iam.enforcement-enabled=true} evaluates every request against the
* caller's policies. All three classes check a decision it makes: the role an HTTP data source
* signs as, and the role an EventBridge target and a DynamoDB data source act as.</li>
* <li>{@code floci.auth.validate-signatures=true} rejects a request whose SigV4 signature does not
* match its credentials. {@code AppSyncHttpDataSourceSidecarIntegrationTest} and
* {@code AwsIamHttpDataSourceIntegrationTest} check the signature an AWS_IAM HTTP data source
* sends with it.</li>
* </ul>
*
* <p>The namespace never reaches {@code AwsIamHttpDataSourceIntegrationTest}, which starts no
* container, and the port is the one it already sends to. {@code EventBridgeAppSyncSidecarIntegrationTest}
* sends every request through an SDK client, which signs it, so signature validation passes it.
*
* <p>A class joins if every setting here is either one it relies on or one that never reaches its
* requests, and if it signs every request it sends.
*/
public class SidecarIamEnforcementProfile extends SidecarContainersProfile {
@Override
public Map<String, String> getConfigOverrides() {
Map<String, String> overrides = new HashMap<>(containerOverrides());
overrides.put("floci.services.iam.enforcement-enabled", "true");
overrides.put("floci.auth.validate-signatures", "true");
return overrides;
}
}