Introduction
AI can get you from an AWS infrastructure idea to working CDK code pretty quickly. Once that code synthesizes, though, how do you check the IAM permissions your application will rely on?
Say you have a role that lets Lambda read from S3. If another role can pass that role to a service, how far do those permissions reach?
I built a CDK plugin called ProofGate to check combinations like this during cdk synth!
I developed ProofGate during Kiroween Hackathon 2026. This post is also part of the AWS Community Builders Advent Calendar 2026.
I had fun building it. Here’s what happened when I tried it out.
mashharuki / proofgate
A Lean-powered pre-deployment validation gate for AWS CDK infrastructure.
ProofGate
English | 日本語
Links
- Site, with a quick start: https://mashharuki.github.io/proofgate/
- Demo video (2 min 33 s): https://youtu.be/4JCRq6Zv5I0
- npm:
@proofgate-cdk/cdk-plugin1.3.2 - Try it without installing anything: Getting started (a GitHub Codespace, no AWS account, about 10 minutes)
- Slides: English, 日本語
Short description
ProofGate is a formal-verification-based security tool for AWS CDK. It detects unintended IAM access paths to protected S3 buckets and stops the deployment before it happens. The correctness of its results is machine-checked by Lean 4.
Description
ProofGate is a CDK validation plugin. It reads the CloudFormation that cdk synth produces, builds a small model of roles, policies, trust, and the protected buckets, and stops the synthesis when a principal can reach a protected bucket through another role. The message names the principal, the role, the service, and the bucket, with a suggested fix.
Four findings (PG-IAM-006 and the wider PG-IAM-004 and PG-IAM-005 are in main…
What I built
ProofGate checks IAM permissions during cdk synth. It examines one synthesized CloudFormation template at a time and stops synthesis if it finds a combination of permissions that could reach a protected S3 bucket through another role.
In the demo, the same CDK app synthesizes normally on its own, then stops with PG-IAM-004 when ProofGate is enabled. I ran the demo through synthesis only. Demo CDK code
Try ProofGate
I used these versions for the demo:
- Node.js 26.13.1
- Lean 4.31.0, installed with elan
- CDK library 2.277.0 and CLI 2.1148.1
- ProofGate 1.3.2
The demo runs without AWS credentials or a deployment. Initial setup downloads files from GitHub and npm and sets up the Lean toolchain. The first run also needs to build the bundled Lean library, so give it a little time.
In GitHub Codespaces, choose Code → Codespaces → Create codespace on main. After setup finishes, run the command below from the repository root. Look for ProofGate version in the CDK report in the output. Since main changes, use the pinned instructions below to reproduce the version I used. Codespaces setup script
node scripts/demo-fix.mjs --app-dir ~/proofgate-npm-demo | Step | What to look for |
|---|---|
| 1. Plain synthesis | Exit code 0. CDK generates a CloudFormation template. |
| 2. Synthesis with ProofGate | Exit code 1 and PG-IAM-004. Look for the source role, target role, service, and bucket. |
| 3. Fix | The script removes an unnecessary PassRole statement from a temporary copy. |
| 4. Synthesis with ProofGate after the fix | Exit code 0. ProofGate runs, and the demo rule reports no finding. |
When you run it yourself, look at the roles and bucket reported in step 2, then see which permission the script removed in step 3.
demo-fix.mjs saves the report as gated.out/validation-report.json in a temporary directory and prints the version and result to the terminal. When you run cdk synth in your own CDK app, look in cdk.out/validation-report.json for validation errors.
The pluginVersion field shows the plugin version. The proofgate.lean.method entry in metadata shows how ProofGate evaluated the certificate.
How the code works
The IAM roles in the demo
Why did removing that permission in step 3 clear the S3 finding?
Start with the data role. The CDK code says Lambda can assume it and that it can read and write objects in the bucket. When reviewing a pull request, you can inspect the synthesized template for clues about which other roles can configure a service to use it.
An IAM role defines the permissions a principal or service can use when it assumes the role. The trust policy says who can assume it. The permissions policy says what they can do once they have.
iam:PassRole lets a principal specify a role when configuring an AWS service in the same account. With sts:AssumeRole, the caller assumes the role. The effective permissions depend on the request context and applicable policies.
Here’s the target role in the demo. assumedBy sets up the trust relationship, and the policy statement grants permissions on objects in the bucket. I’ve left out the imports and surrounding variable definitions. CDK source
const dataRole = new Role(stack, "ProtectedDataRole", { roleName: "proofgate-protected-data-role", assumedBy: new ServicePrincipal("lambda.amazonaws.com"), }); dataRole.addToPolicy( new PolicyStatement({ effect: Effect.ALLOW, actions: ["s3:GetObject", "s3:PutObject"], resources: [`${protectedBucketArn}/*`], }), ); The demo checks for a permission path involving PassRole. The first two conditions in the diagram refer to the source developer role, and the last two refer to the target data role. ProofGate looks for all four in the same template.
For condition 2, ProofGate looks for an Allow that matches a launch-related action in a shared lookup table. It checks the action and skips the statement’s Resource for this condition. For condition 4, it checks supported S3 operations on objects or operations that affect the bucket itself, such as changes to its policy or lifecycle configuration.
flowchart TB P["Source role"] T["Data role"] S["AWS service"] B["Protected S3 bucket"] P -->|"1 Can pass the target role"| T P -->|"2 Has an Allow for a listed launch action"| S T -->|"3 Trusts the service"| S T -->|"4 Has an Allow for a relevant S3 action"| B How ProofGate checks a synthesized template
I implemented ProofGate as a CDK policy validation plugin. During cdk synth, it reads the generated CloudFormation templates one at a time and extracts the role, permission, and trust data it needs. I’ll call that extracted data the IAM model.
flowchart TB A["CDK app"] --> B["Synthesized CloudFormation template"] B --> C["Extractor resolves and normalizes data"] C -->|"Extraction succeeds"| D["Finite IAM model"] C -->|"Unsupported input"| E["PG-IAM-003"] D -->|"No roles"| S["Skip the evaluator and Lean for this template"] D -->|"Roles present"| F["Evaluate in TypeScript and cross-check with Lean"] F -->|"Unable to confirm the result"| E F -->|"Matching path found"| G["PG-IAM-004 or PG-IAM-005"] F -->|"No matching findings"| H["Pass this template"] E --> I["Reject synthesis"] G --> I The demo shows PG-IAM-004. There are three diagnostics to look for when using the plugin.
| Diagnostic | What to check |
|---|---|
PG-IAM-003 | Unsupported syntax or policies, Lean errors, timeouts, or results that disagree. The message points to the input or validation environment. |
PG-IAM-004 | A permission combination that could reach a protected bucket. Release 1.3.2 covers the PassRole case and cases involving Lambda, CodeBuild, or Step Functions resources already using the target role. |
PG-IAM-005 | IAM changes that could grant more permissions. Check which IAM actions the source role can perform and whether they apply to itself, another role, or a newly created role. |
ProofGate fails closed with PG-IAM-003 when the extractor rejects an input or the plugin cannot complete its cross-check.
If a model contains no roles, ProofGate skips both the evaluator and Lean. Synthesis can also pass without a finding when the relevant roles are in separate templates or ProofGate cannot match a protected bucket by name. See Using ProofGate in an existing CDK app for what to check.
The handling of Condition depends on the policy type. A Condition on a permissions statement read from the template is unsupported and triggers PG-IAM-003. In a trust policy, ProofGate evaluates Allow statements without their object-form Condition, so it can overestimate what is allowed.
Deny statements with a Condition are unsupported. Some supported AWS managed policies are static copies, and some of their Allow conditions are omitted. Keep these rules in mind when investigating a finding.
The tests found 532 cases the evaluator missed
Stopping synthesis in the demo was a start. I still wanted to know what would happen with different combinations of roles and policies.
I ran 2,000 models generated with a fixed seed through the old evaluator. A separate implementation called an oracle computed the expected results. In 532 cases, the oracle expected a finding that the evaluator missed.
The first thing I fixed was ? in IAM Resource patterns. It matches any single character, but the old matcher didn’t handle it that way. When I ran the tests again after the fix, the number of misses dropped from 532 to 178. AWS documentation on IAM wildcards
What about the other 178?
Those came down to the way I checked S3 permissions. I had used <bucket>/* as shorthand for every object in a bucket, but the code treated it as a single string when matching it against the policy’s Resource pattern.
For example, if a policy only grants access to <bucket>/reports/*, the string I was checking doesn’t even contain reports/. What I wanted to know was whether at least one key in the protected bucket could match the policy pattern.
I changed the evaluator to treat <bucket>/* as a pattern and check whether any string could match both patterns. That brought the number of misses in this test run down from 178 to zero.
The expected results had a bug too
I wrote the oracle’s matcher separately so it wouldn’t inherit bugs from the product. Even so, it interpreted too narrowly when an ARN wildcard * could match across a colon. I corrected it using results from the IAM Policy Simulator’s SimulateCustomPolicy API.
Two separate evaluators can still make the same mistake and pass the tests. And when they disagree, looking at their answers side by side won’t tell you which one to fix. I had to make that call while working with Kiro.
I thought RS-70 would pass. It didn’t.
I expected RS-70 to pass because its two role-name patterns looked like they didn’t overlap. Before adding PG-IAM-005, the rule for IAM changes, I committed my predictions for ten CDK configurations, including RS-70.
When I finally ran the tests, ProofGate flagged it. Kiro initially treated the result as a false positive and started changing the oracle.
I went back to the IAM CreateRole documentation. Once I accounted for the characters allowed in the new role’s Path, the two patterns could overlap in the model. The logs show Kiro reverting its oracle change and a human approving the correction. The documented Path input rules were the basis for the correction. I didn’t test whether the API call would succeed in AWS. AWS documentation on CreateRole and Path
This was where the earlier commit helped. I could see exactly what I had assumed before running the test. When the expected result changed, I could also trace why.
What I worked out with Kiro before implementation
I got Kiro credits through Kiroween, so I made the most of them! Before coding, I read up on IAM roles and previous AWS security incidents, and used a Lean-specific agent skill to help with the design.
This was the hardest part for me. I spent a lot of time working out exactly what to put in the model so Lean could check the properties I cared about.
flowchart TB R["requirements.md<br/>What the check must do"] -->|"Human approval"| D["design.md<br/>How to make the decision"] D -->|"Human approval"| T["tasks.md<br/>Order of changes and checks"] T --> P["Commit the predictions"] P --> F["Run tests against the unchanged code"] F --> W["Implement the change and run the quality script directly"] W --> O["Compare predictions with results"] O --> Q["Human reviews the diff and evidence"] Q --> M["Merge the pull request"] In Kiro’s security.md and development.md steering files, I wrote down rules such as keeping the TypeScript and Lean results in sync and requiring approval for changes that reduce the number of findings.
MCP servers, research subagents, and an Agent Hook
I used the AWS Documentation MCP Server to look up IAM and S3 behavior. I also used the AWS MCP Server to get ValidatePolicy and SimulateCustomPolicy results during design and implementation. The saved IAM Policy Simulator results are what I used to correct the wildcard matching.
I configured an Agent Hook to run linting, type checks, tests, and checks on the distribution package after a task. The development record shows that I ran the script directly. That run found a Biome error in a copy of the generated output and a problem with the CI YAML.
Setting up MCP servers, skills, and rules was part of the work. I also wanted a repeatable way to check the output automatically.
What can Lean 4 prove?
More tests give me more concrete inputs to check. For the PassRole rule, I also wanted to write down what counted as a finding independently of the evaluator code. I wrote it as a proposition in Lean. That let me prove statements that apply to any model, such as each reported finding corresponding to a case covered by the specification.
Lean 4 is a theorem prover that lets you define functions and propositions and write proofs about them. You can run this example on its own in Lean 4.31.0.
example : ([10, 20] : List Nat).length = 2 := by decide +kernel The equality in the type of example is what we’re proving. The decide tactic uses a decision procedure for that equality. With +kernel, Lean’s kernel also reduces the computation from the decision procedure when checking the proof.
The example uses one fixed list. ProofGate uses both theorems that apply to any model and checks for a particular model.
Proving that the evaluator agrees with the specification
Asking whether a matching string exists
Here are excerpts from the Lean library that ships with ProofGate and from a module it generates. In EscalatesTo, m is the extracted model, p is the source role, t is the target role, and b is the protected bucket. The symbol ∧ means both conditions hold, and ∃ means there is a value that satisfies the condition.
def EscalatesTo (m : Model) (p t : Role) (b : String) : Prop := t ∈ m.roles ∧ t.id ≠ p.id ∧ t.id ∉ m.exempt ∧ (∃ x, RoleIdent t x ∧ Allowed p.stmts "iam:passrole".toList x) ∧ (∃ svc, CanLaunch p svc ∧ Trusts t svc) ∧ Reaches t b The second line says the target role is in the model, is different from the source role, and is outside the exemption list. The remaining conditions say that the source role has a PassRole allowance for a string that RoleIdent recognizes as identifying the target role, that the launch permission and trust relationship point to the same service, and that Reaches holds for the protected bucket.
RoleIdent works with the model’s ARN form, bare role names, and logical IDs. It covers roles whose names are unresolved at synthesis time. Including bare names and logical IDs is an overapproximation. Reaches holds if there is an object key for which a relevant action is allowed. It can also hold for allowed bucket-level actions listed in the lookup table, such as changes to bucket policy, replication, or lifecycle configuration.
The specification asks whether a string satisfying the conditions exists. This is the same question that came up when I fixed the S3 matcher.
Proving that findings satisfies the specification
The evaluator’s findings function enumerates combinations of source roles, target roles, and protected buckets. If pathB returns true, it adds their three identifiers to the list. The roles and buckets are finite, so there’s no need to enumerate every possible ARN or S3 key. Eval.lean
def findings (m : Model) : List (String × String × String) := m.roles.flatMap fun p => m.roles.flatMap fun t => m.buckets.filterMap fun b => if pathB m p t b then some (p.id, t.id, b) else none The theorem intersect_iff connects the result of the pattern intersection function to the existence of a string that matches both patterns.
The main theorem, findings_iff, says that for any model, every tuple in the output corresponds to a source role, target role, and configured bucket with the same identifiers that satisfy the specification. That’s soundness. Completeness is the reverse direction. Every combination that satisfies the specification has its tuple in the output.
safe_iff says the output list is empty exactly when there is no combination in the model that satisfies the specification.
Cross-checking TypeScript and Lean
One thing I revisited after implementation was how much work Lean should do. Through 1.2.1, TypeScript calculated four Booleans for each candidate path, and Lean checked their conjunction. If the TypeScript matcher misread an ARN, Lean still started with the Booleans TypeScript had returned.
In 1.3.0, I changed the input for the PassRole case so Lean could compute the findings itself from the extracted model.
flowchart TB M["Shared input<br/>Roles, statements, trusted services, protected buckets"] M --> T["TypeScript computes PassRole findings"] M --> L["Lean independently computes PassRole findings"] T --> V["Certificate checks that the finding lists are equal"] L --> V V --> R["Plugin checks the exit code, markers, and output"] T --> B["TypeScript computes Booleans for the other two cases"] B --> C["Lean checks the conjunction and the result"] For each stack, generateLean writes the model and TypeScript’s expected list to a Lean module. Here’s the equality that generatedFindings checks, with the definitions at the top of the generated module omitted.
theorem generatedFindings : findings generatedModel = generatedExpected := by decide +kernel If the PassRole list is empty, ProofGate uses safe_iff to prove there is no matching combination in the model. If there are findings, it proves the rule holds for the first one. In kernel mode, the plugin still checks the Lean process’s exit code and #eval markers and compares the emitted PassRole findings with the TypeScript result. Missing output or disagreement triggers PG-IAM-003. For the PG-IAM-004 case involving changes to existing resources and for the IAM changes covered by PG-IAM-005, Lean checks the conjunction of Booleans computed by TypeScript.
What the Lean proofs cover
flowchart TB A["AWS documentation and IAM observations"] X["What actually gets deployed"] B["CloudFormation from this synthesis run"] C["TypeScript extraction and normalization, plus shared AWS lookup tables"] subgraph P["Abstract model used in Lean"] D["Equivalence between EscalatesTo and findings"] E["Equality of finding lists for this model"] end A -.->|"Informs the rule and provides comparison data"| D X -.->|"Assumption: deployment uses the synthesized output"| B B --> C --> D C --> E E --> R["Runtime plugin checks<br/>Lean exit code, markers, and findings"] N["native_decide also trusts the compiler and runtime"] -.-> E If the extractor misses a policy statement, for example, TypeScript and Lean can still agree because both saw the same incomplete model.
Both implementations rely on the same AWS lookup tables and normalized data. The result depends on where that data comes from and how the input is interpreted. AWS authorization also depends on factors such as SCPs, explicit denies, resource policies, conditions, and resources outside the stack. Alongside the certificate checks, I ran generated tests against the extractor and used saved IAM Policy Simulator results and practical CDK configurations.
What I found by testing other configurations
How the generated tests caught missed findings
In property-based testing (PBT), I define a property and check it against generated inputs. For ProofGate, one property is that a path constructed to hold in the model should appear in the findings. I built the test harness in the repository with Kiro to work with batched Lean runs. I wrote the generator and shrinker as part of that harness and didn’t use Kiro’s built-in PBT feature. Introduction to property-based testing
The generator labels cases, and the independent oracle evaluates them too. If the label and the oracle disagree, the harness flags the case for investigation before drawing a conclusion about the product.
When a case fails, the shrinker tries to make it smaller while keeping the conditions needed to reproduce it. If the case still fails after removing an unrelated statement, for example, the smaller version is easier to use as a regression test. A fixed seed lets me reproduce results in another environment.
What I tested and how much
| Check | Inputs and scope |
|---|---|
| Lean theorems and witnesses | For PassRole, findings_iff proves that the specification and evaluator agree. I also prepared witnesses for known configurations and counterexamples for the old implementation. |
| IAM Policy Simulator | I used 58 saved SimulateCustomPolicy results to check Action and Resource pattern matching. |
| Generated tests and differential checks | By default, the pinned source tests 2,000 models and 1,000 extractor fragments. A differential check for the early fixes compared 18,014 inputs. No input lost a finding the old version had reported. |
| CDK examples | The pinned commit includes 84 examples, tested in stages across multiple versions. |
| Model regressions for known paths | I modeled the conditions behind 91 paths from pathfinding.cloud. The November 22, 2026 run reported 60 findings, with 52 under 004 and 8 under 005. |
The TypeScript test that reads the 58 saved results compares the oracle’s matcher and a copy of the product’s matching logic. There were four differences from AWS’s case-sensitive results. In a separate set of 13 rows testing target-role identification, I recorded differences where the account was unknown and where the model matches bare role names broadly. Both tests use different inputs from tests that call a live service or run the CloudFormation extractor.
The shared lookup table has 879 launch-related actions. I extracted it from the November 21, 2026 snapshot of the AWS Service Reference and use it in both TypeScript and Lean. Coverage of the mapping from service operations to authorization actions varies by service. AWS Service Reference
I used CDK library 2.277.0 for the 84 stack examples.
Three problems I found in older versions
While writing the Lean spec in terms of concrete request strings, I noticed that the old PassRole check expected
:role/to appear inResource. Other patterns could still match the target ARN, and the oracle had missed them too. In 1.2.1, I changed the check to look for a string matching both the target role’s ARN pattern and theResourcepattern. Lean still has a counterexample that shows the old implementation missing a path covered by the rule.Once Lean started computing findings independently in 1.3.0, synthesis took longer on models with many PassRole combinations. After measuring that, I added a choice of evaluation methods and a timeout in 1.3.1.
In 1.3.1, all 27 variants of a fictional store app produced
PG-IAM-003. They all used the Step FunctionsEcsRunTaskconstruct. CDK synthesized an IAMResourceexpression containingFn::SelectandFn::Split, which the resolver couldn’t evaluate.
Comparing cdk-nag and IAM Access Analyzer
With cdk-nag 3.1.0 and the AwsSolutionsChecks pack, the same demo reported three instances of AwsSolutions-IAM5 for wildcard permissions. Removing the PassRole statement left two wildcard findings. ProofGate reported the protected bucket and the source and target roles together in one diagnostic. Synthesis passed with ProofGate after the same change. This comparison used one stack, one cdk-nag ruleset, and ProofGate 1.2.0. cdk-nag repository
IAM Access Analyzer can check policy syntax and AWS best practices, run custom policy checks, and analyze external, internal, and unused access. For this comparison, I took one developer-role policy out of the synthesized template. ValidatePolicy returned zero findings before and after the edit. With CheckAccessNotGranted set to check iam:PassRole, the result was FAIL before the edit and PASS afterward. AWS IAM Access Analyzer
A ruleset can surface questionable settings, and a policy check can tell you which permissions an individual policy grants. ProofGate adds a check for combinations of settings in one template that may lead to a protected destination you specify.
Using ProofGate in an existing CDK app
Run npm install --save-exact @proofgate-cdk/cdk-plugin@1.3.2 and set up elan. Register the plugin on your existing app before synthesis and specify the verified ARN of the bucket you want to protect.
import { Validations } from "aws-cdk-lib"; import { ProofGateValidator } from "@proofgate-cdk/cdk-plugin"; Validations.of(app).addPlugins( new ProofGateValidator({ protectedBucketArns: ["arn:aws:s3:::your-protected-bucket"], }), ); When setting it up, compare the *.template.json files in cdk.out with validation-report.json.
Check the bucket name. Choose a bucket with a fixed name and check it against the literal ARN in your config. ProofGate rejects an empty array or an empty string in
protectedBucketArns. It does no validation of ARN syntax or whether the name matches the model. If the template’sAWS::S3::Buckethas noBucketName, the extractor treats its name as opaque at synthesis time. Using a physical name from an earlier deployment can leave the bucket unmatched and produce no diagnostic. AddingBucketNameto an existing bucket can require replacement. Review the CloudFormation change set before making that change.Find both roles. Check which
*.template.jsonfiles contain the source and target roles. When they’re in separate files, the per-template check cannot evaluate their relationship even if one references the other by a literal ARN. Values the extractor cannot resolve, such as some uses ofFn::ImportValue, may triggerPG-IAM-003. Review cross-stack permissions separately, even when the plugin reports nothing.Investigate
PG-IAM-003. Start with the template name and JSON path in the report. Look for an unsupported AWS managed policy,Fn::ImportValuein aResource, or aConditionon a permissions statement. If Lean failed, check the terminal output and evaluation method. In CI, runcdk synthwith the plugin before deployment and make the CDK report available on failure.
CDK’s acknowledge lets you make an exception for a ProofGate rule. allowedPassRoleTargets and allowedPolicyWriters let you specify role-level exceptions by logical ID. These settings affect the findings. IAM permissions change when you update the policy itself.
What I learned and what’s next
When a result disagrees with my prediction, as RS-70 did, I stop and go back through the test and the documentation. Writing down the prediction before implementation tells me where to look for the assumption I got wrong. When I change how an IAM check works, keeping the original prediction, the source I relied on, and the rerun results in one pull request gives both me and my AI tools a trail to follow later.
The main limitation I still want to tackle is following relationships between roles in different stacks. A successful synth can leave configurations outside the check’s scope. If you use ProofGate on your app, start by looking at how the roles and protected bucket appear in the synthesized templates.
The demo shows what ProofGate reads and which permission changes the result, all without deploying to AWS. If you run into a construct it can’t read or a finding that’s hard to understand, I’d love to hear about it. Please share what you can in a GitHub issue.
This was my first time writing a CDK plugin, and there was a lot more to think about than I expected. I still have plenty to learn about Lean and formal veri...


