agentleFS
aws-solutions-library-samplesaws-solutions-library-samples/accelerated-intelligent-document-processing-on-aws/.claude/skills/api-rbac-test/SKILL.md

api-rbac-test

Skill329 starsChanged 6 days agoMIT-0View on GitHub

Use when verifying API authorization (Cognito groups and configuration-version scope) with make api-test or make api-test-static, or when adding a new API operation.

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 3 are distinctive, and 11 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 11

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill to verify that every UI API operation is correctly protected by (a) its required Cognito group(s) and (b) config-version …

    line 8
  2. Very specific:

    The response says which layer produced it: every 403 carries errors[0].authzControl — api-group-floor, resource, resolver or …

    line 105
  3. Very specific:

    Use residual_gap when part of a route's authorization is genuinely impossible on the transport but the rest must still be enforced.

    line 178
  4. Very specific:

    MUST add an entry to scripts/api_rbac_expectations.yaml (and the schema), then regenerate the manifest.

    line 193
  5. Very specific:

    Test users get a random per-run password (printed when NO_TEARDOWN or --setup-only keeps them alive).

    line 248
  6. Very specific:

    Every check records one of these.

    line 338
  7. Very specific:

    Then: which control refused?: Read authzControl in the report's

    line 394
  8. Very specific:

    In-band denial not recognized?: If the op denies via {success:false, error:{type:Unauthorized}} (200), confirm classify()/_denied() treat …

    line 400
  9. Very specific:

    Expectation wrong?: Read the enforced_in file and confirm the actual server-side group set.

    line 403
  10. Very specific:

    Allowed role denied on a NEW op?: Look for Denied <field>: no required-groups entry in the dispatcher log — the operation's groups were …

    line 408
  11. Distinctive:

    Real leak / fail-open?: If a scoped/lower-privilege caller is ALLOWED, check the actual group gate.

    line 413
  12. Distinctive:

    Add the resolver's server-side group/scope check.

    line 428
  13. Very specific:

    Add the @aws_cognito_user_pools directive in schema.graphql.

    line 429
  14. Very specific:

    If the op is also reachable off the REST route (a Function URL route, a direct lambda:InvokeFunction path), put the group check in the …

    line 453

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API RBAC Test — GenAI IDP Accelerator

Use this skill to verify that every UI API operation is correctly protected by (a) its required Cognito group(s) and (b) config-version scope, using two complementary layers that share one source of truth:

  1. Static scan (make api-test-static) — no AWS, CI-safe. Cross-checks the op universe, the schema directives, and the expectations file for drift and missing server-side checks.
  2. Dynamic tests (make api-test STACK_NAME=<stack>) — spins up temporary Cognito users (one per group + a config-version-scoped Author + a second independent user for IDOR), calls every op as every role + unauthenticated + with malformed tokens against a deployed stack, PLUS the mandatory security-focused suites below, and writes an auditable report.

The dynamic harness has already caught a real, shipping vulnerability (config-version scope silently failing open because a resolver was missing a dynamodb:Query IAM grant). Treat a hard fail as real until proven otherwise.

⚠️ "Every operation" is true of the group check, not of the scope check. The dynamic scope suite calls, with the scoped token, getConfigVersion, getConfigVersions and the three discovery operations in SCOPED_DISCOVERY_CELLS (startMultiDocDiscovery, uploadMultiDocDiscoveryZip, uploadDiscoveryDocument), each naming the out-of-scope profile and each built so that no job starts whatever the stack answers. No other scope-enforcing operation is exercised live. Ops marked skip_allowed: in the expectations file are called only in their denied role, because an allowed-role call would start real work — sendChatDocumentMessage starts a chat turn — so their scope enforcement is not reached here and is covered by that component's own unit suite instead. The static scan's S4 reads the code each operation can reach: it asserts that code refers to the caller's config-version scope, and, for a scope_filtered operation, that it applies a per-item scope predicate bottoming out at scope_allows to what it returns, following calls into idp_common. It is a structural check, not dataflow: a broken scope lookup still passes it. Neither layer would have caught issue #970, where the lookup named a DynamoDB index no template declares.

S10 is what makes an operation declare a scope in the first place: any operation whose arguments name a profile, a stored object or a session (read from the words of the argument name) must carry scope_checked, scope_filtered, document_scope_checked, testset_checked or ownership (by argument kind), be callable only by Admin/IAM, or have a known_gap or a SCOPE_KEYED_ARGUMENT_EXEMPT entry. Adding an operation that takes configVersion, objectKey or sessionId? Declare its scope, or S10 fails.

Mandatory security-focused test cases (AppSec checklist)

make api-test covers the AppSec "Minimum Mandatory Security Focused Test Cases for APIs" checklist. Mapping (suite → checklist item), implemented in scripts/api_security_cases.py:

#Checklist itemWhere
1Unauthenticated access deniedrun_group_matrix (unauth cell) + run_token_negatives
2 / 2.2Authorization matrix, negative + positive; role X not authorized for API Yrun_group_matrix (every op × every role)
2.1IDOR — User A's data unreachable by User Brun_idor_suite (chat session ownership); run_inbox_idor_suite (Inbox ownership: another user's message id is not listed, marked or deleted)
2.1Caller-supplied resource reference bounded to the deployment and the caller's config scoperun_caller_supplied_ref_suite — getStepFunctionExecution must refuse an ARN naming another state machine, still serve this deployment's own, and refuse a config-scoped caller an out-of-scope execution. Needs a processed document, else all three SKIP (see below)
2.3Tokens rejected after expiryrun_token_lifecycle_suite (+ token negatives); real-expiry wait via IDP_SECTEST_WAIT_EXPIRY=<seconds>
2.4Tokens revoked after logoutrun_token_lifecycle_suite — global sign-out then re-test; stateless-JWT reuse is a documented gap (GAP-SEC-LOGOUT, WARN — see AUTH.T10)
2.5Deleted resources no longer accessiblerun_deleted_resource_suite (config version create→delete→read-gone)
3Input validation (invalid input rejected)run_input_validation_suite — only a clean 4xx is ever a PASS. By default a 5xx or a silent 200 is recorded against GAP-SEC-INPUT, i.e. a WARN: visible, not blocking, not a pass. IDP_SECTEST_STRICT_INPUT=true drops the gap so the same result is a hard failure
4TLS 1.0/1.1/HTTP refused, TLS 1.2+ acceptedrun_tls_suite (raw-socket protocol probes)

Notes:

  • The AppSec engineer may request additional tests per use case — this is the floor, not the ceiling.
  • Suites that need conditions not present are recorded as SKIP, never silent omissions (e.g. expiry without IDP_SECTEST_WAIT_EXPIRY). A SKIP is not a pass — see the outcome vocabulary below.
  • Threat-model coverage: AUTH.T09 (IDOR), AUTH.T10 (token lifecycle), AUTH.T11 (TLS), AUTH.T13 (IdP group-claim provenance) in security/threat-modeling/feature-threats/rbac-authentication.md.
  • Process a document on the stack before running this, or the three SEC-2.1-CALLER-SUPPLIED-REF checks record SKIP. They need a real execution ARN, which the harness resolves via listDocuments -> getDocument — the list projection does not carry WorkflowExecutionArn. apply_dynamic_args also substitutes that ARN into getStepFunctionExecution's matrix args, because the placeholder ARN in the expectations file is (correctly) refused now, and every one of the four roles the matrix drives is an allowed role for that op (it is ANY_GROUP), so the matrix reads any refusal as a failure.
  • The Cognito pre-token IdP group-mapping trigger is NOT covered here — it is not an API operation. See .claude/skills/live-auth-checks/SKILL.md.

The architecture you are testing (read this first)

  • Single route: the UI calls POST /op/{field} on an API Gateway REST API (logical id HttpApiDispatcher). The Cognito authorizer only authenticates (401 for missing/bad token); it does no group checks.
  • The dispatcher denies by default (http_api_dispatcher/authz.py): before routing, it checks the caller's groups (from the verified JWT claim, never the body) against api_rbac_manifest.json, and a field with no entry there is 403 — unmapped means denied. The manifest is generated from scripts/api_rbac_expectations.yaml by scripts/sdlc/generate_api_rbac_manifest.py; it fails closed if unreadable. So an operation whose groups were never declared is closed, not open.
  • Per-resolver RBAC: each resolver Lambda also reads identity.claims['cognito:groups'] and raises PermissionError → the dispatcher maps that to HTTP 403 with errorType: "Unauthorized". This layer stays: the dispatcher enforces the field-level floor, the resolver enforces per-object scope (config version, test set, ownership) on top of it. The response says which layer produced it: every 403 carries errors[0].authzControl — api-group-floor, resource, resolver or unverified-identity. See "A 403 is two different verdicts" below; the logs (Denied <field>: ... in authz.py, the resolver's own message) are the second stop, not the first.
  • Config-version scope denials are IN-BAND: the configuration & sync resolvers return {success:false, error:{type:"Unauthorized"}} with HTTP 200 (NOT a 403). The harness treats an in-band Unauthorized as a denial.
  • 5 groups (precedence): Admin(0) > Author(1) > Reviewer(2) > Annotator(3) > Viewer(4), defined in template.yaml. That template is where the group vocabulary lives — generate_api_rbac_manifest.py reads it to resolve ANY_GROUP and to reject a group name no AWS::Cognito::UserPoolGroup creates. ⚠️ make api-test's live matrix drives four of them (ROLES in scripts/test_api_rbac.py) — Annotator is not one — and it creates no groupless user. 28 operations are declared ANY_GROUP today, and "denied to a caller in no group" — the whole point of that policy — is asserted offline only, in test_http_api_dispatcher_authz.py. The mechanism is live-proven: step 4 of the chain measured in #1033 saw a real groupless token get 403 with the group-floor message from getFileContents and getFilePresignedUrl. What is missing is that assertion as a repeatable gate over every operation — tracked in #1065.
  • @aws_auth(cognito_groups) is SILENTLY IGNORED on this multi-auth API (it also allows AWS_IAM). Only @aws_cognito_user_pools(...) directives and server-side checks are real. Server-side enforcement is the source of truth; the schema directive is defense-in-depth.
  • IAM_ONLY ops (updateAgentJobStatus, updateDiscoveryJobStatus) must reject every Cognito caller.

The REST route is NOT the only entry path (Function URLs — S6..S9)

Chat streaming is served by a Lambda Function URL (AuthType=AWS_IAM, InvokeMode=RESPONSE_STREAM; ChatStreamProcessorUrl in template.yaml) whose FastAPI app (src/lambda/chat_stream_processor/app.py) drives the chat processors directly — no dispatcher, no resolver. Consequences:

  • An op reachable both ways must enforce its group check in the component that does the work (e.g. src/lambda/agent_chat_processor/index.py), not only in the resolver in front of it. A resolver-only check is enforced on one path.
  • That transport authenticates but carries no cognito:groups: requestContext.authorizer.iam.cognitoIdentity is documented as unused by Function URLs, and the assumed-role session name under the Identity Pool enhanced flow is a pool-wide constant. So there is nothing verified to gate on there; the residual difference is GAP-07 / AUTH.T14.
  • A request-body callerSub is a fallback only — the transport-verified principal wins, and a body value that contradicts it is refused (403), not silently preferred. Both routes go through one helper so they cannot drift. It is nonetheless the effective identity on this transport, because the verified value is that pool-wide constant, so it must not be used as an authorization key. Both processors read identity for that instead, and this route can only report it as None.
  • allowedConfigVersions is therefore not enforced on POST /chat/document. The processor resolves the caller from verified claims and denies a turn whose scope it cannot evaluate; with no claims to resolve from, it stands the check down and logs that it did so once per turn rather than appearing to have consulted the UsersTable. The REST path through the dispatcher does enforce it. Both halves of GAP-07 close when this endpoint verifies a Cognito ID token — and the claims it then returns must include email, which is the only identifier that joins a Cognito principal to a UsersTable row.

Declare every Function URL and route in the function_url_endpoints: section of scripts/api_rbac_expectations.yaml. The scanner's Function-URL checks:

CheckFails when
S6a AWS::Lambda::Url in template.yaml, or a route in its handler, is not declared (or a declared route no longer exists)
S7a route reads a client-supplied identity before the transport-verified one
S8no function in the handler package refuses a contradicting client identity (names the verified value, compares !=, and rejects)
S9the handler named by enforced_in has no group check for the route's groups, or its group list disagrees with the equivalent_op's

⚠️ known_gap: downgrades a finding to WARN; residual_gap: does not — it records the gap in the register for auditability while leaving the checks armed. Use residual_gap when part of a route's authorization is genuinely impossible on the transport but the rest must still be enforced. scripts/sdlc/tests/test_scan_api_rbac_function_urls.py pins S7/S8 against snippets of both shapes, so the rules cannot go inert once the live repo only exercises the passing side.

Three sources of truth that MUST NOT drift

SourceWhere
Op universeFIELD_FUNCTION_MAP (SSM /<stack>/http-api/field-function-map) ∪ ddb_direct._HANDLED ∪ FIELD_ALIASES in the dispatcher
Schema groups@aws_cognito_user_pools(cognito_groups:[...]) in nested/api-resolvers/src/api/schema.graphql
Expectationsscripts/api_rbac_expectations.yaml ← edit this when you add an op
Runtime manifesthttp_api_dispatcher/api_rbac_manifest.json — generated from the expectations file; never hand-edit

The static scan fails if these diverge. When you add an API operation you MUST add an entry to scripts/api_rbac_expectations.yaml (and the schema), then regenerate the manifest.

Files

  • scripts/api_rbac_expectations.yaml — single source of truth (189 ops + gap register). Entry schema is documented at the top of the file.
  • scripts/sdlc/scan_api_rbac.py — static scanner (--strict fails on known gaps, use to confirm a gap was fixed; --json PATH for machine output).
  • scripts/sdlc/generate_api_rbac_manifest.py — writes the dispatcher's required-groups manifest from the expectations file (--check = drift guard, run by make api-test-static).
  • nested/api-resolvers/src/lambda/http_api_dispatcher/authz.py — the default-deny enforcement point.
  • scripts/test_api_rbac.py — dynamic harness. inconclusive() / classify() / _record() / hard_failures() are where an outcome becomes a verdict; scripts/sdlc/tests/test_api_rbac_verdicts.py pins them offline, including a run in which every operation times out (which must not be green).
  • scripts/api_security_cases.py — the mandatory suites. _inconclusive_response() and _tls_probe() are the equivalents there; _tls_probe TCP-connects separately from the handshake so an unreachable host cannot read as "the server refused this protocol".
  • lib/idp_common_pkg/tests/unit/test_http_api_dispatcher_authz.py — manifest parity (enumerated from FIELD_ALIASES, ddb_direct._HANDLED and the template's field→function map) plus the deny paths.

Environment (gotchas)

# ALL AWS calls target the deployment account — use AWS_PROFILE=default,
# NOT the sandbox's ambient creds (which may point elsewhere). Confirm first:
AWS_PROFILE=default aws sts get-caller-identity

# The harness prefers AWS CLI v2 at /usr/local/bin/aws (the conda `aws` on PATH
# is v1 and lacks some flags). It handles this internally via AWS_BIN.

Workflow

# 1. Static scan — run on every change to an API op / schema / expectations.
make api-test-static                 # exit 0 with WARNs for known gaps
make api-test-static STRICT=1        # exit 1 on any known gap (verify a fix)

# 2. Dynamic tests against a deployed stack (needs deploy-account creds).
AWS_PROFILE=default make api-test STACK_NAME=IDP1 REGION=us-west-2
#   -> writes ./api-test-results/<stack>-<ts>/{report.md,report.json,meta.json}
#   REPORT_DIR=<dir>   override output location
#   NO_TEARDOWN=1      keep the temp Cognito users (debugging; rerun teardown
#                      later with:  python3 scripts/test_api_rbac.py \
#                        --stack-name <s> --region <r> --teardown-only)

The harness always tears down its temp users and restores the app client's original auth flows on exit (even NO_TEARDOWN only skips the user delete). Test users get a random per-run password (printed when NO_TEARDOWN or --setup-only keeps them alive). Exit code is non-zero only on hard fails (a real leak) — known gaps are WARNs.

A 403 is two different verdicts — read authzControl first

⚠️ 403/Unauthorized is the response shape for two controls that answer opposite questions, and conflating them is the worst mistake available to this layer:

The response meansControlauthzControl
"this caller's groups do not admit this operation"the field-level floor in authz.py — also an undeclared field and an IAM_ONLY opapi-group-floor
"this caller's groups were fine and the object they named was refused"a per-object control in a resolver: the bucket allow-list, the write-once key rule, chat-session ownership, the test-set selection scope, the per-document config-profile scope on object bytesresource
the resolver refused and did not say which control it was — every resolver's own group check is herea resolverresolver
an invocation asserted its own identitynormalize_eventunverified-identity

The matrix asserts the first and cannot avoid provoking the second, because it drives every operation with deliberately bogus arguments. With one indistinguishable shape for both, eight cells of one run reported three per-object controls working correctly as group-authorization failures, and the curated snapshot published RBAC dynamic — FAIL ❌ (8 hard failures) for a release whose authorization was fine (#1308). Establishing that those eight were not a regression took a by-hand comparison against a prior run that happened to still be on disk.

How the harness scores it (classify(), pinned offline in scripts/sdlc/tests/test_api_rbac_refusal_attribution.py):

Cellapi-group-floor, resolver, or no labelresource
an allowed role was refusedFAIL — the shape a real regression takesERROR 🛑 — the floor admitted the caller and a per-object control refused the object, so the cell did not measure the group check. Not a pass, still blocking, and it names the control
a disallowed role was refusedPASSFAIL — the floor runs before routing, so a caller it must refuse cannot reach a resolver; a resource label here means the floor did not refuse somebody it must

⚠️ The remedy for an ERROR here is to fix the operation's ARGUMENT, not to register a gap. Give the operation an argument the per-object control admits so the group floor is what answers — the pattern getFileContents uses (an in-allow-list bucket with a key that does not exist) and the one autoDetectSections, addDocumentsToTestSetByKey and getChatMessages were given (an empty required argument, which the resolver's own validation rejects before it consults the control; that source ordering is pinned by test_the_argument_guard_runs_before_the_per_object_control). Scoring it green, or putting it in the gap register, turns a cell that measured nothing into a cell that reports success — the worse half of the defect.

⚠️ An unlabelled refusal gets the STRICT verdict. Only an explicit resource leaves the hard-failure branch, so a per-object control that forgets to declare itself costs a visible failure rather than a silent pass. Declare one by raising ResourceAccessDenied (idp_common.api_adapter; a PermissionError subclass, recognised by class name across the invoke boundary, so a layerless resolver may declare its own). Keep the Unauthorized message prefix.

⚠️ Declare it per BRANCH, and uniformly across the ones that decide about the object. A control whose refusal sites split between the two labels tells the caller which branch answered, and for an object-scoped control that is an existence oracle: resource on "exists but out of your scope" beside resolver on "no such object" is one bit per key, over objects entirely outside the caller's scope. So convert every branch that decides about the object the caller named, including any budget or cap whose refusal depends on which objects exist, and leave the branches that are facts about the deployment or the principal unattributed — an unevaluable scope, a throttled table, an unwired table name. resolver is the true answer for those and the strict reading is what keeps a deployment fault in the row an operator reads first. document_scope and key_scope in get_file_contents_resolver are the worked example of the split (#1478), and key_scope._assert_test_set_allowed is the counter-example: it folds the resolver's own group check into the same exception as its per-object one, so it stays unattributed — resource there would lose a group refusal, which is the one misattribution direction that matters.

⚠️ object_scoped_roles: is not the way to cover a control keyed on allowedConfigVersions. That key names a role the matrix drives, and every matrix principal is unscoped, so a config-scope control is a no-op for all of them and the cell fails as NOT REFUSED. Those belong in the config-version scope suite, where a seeded scoped Author exists — run_document_bytes_scope_suite is the pattern: refuse the scoped caller a real document's bytes, require resource on the refusal, and assert an unrestricted Admin is not refused the same URI so the first arm cannot pass on a deployment that refuses the object to everybody. "Not refused" rather than "served" on purpose: a 400 File not found is the honest answer on a stack whose input bucket has been swept, and requiring a 200 would fail there.

⚠️ An absent label is not the same as resolver. None means the deployment did not say — a stack older than the field, the route's Cognito authorizer answering 401 ahead of the dispatcher, or an in-band {success:false,error:{type: "Unauthorized"}} 200. Every row in report.json carries authz_control, including passes, so a report whose column is empty throughout is one where this whole distinction was inert and the verdicts are the pre-#1308 ones. Check that before reading a run as having exercised it.

The five outcomes — a refusal and an inconclusive result are different

Every check records one of these. passed is True for exactly one of them.

OutcomeMeansExit code
PASS ✅the check ran and the API behaved as required0
FAIL ❌the check ran and the API did notnon-zero
ERROR 🛑the check could not be runnon-zero
SKIP ⏭️a precondition for the check is absent0
WARN ⚠️a FAIL or ERROR registered against a known_gap0

ERROR exists because this harness asserts refusals. Its positive arms can only ask "was this NOT denied?", and a request that never completed is not denied either — so a timeout, a dead connection, an empty body, a body that will not parse and a 5xx all used to satisfy them. inconclusive() in scripts/test_api_rbac.py is the one place that judgement is made; classify() consults it before any cell-specific rule, so no cell can pass on a result that established nothing.

Two things follow that are easy to get wrong when adding a suite:

  • A known_gap decides whether to block, not whether the check ran. A gapped ERROR is a WARN and still carries inconclusive: true, so it appears in the report's "Could not be run" section. GAP-SEC-INCONCLUSIVE-5XX registers the 5xx case, because a resolver refusal raised as a bare Exception is all the dispatcher can map to 500, and this harness deliberately sends bogus arguments. Not-found refusals now answer 404 (errorType: "ResourceNotFound"); the gap entry in scripts/api_rbac_expectations.yaml is where what remains at 500 is listed. A timeout is not registered and is a hard failure.
  • A 5xx is inconclusive for a "was it refused?" assertion and conclusive for a "does this body contain X?" one. The IDOR suite is the second kind — the body is in hand and the marker is not in it — so it passes treat_5xx=False. Everything else is the first kind.

GAP-SEC-INCONCLUSIVE-5XX is assigned from an observed response rather than declared on an operation, so it declares assigned_by: in the register; the static scanner's S0 orphan check then verifies the reference in that file instead of switching off.

Reading the report

  • meta.json — stack, account, git_sha, api_base, per-run totals (passed, failed, errored, skipped, hard_fail, gap_warn), request IDs.
  • report.md — a Could not be run section first, then hard failures, known-gap warnings, and the full group matrix (op × role) with the marks above.
  • A finding is a hard fail only if it has no known_gap; documented gaps (GAP-01..) surface as WARN so they stay visible without failing the gate.
  • scripts/security/curate_results.py carries the distinction into the published snapshot: a run with no hard failure but some check that could not be run is reported as PASS with reservations ⚠️, not PASS.

When a hard fail appears — triage order

  1. Is it a failure at all, or a check that could not run? 🛑 rows are in the report's own section. A timeout or a dead connection is an environment problem; a 5xx is usually a resolver raising a bare Exception for a validation refusal (see GAP-SEC-INCONCLUSIVE-5XX) and is fixed by giving that refusal a ValueError, not by widening anything here.

    Then: which control refused? Read authzControl in the report's Control column before anything else below. resource means the group floor admitted the caller and a per-object control answered — not an RBAC regression, and the remedy is the operation's argument (see above). api-group-floor on an allowed role is the real thing. An empty column means this run could not attribute refusals at all, so every verdict in it is the pre-authzControl one.

  2. In-band denial not recognized? If the op denies via {success:false, error:{type:Unauthorized}} (200), confirm classify()/_denied() treat in-band Unauthorized as denied. (Config & sync resolvers use this.)
  3. Expectation wrong? Read the enforced_in file and confirm the actual server-side group set. The code is the source of truth; fix the YAML.
  4. Test input short-circuits? For mutations, auth is checked BEFORE the bogus id is used, so an allowed role legitimately gets 400 (not-found) — that's a pass, not a leak. A disallowed role must still get Unauthorized.
  5. Allowed role denied on a NEW op? Look for Denied <field>: no required-groups entry in the dispatcher log — the operation's groups were never declared, so the floor denies everyone. Declare them and regenerate the manifest (see the checklist below); do not widen the manifest to make the symptom go away.
  6. Real leak / fail-open? If a scoped/lower-privilege caller is ALLOWED, check the actual group gate. On every REST operation the scope lookup fails closed — resolve_allowed_config_versions in idp_common.config_scope raises ScopeLookupError for a missing UsersTable, an absent email claim or any failed dynamodb:Query, and each REST consumer turns that into a refusal — so a missing IAM grant presents as a denial, not as an unrestricted caller. In the resolver's CloudWatch logs, look for "config-version scope lookup failed on EmailIndex" at ERROR. ⚠️ The chat-streaming transport is the exception and is not a REST operation: see GAP-07 and AUTH.T07's residuals. An empty page is still deliberately unrestricted (scoping is opt-in), so a caller with no UsersTable row legitimately sees everything: check the row exists before reading a broad result as a leak.

Adding a new API operation — checklist

  1. Add the resolver's server-side group/scope check.
  2. Add the @aws_cognito_user_pools directive in schema.graphql.
  3. Declare the operation's required groups in scripts/api_rbac_expectations.yaml (mirror a similar op) — this is now the source the dispatcher enforces, not only what the tests expect.
  4. Regenerate the dispatcher manifest: python3 scripts/sdlc/generate_api_rbac_manifest.py, and commit the changed nested/api-resolvers/src/lambda/http_api_dispatcher/api_rbac_manifest.json.
  5. Route it. A new resolver Lambda gets one key in HttpApiFieldFunctionMapParam (nested/api-resolvers/template.yaml); a field served by an existing Lambda goes in FIELD_ALIASES (http_api_dispatcher/index.py) instead. An unrouted field is default-denied. scripts/tests/test_http_api_field_map_size.py checks that the map's resolved worst case still fits the 8,192-byte SSM Advanced-tier limit.
  6. Regenerate the validation spec: python3 scripts/sdlc/generate_api_validation_spec.py, and commit the changed http_api_dispatcher/api_validation_spec.json (the dispatcher's argument check).
  7. Regenerate the UI types: make codegen rewrites src/ui/src/graphql/generated/; never hand-edit it.
  8. Update the stated policy counts. scripts/tests/test_api_policy_counts_in_docs.py and scripts/tests/test_well_architected_doc.py compare every page that states an operation or policy count against the expectations file; run them and fix the prose they name.
  9. make api-test-static must be clean (it runs the manifest drift check too), then run make api-test live.
  10. If the op is also reachable off the REST route (a Function URL route, a direct lambda:InvokeFunction path), put the group check in the component that does the work and declare the route under function_url_endpoints: — otherwise S6 fails and the check covers only one path. The dispatcher's default deny does not help there: it gates the REST route only.

⚠️ Steps 3–4 are not optional bookkeeping. The dispatcher denies by default, so an operation with no manifest entry returns 403 for everyone — including Admin — no matter what its resolver allows. If a brand-new operation 403s, the fix is to declare its groups and regenerate (steps 3–4). Do not "fix" it by widening an existing entry, adding a bypass, or making an unmapped field fall through: unmapped-means-denied is the property this layer exists to provide, and the reason a forgotten check on a group-scoped operation is no longer an open endpoint. Declaring an operation ANY to make a 403 go away is exactly the widening this warns against: ANY means the dispatcher checks authentication only, so a forgotten resolver check on an ANY operation is still reachable by any authenticated caller — including one in no group, which self-signup produces. 8 of the 189 declared operations are ANY, each with a note in the expectations file saying why that is the intended answer for that operation, not for the section it sits in. In full: getMyProfile, listChatSessions, getLatestPublishedVersion, listFinetuningJobs, getFinetuningJob, listInstalledFeatures, listCatalogFeatures, checkFeatureEntitlement.

The four policies — pick the weakest one that is still correct

DeclareMeansUse for
[Admin, Author, ...]one of those groupsanything only a subset of roles should do
ANY_GROUPany group template.yaml creates; a caller in no group is refusedoperations every onboarded role legitimately needs, where "onboarded at all" is the real requirement — document content, anything that leads to it, and mutations
ANYauthentication onlythe caller's own profile or own records, public metadata, whole-deployment platform state
IAM_ONLYno Cognito caller at allbackend-written status updates

⚠️ "Enumeration, so it discloses no content" is not a reason. It was the recorded reason for listDocumentsDateHour, listDocumentsDateShard and listDocumentVersions, and issue #1033 measured a caller in no group composing them into a chain that ended in extracted personal data: an object key from an index listing, then a run's section and page URIs plus a model-written description of the contents, then the execution input. Ask what the payload leads to, not only what it literally contains.

Three more things that pass as reasons and are not:

  • A reason written for the set. listDocumentsDateShard recorded only "see listDocumentsDateHour — same index-partition enumeration, same decision", and getChatMessages only "see listChatSessions — own-sessions-only ownership scope, same decision". Read for whether they hold broadly, both pass; read against the one operation carrying them, the second names a different mechanism (listChatSessions uses a DynamoDB key condition on the caller's partition; getChatMessages layers a separate ownership check that returns true when its table is unset). Write one member's worth of reason, every time.
  • A narrowing that stands down for exactly the caller in question. Two of the three per-object narrowings are inert for a self-registered account: resolve_allowed_config_versions returns None — deliberately unrestricted — for a caller no UsersTable row matches, and a caller in no group is not a Reviewer. So "this op is scope-filtered" was never an argument about the groupless caller.
  • A reason about the wrong dict. listFinetuningJobs is ANY because its projection carries no document location, while the DynamoDB row it reads does. If the premise is computable, compute it: finetuning_jobs_resolver/test_projected_keys.py pins the key set, so adding one line cannot quietly change the policy's meaning.

⚠️ Do not spell ANY_GROUP out as the five group names. The sentinel is resolved against the AWS::Cognito::UserPoolGroup resources in template.yaml by generate_api_rbac_manifest.py on every build, so a sixth group is covered automatically; five names written per operation would silently stop covering it — the "fix applied to the instance and not the class" defect this repo keeps hitting. The schema.graphql directive does have to name them all, because GraphQL cannot express "any group"; check S2 fails until it does, which is the intended way to be told a group was added. Check S0 rejects an unrecognised sentinel outright, because the scanner alone would not notice one — S2 would compare a set of its characters and S3 would accept a resolver with no check at all. (make api-test-static would still fail, one command later, on the generator's --check; S0 is what makes the scanner sound on its own and what covers a Function-URL route policy, which the generator never reads.) authz.py never sees ANY_GROUP: it is expanded before the manifest is written, and an unexpanded one there means a broken build and is treated as one (deny-all).

⚠️ A group floor is not the whole control, even where it now reaches the bytes. It gates the REST API. The Identity Pool attaches one authenticated role with no role mappings, so whatever that role grants is held by every signed-in user, group or no group — which is why it grants nothing on the Input and Output buckets and no s3:GetObject or s3:ListBucket on any bucket, and why the UI asks getFileContents / getFilePresignedUrl / getFilePresignedUrls for every document byte. For the document read path the floor and the asset therefore coincide. What the floor still does not supply is per-document authorization: document_scope matches the owning document's ConfigVersion against the caller's allowedConfigVersions, which refuses a scoped caller a document outside their profiles and refuses an unscoped one nothing, scoping being opt-in per user. So do not describe an ANY_GROUP operation as making document content unreachable; it makes that operation unreachable, and on this path that is as far as the floor goes. See the residuals in docs/rbac.md and AUTH.T03.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.