Repository navigation
Description
Summary
The embedded authorization server fails the whole authorization when any leg of a multi-upstream chain fails. A user who cancels a secondary provider's consent screen, or meets a secondary provider outage, gets no authorization code and loses every upstream, the identity provider included.
This adds an opt-in authserver.Config option that makes a failed non-first leg non-fatal. The walk records the leg as skipped, continues to the next missing leg, and issues the authorization code without it. The first (identity) leg stays fatal. With the option off, behaviour is unchanged.
This is a narrow first step toward #5162 (graceful degradation). It covers the walk only. Per-backend filtering and a retry endpoint stay with #5162.
Background
continueChainOrComplete(pkg/authserver/server/handlers/callback.go) asksnextMissingUpstreamfor the next leg with no satisfying stored token, and redirects there.handleUpstreamErroranswers an error the IdP returns in place of a code by writing that error to the client. The authorization ends.- A failed code exchange or ID-token validation on a later leg also ends the authorization.
- If the next leg's authorization URL cannot be built,
continueChainOrCompletealso ends the authorization with a server error. - The effective chain is computed once on the first leg and carried in
PendingAuthorization.ChainUpstreams. A later leg reuses it aftervalidateChain.
Embedders that already present a missing upstream to the user in-band (for example, by answering a tool call with a connect link) can complete the authorization without the failed leg and let the user connect it later.
Scenario 1. A failed non-first leg is skipped
With Config.NonFatalSecondaryLegs set, these failures on a non-first leg mark that leg skipped and continue the walk:
- an error the IdP returns in place of a code (
access_denied,server_error, and the rest); - a failed code exchange, or a failed ID-token validation, on that leg's callback;
- a failure to build that leg's authorization URL before the redirect.
The pending authorization carries the skipped legs forward in a new SkippedUpstreams field, so nextMissingUpstream does not prompt for a skipped leg again in the same walk. validateChain validates SkippedUpstreams as a subset of ChainUpstreams that never contains the first upstream.
These stay fatal whatever the option says:
- every failure on the first leg;
- a missing, unknown or replayed
state, a failed browser-binding check, or any other check that ties the callback to the browser that started the authorization; - a storage failure loading or storing the pending authorization.
The second group is what stops a forwarded callback URL from completing someone else's authorization. Skipping past it would issue an authorization code in the wrong browser.
Acceptance:
- AC1.1: With the option set and a three-upstream chain, an IdP
error=access_deniedon the second leg redirects the browser to the third leg. When the third leg completes, the client receives an authorization code.- verify:
Unit: TestCallback_NonFatalSecondaryLeg_IdPErrorSkipsTheLeg
- verify:
- AC1.2: With the option set, a failed code exchange on the last leg issues the authorization code. The skipped leg has no stored token. Every token stored by earlier legs is still stored.
- verify:
Unit: TestCallback_NonFatalSecondaryLeg_ExchangeFailureCompletesTheChain
- verify:
- AC1.3: With the option set, a failure to build the next leg's authorization URL skips to the leg after it, or completes the chain when it was the last.
- verify:
Unit: TestCallback_NonFatalSecondaryLeg_AuthorizeURLFailureSkips
- verify:
- AC1.4: A skipped leg is not prompted again in the same walk, even though it still has no satisfying token.
- verify:
Unit: TestNextMissingUpstream_IgnoresSkippedLegs
- verify:
- AC1.5: With the option set, a first-leg failure, a state mismatch, or a browser-binding mismatch on any leg still ends the authorization with an error to the client.
- verify:
Unit: TestCallback_NonFatalSecondaryLeg_BindingAndFirstLegFailuresStayFatal
- verify:
- AC1.6: A pending authorization whose
SkippedUpstreamsnames the first upstream, or a name outsideChainUpstreams, is rejected as a stale or tampered pending.- verify:
Unit: TestValidateChain_RejectsInvalidSkippedUpstreams
- verify:
- AC1.7: With the option unset, every case above behaves as it does today.
- verify:
Unit: TestCallback_SecondaryLegFailureIsFatalByDefault
- verify:
- AC1.8: Each skipped leg logs once at WARN with the provider name and the failure class, and no token, code or user value.
- verify:
Unit: TestCallback_NonFatalSecondaryLeg_IdPErrorSkipsTheLeg, asserting parsed structured log fields
- verify:
Scenario 2. Storage round-trips the skipped legs
SkippedUpstreams is persisted by every PendingAuthorizationStorage backend.
Acceptance:
- AC2.1: Memory and Redis storage store and load
SkippedUpstreamsunchanged. A pending written without the field loads with none skipped.- verify:
Unit: TestPendingAuthorization_SkippedUpstreamsRoundTrip (memory and Redis)
- verify:
Out of scope
| Item | Defer to | Why |
|---|---|---|
| Filtering backends whose upstream is missing, and the retry endpoint | #5162 | This change covers the walk only. |
| Exposing the option in RunConfig or the operator CRDs | follow-up | Embedders set it on authserver.Config first. |
| Changing the default | #5162 | Opt-in keeps every current embedder's behaviour. |
Delivery shape
One PR. The option, the pending field, and the walk change are one behaviour with no demoable split.
Definition of done
- Every checkbox above is checked, and every
verify:test exists and is green. task lintandtask testpass.- The
authserver.Configoption is documented on the field.
Activity
Make secondary chain legs optionally non-fatal (stacklok#7311)