Let a service require its callers to be authenticated - #235
Merged
Conversation
added 2 commits
August 9, 2026 12:53
The proxy at /services/redirect/{name} carries no authentication: whoever
reaches the Endpoint reaches the service through it, whatever the service's
own rules are.
A service can now ask for callers to be authenticated first, with a
requires_auth extra. The Endpoint then validates the bearer token exactly as
everywhere else before forwarding anything: an anonymous caller gets 401 with
a challenge and the service is never contacted, and an authentication service
that is down still answers 502 rather than being mistaken for a bad token.
Subpaths are gated too, or the gate would be a formality.
Absent, false or anything unrecognised means open, so every service
registered until now behaves exactly as it did.
get_service_url keeps its signature and its fifteen tests; the access rule
comes from a new get_service_access it delegates to, so both answers still
cost one catalog search.
The sequence diagram shows the order of calls; it does not answer the question an operator has when protecting a service, which is who is let in and what each refusal looks like. The flowchart puts the registration decision at the top and the per-call questions underneath — found, protected, token presented, token accepted, service reachable — with the status each dead end produces. It also states that a rejected token currently surfaces as 502 rather than 401, so the picture matches what an operator will actually see.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The proxy at
/services/redirect/{name}has no authentication of its own. Whoever can reach the Endpoint can reach every registered service through it, whatever the service's own access rules are.A service can now ask for callers to be authenticated first:
From then on the Endpoint validates the caller's bearer token — the same validation as everywhere else — before forwarding anything.
A service without that extra is exactly as open as before, which is every service registered until now. Per service rather than a global switch, so an Endpoint can offer public and protected services side by side.
What it is, and is not
It checks that the caller holds a token this Endpoint can validate. It is authentication, not authorization: it does not look at groups or roles. A service needing finer rules still applies them itself, and can — the proxy forwards the
Authorizationheader, so the token reaches it.That forwarding is worth stating plainly, and the diagram now does: whoever registers a service receives the tokens of everyone who reaches it through the proxy. Registering requires a writer role, so it is not open to anonymous callers, but it matters when pointing a service at somewhere you do not control.
Verified
Against a live Endpoint, with a service registered carrying the extra:
This service requires authentication. Provide a bearer token.,WWW-Authenticate: BearerPlus 23 new unit tests covering the extra's spellings, the gate on its own — including that a 502 from the authentication service is not rewritten into a 401 — and both proxy routes, asserting the service is never contacted when the caller is refused. 1230 tests in total,
black --check .andflake8clean.Found while testing, not fixed here
A token that is simply wrong answers 502, everywhere in the API, not just here: the authentication service answers
400for a token it rejects andget_current_usermaps unrecognised statuses to 502. So a mistyped token is reported as the authentication service being broken. Filed as #234.