Repository navigation
feat: log the OAuth2 provider state and registered apps at startup - #29267
Conversation
Add an opt-in deployment flag for Coder's OAuth 2.1 authorization server. The flag is off by default and nothing reads it yet; a follow-up moves the OAuth2 routes and dashboard navigation off the oauth2 experiment and onto this flag. - Add oauth2.provider.enable (--oauth2-provider-enable, CODER_OAUTH2_PROVIDER_ENABLE) under a new Provider group beneath OAuth2, and reword the OAuth2 group so it covers more than GitHub login. - Add oauth2_provider to the build info response so the dashboard can read the provider state without an admin-only config request. - Turn the flag on by default in coderdtest so existing OAuth2 tests keep working once the routes are gated on it. - Regenerate API docs, TypeScript types, the CLI reference, and golden files. Part of PLAT-492.
Read the build info flag value through api.DeploymentValues like the neighbouring fields, and distinguish OAuth2ProviderConfig from OAuth2ProviderSettings in its doc comment.
Move every OAuth2 provider gate off the oauth2 experiment and onto the deployment flag added in the previous commit. The flag is off by default, so a deployment that relied on CODER_EXPERIMENTS=oauth2 must set it or its OAuth2 clients receive 404 responses after upgrading. - Add httpmw.RequireOAuth2Provider, which answers 404 while the provider is disabled. A disabled provider looks like a deployment that never had one. There is no bypass for development builds. - Use it on both discovery documents, the /oauth2 tree, the admin apps API, and the MCP HTTP endpoint, which keeps its mcp-server-http experiment check. The AI Gateway's deprecated MCP injection reads the flag too. - Keep /api/v2/oauth2-provider/settings reachable while disabled so an admin can configure dynamic client registration before enabling the provider. - Gate both OAuth2 navigation items on the new build info field instead of the experiment, and drop the development-build escape hatch. The oauth2 experiment is still parsed and reported; a follow-up makes it a no-op with a specific warning. Part of PLAT-492.
RequireOAuth2Provider takes a bool: the flag is read once at startup in three places, so the closure promised a runtime toggle that would ship half-working. The settings comment moves onto the route it describes, and both enabled sidebar stories set the flag explicitly instead of relying on the fixture default.
The MCP HTTP endpoint no longer has a development-build bypass for the mcp-server-http experiment, so tests that reach it must opt in.
…ER_ENABLE The oauth2 experiment no longer does anything. ReadExperiments drops it from the result and logs one warning per process naming the flag, so an admin whose OAuth2 clients start getting 404s after upgrading sees why. The constant stays known for one release so the warning can be specific; the next release removes it.
The deprecation warning promised removal in the next release, which no ticket backed. Removal is now tracked in PLAT-635, so the message says a future release and the code comment names the ticket. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Trim the doc comment on the message constant to its purpose so it cannot drift from the literal. Assert the deprecation warning by count instead of an exact warn slice, which coupled the test to the safety classification of an unrelated experiment, and check explicitly that no unknown-experiment warning leaks. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Every coder server start logs one info line stating whether the OAuth2 provider is enabled, naming CODER_OAUTH2_PROVIDER_ENABLE. When the provider is disabled and applications are still registered, one warning gives the count and the flag to set. A failed query is logged and does not abort startup. The SpammyLogs test allows two more rows for the new line.
|
/coder-agents-review |
|
/coder-agents-review |
|
/coder-agents-review |
Experiments carry no compatibility guarantee and previously graduated experiments were deleted outright, so the oauth2 experiment goes the same way. The constant, its display name, the known-list entry and the recognized no-op branch in ReadExperiments are gone, along with the once-per-process deprecation warning and its tests. A leftover CODER_EXPERIMENTS=oauth2 value is now handled like any other unknown experiment: the server logs "ignoring unknown experiment" and nothing gates on it. The startup provider-state lines and the release note carry the migration message pointing at CODER_OAUTH2_PROVIDER_ENABLE.
|
/coder-agents-review |
|
Chat: Review in progress (16/16 reviewers complete) | View chat deep-review v0.9.0 | Round 2 | Last posted: Round 2, 7 findings (1 P0, 1 P3, 4 Nit, 1 Note), COMMENT. Review Finding inventoryFinding inventory - PR #29267Findings
Contested and acknowledgedNone. Round logRound 1Netero-only first pass. 1 P0. Reviewed against bbaa055..68a5306. P0 blocks panel per pre-panel Netero gate; posting first-pass review only. CI red (gen, lint, test-go-pg, test-go-pg-17, test-go-race-pg); the P0 is the root cause of the lint and test-go jobs. Round 2 updateChurn guard: PROCEED. CRF-1 addressed in 3581cf8 (switched test to About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
First-pass review only. These are mechanical findings from Netero; the full review panel has not yet reviewed this PR and will do so after the first-pass finding is addressed.
The change itself is small and well-scoped: one startup log line recording whether the OAuth2 provider is enabled, a warning when it is disabled with apps still registered, and a table-driven test covering enabled, disabled-no-apps, disabled-with-apps, and query-error cases. The AsSystemRestricted startup read carries the right //nolint:gocritic justification, and the SpammyLogs threshold bump is explained by a comment.
One blocker: the new test references a logRecorder type that does not exist anywhere in the tree, so the coderd test package does not compile. This is the root cause of the failing lint and test-go CI jobs. gen also fails in CI; that may be independent and is worth checking separately.
Severity count: 1 P0.
As Netero put it: production code builds, so "the failure is isolated to this test file" but it takes the whole coderd test binary down with it.
🤖 This review was automatically generated with Coder Agents.
The test referenced a logRecorder type that was never defined, so the coderd package failed to compile in test mode and every Go CI job broke. Reuse the existing testutil.FakeSink instead of adding a new helper.
|
/coder-agents-review |
There was a problem hiding this comment.
The panel reviewed this round; the P0 from round 1 is resolved. CRF-1 (undefined logRecorder) is verified fixed in 3581cf8: the test now uses the existing testutil.FakeSink, go test ./coderd/ -run TestLogOAuth2ProviderState passes, and LogOAuth2ProviderState reads 100% covered. The fix reuses infrastructure rather than adding a new helper, which is the right call.
The change is small, well-scoped, and honest. Pariston tried to build a case against it and could not: a default-off, startup-only flag that silently strands registered apps is correctly diagnosed, the log-line mechanism fits a boot-only value better than an audit row or settings page, and the PR description discloses those absences plainly. The AsSystemRestricted startup read is authorized correctly (ActionRead on ResourceOauth2App), carries an accurate //nolint:gocritic justification, and exposes only a count, not app contents.
Nothing here blocks. The remaining findings are one test-completeness gap and a cluster of convention nits, all in code the author should settle now since no follow-up round is assumed.
The strongest signal is a test that looks thorough but does not pin the feature's stated deliverable: the flag field. As Bisky put it, "Four rows, four genuinely different code paths... No costume jewelry", but the helper "throws away every field, so the flag field that is the whole point of the info line is never asserted." Chopper adds that the query-error branch would still pass if slog.Error(err) were dropped.
Two observations not worth an inline comment: the helper is exported from coderd for a single cli caller while its startup siblings are unexported cli helpers (Ryosuke: defensible, coderd.ReadExperiments is the counter-precedent), and the level-filter predicate in the test is now the fourth hand-written copy in the repo (Robin: a shared testutil AtLevel(level) predicate would retire all four next time someone touches that package).
Severity count: 1 P3, 4 Nit, 1 Note.
🤖 This review was automatically generated with Coder Agents.
Move the registered application count from the warning text into a structured field so the message is static, rename the flag field variable, drop the redundant const comment, and assert the logged fields in the test.
…ENABLE (#29257) Third of five for PLAT-492. Removes the oauth2 experiment entirely; CODER_EXPERIMENTS=oauth2 is now treated as an unknown experiment and nothing depends on it. Stacked on #29251. No migration. Removes ExperimentOAuth2 and its generated/API references. Removed outright per review, consistent with experiments having no compatibility guarantee. Migration guidance is covered by the startup logging in #29267 and docs/release notes in #29268, both pointing to CODER_OAUTH2_PROVIDER_ENABLE. Existing unknown-experiment handling and tests already cover leftover oauth2 values. After this merges, main is safe to cut a release from.
dylanhuff-at-coder
left a comment
There was a problem hiding this comment.
One non-blocking comment on the startup warning, otherwise lgtm
…survive disable Disabling the provider blocks new authorizations and token exchanges but does not invalidate already-issued access tokens, which keep authenticating API requests until they expire or are revoked. The prior wording implied existing authorizations stopped working entirely.
TL;DR
Fourth of five for PLAT-492. Every
coder serverstart logs whether the OAuth2 provider is enabled, namingCODER_OAUTH2_PROVIDER_ENABLE. If the provider is off but applications are still registered, one warning gives the count and the flag to set.oauth2experiment.Implementation Details
coderd.LogOAuth2ProviderStatelogsoauth2 provider enabledoroauth2 provider disabledat info with aflagfield.GetOAuth2ProviderAppsunder a system context and warns with the count. A query error is logged at warn and startup continues.cli/server.gocalls it once after the database connects, beforecoderd.New.TestServer/SpammyLogsallows two more rows. The new line wraps to two rows at 80 columns.Tests
TestLogOAuth2ProviderStateruns adbmocktable: enabled, disabled with zero apps, disabled with two apps, and a query error. Each case asserts exactly one info line and the expected warnings.Manual Tests
Run 2026-09-14 in a Coder workspace against embedded Postgres. Two checkouts share one
.coderv2:~/coder-beforeat the merge base (v2.37.0-devel+c26a6b86a9, before the stack) and~/coderat the stack head (v2.37.0-devel+d3df4aa16a, #29248 through this PR). Each scenario restartsscripts/develop.shundertmuxwith a different environment, so the same database, session and registered apps carry across every upgrade and flag change. Requests run on the workspace againstlocalhost:3000. Token values are shown as prefix and length only.Scenario summary, all 36
CODER_EXPERIMENTS=oauth2reports["oauth2"]HERE BE DRAGONSline foroauth2and no line namingCODER_OAUTH2_PROVIDER_ENABLEoauth2_providerfield--oauth2-provider-enableas an unknown flagignoring unknown experiment,oauth2 provider disabled, and the warning naming 2 registered appsHERE BE DRAGONSline foroauth2on the new binaryoauth2through like any unknown valueoauth2_provider: false/oauth2/registerstays 404oauth2 provider enabled, no apps warningenabledlineoauth2_provider: true; experiments[]mcp-server-httpCODER_EXPERIMENTS=OAuth2is lower-cased in the warningCODER_EXPERIMENTS=*never mentionsoauth2; routes 404--oauth2-provider-enableon the command line enables the provider;--helpshows the optionoauth2.provider.enable: truein YAML enables the providerCODER_OAUTH2_PROVIDER_ENABLE=trueon the old binary is ignoredThree expectations in the runbook were wrong and are corrected in the notes below: the unknown-experiment and dragons lines print four times per start, not three; the old binary's MCP route answers 415 rather than 403 because the dev bypass skips the experiment gate; and a second code grant for the same user and app replaces the previous token pair instead of adding one.
Environment and shell helpers
start_serverrunsdevelop.shin a detachedtmuxsession with the given environment and tees the log to a per-start file.stop_serverends the session and also stops the embedded Postgres, which otherwise outlivesdevelop.shand blocks the next start onpostmaster.pid.Request helpers, run on the workspace:
Fixtures, registered through the API on the pre-upgrade binary:
1. Baseline: the pre-upgrade binary with the experiment (scenarios 1 to 5)
The dragons line prints four times, once per
ReadExperimentscall at startup. The MCP route answers 415, not the 403 first expected:RequireExperimentWithDevBypassreturns early on a dev build, so the request reaches the MCP transport and its Content-Type check answers. This is the baseline section 4 is compared against. The unknown-flag error is why the release note recommends the environment variable for the zero-downtime path.2. Fixtures: two apps and a live token pair (scenarios 6 to 9)
2|1|1and0are the invariant the upgrade must not move. The row ids are kept so section 4 can show the same rows survive, not just the same counts.3. Upgrade in place, environment unchanged (scenarios 10 to 14)
CODER_EXPERIMENTS=oauth2is still set; the flag is not. This is the moment the startup lines in this PR are for.The same session token authenticates across the restart. The state line and the apps warning print once each; the count in the warning is the two fixtures.
ReadExperimentswarns about the unknown value but still appends it, so the endpoint keeps echoingoauth2; nothing reads it, as section 4 shows.4. Flag unset: what an upgraded deployment sees (scenarios 15 to 22)
Every route that served in section 1 now 404s, including the apps list under a valid Owner session and the MCP route. The body is the generic
RouteNotFound, not an RFC 6749 error, so a disabled provider looks like a deployment that never had one. The access token keeps working because the API key middleware does not consult the gate; the refresh token is refused before the handler runs, so its row is untouched. Settings are outside the gate, so DCR can be pre-configured while/oauth2/registerstays 404. The only audit row since the upgrade is the PUT: the startup query in this PR runs under a system context and audits nothing. Schema version and every row id are what they were before the upgrade.Dashboard, as the Owner: no "OAuth2 Applications" item in the Deployment sidebar (
/deployment/overview) or the Account sidebar (/settings/account). Typing/deployment/oauth2-provider/appsdirectly renders the page with a "Route not found." error box above an empty table.5. The admin sets the flag (scenarios 23 to 29)
With the flag on, the apps warning is gone because the check returns before the query. With the experiment removed as well, the api child logs no warning of any kind. Every route from section 1 is back;
registeris 400 rather than 403 because DCR was switched on in section 4, and MCP is 403 namingmcp-server-httpbecause the new binary has no dev bypass. The refresh token that section 4 could not redeem redeems here unchanged, which is the observable form of "preserved". The counts stay2|1|1after the second grant because the code grant deletes the previous key with the same token name for that user and app before inserting (coderd/oauth2provider/tokens.go, "Delete the previous key, if any"), so there is one live pair per user per app.Dashboard, as the Owner: "OAuth2 Applications" is present in both sidebars, and
/deployment/oauth2-provider/appslistsplat492-idleandplat492-live.6. Edge cases and the other flag forms (scenarios 30 to 36)
The MCP experiment alone no longer suffices:
RequireOAuth2Providerruns beforeRequireExperiment, so the 404 wins over the 403. Mixed case is lower-cased before the switch.*expands toExperimentsSafe, which never containedoauth2. All three flag forms produce the same state line and build info value. The old binary ignores the new environment variable entirely, which is the zero-downtime path: set the variable, then upgrade.Incidental, outside this stack: the MCP 403 message reads "Functionality functionality" because the experiment's display name already ends in that word and the middleware template appends it again.