Repository navigation
feat(iam): every condition operator AWS documents, and a producer for the keys they need (#714) - #729
Merged
Merged
Conversation
… the keys they need (#714) Nine of AWS's twenty-six condition operators were implemented. The numeric family, the date family, the IP family, BinaryEquals, StringEqualsIgnoreCase / StringNotEqualsIgnoreCase and the ...IfExists suffix all fell through to a deny, so a policy real IAM accepts and evaluates was at best a false refusal here. The operator layer now lives in one place, emulator/iam_condition_operators.go. Four bugs in the operators that were already there: - Under ForAllValues:/ForAnyValue: an absent key returned true without consulting the operator at all, so an Allow written with an operator substrate could not evaluate -- or a misspelled one, which nothing rejects at write time -- was granted. That is a live false allow, and given how few keys have producers it was the common case. - ArnNotEquals compared with ==, so the negation was satisfied by every ARN that was not byte-equal to the pattern. A Deny so written fired against the principals its wildcard exempted; an Allow so written granted everyone. - ARN matching ran one glob over the whole string, letting a * cross a colon: arn:aws:sns:*:topic matched a five-component ARN whose account it never named. AWS compares each of the six components separately. - StringOrSlice.UnmarshalJSON rejected unquoted numbers and Booleans, which the IAM grammar declares legal ("Quotation marks are optional for numeric and Boolean values"), so {"Bool": {"aws:SecureTransport": false}} got MalformedPolicyDocument. Two rules substrate never had, both AWS's: an absent key follows the operator's polarity (negated operators answer true), and a key present with an empty value counts as absent everywhere except Null. Producers, because an operator is only as useful as the keys it can compare. AuthController gained an optional TimeController, so aws:CurrentTime and aws:EpochTime are real and replay-safe -- deliberately not reqCtx.Timestamp, which is time.Now() on the HTTP path. aws:PrincipalArn is now written at all four enforcement gates rather than in the simulator alone; a live SDK run showed that without it, this change's own absent-key rule turned an ArnNotEquals exemption into its opposite. Provenance for the readings AWS does not document is in CHANGELOG.md and docs/services.md, which gained the operator reference it never had. Closes #714
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.
Nine of AWS's twenty-six condition operators were implemented. The numeric family, the date
family, the IP family,
BinaryEquals,StringEqualsIgnoreCase/StringNotEqualsIgnoreCase(which AWS uses in its own
ec2:CreateTagsexample) and the...IfExistssuffix all fellthrough to a deny, so a policy real IAM accepts and evaluates was at best a false refusal
here. The operator layer now lives in one place,
emulator/iam_condition_operators.go, anddocs/services.mdgained the operator reference it never had.Four bugs in the operators that were already there
ForAllValues:/ForAnyValue:returned
truewithout consulting the operator at all, so anAllowwritten with anoperator substrate cannot evaluate — or a misspelled one, which nothing rejects at write
time — was granted. iam: the condition operator families substrate does not implement are discarded, not refused — ...IfExists, ArnNotLike, numeric, date, IpAddress #714 called this "safe"; it is the opposite, and given how few keys
have producers it was the common case.
ArnNotEqualscompared with==. No real ARN is byte-equal to a pattern containing*, so the negation was always satisfied: aDenyso written fired against the veryprincipals its wildcard exempted, and an
Allowso written granted everyone.globMatchran over the whole string, soarn:aws:sns:*:topicmatched a five-component ARN whose account it never named. AWS: "Eachof the six colon-delimited components of the ARN is checked separately."
("Quotation marks are optional for numeric and Boolean values"), so
{"Bool": {"aws:SecureTransport": false}}gotMalformedPolicyDocument.Two rules substrate never had, both AWS's: an absent key follows the operator's polarity
(negated operators answer
true), and a key present with an empty value counts as absent,everywhere except
Null, whose whole job is to see it.Producers
An operator is only as useful as the keys it can compare.
AuthControllergained an optionalTimeController(WithAuthTimeController), soaws:CurrentTime/aws:EpochTimeare real and replay-safe — read once per request, anddeliberately not
reqCtx.Timestamp, which istime.Now()on the HTTP path. Without aclock both keys stay absent rather than falling back to wall time: a documented false deny in
exchange for a replayable one.
aws:PrincipalArnis now written at all four enforcement gates, not in the simulator alone.That divergence was found by the live SDK run below, and it was not merely cosmetic: with the
key absent, this PR's own absent-key polarity rule made
"ArnNotEquals": {"aws:PrincipalArn": "arn:aws:iam::*:user/carol"}— an exemption — satisfiedby every caller, so the
Denyfired on carol herself.aws:PrincipalAccount,aws:useridandaws:usernamestay absent: each needs a derivation substrate cannot make honestly for everyprincipal kind.
Corrections to the issue
dangerous direction, per the first bug above.
ArnLikeis aliased toArnEquals, which AWS documents as distinct" — refuted. AWS:"The
ArnEqualsandArnLikecondition operators behave identically." The alias is correct;the
==is the bug.StringEqualsIgnoreCase/StringNotEqualsIgnoreCaseand theunquoted-value grammar.
ForAllValuesover an absent key is a match per AWS ("returns true if there are nocontext keys in the request"), so the fix distinguishes recognized from unrecognized
operators rather than making every qualified operator consult its base.
Provenance
AWS documents no answer for these; each is substrate's recorded reading. An unparseable policy
value is skipped; an unparseable context value fails a positive operator and satisfies a
negated one.
"2020"is both a legal W3C year and a legal epoch second — the year wins. A bareIPv6 address is a
/128(AWS's "/32" sentence is written for IPv4; taking it literally wouldturn one address into 2^96). Go's spellings of infinity, NaN and hexadecimal floats are not
numbers.
ForAnyValue:<operator>IfExistsis where AWS's two rules conflict and the suffix wins,on the strength of "Other condition elements … can still result in a nonmatch, but not a
missing key when checked with
...IfExists". A set-qualifiedNulldoes not match at all. Anoperator substrate does not recognize denies — real IAM answers
MalformedPolicyDocumentatwrite time and substrate does not validate operator names at all.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issuesmake test(race,-count=1) green;make coverage82.6% total,emulator83.3%make docs-reference docs-reference-check docs-versions;npm --prefix docs run buildplusan
href="#…"vsid="…"diff overdist/services.html— no dangling anchorsgo vet -C test/e2e ./... && go test -C test/e2e ./...greenway each exposed a real gap — the hex-float guard's actual job, and
ForAnyValue's operatorcheck being load-bearing only for a present-key
Null— and both are now pinned.awsCLI,AWS_MAX_ATTEMPTS=1): 31 probes over allseven areas, including the
aws:PrincipalArninversion this PR then fixed.Closes #714