fix(logs): require the policy type's read permission for DescribeAccountPolicies (#6097)

This commit is contained in:
Niels Kootstra authored and GitHub committed 2026-10-20 17:15:13 -04:00
1 parent 5fa67625c1
commit 73e890dbc7
3 files changed
+63 -7

No files matched your search

+4
View File
@@ -1495,6 +1495,10 @@ for `DATA_PROTECTION_POLICY`, `logs:PutSubscriptionFilter` for `SUBSCRIPTION_FIL
`logs:PutMetricExtractionPolicy` for `METRIC_EXTRACTION_POLICY`. Without it the request is refused with
`AccessDeniedException` and no policy is stored. The `iam:PassRole` a subscription filter policy with a
`RoleArn` also needs is not checked.
`DescribeAccountPolicies` likewise needs the read action for the type it lists:
`logs:GetDataProtectionPolicy`, `logs:DescribeSubscriptionFilters`, `logs:GetTransformer` or
`logs:DescribeIndexPolicies`. Its reference names none for `METRIC_EXTRACTION_POLICY`, which needs only
`logs:DescribeAccountPolicies`.
**Secrets Manager secrets.** A request that names a secret by its name, or by a partial ARN without
the random suffix, is evaluated against the stored secret's full ARN, suffix included, so a
@@ -550,10 +550,11 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
}
}
// PutAccountPolicy also needs the action for the type of policy it creates, as its API
// reference says. An unknown type needs nothing more: the handler refuses it.
if ("logs:PutAccountPolicy".equals(action)) {
String typeAction = accountPolicyTypeAction(arnBuilder.readJsonBody(ctx));
// PutAccountPolicy also needs the action for the type of policy it creates, and
// DescribeAccountPolicies the one for the type it lists, as their API references say. An
// unknown type needs nothing more: the handler refuses it.
if ("logs:PutAccountPolicy".equals(action) || "logs:DescribeAccountPolicies".equals(action)) {
String typeAction = accountPolicyTypeAction(action, arnBuilder.readJsonBody(ctx));
if (typeAction != null && abortIfDenied(ctx, caller, principal, typeAction, action, credentialScope,
resources, targetContexts, region, accountId, akid)) {
return;
@@ -638,11 +639,22 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
private static final Set<String> GOVERNANCE_BYPASS_ACTIONS =
Set.of("s3:PutObjectRetention", "s3:DeleteObject", "s3:DeleteObjectVersion");
private static String accountPolicyTypeAction(JsonNode body) {
private static String accountPolicyTypeAction(String action, JsonNode body) {
if (body == null) {
return null;
}
return switch (body.path("policyType").asText()) {
String policyType = body.path("policyType").asText();
if ("logs:DescribeAccountPolicies".equals(action)) {
// The reference names no read action for metric extraction policies.
return switch (policyType) {
case "DATA_PROTECTION_POLICY" -> "logs:GetDataProtectionPolicy";
case "SUBSCRIPTION_FILTER_POLICY" -> "logs:DescribeSubscriptionFilters";
case "TRANSFORMER_POLICY" -> "logs:GetTransformer";
case "FIELD_INDEX_POLICY" -> "logs:DescribeIndexPolicies";
default -> null;
};
}
return switch (policyType) {
case "DATA_PROTECTION_POLICY" -> "logs:PutDataProtectionPolicy";
case "SUBSCRIPTION_FILTER_POLICY" -> "logs:PutSubscriptionFilter";
case "TRANSFORMER_POLICY" -> "logs:PutTransformer";
@@ -24,7 +24,8 @@ import static org.hamcrest.Matchers.equalTo;
/**
* PutAccountPolicy also needs the action for the type of policy it creates, as its API reference
* says: "To use this operation, you must be signed on with the correct permissions depending on the
* type of policy that you are creating."
* type of policy that you are creating." DescribeAccountPolicies likewise needs the read action of the
* type it lists, for the four types its reference names.
*/
@QuarkusTest
@TestProfile(IamEnforcementProfile.class)
@@ -96,6 +97,45 @@ class CloudWatchLogsAccountPolicyIamEnforcementIntegrationTest {
.body("__type", equalTo("InvalidParameterException"));
}
@ParameterizedTest
@CsvSource({
"DATA_PROTECTION_POLICY, GetDataProtectionPolicy",
"SUBSCRIPTION_FILTER_POLICY, DescribeSubscriptionFilters",
"TRANSFORMER_POLICY, GetTransformer",
"FIELD_INDEX_POLICY, DescribeIndexPolicies"})
void callerAllowedOnlyDescribeAccountPoliciesIsRefusedThePolicyType(String policyType, String typeAction) {
String caller = user(allow("DescribeAccountPolicies"));
describeAccountPolicies(caller, policyType)
.statusCode(400)
.body("__type", equalTo("AccessDeniedException"))
.body("message", containsString("logs:" + typeAction));
}
@ParameterizedTest
@CsvSource({
"DATA_PROTECTION_POLICY, GetDataProtectionPolicy",
"SUBSCRIPTION_FILTER_POLICY, DescribeSubscriptionFilters",
"TRANSFORMER_POLICY, GetTransformer",
"FIELD_INDEX_POLICY, DescribeIndexPolicies"})
void callerAllowedThePolicyTypeReadActionDescribesThePolicies(String policyType, String typeAction) {
String caller = user(allow("DescribeAccountPolicies") + "," + allow(typeAction));
describeAccountPolicies(caller, policyType).statusCode(200);
}
@Test
void metricExtractionPoliciesNeedOnlyDescribeAccountPolicies() {
String caller = user(allow("DescribeAccountPolicies"));
describeAccountPolicies(caller, "METRIC_EXTRACTION_POLICY").statusCode(200);
}
private ValidatableResponse describeAccountPolicies(String caller, String policyType) {
return LogsAuthorizationFixtures.call(endpoint.getPort(), caller, REGION, "DescribeAccountPolicies",
Map.of("policyType", policyType)).then();
}
private ValidatableResponse putAccountPolicy(String caller, String region, String policyName,
String policyType) {
return LogsAuthorizationFixtures.call(endpoint.getPort(), caller, region, "PutAccountPolicy",