Speed up IAM privilege-escalation rules on large Terraform repos#227
Merged
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: d6ace84 | Docs | Datadog PR Page | Give us feedback! |
… attachment lookups avoid rescanning every document per attachment.
whitemerch
force-pushed
the
chakib.hamie/fix_iam_rules_pt2
branch
from
June 30, 2026 16:27
e38cc08 to
d374ba5
Compare
whitemerch
marked this pull request as ready for review
June 30, 2026 17:18
MarshalX
previously approved these changes
Jul 1, 2026
MarshalX
approved these changes
Jul 1, 2026
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.
Motivation
On large Terraform repositories, the IAM privilege-escalation rule family was a major scan bottleneck. Each rule rebuilt dangerous-permission sets by resolving
policy_arnattachments with an O(attachments × documents) document rescan. This is a followup of #221, which improved these queries, but there was a bigger improvement possible.Changes
IAM helpers (
common.rego)Build
_policy_name_wildcard_permsonce per query in a single pass over managed policy resources. Attachment branches for roles, users, and groups now resolvepolicy_arnreferences via membership in that set instead of rescanning every document for each attachment.Tests
Add regression coverage for inline policies, cross-document attachment resolution, and non-wildcard policy exclusion.
Author Checklist
QA Instruction
opa test assets/libraries/ --v1-compatibleOn
cloud-inventory(29,788 files, full rule corpus): scan time dropped from ~8m to ~1m53s, with 0 slow IAM privilege-escalation rules (previously 19 rules at ~3 min each).Blast Radius
Affects Terraform IAM privilege-escalation rules that use
*_unrecommended_permission_policy_scenariosincommon.rego. No CLI or engine behavior changes.Additional Notes
N/A
I submit this contribution under the Apache-2.0 license.