Skip to content

authserver: opt-in non-fatal secondary chain legs #7310

Done

Description

@tgrunnagle

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) asks nextMissingUpstream for the next leg with no satisfying stored token, and redirects there.
  • handleUpstreamError answers 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, continueChainOrComplete also 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 after validateChain.

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_denied on 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
  • 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
  • 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
  • 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
  • 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
  • AC1.6: A pending authorization whose SkippedUpstreams names the first upstream, or a name outside ChainUpstreams, is rejected as a stale or tampered pending.
    • verify: Unit: TestValidateChain_RejectsInvalidSkippedUpstreams
  • AC1.7: With the option unset, every case above behaves as it does today.
    • verify: Unit: TestCallback_SecondaryLegFailureIsFatalByDefault
  • 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

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 SkippedUpstreams unchanged. A pending written without the field loads with none skipped.
    • verify: Unit: TestPendingAuthorization_SkippedUpstreamsRoundTrip (memory and Redis)

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

  1. Every checkbox above is checked, and every verify: test exists and is green.
  2. task lint and task test pass.
  3. The authserver.Config option is documented on the field.

Activity

  1. added
    enhancement
    size/M
    on Nov 25, 2026
  2. added
    needs-triage
    on Nov 25, 2026
  3. self-assigned this
    on Nov 25, 2026
  4. added a commit that references this issue on Nov 26, 2026
    2cc6fb9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

authenhancementneeds-triagesize/M

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions