Skip to content

Add README for pkg/authserver - #7301

Merged
jhrozek merged 3 commits into
mainfrom
as-readme
Nov 25, 2026
Merged

jhrozek merged 3 commits into
mainfrom
as-readme

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Embedders of pkg/authserver currently have to read the code to learn what the package offers, how to mount it, and where the architecture docs live. This adds a README that serves as the single entry point for prospective adopters.

  • Describes pkg/authserver as an embeddable Go OAuth 2.0 authorization server built on Ory Fosite, with no MCP or ToolHive proxy dependency.
  • Covers the supported grants and standards, the storage and upstream credential model, and the two entry points (authserver.New and runner.NewEmbeddedAuthServer).
  • Includes a quick-start example and links to the storage, token exchange, and SPIFFE architecture docs under docs/arch/.

Type of change

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

Test plan

  • Manual testing (describe below)

Manual checks, all run locally:

  • Confirmed every relative link resolves in the repo (pkg/authserver/server.go, config.go, runner/embeddedauthserver.go, and the three docs/arch/ pages), and that the #bound-id-jag-assertions anchor matches a heading in docs/arch/17-token-exchange-delegation.md.
  • Confirmed the quick-start identifiers exist in the current code: authserver.Config (Issuer, AllowedAudiences, Upstreams), authserver.UpstreamConfig (Name, Type, OIDCConfig), upstream.OIDCConfig, storage.NewMemoryStorage, and the Server methods used in the example.

Docs-only change, so no unit, e2e, or lint runs were needed.

Adopters who want to embed the auth server need one place to learn what the package covers, how to mount it, and where the architecture docs are. The README describes pkg/authserver as an embeddable Go OAuth 2.0 authorization server, with its supported grants and standards, a quick start, and an overview of its components.

Affected components: pkg/authserver (documentation only)

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 25, 2026 12:02
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Nov 25, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a few fixes before merge: the README is accurate on endpoints, types and links, but the quick-start snippet and a few framing claims would mislead an embedder.

Design: A package-level README next to the code is the right owner for an embedder entry point, and pointing at docs/arch 11/17/18 for depth avoids a second source of truth. The drift risk is in the parts that restate feature status and standards from those pages; keeping those to a short list with links would reduce it.

  1. pkg/authserver/README.md:89-91: the quick start mounts mux.Handle("/.well-known/", srv.Handler()). That prefix captures every well-known path, but the handler only registers jwks.json, oauth-authorization-server[/*] and openid-configuration[/*] (server/handlers/handler.go:511-515); everything else 404s from the auth server's router. A resource server that serves its own /.well-known/oauth-protected-resource on the same mux (the headline use case) loses it by copying this snippet. Fix: mount the specific paths, or add a comment warning about the prefix.
  2. README.md:36-39, :149-151: the README says embedders commonly wrap storage with decorators, but not that storage.Storage deliberately does not embed DCRCredentialStore / DeviceCodeStorage / RememberedConsentStorage. newServer asserts these on the unwrapped base store and fails with storage backend %T does not implement storage.DCRCredentialStore (server_impl.go:385-387). A decorator without Unwrap() Storage, or a from-scratch backend, fails at authserver.New. Fix: one sentence saying decorators must expose Unwrap() (see storage/client_admission.go) and custom backends must implement the optional interfaces.
  3. README.md:9-14 and the PR body: "no dependency on MCP" is overstated. There are no MCP imports, but behaviour is MCP-shaped: config.go:2438 rejects an empty AllowedAudiences ("required for MCP compliance"), server/provider.go:632 forces S256 per the MCP spec, and the default client is named "ToolHive MCP Client" (config.go:1624). A non-MCP embedder hits the mandatory audience list immediately. Fix: say there is no MCP code dependency, but defaults/validation follow MCP conventions, and that AllowedAudiences is required.
  4. README.md:11-14: only pkg/oauthproto and pkg/networking are named as shared dependencies, but non-test code also imports pkg/auth/dcr, pkg/storageerr, pkg/redisconfig and pkg/bodylimit/httplimit (about 12 packages in total). Fix: list them all or say "several shared packages".
  5. README.md:222-231: the "How applications use it" section names "Stacklok Enterprise Platform" and "mecatl" as consumers. Nothing in the repo supports either (mecatl appears only as an example client ID in docs/arch/17). Please confirm both are meant to be named in a public README, or limit the section to ToolHive proxy and vMCP.
  6. README.md:126-128: OAuthRoutes / WellKnownRoutes are methods on server/handlers.Handler (handler.go:333,510), and authserver.New doesn't expose that type. A reader can't act on this as written. Fix: qualify them, or drop the sentence and point at Server.Handler().
  7. README.md:245: "device flow requires a single upstream" reads as a config constraint, but it is only checked at request time (server/handlers/device_verification.go:107); there is no startup validation. Fix: say enabling it with several upstreams fails at the verification step.

Simpler alternative: trim the two standards tables and the delegation/SPIFFE prose to a short supported-features list linking to docs/arch/17 and docs/arch/18. That cuts about a third of the file and most of the drift risk.

Not blocking, outside this diff: pkg/authserver/docs.go still says only in-memory storage exists and shows an UpstreamConfig{{Config: ...}} field that doesn't exist, so go doc readers will see the old version.

🤖 Reviewed with Claude Code

jhrozek and others added 2 commits November 25, 2026 13:23
Incorporate review feedback on pkg/authserver/README.md without making it overly low-level:

- Mount explicit /.well-known/* routes in the quick start so sibling well-known paths (such as RFC 9728 protected-resource metadata) are not shadowed.
- Clarify that pkg/authserver has no MCP code dependency while following MCP defaults/validation (including required AllowedAudiences) and list its shared utility packages more accurately.
- Qualify OAuthRoutes/WellKnownRoutes on handlers.Handler, note Unwrap() and optional capability interfaces for storage decorators/custom backends, note device flow's verification-time single-upstream check, and update ID-JAG to reflect that cnf/DPoP is rejected at both issuance and redemption.
- Add a concise Package layout table showing which subpackages are standalone vs. Fosite grant factories.

Co-authored-by: Mecatl <[email protected]>
Refresh pkg/authserver/docs.go so go doc matches the current API: fix the non-existent UpstreamConfig.Config field, document Redis alongside memory storage, mount explicit /.well-known/* routes, and update the supported flows and subpackage list.

Co-authored-by: Mecatl <[email protected]>
@github-actions github-actions Bot added size/M Medium PR: 300-599 lines changed and removed size/S Small PR: 100-299 lines changed labels Nov 25, 2026
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.94%. Comparing base (1082992) to head (7beae27).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7301      +/-   ##
==========================================
- Coverage   81.95%   81.94%   -0.01%     
==========================================
  Files         922      922              
  Lines       93367    93367              
==========================================
- Hits        76521    76513       -8     
- Misses      16841    16849       +8     
  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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of 7beae27: approve. The two new commits fix the factual problems from the earlier review, and I checked the new claims against the code.

  1. Well-known mount: resolved. The quick start mounts /oauth/ plus the explicit well-known paths, which matches WellKnownRoutes.
  2. Storage decorators: resolved. The README now says decorators must expose Unwrap() storage.Storage, matching server_impl.go.
  3. "No dependency on MCP": resolved. It now says "no code dependency" and notes that AllowedAudiences is required.
  4. Shared packages: resolved. It says "several" and adds pkg/auth/dcr, so the list is accurate.
  5. Named consumers (Stacklok Enterprise Platform, mecatl): not resolved. This is a question, not a blocker: confirm you want these two names in a public README, or drop them.
  6. OAuthRoutes / WellKnownRoutes: resolved. They are now qualified as handlers.Handler methods.
  7. Device flow single upstream: resolved. The README now says multi-upstream deployments fail at verification, which matches the per-request 500 in device_verification.go.
  8. Stale docs.go: resolved. The package doc is rewritten, and the example's types and fields exist.

Optional: the "can be imported independently" line lists storage, which still pulls in server (Fosite wiring). Either drop it from that list or say "without the root package".

🤖 Reviewed with Claude Code

@jhrozek
jhrozek merged commit 10943fb into main Nov 25, 2026
49 of 50 checks passed
@jhrozek
jhrozek deleted the as-readme branch November 25, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants