Skip to content

Let a service require its callers to be authenticated - #235

Merged
rbardaji merged 2 commits into
mainfrom
feature/235-protected-services
Aug 9, 2026
Merged

Let a service require its callers to be authenticated#235
rbardaji merged 2 commits into
mainfrom
feature/235-protected-services

Conversation

@rbardaji

@rbardaji rbardaji commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

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:

curl -X POST http://localhost:8002/services \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"service_name":"private-service", ..., "extras":{"requires_auth":"true"}}'

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 Authorization header, 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:

Request Result
Protected, no token 401 This service requires authentication. Provide a bearer token., WWW-Authenticate: Bearer
Protected, valid token 200, the service's own response
Protected, subpath, no token 401
Open service, no token 200, unchanged
Unknown service 404, unchanged

Plus 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 . and flake8 clean.

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 400 for a token it rejects and get_current_user maps unrecognised statuses to 502. So a mistyped token is reported as the authentication service being broken. Filed as #234.

Raul Bardaji 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.
@rbardaji
rbardaji merged commit 313e3d2 into main Aug 9, 2026
1 check passed
@rbardaji
rbardaji deleted the feature/235-protected-services branch August 9, 2026 20:09
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