Skip to content

feat(iam): every condition operator AWS documents, and a producer for the keys they need (#714) - #729

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/714-condition-operators
Aug 22, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/714-condition-operators

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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:CreateTags example) 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, and
docs/services.md gained the operator reference it never had.

Four bugs in the operators that were already there

  • A set qualifier over an absent key granted the statement. ForAllValues:/ForAnyValue:
    returned true without consulting the operator at all, so an Allow written with an
    operator 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.
  • ArnNotEquals compared with ==. No real ARN is byte-equal to a pattern containing
    *, so the negation was always satisfied: a Deny so written fired against the very
    principals its wildcard exempted, and an Allow so written granted everyone.
  • An ARN wildcard crossed a colon. One globMatch ran over the whole string, so
    arn:aws:sns:*:topic matched a five-component ARN whose account it never named. AWS: "Each
    of the six colon-delimited components of the ARN is checked separately."
  • Unquoted numbers and Booleans were refused. The IAM grammar declares them 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, whose whole job is to see it.

Producers

An operator is only as useful as the keys it can compare.

AuthController gained an optional TimeController (WithAuthTimeController), so
aws:CurrentTime/aws:EpochTime are real and replay-safe — read once per request, and
deliberately not reqCtx.Timestamp, which is time.Now() on the HTTP path. Without a
clock both keys stay absent rather than falling back to wall time: a documented false deny in
exchange for a replayable one.

aws:PrincipalArn is 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 — satisfied
by every caller, so the Deny fired on carol herself. aws:PrincipalAccount, aws:userid and
aws:username stay absent: each needs a derivation substrate cannot make honestly for every
principal kind.

Corrections to the issue

  • "an unimplemented operator falls to the closing deny-by-default (safe)" — false in the
    dangerous direction
    , per the first bug above.
  • "ArnLike is aliased to ArnEquals, which AWS documents as distinct" — refuted. AWS:
    "The ArnEquals and ArnLike condition operators behave identically." The alias is correct;
    the == is the bug.
  • The operator list omitted StringEqualsIgnoreCase/StringNotEqualsIgnoreCase and the
    unquoted-value grammar.
  • ForAllValues over an absent key is a match per AWS ("returns true if there are no
    context 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 bare
IPv6 address is a /128 (AWS's "/32" sentence is written for IPv4; taking it literally would
turn one address into 2^96). Go's spellings of infinity, NaN and hexadecimal floats are not
numbers. ForAnyValue:<operator>IfExists is 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-qualified Null does not match at all. An
operator substrate does not recognize denies — real IAM answers MalformedPolicyDocument at
write time and substrate does not validate operator names at all.

Verification

  • gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... → 0 issues
  • make test (race, -count=1) green; make coverage 82.6% total, emulator 83.3%
  • make docs-reference docs-reference-check docs-versions; npm --prefix docs run build plus
    an href="#…" vs id="…" diff over dist/services.html — no dangling anchors
  • go vet -C test/e2e ./... && go test -C test/e2e ./... green
  • Mutation testing: 26 mutations, one decision each, all caught. Two survivors along the
    way each exposed a real gap — the hex-float guard's actual job, and ForAnyValue's operator
    check being load-bearing only for a present-key Null — and both are now pinned.
  • Live SDK run against a built binary (aws CLI, AWS_MAX_ATTEMPTS=1): 31 probes over all
    seven areas, including the aws:PrincipalArn inversion this PR then fixed.

Closes #714

… 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
@scttfrdmn
scttfrdmn merged commit 8ac1e76 into main Aug 22, 2026
15 checks passed
@scttfrdmn
scttfrdmn deleted the feat/714-condition-operators branch August 22, 2026 05:18
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.46835% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/substrate/main.go 0.00% 2 Missing ⚠️
emulator/authz.go 92.85% 1 Missing and 1 partial ⚠️
emulator/iam_types.go 92.30% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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: the condition operator families substrate does not implement are discarded, not refused — ...IfExists, ArnNotLike, numeric, date, IpAddress

1 participant