Skip to content

Add a runner option for non-fatal secondary legs - #7377

Open
jhrozek wants to merge 1 commit into
stacklok:mainfrom
jhrozek:runner-nonfatal-legs
Open

jhrozek wants to merge 1 commit into
stacklok:mainfrom
jhrozek:runner-nonfatal-legs

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Mecatl builds its embedded gateway's authorization server through runner.NewEmbeddedAuthServerWithStorage. The earlier PR "Make secondary chain legs optionally non-fatal" (Make secondary chain legs optionally non-fatal #7311) added authserver.Config.NonFatalSecondaryLegs, but the runner builds the Config from the RunConfig and its options, and neither carried the setting. An embedder could turn it on only by calling authserver.New and repeating the runner's resolution, so a user who cancelled one provider's consent at their first sign-in still failed the whole sign-in.
  • Adds runner.WithNonFatalSecondaryLegs(), which sets the field on the server the runner builds. It works with both NewEmbeddedAuthServer and NewEmbeddedAuthServerWithStorage. Without it nothing changes.
  • Like the field, it is Go-only: there is no RunConfig or CRD field, so config files and operator CRDs cannot enable it.

Closes #7370

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (scoped: go test -race ./pkg/authserver/runner/ with the Taskfile's flags; the full task test is left to CI)
  • E2E tests (task test-e2e)
  • Linting (scoped: golangci-lint run ./pkg/authserver/runner/, 0 issues; the repo-wide task lint-fix is left to CI)
  • Manual testing (describe below)

The new table test, TestIntegration_EmbeddedAuthServer_NonFatalSecondaryLegs, builds a three-upstream chain through the runner and has the second leg's user deny consent:

  • With the option, the walk continues to the third upstream and the client gets an authorization code and its state back.
  • Without it, the walk stops at the second upstream and the client gets error=access_denied.

These are the two "done when" cases in the issue. The test fails if the NonFatalSecondaryLegs line in resolvedCfg is removed. The skip rules themselves are covered by the existing handler tests, so this test only proves the wiring.

Does this introduce a user-facing change?

Only for embedders that build the auth server through the runner and pass the new option. Config files, the CLI and operator CRDs are unchanged.

  • Before: a failed or cancelled leg after the first ended the whole authorization with an error to the client, because the runner offered no way to enable the skip.
  • After, option passed: that leg is skipped, the walk goes on to the next missing leg, and the authorization code is issued without that provider. Which failures can be skipped, and which stay fatal, is documented on authserver.Config.NonFatalSecondaryLegs.
  • After, option not passed: no change.

Special notes for reviewers

  • Prerequisite, not a user-visible fix on its own. The user and the identity link are created at the first leg's callback, so a cancelled later leg already leaves the user with an account today. What the option changes is that the sign-in completes and returns a code. For Mecatl, nothing a user sees improves until its other pieces land; the Mecatl side is the issue "Skip a failed provider leg at the embedded gateway's first sign-in" (Skip a failed provider leg at the embedded gateway's first sign-in mecatl#3025). It needs the first ToolHive release that contains this change, and it is a blocker of "Connect link for a missing provider connection, through the gateway's URL elicitation" (Connect link for a missing provider connection, through the gateway's URL elicitation mecatl#2973).
  • Go-only by design, as in the issue. A RunConfig or CRD field, if one is wanted, is separate work ("vMCP: graceful degradation when one upstream IdP fails in multi-upstream auth", vMCP: graceful degradation when one upstream IdP fails in multi-upstream auth #5162).
  • No validation in the option. A server with one upstream, and a SingleLeg authorization, ignore it, so refusing it would break an embedder that sets it on every gateway.
  • What the option's doc comment warns about: with storage that keeps tokens across authorizations (user-keyed storage), a token from an earlier sign-in is kept for a skipped provider, and if it cannot be refreshed the issued token is unusable until replaced. It also says to upgrade every replica that shares the storage before enabling the option, and to turn it off and let pending authorizations drain before rolling back.
  • Test helper change. walkChain now delegates to a walkChainWithDenial variant, with an empty denied host meaning the old behaviour, so the existing filter tests are untouched. newFilterTestServer takes optional runner options.

Implementation plan

Approved implementation plan
  1. Option (pkg/authserver/runner/embeddedauthserver.go): add a nonFatalSecondaryLegs bool field after userKeyedUpstreamStorage; add WithNonFatalSecondaryLegs() after WithAccessTokenType, no arguments, following the file's With<Field> naming; set NonFatalSecondaryLegs: options.nonFatalSecondaryLegs in resolvedCfg. No validation. The doc comment links to the Config field instead of copying its list of skippable failures.
  2. Test: one table-driven behaviour test through the runner, with a three-upstream chain and a denied second leg. Row one passes the option and expects the third upstream to be visited and a code to be issued. Row two omits it and expects the walk to stop with error=access_denied. The denial is simulated by calling the callback with error=access_denied and the state from the leg's authorize URL, because mockoidc cannot inject that error on the authorize request. No unit test of option resolution, because it cannot catch a missing resolvedCfg line, and no log assertions.
  3. Docs: in docs/arch/11-auth-server-storage.md and pkg/authserver/README.md, say to pass the runner option when using the runner and to set the Config field when calling authserver.New directly. Keep "not a RunConfig field".
  4. Review: a three-reviewer panel (Go correctness, API design and docs, OAuth flow and security) reviewed the first version; its findings were applied before this PR, and the work is squashed into one commit.

Embedders that build the auth server through the runner could not
turn on Config.NonFatalSecondaryLegs, so a user who cancelled one
provider's consent at first sign-in failed the whole sign-in.

Add runner.WithNonFatalSecondaryLegs, which sets the field on the
server the runner builds. It stays Go-only: there is no RunConfig or
CRD field, so config files and operator CRDs cannot enable it. Without
the option, behaviour is unchanged.

This unblocks Mecatl's embedded gateway, which builds its
authorization server through the runner. Once Mecatl bumps its
ToolHive pin to a release with this option and passes it, a user who
cancels one provider's consent at their first sign-in still gets an
account, and that provider stays unconnected until they connect it.
That is the first sign-in part of Mecatl's "Connect link for a missing
provider connection, through the gateway's URL elicitation"
(stacklok/mecatl#2973). The rest of that work, such as user-keyed
storage and the credential reader, is separate.

Closes stacklok#7370

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 29, 2026 20:24
@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.64%. Comparing base (ccca33f) to head (157cb3e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7377   +/-   ##
=======================================
  Coverage   82.63%   82.64%           
=======================================
  Files         934      934           
  Lines       97043    97045    +2     
=======================================
+ Hits        80196    80202    +6     
+ Misses      16842    16838    -4     
  Partials        5        5           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

Embedded runner: an option to set NonFatalSecondaryLegs

1 participant