Skip to content

fix(authz): report the denial code the service's wire protocol uses (#595) - #601

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/595-access-denied-code
Aug 9, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/595-access-denied-code

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #595

Why

The generic authorization gate returned AccessDeniedException for every service, while #593's trust-policy gate returned the bare AccessDenied AWS actually sends for STS. Substrate therefore answered one conceptual outcome with two different codes depending on which gate refused, and a consumer matching on the code got a denial it could not identify — the case IaC error handling is most likely to branch on.

The audit, and what it does and does not settle

Posted in full on #595, including a correction to my first pass. Run across every botocore model, deduplicated by service (botocore ships many versioned models per service, so counting files inflates the XML side nineteen-fold) and restricted to shapes carrying "exception": true:

family services bare AccessDenied AccessDeniedException
XML (query 17, rest-xml 4, ec2 1) 22 1 (cloudfront) 0
JSON (json 149, rest-json 242, cbor 2) 393 0 233
  • The JSON arm is settled by the models: all 233 services that declare the shape use the suffixed form, none the bare one.
  • The XML arm is not. Only CloudFront declares it at all, so n=1. What decides it instead is that no query-protocol service models an access-denied shape — all 17, STS and IAM and CloudFormation among them — and neither do S3 or EC2, which declare no exception shapes whatsoever. Every service where this code is observable in substrate is in that set, so the value is observed AWS behaviour, not modelled: AWS's own CLI output for a refused sts:AssumeRole (quoted in STS: identity-policy denials report AccessDeniedException where AWS sends AccessDenied #595), and what s3_publicaccess.go:22-35 already documents for S3.

Keying on wire protocol rather than on a hand-maintained per-service table means a newly registered plugin inherits the right code from its existing classification, with no second table to keep in step. TestAccessDeniedCode_MatchesTheServiceErrorProtocol asserts that property over every registered service rather than over a sample, so a plugin added later is covered without anyone remembering to extend a list.

The IAM plugin's own gate is fixed with it

IAMPlugin.authorize is a separate gate and built its ~40 denials from a hardcoded AccessDeniedException. Fixing only AuthController would have left substrate reporting two codes for one service — this issue's complaint restated one level down. IAM speaks the query protocol, so its denials are now bare too, routed through a named constant that a test pins against what accessDeniedCodeFor derives for "iam".

Blast radius

cfn_deployer.go surfaces a CheckAccess denial as a resource's Error, and #501 renders that as a StackEvent ResourceStatusReason — so the denial text in CloudFormation stack events and DescribeStackResources changes. Those 12 assertions, and the docs in docs/services.md and docs/testing-guide.md that quoted the old code (including a paragraph that explicitly documented the two-code behaviour as correct), are updated in this same commit.

Tests

Four new, plus the two-gate agreement test #595 asks for by name: an identity denial and a trust-policy denial on the same role must report one code, so they cannot drift apart again. It asserts they are equal and that the shared value is AccessDenied, so agreeing on the wrong code would not satisfy it.

Verification

gofmt · go build · go vet · golangci-lint run ./... → 0 issues · make test (race) · make docs-reference-check docs-versions · go test -C test/e2e ./... · npm --prefix docs run build.

Live server with the AWS CLI (AWS_MAX_ATTEMPTS=1), confirming the split reaches a real client: STS → AccessDenied, IAM → AccessDenied, SQS → AccessDeniedException, DynamoDB → AccessDeniedException; and all three gates (identity, trust-policy, IAM-plugin) reporting AccessDenied on XML services with the message distinguishing which one refused.

Mutation testing — 6 mutants, all CAUGHT, tree verified clean after each restore:

mutation verdict
protocol→code mapping inverted CAUGHT
boundary denial site left on the old literal CAUGHT
policy-decision denial site left on the old literal CAUGHT
IAM plugin constant reverted to the suffixed form CAUGHT
errProtoS3XML dropped from the XML arm CAUGHT
contentType ignored in the fallback CAUGHT

One note on method: the boundary-site mutant first read SURVIVED under a -run 'Authz|…' filter that does not match TestAuthController_*. Re-run against the whole package it is caught by TestAuthController_PermissionBoundary_Deny. The filter was the defect, not the coverage; all six verdicts above are from full-package runs.

…595)

The generic authorization gate returned AccessDeniedException for every
service, while #593's trust-policy gate returned the bare AccessDenied AWS
actually sends for STS. Two gates therefore reported two different codes for
one conceptual outcome, and a consumer matching on the code got a denial it
could not identify — the case IaC error handling is most likely to branch on.

Audited across every botocore model, deduplicated by service (botocore ships
many versioned models per service, so counting files inflates the XML side
nineteen-fold) and restricted to shapes carrying "exception": true. The JSON
side is unanimous: all 233 services that model the shape use the suffixed
form, none the bare one. The XML side is not settled by the models at all —
only CloudFront declares the shape, and no query-protocol service declares
one, nor do S3 or EC2. Every service where this code is observable in
substrate is in that set, so the XML value is observed AWS behavior: the CLI
output for a refused sts:AssumeRole quoted in #595, and what
s3_publicaccess.go already documents for S3.

Keying on protocol rather than on a per-service table means a newly
registered plugin gets the right code from its existing classification, with
no second table to keep in step. A test asserts that property over every
registered service rather than over a sample, and the two-gate agreement test
#595 asks for pins that an identity denial and a trust-policy denial cannot
drift apart again.

The IAM plugin's own gate is fixed with it: it runs a separate authorize()
and built its ~40 denials from a hardcoded literal, so fixing only the
controller would have left substrate reporting two codes for one service —
this issue's complaint restated one level down. IAM speaks the query
protocol, so its denials are bare too.

Because cfn_deployer surfaces a denial as a resource's error and #501 renders
that as a StackEvent ResourceStatusReason, the denial text in stack events
and DescribeStackResources changes with it; those assertions and the docs
that quoted the old code are updated in the same commit.
@scttfrdmn
scttfrdmn merged commit 433ed81 into main Aug 9, 2026
15 checks passed
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 22.00000% with 39 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_plugin.go 5.00% 38 Missing ⚠️
emulator/error_protocol.go 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn deleted the fix/595-access-denied-code branch August 9, 2026 17:48
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.

STS: identity-policy denials report AccessDeniedException where AWS sends AccessDenied

1 participant