Skip to content

feat(iam): a tool can ask before it acts (#579) - #644

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/iam-simulate
Aug 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/iam-simulate

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #579

SimulatePrincipalPolicy and SimulateCustomPolicy are the only AWS APIs that decide
whether a principal may do X to Y without doing X to Y, and neither was implemented. So
the one code path in a consumer that decides whether to proceed at all was the one path
with no emulator coverage. iam_managed.go already granted iam:SimulatePrincipalPolicy
and iam:SimulateCustomPolicy in its bundled policies, so substrate advertised permission
for operations that answered InvalidAction.

One evaluator, not two

Both operations run the same evaluator the request gate enforces with. Evaluate
already implemented the IAM algorithm and already produced exactly the three outcomes the
API reports, so this exposes existing evaluation over the wire rather than writing a second
one. That is the property worth having, and it is tested directly: one user, one policy and
two actions go through the simulator and through the enforced path, and the decisions must
agree. A simulated decision that could disagree with an enforced one would be worse than no
simulator at all, because a consumer would trust the preflight and then be refused.

The three-way distinction is the feature

allowed, explicitDeny and implicitDeny are reported separately. Collapsing them would
look like coverage while telling a consumer the wrong thing: an assertion that "the policy
explicitly forbids this" would pass on what is really a missing grant. The decisive test
puts a group managed allow, an inline deny and an ungranted action in one response, so
a handler returning a uniform answer fails.

What the response reports

  • MatchedStatements gained the AWS Statement shape (SourcePolicyId,
    SourcePolicyType), so a caller learns which policy decided — the whole output of a
    simulation. Evaluate therefore had to learn a document's provenance:
    SourcedPolicyDocument + EvaluateSourced carry it, and Evaluate delegates with its
    signature untouched for authz.go, sts_plugin.go and 737 lines of existing tests.
  • MissingContextValues names every condition key a matching-but-for-the-condition
    statement tested and the request had no value for. Without it a conditional grant reads
    as a clean implicitDeny with no indication the answer would change. A key present with
    an empty value is set, not missing — the Null operator exists to test absence.
  • A permissions boundary that does not allow flips an allowed to an implicit deny and
    reports AllowedByPermissionsBoundary=false; a boundary caps what is reachable rather
    than denying by name, and an identity policy's explicit deny stays explicit. A supplied
    boundary replaces the entity's stored one, per the reference.
  • CallerArn defaults to PolicySourceArn and populates aws:PrincipalArn;
    ResourceOwner populates aws:ResourceAccount; an explicit ContextEntry wins over
    both. ResourceArns defaults to ["*"], every action is evaluated against every
    resource, MaxItems defaults to 100 (valid 1–1000).

Deliberately not evaluated

Stated in the code and owed to docs/services.md in the docs PR, rather than faked:

  • SCPs. Organizations stores them and CheckAccess never consults them either, so
    simulating them would report a bound substrate does not enforce.
    OrganizationsDecisionDetail is therefore absent rather than present-and-false — a
    test asserts its absence, because present-and-false is a claim.
  • StartPosition/EndPosition. Offsets into the document as submitted; substrate
    stores a parsed PolicyDocument, so any offset would be fabricated.
  • ResourceHandlingOption, PolicyExclusionList, EvalDecisionDetails,
    ResourceSpecificResults
    — cross-account constructs.
  • An attached AWS managed policy substrate does not bundle contributes no statements rather
    than a guess, and does not fail the simulation.

Correction to the issue

There is no 25-action cap. #579 asserted one; no action-count limit appears in the API
reference or the model, and modelling it would refuse requests AWS accepts. A test drives
30 actions through one call and expects 30 answers on one page — which also pins MaxItems'
default at 100 rather than 25.

Provenance

SourcePolicyType emits IAM Policy / Resource Policy, from the reference's sample
responses
, which diverge from the model's PolicySourceType enum
(user/group/role/aws-managed/user-managed/resource/none). The doc values are
what an SDK actually receives, so those are what substrate emits; the divergence is
commented at the constants. SourcePolicyId being a policy name rather than an ARN comes
from the same samples.

Verification

SimulatePrincipalPolicy and SimulateCustomPolicy are the only AWS APIs that
decide whether a principal may do X to Y without doing X to Y, and neither
existed — so the one code path in a consumer that decides whether to proceed at
all was the one path with no emulator coverage. iam_managed.go already granted
iam:Simulate* in its bundled policies, so substrate advertised permission for
operations that answered InvalidAction.

Both run the same evaluator the request gate enforces with. Evaluate already
implemented the IAM algorithm and already produced the three outcomes the API
reports, so this exposes existing evaluation over the wire rather than writing a
second one: a simulated decision that could disagree with an enforced one would
be worse than no simulator, because a consumer would trust the preflight and
then be refused.

MatchedStatements gained the AWS Statement shape, so SourcedPolicyDocument and
EvaluateSourced carry a document's provenance and Evaluate delegates to them
with its signature untouched. MissingContextValues stops a conditional grant
reading as a clean implicitDeny. A boundary that does not allow flips an allowed
to an *implicit* deny and reports the detail element; an explicit deny stays
explicit.

Not evaluated, and documented rather than faked: SCPs (CheckAccess does not
consult them either, so OrganizationsDecisionDetail is absent rather than
present-and-false), statement positions (substrate stores parsed documents, so
any offset would be fabricated), and the cross-account members.

There is no 25-action cap — the issue asserted one, and neither the reference
nor the model has any action-count limit.
@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.30084% with 42 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_simulate.go 86.88% 20 Missing and 20 partials ⚠️
emulator/iam_eval.go 96.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 2fc9a5b into main Aug 15, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the feat/iam-simulate branch August 15, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IAM: SimulatePrincipalPolicy and SimulateCustomPolicy are unimplemented, so no tool can test its own permission preflight

1 participant