feat: add the CODER_OAUTH2_PROVIDER_ENABLE deployment flag (#29248)

First of five PRs for PLAT-492, adding the opt-in CODER_OAUTH2_PROVIDER_ENABLE flag for the OAuth 2.1 provider. It defaults to false and is not enforced yet, so there is no behavior change.

Adds the CLI/env/YAML flag and exposes oauth2_provider in build info.
Enables it by default in tests to prepare for route gating.
Updates tests, golden files, and frontend fixtures.
Follow-ups will gate routes/UI, retire the experiment, add startup logging, and update docs.
This commit is contained in:
Bobby Ho authored and GitHub committed 2026-09-14 08:31:26 -07:00
1 parent 2389af0932
commit 1cc73bc43f
16 files changed
+175 -6

No files matched your search

+7
View File
@@ -693,6 +693,13 @@ OAUTH2 / GITHUB OPTIONS:
Base URL of a GitHub Enterprise deployment to use for Login with
GitHub.
OAUTH2 / PROVIDER OPTIONS:
--oauth2-provider-enable bool, $CODER_OAUTH2_PROVIDER_ENABLE (default: false)
Enable the OAuth 2.1 authorization server, which lets external
applications (such as MCP clients) obtain tokens for Coder on behalf
of users. Disabled by default. When disabled, the OAuth2 endpoints and
discovery documents return 404.
OIDC OPTIONS:
--oidc-group-auto-create bool, $CODER_OIDC_GROUP_AUTO_CREATE (default: false)
Automatically creates missing groups from a user's groups claim.
+6
View File
@@ -321,6 +321,12 @@ oauth2:
# Base URL of a GitHub Enterprise deployment to use for Login with GitHub.
# (default: <unset>, type: string)
enterpriseBaseURL: ""
provider:
# Enable the OAuth 2.1 authorization server, which lets external applications
# (such as MCP clients) obtain tokens for Coder on behalf of users. Disabled by
# default. When disabled, the OAuth2 endpoints and discovery documents return 404.
# (default: false, type: bool)
enable: false
oidc:
# Whether new users can sign up with OIDC.
# (default: true, type: bool)
+15
View File
@@ -19299,6 +19299,10 @@ const docTemplate = `{
"description": "ExternalURL references the current Coder version.\nFor production builds, this will link directly to a release. For development builds, this will link to a commit.",
"type": "string"
},
"oauth2_provider": {
"description": "OAuth2Provider reports whether the OAuth 2.1 authorization server is\nenabled. The dashboard uses it to show or hide OAuth2 navigation.",
"type": "boolean"
},
"provisioner_api_version": {
"description": "ProvisionerAPIVersion is the current version of the Provisioner API",
"type": "string"
@@ -25193,6 +25197,9 @@ const docTemplate = `{
"properties": {
"github": {
"$ref": "#/definitions/codersdk.OAuth2GithubConfig"
},
"provider": {
"$ref": "#/definitions/codersdk.OAuth2ProviderConfig"
}
}
},
@@ -25369,6 +25376,14 @@ const docTemplate = `{
}
}
},
"codersdk.OAuth2ProviderConfig": {
"type": "object",
"properties": {
"enable": {
"type": "boolean"
}
}
},
"codersdk.OAuth2ProviderGrantType": {
"type": "string",
"enum": [
+15
View File
@@ -17341,6 +17341,10 @@
"description": "ExternalURL references the current Coder version.\nFor production builds, this will link directly to a release. For development builds, this will link to a commit.",
"type": "string"
},
"oauth2_provider": {
"description": "OAuth2Provider reports whether the OAuth 2.1 authorization server is\nenabled. The dashboard uses it to show or hide OAuth2 navigation.",
"type": "boolean"
},
"provisioner_api_version": {
"description": "ProvisionerAPIVersion is the current version of the Provisioner API",
"type": "string"
@@ -23021,6 +23025,9 @@
"properties": {
"github": {
"$ref": "#/definitions/codersdk.OAuth2GithubConfig"
},
"provider": {
"$ref": "#/definitions/codersdk.OAuth2ProviderConfig"
}
}
},
@@ -23194,6 +23201,14 @@
}
}
},
"codersdk.OAuth2ProviderConfig": {
"type": "object",
"properties": {
"enable": {
"type": "boolean"
}
}
},
"codersdk.OAuth2ProviderGrantType": {
"type": "string",
"enum": [
+1
View File
@@ -773,6 +773,7 @@ func New(options *Options) *API {
DeploymentID: api.DeploymentID,
WebPushPublicKey: api.WebpushDispatcher.PublicKey(),
Telemetry: api.Telemetry.Enabled(),
OAuth2Provider: api.DeploymentValues.OAuth2.Provider.Enable.Value(),
}
api.SiteHandler, err = site.New(&site.Options{
CacheDir: siteCacheDir,
+15
View File
@@ -56,6 +56,21 @@ func TestBuildInfo(t *testing.T) {
require.NoError(t, err)
require.Equal(t, buildinfo.ExternalURL(), buildInfo.ExternalURL, "external URL")
require.Equal(t, buildinfo.Version(), buildInfo.Version, "version")
require.True(t, buildInfo.OAuth2Provider, "coderdtest enables the OAuth2 provider by default")
}
func TestBuildInfoOAuth2ProviderDisabled(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
dv.OAuth2.Provider.Enable = false
}),
})
ctx := testutil.Context(t, testutil.WaitLong)
buildInfo, err := client.BuildInfo(ctx)
require.NoError(t, err)
require.False(t, buildInfo.OAuth2Provider)
}
func TestDERP(t *testing.T) {
+3
View File
@@ -1861,6 +1861,9 @@ func DeploymentValues(t testing.TB, mut ...func(*codersdk.DeploymentValues)) *co
opts := cfg.Options()
err := opts.SetDefaults()
require.NoError(t, err)
// The OAuth2 provider is off by default in production. Tests turn it on
// so OAuth2 routes are reachable without extra setup.
cfg.OAuth2.Provider.Enable = true
for _, fn := range mut {
fn(cfg)
}
+30 -2
View File
@@ -976,7 +976,17 @@ type PprofConfig struct {
}
type OAuth2Config struct {
Github OAuth2GithubConfig `json:"github" typescript:",notnull"`
Github OAuth2GithubConfig `json:"github" typescript:",notnull"`
Provider OAuth2ProviderConfig `json:"provider" typescript:",notnull"`
}
// OAuth2ProviderConfig configures Coder's own OAuth 2.1 authorization server.
// This is separate from the GitHub login integration. It is also distinct
// from OAuth2ProviderSettings: this struct decides whether the server is on
// at all, while OAuth2ProviderSettings holds runtime behavior such as
// dynamic client registration that admins change while it runs.
type OAuth2ProviderConfig struct {
Enable serpent.Bool `json:"enable" typescript:",notnull"`
}
type OAuth2GithubConfig struct {
@@ -1599,7 +1609,7 @@ communicating directly.`,
}
deploymentGroupOAuth2 = serpent.Group{
Name: "OAuth2",
Description: `Configure login and user-provisioning with GitHub via oAuth2.`,
Description: `Configure OAuth2: GitHub login and user-provisioning, and Coder's own OAuth 2.1 authorization server.`,
YAML: "oauth2",
}
deploymentGroupOAuth2GitHub = serpent.Group{
@@ -1607,6 +1617,11 @@ communicating directly.`,
Name: "GitHub",
YAML: "github",
}
deploymentGroupOAuth2Provider = serpent.Group{
Parent: &deploymentGroupOAuth2,
Name: "Provider",
YAML: "provider",
}
deploymentGroupOIDC = serpent.Group{
Name: "OIDC",
YAML: "oidc",
@@ -2700,6 +2715,16 @@ communicating directly.`,
Group: &deploymentGroupOAuth2GitHub,
YAML: "enterpriseBaseURL",
},
{
Name: "OAuth2 Provider Enable",
Description: "Enable the OAuth 2.1 authorization server, which lets external applications (such as MCP clients) obtain tokens for Coder on behalf of users. Disabled by default. When disabled, the OAuth2 endpoints and discovery documents return 404.",
Flag: "oauth2-provider-enable",
Env: "CODER_OAUTH2_PROVIDER_ENABLE",
Value: &c.OAuth2.Provider.Enable,
Group: &deploymentGroupOAuth2Provider,
YAML: "enable",
Default: "false",
},
// OIDC settings.
{
Name: "OIDC Allow Signups",
@@ -5118,6 +5143,9 @@ type BuildInfoResponse struct {
DashboardURL string `json:"dashboard_url"`
// Telemetry is a boolean that indicates whether telemetry is enabled.
Telemetry bool `json:"telemetry"`
// OAuth2Provider reports whether the OAuth 2.1 authorization server is
// enabled. The dashboard uses it to show or hide OAuth2 navigation.
OAuth2Provider bool `json:"oauth2_provider"`
WorkspaceProxy bool `json:"workspace_proxy"`
+12 -1
View File
@@ -1308,7 +1308,7 @@ The endpoint to which to send webhooks.
## OAuth2
Configure login and user-provisioning with GitHub via oAuth2.
Configure OAuth2: GitHub login and user-provisioning, and Coder's own OAuth 2.1 authorization server.
### GitHub
@@ -1385,6 +1385,17 @@ Base URL of a GitHub Enterprise deployment to use for Login with GitHub.
- CLI flag: [`--oauth2-github-enterprise-base-url`](../../reference/cli/server.md#--oauth2-github-enterprise-base-url)
- YAML key: `oauth2.github.enterpriseBaseURL`
### Provider
#### Enable
Enable the OAuth 2.1 authorization server, which lets external applications (such as MCP clients) obtain tokens for Coder on behalf of users. Disabled by default. When disabled, the OAuth2 endpoints and discovery documents return 404.
- Environment variable: `CODER_OAUTH2_PROVIDER_ENABLE`
- CLI flag: [`--oauth2-provider-enable`](../../reference/cli/server.md#--oauth2-provider-enable)
- YAML key: `oauth2.provider.enable`
- Default value: `false`
## OIDC
### Enable OIDC group auto create
+4
View File
@@ -62,6 +62,7 @@ curl -X GET http://coder-server:8080/api/v2/buildinfo \
"dashboard_url": "string",
"deployment_id": "string",
"external_url": "string",
"oauth2_provider": true,
"provisioner_api_version": "string",
"telemetry": true,
"upgrade_message": "string",
@@ -430,6 +431,9 @@ curl -X GET http://coder-server:8080/api/v2/deployment/config \
"default_provider_enable": true,
"device_flow": true,
"enterprise_base_url": "string"
},
"provider": {
"enable": true
}
},
"oidc": {
+29 -3
View File
@@ -2060,6 +2060,7 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
"dashboard_url": "string",
"deployment_id": "string",
"external_url": "string",
"oauth2_provider": true,
"provisioner_api_version": "string",
"telemetry": true,
"upgrade_message": "string",
@@ -2077,6 +2078,7 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
| `dashboard_url` | string | false | | Dashboard URL is the URL to hit the deployment's dashboard. For external workspace proxies, this is the coderd they are connected to. |
| `deployment_id` | string | false | | Deployment ID is the unique identifier for this deployment. |
| `external_url` | string | false | | External URL references the current Coder version. For production builds, this will link directly to a release. For development builds, this will link to a commit. |
| `oauth2_provider` | boolean | false | | Oauth2 provider reports whether the OAuth 2.1 authorization server is enabled. The dashboard uses it to show or hide OAuth2 navigation. |
| `provisioner_api_version` | string | false | | Provisioner api version is the current version of the Provisioner API |
| `telemetry` | boolean | false | | Telemetry is a boolean that indicates whether telemetry is enabled. |
| `upgrade_message` | string | false | | Upgrade message is the message displayed to users when an outdated client is detected. |
@@ -7486,6 +7488,9 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o
"default_provider_enable": true,
"device_flow": true,
"enterprise_base_url": "string"
},
"provider": {
"enable": true
}
},
"oidc": {
@@ -8093,6 +8098,9 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o
"default_provider_enable": true,
"device_flow": true,
"enterprise_base_url": "string"
},
"provider": {
"enable": true
}
},
"oidc": {
@@ -10771,15 +10779,19 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith
"default_provider_enable": true,
"device_flow": true,
"enterprise_base_url": "string"
},
"provider": {
"enable": true
}
}
```
### Properties
| Name | Type | Required | Restrictions | Description |
|----------|------------------------------------------------------------|----------|--------------|-------------|
| `github` | [codersdk.OAuth2GithubConfig](#codersdkoauth2githubconfig) | false | | |
| Name | Type | Required | Restrictions | Description |
|------------|----------------------------------------------------------------|----------|--------------|-------------|
| `github` | [codersdk.OAuth2GithubConfig](#codersdkoauth2githubconfig) | false | | |
| `provider` | [codersdk.OAuth2ProviderConfig](#codersdkoauth2providerconfig) | false | | |
## codersdk.OAuth2Error
@@ -10948,6 +10960,20 @@ Git clone makes use of this by parsing the URL from: 'Username for "https://gith
| `client_secret_full` | string | false | | |
| `id` | string | false | | |
## codersdk.OAuth2ProviderConfig
```json
{
"enable": true
}
```
### Properties
| Name | Type | Required | Restrictions | Description |
|----------|---------|----------|--------------|-------------|
| `enable` | boolean | false | | |
## codersdk.OAuth2ProviderGrantType
```json
+11
View File
@@ -461,6 +461,17 @@ Allow all logins, setting this option means allowed orgs and teams must be empty
Base URL of a GitHub Enterprise deployment to use for Login with GitHub.
### --oauth2-provider-enable
| | |
|-------------|--------------------------------------------|
| Type | <code>bool</code> |
| Environment | <code>$CODER_OAUTH2_PROVIDER_ENABLE</code> |
| YAML | <code>oauth2.provider.enable</code> |
| Default | <code>false</code> |
Enable the OAuth 2.1 authorization server, which lets external applications (such as MCP clients) obtain tokens for Coder on behalf of users. Disabled by default. When disabled, the OAuth2 endpoints and discovery documents return 404.
### --oidc-allow-signups
| | |
+7
View File
@@ -694,6 +694,13 @@ OAUTH2 / GITHUB OPTIONS:
Base URL of a GitHub Enterprise deployment to use for Login with
GitHub.
OAUTH2 / PROVIDER OPTIONS:
--oauth2-provider-enable bool, $CODER_OAUTH2_PROVIDER_ENABLE (default: false)
Enable the OAuth 2.1 authorization server, which lets external
applications (such as MCP clients) obtain tokens for Coder on behalf
of users. Disabled by default. When disabled, the OAuth2 endpoints and
discovery documents return 404.
OIDC OPTIONS:
--oidc-group-auto-create bool, $CODER_OIDC_GROUP_AUTO_CREATE (default: false)
Automatically creates missing groups from a user's groups claim.
+18
View File
@@ -1792,6 +1792,11 @@ export interface BuildInfoResponse {
* Telemetry is a boolean that indicates whether telemetry is enabled.
*/
readonly telemetry: boolean;
/**
* OAuth2Provider reports whether the OAuth 2.1 authorization server is
* enabled. The dashboard uses it to show or hide OAuth2 navigation.
*/
readonly oauth2_provider: boolean;
readonly workspace_proxy: boolean;
/**
* AgentAPIVersion is the current version of the Agent API (back versions
@@ -6592,6 +6597,7 @@ export const OAuth2ClientTypes: OAuth2ClientType[] = ["confidential", "public"];
// From codersdk/deployment.go
export interface OAuth2Config {
readonly github: OAuth2GithubConfig;
readonly provider: OAuth2ProviderConfig;
}
// From codersdk/oauth2.go
@@ -6711,6 +6717,18 @@ export interface OAuth2ProviderAppSecretFull {
readonly client_secret_full: string;
}
// From codersdk/deployment.go
/**
* OAuth2ProviderConfig configures Coder's own OAuth 2.1 authorization server.
* This is separate from the GitHub login integration. It is also distinct
* from OAuth2ProviderSettings: this struct decides whether the server is on
* at all, while OAuth2ProviderSettings holds runtime behavior such as
* dynamic client registration that admins change while it runs.
*/
export interface OAuth2ProviderConfig {
readonly enable: boolean;
}
// From codersdk/oauth2.go
export type OAuth2ProviderGrantType =
| "authorization_code"
+1
View File
@@ -248,6 +248,7 @@ export const MockBuildInfo: TypesGen.BuildInfoResponse = {
deployment_id: "510d407f-e521-4180-b559-eab4a6d802b8",
webpush_public_key: "fake-public-key",
telemetry: true,
oauth2_provider: true,
};
export const MockSupportLinks: TypesGen.LinkConfig[] = [
+1
View File
@@ -11,6 +11,7 @@ const baseBuildInfo: BuildInfoResponse = {
upgrade_message: "",
deployment_id: "test",
telemetry: false,
oauth2_provider: false,
};
describe("getPrereleaseFlag", () => {