Skip to content

Return a specific reason in Core 401 responses#407

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

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

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 force-pushed the swi-UID2-7235-meaningful-401 branch from b88683b to c140ece Compare June 5, 2026 00:05
@swibi-ttd swibi-ttd closed this Jun 5, 2026
@swibi-ttd

Copy link
Copy Markdown
Contributor Author

Superseded by #409 — recreating on a clean branch; this branch picked up CI snapshot/merge commits. Closing.

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