Repository navigation
fix(iam): parse Explainable-IAM denial logs in the policy analyzer - #87
Open
HarshCasper wants to merge 2 commits into
Open
HarshCasper wants to merge 2 commits into
HarshCasper wants to merge 2 commits into
Conversation
The IAM policy analyzer only recognised the legacy denial log line
("Request for service '..' by principal '..' for operation '..' denied.").
Current LocalStack (2026.x) emits the Explainable-IAM format instead:
User: <principal> is not authorized to perform: <service:Action>
on resource: <arn> because ...
so analyze-policies reported "No IAM Denials Found" and generated nothing
against a running LocalStack. This also affects denials raised for Lambda
execution roles (assumed-role principals), which only appear in the new format.
- log-retriever: detect the Explainable-IAM line (principal, action, resource,
service) in addition to the legacy one.
- iam-policy.logic: only fall back to the nearby-log resource when the denial
line did not already carry one, so the richer new format is not overwritten.
- tests: cover both formats, assumed-role principals, object-scoped S3 ARNs,
and that the DEBUG 'Necessary permissions' lines are not themselves denials.
HarshCasper
force-pushed
the
fix/explainable-iam-denials
branch
from
October 5, 2026 17:31
0070ace to
8a42932
Compare
Actions such as dynamodb:ListTables log no "on resource:" clause, so the Explainable IAM pattern did not match them. Make the clause optional.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(iam): parse Explainable-IAM denial logs in the policy analyzer
Problem
localstack-iam-policy-analyzer→analyze-policiesreturns "No IAM Denials Found"against current LocalStack, even when IAM enforcement is denying requests.
The log parser only matches the legacy denial line:
Current LocalStack (2026.x, verified on 2026.9.0) emits the Explainable-IAM format:
Because the parser never flags these as denials, no policy is generated. This also hides
denials raised against Lambda execution roles (assumed-role principals), which only
surface in the new format.
Fix
src/lib/logs/log-retriever.ts: additionally detect the Explainable-IAM line and extractprincipal, action, resource and service. The legacy format still works.
src/lib/iam/iam-policy.logic.ts: the nearby-log resource enrichment now fills the resourceonly if the denial line did not already provide one, so the resource parsed from the new
format is not overwritten by a stale nearby line.
src/lib/logs/log-retriever.iam.test.ts: new unit tests for both formats, assumed-roleprincipals, object-scoped S3 ARNs, and that the DEBUG
Necessary permissions ...lines arenot misclassified as denials.
Verification
Against LocalStack 2026.9.0 with
ENFORCE_IAM=1, after an app's Lambda hit AccessDenied under astripped role,
analyze-policiesnow reports the denials and emits a correct least-privilegepolicy for the
assumed-role/<role>/<fn>principal.yarn jestgreen (new tests included).Notes