Skip to content

Put the authorization details reachability rule in one place - #7281

Merged
rdimitrov merged 1 commit into
mainfrom
as2-call-binding-1-registry-reachable
Nov 24, 2026
Merged

rdimitrov merged 1 commit into
mainfrom
as2-call-binding-1-registry-reachable

Conversation

@rdimitrov

Copy link
Copy Markdown
Member

Summary

An authorization_details registry is refused at startup when no enabled grant could ever reach it. Today that rule ("the registry needs token exchange") is written out three times: in Config.Validate and at two points in the embedded runner. "Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (#7061) will make the JWT-bearer grant a second consumer of the registry, so the rule has to change, and it should change in one place rather than three.

  • Add authserver.AuthorizationDetailsRegistryReachable(tokenExchangeEnabled bool) bool, the single rule for when a registry is reachable. Today it is true only when token exchange is enabled, which is exactly the existing check.
  • Add the sentinel authserver.ErrAuthorizationDetailsRegistryUnreachable, with the existing text "authorization details registry requires token exchange to be enabled".
  • Use both at the three sites: Config.validateAuthorizationDetailsRegistryReachable (renamed from validateAuthorizationDetailsRequiresTokenExchange), newEmbeddedAuthServerWithStorage, and validateAuthorizationDetailsRegistryForRunConfig.
  • Name the sentinel in the wiring paragraph of docs/arch/17-token-exchange-delegation.md.

Part of #7061. A later change adds the JWT-bearer half of the rule (a registry is also reachable when a trusted issuer has a JWT-bearer policy) and updates the error text with it.

Type of change

  • Refactoring (no behavior change)

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)

New and ported tests:

  • TestAuthorizationDetailsRegistryReachable (pkg/authserver/config_test.go): a table over the rule, plus a check that Config validation returns the sentinel. The registry fixture is now shared with TestConfigValidate, whose existing row now matches the full error text.
  • TestEmbeddedAuthServer_AuthorizationDetailsRegistryReachability (renamed from ..._RequiresTokenExchange) runs both constructors against three inbound-grant shapes: an empty block (token exchange off, refused with the sentinel before upstream discovery), no block (the legacy default, token exchange on, accepted) and an explicit token_exchange block (accepted). The accepted rows are new; before, only the refusal was tested.
  • TestValidateAuthorizationDetailsRegistryForRunConfig tests the early RunConfig check on its own. Without it, the NewEmbeddedAuthServer refusal row would still pass if that check were removed, because newEmbeddedAuthServerWithStorage refuses the same config later, after storage is created.

Also ran go test -race ./pkg/authserver/... and golangci-lint run ./pkg/authserver/... on the final tree.

Changes

File Change
pkg/authserver/config.go Sentinel error, AuthorizationDetailsRegistryReachable, renamed validator
pkg/authserver/runner/embeddedauthserver.go Both runner checks call the shared rule and return the sentinel
docs/arch/17-token-exchange-delegation.md Wiring paragraph names the sentinel
pkg/authserver/config_test.go, pkg/authserver/runner/embeddedauthserver_test.go Tests above

Does this introduce a user-facing change?

No. The refusal happens under the same conditions, at the same point in startup, with the same message. Embedders can now also match it with errors.Is(err, authserver.ErrAuthorizationDetailsRegistryUnreachable); before, it was an unwrapped fmt.Errorf with no sentinel.

Special notes for reviewers

  • AuthorizationDetailsRegistryReachable takes a bool rather than a Config or RunConfig because the two callers compute "token exchange on" differently: Config from DisableTokenExchange, the runner from NormalizeInboundGrants. Today its body is just return tokenExchangeEnabled; it exists so the JWT-bearer half lands as one change to one function signature, and the compiler then points at every caller.
  • The runner test's storage constructor now takes the subtest's *testing.T. Before, it captured the parent test's t, so the memory storage was closed only when the whole parent test finished.

🤖 Generated with Claude Code

A registry for authorization_details is refused at startup when no
enabled grant could reach it. The rule was written out three times:
in Config validation and at two points in the embedded runner. The
JWT-bearer grant is about to become a second consumer of the
registry, so the rule should change in one place.

Add AuthorizationDetailsRegistryReachable and the sentinel
ErrAuthorizationDetailsRegistryUnreachable, and use them at all three
sites. The rule is still "token exchange is enabled" and the error
text is unchanged, so behaviour is the same.

The runner tests now cover accepted configs as well as the refusal,
pin the early RunConfig check on its own, and pass the subtest's
testing.T to the storage constructor so cleanup runs per subtest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the size/S Small PR: 100-299 lines changed label Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.85%. Comparing base (8d64314) to head (435f3c8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7281      +/-   ##
==========================================
- Coverage   81.86%   81.85%   -0.02%     
==========================================
  Files         915      915              
  Lines       92868    92870       +2     
==========================================
- Hits        76029    76016      -13     
- Misses      16834    16849      +15     
  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.

@rdimitrov
rdimitrov merged commit a4dc984 into main Nov 24, 2026
47 checks passed
@rdimitrov
rdimitrov deleted the as2-call-binding-1-registry-reachable branch November 24, 2026 21:49
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants