Repository navigation
feat(iam): a tool can ask before it acts (#579) - #644
Merged
Merged
Conversation
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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Closes #579
SimulatePrincipalPolicyandSimulateCustomPolicyare the only AWS APIs that decidewhether 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.goalready grantediam:SimulatePrincipalPolicyand
iam:SimulateCustomPolicyin its bundled policies, so substrate advertised permissionfor operations that answered
InvalidAction.One evaluator, not two
Both operations run the same evaluator the request gate enforces with.
Evaluatealready 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,explicitDenyandimplicitDenyare reported separately. Collapsing them wouldlook 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
MatchedStatementsgained the AWSStatementshape (SourcePolicyId,SourcePolicyType), so a caller learns which policy decided — the whole output of asimulation.
Evaluatetherefore had to learn a document's provenance:SourcedPolicyDocument+EvaluateSourcedcarry it, andEvaluatedelegates with itssignature untouched for
authz.go,sts_plugin.goand 737 lines of existing tests.MissingContextValuesnames every condition key a matching-but-for-the-conditionstatement tested and the request had no value for. Without it a conditional grant reads
as a clean
implicitDenywith no indication the answer would change. A key present withan empty value is set, not missing — the
Nulloperator exists to test absence.allowedto an implicit deny andreports
AllowedByPermissionsBoundary=false; a boundary caps what is reachable ratherthan denying by name, and an identity policy's explicit deny stays explicit. A supplied
boundary replaces the entity's stored one, per the reference.
CallerArndefaults toPolicySourceArnand populatesaws:PrincipalArn;ResourceOwnerpopulatesaws:ResourceAccount; an explicitContextEntrywins overboth.
ResourceArnsdefaults to["*"], every action is evaluated against everyresource,
MaxItemsdefaults to 100 (valid 1–1000).Deliberately not evaluated
Stated in the code and owed to
docs/services.mdin the docs PR, rather than faked:CheckAccessnever consults them either, sosimulating them would report a bound substrate does not enforce.
OrganizationsDecisionDetailis therefore absent rather than present-and-false — atest asserts its absence, because present-and-false is a claim.
StartPosition/EndPosition. Offsets into the document as submitted; substratestores a parsed
PolicyDocument, so any offset would be fabricated.ResourceHandlingOption,PolicyExclusionList,EvalDecisionDetails,ResourceSpecificResults— cross-account constructs.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
SourcePolicyTypeemitsIAM Policy/Resource Policy, from the reference's sampleresponses, which diverge from the model's
PolicySourceTypeenum(
user/group/role/aws-managed/user-managed/resource/none). The doc values arewhat an SDK actually receives, so those are what substrate emits; the divergence is
commented at the constants.
SourcePolicyIdbeing a policy name rather than an ARN comesfrom the same samples.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...— 0 issuesmake test(race) green;emulatorcoverage 82.5%, every function iniam_simulate.go≥81%TestSimulateWire_OverTheQueryProtocolposts a genuine urlencoded form body, since everyparameter these operations take is a
.member.Nlist andMaxItemsarrives as astring — the IAM query-protocol list parameters never reach a handler, so TagUser/UntagUser/TagRole/UntagRole silently discard what an SDK sends #639/IAM MaxItems and MaxSessionDuration are rejected over the wire: a query-protocol integer arrives as a string #642 shapes. An unroutable operation (Service Quotas: the increase-history operation is unreachable from any SDK #636) is caught here too.
ContextEntries.member.1.ContextKeyValues.member.1has no JSON-body form at all, so thenested-member tests are form-body only.