Repository navigation
Make secondary chain legs optionally non-fatal - #7311
Conversation
A user who cancels a secondary provider's consent screen, or meets a secondary provider outage, loses the whole authorization today, the identity provider included. Embedders that already offer a connect link for a missing upstream can do better. Add the opt-in authserver.Config.NonFatalSecondaryLegs. When set, an IdP error, a failed code exchange, or a failure to build the authorization URL on a non-first leg records that leg in the new PendingAuthorization.SkippedUpstreams, logs one WARN, and continues the walk; the authorization code is issued without the leg. The first leg, state and browser-binding checks, and storage failures stay fatal. Memory and Redis storage persist the new field, and resolveChain rejects a skipped set that names the first upstream or a name outside the carried chain. Closes #7310 Co-Authored-By: Claude Opus 5.5 <[email protected]>
canSkipLeg excludes SingleLeg authorizations so a cancelled or failed connect-one-backend flow never issues a code with nothing connected, but no test pinned it. Add IdP-error and exchange-failure cases for a SingleLeg pending on a later upstream with NonFatalSecondaryLegs set. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7311 +/- ##
==========================================
- Coverage 82.39% 82.36% -0.04%
==========================================
Files 936 936
Lines 95494 95567 +73
==========================================
+ Hits 78680 78710 +30
- Misses 16809 16852 +43
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tgrunnagle
left a comment
There was a problem hiding this comment.
Review
This is a new opt-in feature (authserver.Config.NonFatalSecondaryLegs) plus the refactor of continueChainOrComplete it needs, with tests. The approach is sound. With the option unset, behaviour is unchanged.
- Skip ordering. Every skip decision runs after
validateAndConsumePending, so state, browser-binding, expiry and single-use checks stay fatal. An unknown or replayed state takes the not-found arm, where no pending exists to skip. - First leg and SingleLeg. The first (identity) leg can never be skipped.
canSkipLegexcludesupstreams[0]and SingleLeg, andcanSkipCallbackLegalso requiresResolvedUserID. - Termination. The new walk loop terminates, because each iteration adds one distinct non-first chain member that
nextMissingUpstreamthen excludes. SkippedUpstreamsvalidation.SkippedUpstreamsis validated on every consumer path throughresolveChain, and both storage backends clone it on store and load.- Identity check.
verifyChainIdentitystill checks the first leg, which can never be skipped, before a code is issued.
All kept findings are LOW: log-line accounting for the IdP-error path, a stale doc comment, how resolveChain was restructured, and test gaps around the new guards.
Cross-cutting.
- Docs. The option is embedder-only and off by default, so
docs/anddocs/arch/need no change beyond the README bullet and the field doc comment that ship here. - Size. The PR is about 300 non-test lines across 8 files, within the project's limits.
- PR body. It states the deliberate narrowing (SingleLeg,
ResolvedUserID, "provider not found" stays fatal). - Compatibility. The Redis field is
omitempty, so pendings written before it load with nothing skipped.
Recommendation: approve once the author has weighed the findings below; none is a bug that would cause incorrect behavior, a security issue, or data loss on merge.
Findings
| # | Severity | Finding | Location | Raised by |
|---|---|---|---|---|
| 1 | LOW | An IdP error on a skipped leg logs two WARN lines, but the docs say "once" | pkg/authserver/server/handlers/callback.go:783 |
correctness, readability, docs |
| 2 | LOW | A skipped code-exchange failure loses its error detail at the default log level | pkg/authserver/server/handlers/callback.go:231 |
security |
| 3 | LOW | handleUpstreamError doc comment lists only the pre-change outcomes |
pkg/authserver/server/handlers/callback.go:782 (doc comment at 745-748) |
readability |
| 4 | LOW | resolveChain is wrapped in an immediately-invoked closure to add one trailing check |
pkg/authserver/server/handlers/handler.go:636 |
readability, scope |
| 5 | LOW | ResolvedUserID guard and ar != nil check have no test that would fail without them |
pkg/authserver/server/handlers/callback_nonfatal_legs_test.go:301 |
tests |
| 6 | LOW | WARN assertions cover only the idp_error class |
pkg/authserver/server/handlers/callback_nonfatal_legs_test.go:213 |
tests |
| 7 | LOW | No test for a skipped leg that already holds a stored token | pkg/authserver/server/handlers/callback_nonfatal_legs_test.go:161 |
tests |
| 8 | LOW | Two test names do not match what they assert, and one assertion is hard to read | pkg/authserver/server/handlers/callback_nonfatal_legs_test.go:427 |
readability |
How to test
task test(or scope topkg/authserver/...) andtask lint: both should pass.- Break the skip ordering: move the
canSkipCallbackLegbranch inhandleUpstreamErrorabovevalidateAndConsumePending. The browser-binding case inTestCallback_NonFatalSecondaryLeg_BindingAndFirstLegFailuresStayFatalshould fail. - Remove the
slices.Contains(skipped, name)check innextMissingUpstream.TestNextMissingUpstream_IgnoresSkippedLegsand the IdP-error walk test should fail. - Remove
!pending.SingleLegfromcanSkipLeg. The SingleLeg cases should fail. - Remove
pending.ResolvedUserID != ""fromcanSkipCallbackLeg. Nothing fails today, which is the test gap noted below.
Reviewed by dev:review-pr (finders: correctness, readability, security, tests, scope discipline, documentation). Generated with Claude Code.
Addresses #7311 review comments: - LOW callback.go:783 (4700545431): docs now say an IdP-error skip also carries the existing upstream-error WARN - LOW callback.go:231 (4700545442): split identity_resolution from code_exchange so the WARN names the cause - LOW callback.go:782 (4700545451): handleUpstreamError doc names the skip outcome - LOW handler.go:636 (4700545461): validate SkippedUpstreams first in resolveChain instead of wrapping it in a closure Co-Authored-By: Claude Opus 5.5 <[email protected]>
Addresses #7311 review comments: - LOW callback_nonfatal_legs_test.go:301 (4700545480): cases for a pending with no resolved user and a corrupt stored redirect URI - LOW callback_nonfatal_legs_test.go:213 (4700545495): assert the skip WARN for code_exchange, identity_resolution and each authorization_url skip - LOW callback_nonfatal_legs_test.go:161 (4700545509): a skipped leg keeps its earlier stored credential - LOW callback_nonfatal_legs_test.go:427 (4700545515): rename tests to what they cover; count every WARN on the IdP-error walk Co-Authored-By: Claude Opus 5.5 <[email protected]>
tgrunnagle
left a comment
There was a problem hiding this comment.
Review
Incremental review of the 2 commits since 668baa70c. All eight findings from the previous review are resolved in the code (threads replied to and resolved). The new commits are targeted fixes and leave the approach unchanged.
Resolved since the last review
- Two WARN lines on an IdP-error skip against "logged once" docs (
pkg/authserver/config.go,pkg/authserver/README.md,logSkippedLeg): the docs and comments now describe the extra existing WARN, and the test asserts both messages. - Code-exchange failure detail at the default level (
callback.go):exchangeFailureClasssplitscode_exchangefromidentity_resolution, and no token-request failure wrapsupstream.ErrIdentityResolutionFailed. handleUpstreamErrordoc comment (callback.go): now names the skip outcome.resolveChainclosure (handler.go):validateSkippedruns first and the original branches are untouched; no regression in which pendings are rejected.- Test gaps for the
ResolvedUserIDguard andar != nilcheck, the WARN classes, and a skipped leg with a stored token: each new case fails if the guard it targets is removed. - Test names and the assertion closure: renamed, and replaced by
skipRecords/skipRecord.
Findings
| # | Severity | Finding | Location | Raised by |
|---|---|---|---|---|
| 1 | LOW | Stray blank line at the top of TestCallback_NonFatalSecondaryLeg_AuthorizeURLFailureSkips |
pkg/authserver/server/handlers/callback_nonfatal_legs_test.go:299 |
correctness, readability |
| 2 | LOW | The validate-before-filter ordering in resolveChain is not pinned by a test |
pkg/authserver/server/handlers/callback_nonfatal_legs_test.go:542 |
correctness, tests |
| 3 | LOW | The rewrapped README line is about 100 characters wide | pkg/authserver/README.md:180 |
readability |
None of these affects behavior. The change keeps its earlier shape: opt-in, off by default, binding and state checks still fatal.
Recommendation: approve once the author has weighed the nits above.
How to test
task testandtask lintshould pass.- Reorder
resolveChainsovalidateSkippedruns aftercomputeChain: nothing fails today (the first finding above). - Remove
pending.ResolvedUserID != ""fromcanSkipCallbackLeg, orar != nilfromhandleUpstreamError:TestCallback_NonFatalSecondaryLeg_UnskippableFailuresStayFatalshould now fail. - Check
skippedafter the stored-token lookup innextMissingUpstream:TestCallback_NonFatalSecondaryLeg_SkippedLegKeepsItsStoredTokenshould fail.
Reviewed by dev:review-pr (incremental; finders: correctness, readability, tests). Generated with Claude Code.
Addresses #7311 review comments: - LOW callback_nonfatal_legs_test.go:299 (4700902862): drop the stray blank line - LOW callback_nonfatal_legs_test.go:542 (4700902874): assert the rejection error and that the filter never runs - LOW README.md:180 (4700902881): re-wrap the bullet Co-Authored-By: Claude Opus 5.5 <[email protected]>
jhrozek
left a comment
There was a problem hiding this comment.
Nice work, the ordering is right: every skip happens after the state, binding and consume checks, and SingleLeg and the first leg stay fatal. A few things inline, plus two that don't have a line to hang on.
The behaviour change should get a paragraph in docs/arch/11-auth-server-storage.md, since CLAUDE.md asks for a docs/ update when a request can now succeed where it used to fail. Worth covering the rollout there too: an older replica drops skipped_upstreams and re-prompts the leg, and a replica with the option off still honours skips another replica recorded (nextMissingUpstream doesn't look at the option). I'm fine with the latter as long as it's written down. Ignoring the list when the option is off is the alternative if you'd rather it be strict.
Also worth a line in the PR body: any ExchangeCodeForIdentity error is skippable, including a transient 503 or a nonce mismatch. I think that's fine since nothing gets stored for that leg and identity is only checked on the first leg, but it should read as deliberate.
Addresses #7311 review comments: - handler.go:643 (4706980181): a first-leg pending that carries a chain or skipped legs is rejected; later legs validate the chain before the skipped set, so the set is checked against the chain the walk actually uses - callback.go:1133 (4706980191): canSkipLeg needs more than one upstream, so a handler without upstreams cannot panic on an IdP-error callback - callback.go:1155 (4706980197): log the skip once the chain has validated, so a rejected pending leaves no skip WARN and a stale pending keeps its stale-pending error - callback.go:1159 (4706980202): assert the skip paths read chain state with the resolved user in context Co-authored-by: Mecatl <[email protected]>
Addresses #7311 review comment server_impl.go:240 (4706980210): assert the option reaches the authorization server config from authserver.Config, so dropping either copy fails a test. Co-authored-by: Mecatl <[email protected]>
Addresses #7311 review comments: - config.go:2142 (4706980172): a skip leaves an earlier credential in place, and the token validator and refresh guard still treat an unusable stored credential as fatal for the session; list every failure that stays fatal; name identity resolution failures - review body: add a docs/arch section covering what is skipped, what stays fatal, the stored skipped set, and the rolling-upgrade and rollback order Co-authored-by: Mecatl <[email protected]>
|
Trey is on PTO and this was in the way of something I'm working on, so I pushed the review fixes myself. The two points from the review body are covered too: docs/arch/11 has a new section with the rollout and rollback order (an option-off replica still honours recorded skips; that's documented rather than changed), and the PR body now says transient and nonce exchange failures are skippable on purpose, along with the kept-credential trade-off. |
…atal-secondary-legs # Conflicts: # pkg/authserver/README.md
Summary
authserver.Config.NonFatalSecondaryLegs. When set, a failed non-first leg is recorded as skipped, the walk continues to the next missing leg, and the authorization code is issued without the skipped leg. With the option unset, behaviour is unchanged.Closes #7310
Type of change
Test plan
task test)task test-e2e)task lint)Changes
pkg/authserver/config.goConfig.NonFatalSecondaryLegs, documented on the fieldpkg/authserver/server_impl.go,pkg/authserver/server/provider.goDeviceFlowEnabledpkg/authserver/storage/types.go,memory.go,redis.goPendingAuthorization.SkippedUpstreams; memory clones it, Redis persists it asskipped_upstreams,omitemptypkg/authserver/server/handlers/handler.gonextMissingUpstreampasses over skipped legs;resolveChainrejects a first-leg pending that carries a chain or skipped legs, and on later legs validates the chain, thenSkippedUpstreamsviavalidateSkippedpkg/authserver/server/handlers/callback.gocompleteChainandredirectToNextLegextracted fromcontinueChainOrComplete, which now loopspkg/authserver/README.md,docs/arch/11-auth-server-storage.mdpkg/authserver/server/handlers/callback_nonfatal_legs_test.go,handler_chain_test.go,pkg/authserver/storage/pending_skipped_upstreams_test.go,pkg/authserver/server_impl_test.go,pkg/authserver/server/provider_test.goDoes this introduce a user-facing change?
Only for embedders that set
Config.NonFatalSecondaryLegs. It is not exposed through RunConfig or the operator CRDs.idp_error,code_exchange,identity_resolution,authorization_url). An IdP-error skip is also preceded by the existing "upstream IDP returned error" WARN.These stay fatal whatever the option says: every first-leg failure, a missing/unknown/replayed
state, a failed browser-binding check, the consent-stage check, a pending whose stored redirect URI cannot be parsed, an upstream provider that is not configured, and storage failures loading or storing the pending authorization.Special notes for reviewers
validateAndConsumePending.SingleLegauthorizations are never skipped. They have no chain, so skipping would issue a code with nothing connected.ResolvedUserIDset. A callback that would establish the user is always fatal.identity_resolutionwhen the error wrapsupstream.ErrIdentityResolutionFailed(nonce, ID-token or subject validation) andcode_exchangeotherwise, so operators can tell the two apart at the default level. The existing "upstream IDP returned error" WARN inhandleUpstreamErroris unchanged, so an IdP-error skip logs that line plus the skip line.resolveChainrejects a first-leg pending that names either before the filter runs. On a later leg it validates the carried chain, thenvalidateSkippedchecks the skipped set against that chain: no first upstream, no outsiders, no duplicates. The skip WARN is logged only once the chain has validated, so a rejected pending leaves no skip record.ExchangeCodeForIdentityerror on a later leg is skippable, including a transient token-endpoint failure and a nonce or ID-token failure. This is deliberate: nothing is stored for the skipped leg, and identity comes only from the first leg, so the skip gains an attacker nothing.storage.UserKeyedUpstreamStorage), a kept credential the walk could not refresh still fails the whole session inTokenValidatorand the refresh guard. That all-or-nothing behaviour is outside this PR and will be handled with the user-keyed storage work; the field doc and docs/arch state the caveat.skipped_upstreamsand prompts the skipped leg again, and a replica with the option off still honours skips another replica recorded for the life of the pending. Both are documented in docs/arch/11 rather than changed: upgrade every replica before enabling the option, and turn it off and let in-flight authorizations drain before rolling back.TestValidateChain_RejectsInvalidSkippedUpstreams; it isTestResolveChain_RejectsInvalidSkippedUpstreamshere because it exercisesresolveChain, the path that rejects the pending. AC1.5's test is likewiseTestCallback_NonFatalSecondaryLeg_UnskippableFailuresStayFatal, since it also covers SingleLeg, unresolved-user and tampered pendings.Verification
At 00dbe6b, clean tree:
task lint-fix: exit 0, "0 issues."task test: exit 0, no failures (grep for❌/build failed/--- FAIL= 0)At 8a38d77 (review fixes), for
./pkg/authserver/...:go test -raceexit 0 with no failures,golangci-lint run0 issues,go vetexit 0.At 873aedb (main merged in, README conflict resolved), for
./pkg/authserver/...:go test -raceexit 0 with no failures,golangci-lint run0 issues.No pre-existing failures in the baseline. Build was not run separately; packages compile as part of the test run. E2E tests were not run.
Acceptance criteria:
TestCallback_NonFatalSecondaryLeg_IdPErrorSkipsTheLeg(leg 2access_deniedredirects to provider-3, then 303 with code)TestCallback_NonFatalSecondaryLeg_ExchangeFailureCompletesTheChain(token-request and identity-validation failures), plusTestCallback_NonFatalSecondaryLeg_SkippedLegKeepsItsStoredTokenfor a skipped leg with an earlier credentialTestCallback_NonFatalSecondaryLeg_AuthorizeURLFailureSkips(3 cases, each asserting one skip WARN per failed leg)TestNextMissingUpstream_IgnoresSkippedLegsTestCallback_NonFatalSecondaryLeg_UnskippableFailuresStayFatal(also covers SingleLeg, a pending with no resolved user, and a corrupt stored redirect URI)TestResolveChain_RejectsInvalidSkippedUpstreams(also covers first-leg pendings that carry a chain or skipped legs, and asserts the upstream filter never runs for a rejected pending)TestCallback_SecondaryLegFailureIsFatalByDefaultTestCallback_NonFatalSecondaryLeg_IdPErrorSkipsTheLeg(asserts the walk's WARN lines and exactly one parsed skip record withlevel,msg,provider,failure_class); the exchange and authorization-URL tests assert their skip records tooTestPendingAuthorization_SkippedUpstreamsRoundTrip(memory and Redis)task lintandtask testpass; option documented onConfig.NonFatalSecondaryLegsinpkg/authserver/config.go🤖 Generated with Claude Code