From b1f953efb1972b86f1a0faf092ee0205b5b5f523 Mon Sep 17 00:00:00 2001 From: Feyikemi Ogunsanya <54103882+Agboolafeyikemi@users.noreply.github.com> Date: Fri, 7 Aug 2026 23:20:39 +0100 Subject: [PATCH] fix(iam): seed AmazonAPIGatewayPushToCloudWatchLogs managed policy (#2147) * fix(iam): seed AmazonAPIGatewayPushToCloudWatchLogs managed policy Floci seeded 52 AWS-managed policies at boot but none matched API Gateway, so AttachRolePolicy for this standard service-role policy returned NoSuchEntity. It's the policy attached to the API Gateway CloudWatch-logs role that aws_api_gateway_account depends on, so this blocked the first apply of any Terraform config that enables API Gateway access logging. Fixes #2121 * test(iam): add regression test for AmazonAPIGatewayPushToCloudWatchLogs seeding Reproduces #2121: GetPolicy for the API Gateway CloudWatch-logs managed policy returned 404 NoSuchEntity before the fix. --- .../services/iam/AwsManagedPolicies.java | 4 ++++ .../services/iam/IamIntegrationTest.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/AwsManagedPolicies.java b/src/main/java/io/github/hectorvent/floci/services/iam/AwsManagedPolicies.java index d65067fba6..79bf611ffa 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iam/AwsManagedPolicies.java +++ b/src/main/java/io/github/hectorvent/floci/services/iam/AwsManagedPolicies.java @@ -127,6 +127,10 @@ final class AwsManagedPolicies { new ManagedPolicyDef("CloudWatchLambdaApplicationSignalsExecutionRolePolicy", "/", "Provides write access to X-Ray and CloudWatch Application Signals log group."), + // API Gateway execution role policy + new ManagedPolicyDef("AmazonAPIGatewayPushToCloudWatchLogs", "/service-role/", + "Allows API Gateway to push logs to CloudWatch Logs."), + // Config execution role policy new ManagedPolicyDef("AWSConfigRulesExecutionRole", "/service-role/", "Allows AWS Config Rules Lambda functions to call AWS services and read the configuration of AWS resources."), diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java index 3aab7d378e..1afb7123d6 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamIntegrationTest.java @@ -254,6 +254,25 @@ class IamIntegrationTest { equalTo("arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole")); } + @Test + @Order(18) + void getApiGatewayPushToCloudWatchLogsPolicy() { + given() + .formParam("Action", "GetPolicy") + .formParam("PolicyArn", + "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs") + .header("Authorization", + "AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request") + .when() + .post("/") + .then() + .statusCode(200) + .body("GetPolicyResponse.GetPolicyResult.Policy.PolicyName", + equalTo("AmazonAPIGatewayPushToCloudWatchLogs")) + .body("GetPolicyResponse.GetPolicyResult.Policy.Arn", + equalTo("arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs")); + } + @Test @Order(9) void stsGetCallerIdentityFallsBackForUnseededFlociAccessKey() {