Skip to content

UID2-7235 Return a specific reason in Core 401 responses#409

Open
swibi-ttd wants to merge 3 commits into
mainfrom
swi-UID2-7235-meaningful-401-v2
Open

UID2-7235 Return a specific reason in Core 401 responses#409
swibi-ttd wants to merge 3 commits into
mainfrom
swi-UID2-7235-meaningful-401-v2

Conversation

@swibi-ttd
Copy link
Copy Markdown
Contributor

Problem

A 401 from /attest (and other auth-gated endpoints) returns a bare Unauthorized. An operator hitting this at startup can't tell a mistyped/unknown key from a disabled key or a missing role, which makes onboarding failures hard to diagnose.

Change

GenericFailureHandler now returns a JSON body on 401 with a reason and an actionable message, inferred from the resolved auth profile:

  • no profile → unrecognized_key
  • profile present + disabled → key_disabled
  • profile present + wrong role → insufficient_role

The body propagates into the operator's attestation log, so the cause is visible at the point of failure. Non-401 responses are unchanged.

Tests

GenericFailureHandlerTest covers all three reasons and the non-401 passthrough.

Notes

  • This applies to all Core 401s, not only /attest. It's backward-compatible (callers check the status code; the body is informational) and all Core endpoints authenticate via operator keys, so the wording holds.

A 401 from /attest (and other auth-gated endpoints) previously returned a bare "Unauthorized", giving operators no way to distinguish a mistyped/unknown key from a disabled key or a role problem. GenericFailureHandler now returns a JSON body with a reason (unrecognized_key / key_disabled / insufficient_role) and an actionable message, inferred from the resolved auth profile. The body surfaces in the operator's attestation log.

Adds GenericFailureHandlerTest covering all three reasons and the non-401 passthrough.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@swibi-ttd swibi-ttd changed the title Return a specific reason in Core 401 responses UID2-7235 Return a specific reason in Core 401 responses Jun 5, 2026
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.

1 participant