Repository navigation
feat(iam): evaluate ForAllValues/ForAnyValue, and populate aws:TagKeys (#690) - #703
Merged
Merged
Conversation
#690) Neither set qualifier was parsed anywhere in substrate, so "ForAllValues:StringEquals" reached the operator switch whole, matched none of the nine operators it knows, and fell through to its deny-by-default — the statement was discarded before its condition key was ever looked at. The issue reported this as an unpopulated aws:TagKeys making such a statement allow. It is the opposite, and worse in both directions: an Allow so written was a false deny, including AWS's own documented ec2:DeleteTags examples, and a Deny so written was silently inert, so a guardrail written the way AWS recommends refused nothing. EvaluationRequest gains MultiContext for AWS's multivalued keys, the qualifier is parsed off the operator with AWS's absent-key rules for each, an unrecognized qualifier still does not match, Null consults both maps so AWS's recommended ForAllValues + Null:false pairing works, aws:TagKeys is derived from the aws:RequestTag entries CheckAccess already read, and the simulator keeps every ContextKeyValues value instead of the first.
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 #690
ForAllValues:andForAnyValue:were never parsed anywhere in substrate."ForAllValues:StringEquals"reachedevaluateConditionKeywhole, matched none of the nine operators it knows, and fell through to its// Unknown operator — deny by default. The statement was discarded before its condition key was ever looked at.The issue's premise is inverted, and the truth is worse in both directions. It reported that an unpopulated
aws:TagKeysmade such a statement allow. In fact anAllowso written was a false deny — including all three of AWS's documentedec2:DeleteTagsexample policies, none of which permitted anything — and aDenyso written was silently inert, so a guardrail written the way AWS recommends refused nothing at all. Populatingaws:TagKeysalone would have changed nothing; the qualifier parse is the load-bearing half.What changed
EvaluationRequest.MultiContext map[string][]string, besideContext. Two maps rather than one widened tomap[string][]string, because IAM itself draws that line: a key is single- or multivalued by its nature, "multivalued context keys require a condition set operator", and AWS says outright not to use a set operator on a single-valued key. Keeping them apart leaves all nine existing operators'ctx[key]lookup byte-identical, so adding a multivalued key cannot change a decision that never named one.ForAllValuesis true when every request value satisfies the base operator and true when the key is absent or empty ("It also returnstrueif there are no context keys in the request");ForAnyValueneeds one match and is false when absent or empty ("For no matching context key or if the key does not exist, the condition returnsfalse"). An unrecognized qualifier —ForSomeValues:, a lowercaseforallvalues:— still does not match, which is the deny-by-default an unknown operator already got.Nullconsults both maps. AWS's Important note says to always pairForAllValueswith"Null": {"<key>": "false"}, and all four of itsaws:TagKeysexamples do. Substrate'sNullcompares a single string, so a key carried only inMultiContextread as null — without this the recommended pattern would still deny every request it was written to allow, and the qualifier fix would have looked like it worked while changing nothing for a real policy.aws:TagKeysis populated inCheckAccess, sorted.ContextKeyValues.member.Nvalue instead of the first, andunsetConditionKeysconsultsMultiContextso a key that decided the call is not also reported as missing.Deviation from the plan:
aws:TagKeysis derived, not gatheredThe plan had
addRequestTagsgain the multi map as a parameter and each of its seven service arms populate it. It is instead derived from theaws:RequestTag/<key>entries that function already produces: the keys ofaws:RequestTag/*are the request's tag keys, so one reading of the request covers all seven arms — EC2'sTagSpecification.N.Tag.M.Keyand a directCreateTags/DeleteTags'Tag.N.Key, IAM's and Organizations'Tagslists, Lambda'sTagsmap, Config'sTags, S3'sx-amz-tagging— an arm added later is covered for free, and the two cannot drift into disagreeing about what the request asked for.The sort is load-bearing but unobservable through any API surface. Three of those arms iterate a Go map, whose order is randomized per run, and a
ForAllValuesdecision quantifies over the slice — an unsorted value would make a denial depend on map iteration order, which an event log that must replay identically cannot tolerate. But every operator that reads the key is set-semantic, so reordering changes no decision, and no request can observe it. It is therefore asserted throughRequestTagKeysForTestinexport_test.go, following theS3PersistedContentEncodingForTestprecedent, rather than through a test that pretends an API observes it.Fail-before
Recorded at
main(75fbf6d) in a throwaway worktree, with only the new test file copied in. Two of the new tests cannot be recorded there at all — they exerciserequestTagKeys, which this PR introduces — and the unit-level ones do not compile against aEvaluationRequestwith noMultiContext, so what ran is the two tests that use only pre-existing API:The shape is the inverted premise itself: every row AWS's policy permits fails, and every refusal "passes" because everything was refused.
Regression pinned explicitly
AmazonRDSFullAccessandAmazonRDSReadOnlyAccesseach carry a realForAllValues:StringEqualsoverdevops-guru:ServiceNames, paired withNull: false. Both statements were discarded before this PR.TestIAMManaged_RDSPoliciesStillWithholdDevOpsGuruasserts they still withhold the grant from a request naming no service names (theNullarm refuses it) and now make it when one namesRDS— two bundled policies quietly widening would be the fix escaping its own blast radius.Live run
substrate server --address :4678from a scratch directory, real AWS CLI,AWS_MAX_ATTEMPTS=1, torn down withlsof -ti:4678 | xargs kill. AWS's "may only apply approved tags" policy (ForAllValues:StringEqualsoveraws:TagKeys+Null: false):run-instancestaggingDepartmenti-045a59b0fa812e9f— a false deny before this PREnvironmentAccessDeniedonec2:RunInstancesAccessDenied— theNull: falsearm, per AWS's notecreate-tags Key=CostCentercreate-tags Key=EnvironmentAccessDeniedonec2:CreateTagsdelete-tags Key=CostCenter(no value)ForAnyValueDeny onSecret, then taggingSecretAccessDenied— the inert guardrail now firesDepartmentsimulate-custom-policy,ContextKeyValues=Department,CostCenterallowed, no missing context valuesDepartment,EnvironmentimplicitDeny— the second value is evaluated, not discardedMutation testing
Nine mutants, anchor count asserted
== 1over the whole file,gofmt -w && go vetso a non-compiling mutant is BROKEN rather than a result, full-packagego test -race -count=1 ./emulator/plusgo test -C test/e2e ./...with no-runfilter, restore verified byte-for-byte.ForAllValuesis false on an absent or empty keyForAnyValueis true on an absent or empty keyNullignoresMultiContextunsetConditionKeysignoresMultiContextaws:TagKeyssort is droppedCheckAccessdoes not populateaws:TagKeysContextKeyValuesvalueThe survivor is disclosed because it found a real hole in the test, not in the code.
MissingContextValuesis gathered only for a statement ruled out by its condition, so the assertion I had written — on an allowed request — never reached that code at all. The case a caller actually meets is a refusal: a policy that listsDepartmentand a request namingEnvironmentis denied, and reportingaws:TagKeysas a missing context value there would send the caller looking for the wrong bug when the value it supplied is precisely why the call failed. That assertion was added and the mutant re-run: KILLED.Compatibility
A previously-inert
Denywill start firing, and a previously-deniedAllowmay start permitting. Both are visible to any consumer using AWS's documented tag-scoped policies. Two bundled managed policies newly grantdevops-guru:SearchInsightsto a request namingServiceNames=RDS— which is what their real documents say.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...(0 issues),make test(race),make coverage(82.9% onemulator),make docs-reference-check,make docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...andgo test -C test/e2e ./...all green.Docs
A new
### Multivalued condition keys: ForAllValues and ForAnyValuesection in the IAM chapter: the per-qualifier table including both absent-key rules, AWS'sNullpairing with the JSON it recommends, the note that the same vacuity bites aDenythe other way, which keys are multivalued and where each is populated from, why the value is sorted, and the one authorization path (iam:actions inside the IAM plugin) that populates neither map. The EC2 authorization chapter's "Not covered —aws:TagKeys" bullet is replaced by a pointer to it; the secondec2:CreateTagspass stays listed as not covered, since that is #691.