Home/For responders/Reviewing infrastructure as a defender
Reviewing infrastructure as a defender
Responders rarely write the Terraform. They review it, and a good review catches the change that would have become the next incident.
Read the plan as well as the code
The code says what someone meant. The plan says what will happen. In the plan, stop at any of these:
- A replacement or destroy of anything that contains data or logs
- Logging switched off, or a retention period shortened
- Deletion protection removed, or
force_destroyswitched on - Anything opened to
0.0.0.0/0,allUsers, or a principal of* - A trust policy or role binding changed
Trust policies: who can become this role
A role's permissions say what it can do. Its trust policy says who can become it, and that is where reviews most often miss something.
The common case today is a pipeline assuming a cloud role through federation. This trust policy lets GitHub Actions assume the role, and says nothing about which repository:
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
}
}
Every workflow in every repository on GitHub can get a token with that audience, so every one of them can assume this role. The fix is a condition on the subject, naming the repository and branch:
"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:your-org/your-repo:ref:refs/heads/main"
}
Google Cloud has the same trap. A workload identity provider for GitHub needs an attribute condition naming the repository.
Permissions that grant other permissions
Some permissions look harmless and let whoever has them become someone more powerful. Treat them as the most powerful permission they lead to.
| Cloud | Permission | What it really allows |
|---|---|---|
| AWS | iam:PassRole on * | Handing any role to a service you control, then acting as that role |
| AWS | iam:CreatePolicyVersion | Rewriting a policy you are already attached to |
| AWS | lambda:UpdateFunctionCode | Running your code as that function's role |
| Google Cloud | roles/iam.serviceAccountTokenCreator | Minting tokens as the service account |
| Google Cloud | roles/iam.serviceAccountUser | Attaching the service account to resources you run |
| Google Cloud | setIamPolicy on a project | Granting yourself anything in the project |
Guardrails above the account
Account-level permissions can be changed by whoever controls the account. Organisation-level policies cannot, which is why they carry the rules that must stay in force even after a compromise.
- AWS: service control policies limit what principals in member accounts can do, such as leaving the organisation or switching off CloudTrail. Resource control policies limit what can be done to resources, which is the basis of a data perimeter.
- Google Cloud: organisation policy constraints, such as
iam.disableServiceAccountKeyCreationandiam.allowedPolicyMemberDomains, and VPC Service Controls perimeters, which stop data leaving a set of projects even with valid credentials.
The guardrail and data perimeter templates build these on AWS and Google Cloud.
Pipelines and supply chain
- Stored cloud keys. A pipeline with an access key is one leaked log away from an incident. Federation replaces the key with a token per run.
- Third-party actions pinned by tag. Whoever controls an action's repository can move a tag to different code. That happened to the tj-actions/changed-files action in March 2025, and secrets leaked from the pipelines using it. A full commit SHA cannot be moved.
- The token's permissions. A workflow should start with
permissions: contents: readand add only what each job needs. pull_request_targetthat checks out the pull request. That runs a stranger's code with your secrets.- Provenance. Signing images and checking the signature at admission means only what your pipeline built can run. A signed SBOM attached to each image answers the first question of a dependency incident: which running images contain the affected package. The CI/CD signals workflow produces both, and the admission policy checks both.
This site's own workflow is a worked example. Every action is pinned to a full commit SHA, with Dependabot proposing updates. Tools are verified against published checksums, no scripts are piped from the internet, and every job gets a read-only GitHub token. The one job that publishes the site has a Cloudflare token that can edit Pages projects and nothing else. It runs only after every check passes on main, and runs nothing from the repository.
Questions to ask in any review
- Who can become this role, and is that list as short as it can be?
- Does anything here grant a permission that grants other permissions?
- If this is misused, what records it, and could the person misusing it switch that record off?
- If this is deleted, what is lost, and can anyone restore it?
- Does the plan destroy or replace anything that contains data?