11# External Authentication
22
3+ Coder supports external authentication via OAuth2.0. This allows enabling any OAuth provider as well as integrations with Git providers,
4+ such as GitHub, GitLab, and Bitbucket.
5+
6+ External authentication can also be used to integrate with external services
7+ like JFrog Artifactory and others.
8+
39To add an external authentication provider, you'll need to create an OAuth
4- application. The following providers are supported :
10+ application. The following providers have been tested and work with Coder :
511
6- - [ GitHub] ( #github )
7- - [ GitLab] ( https://docs.gitlab.com/ee/integration/oauth_provider.html )
8- - [ BitBucket] ( https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/ )
912- [ Azure DevOps] ( https://learn.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops )
1013- [ Azure DevOps (via Entra ID)] ( https://learn.microsoft.com/en-us/entra/architecture/auth-oauth2 )
14+ - [ BitBucket] ( https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/ )
15+ - [ GitHub] ( #github )
16+ - [ GitLab] ( https://docs.gitlab.com/ee/integration/oauth_provider.html )
17+
18+ If you have experience with a provider that is not listed here, please
19+ [ file an issue] ( https://github.com/coder/internal/issues/new?title=request%28docs%29%3A+external-auth+-+request+title+here%0D%0A&labels=["customer-feedback","docs"]&body=doc%3A+%5Bexternal-auth%5D%28https%3A%2F%2Fcoder.com%2Fdocs%2Fadmin%2Fexternal-auth%29%0D%0A%0D%0Aplease+enter+your+request+here%0D%0A )
1120
12- The next step is to configure the Coder server to use the OAuth application by
13- setting the following environment variables:
21+ ## Configuration
22+
23+ After you create an OAuth application, set environment variables to configure the Coder server to use it:
1424
1525``` env
1626CODER_EXTERNAL_AUTH_0_ID="<USER_DEFINED_ID>"
1727CODER_EXTERNAL_AUTH_0_TYPE=<github|gitlab|azure-devops|bitbucket-cloud|bitbucket-server|etc>
18- CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
19- CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
28+ CODER_EXTERNAL_AUTH_0_CLIENT_ID=<OAuth app client ID>
29+ CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=<OAuth app client secret>
2030
21- # Optionally, configure a custom display name and icon
31+ # Optionally, configure a custom display name and icon:
2232CODER_EXTERNAL_AUTH_0_DISPLAY_NAME="Google Calendar"
2333CODER_EXTERNAL_AUTH_0_DISPLAY_ICON="https://mycustomicon.com/google.svg"
2434```
2535
2636The ` CODER_EXTERNAL_AUTH_0_ID ` environment variable is used for internal
27- reference. Therefore, it can be set arbitrarily (e.g., ` primary-github ` for your
28- GitHub provider) .
37+ reference. Set it with a value that helps you identify it. For example, you can use ` CODER_EXTERNAL_AUTH_0_ID=" primary-github" ` for your
38+ GitHub provider.
2939
30- ## GitHub
40+ Add the following code to any template to add a button to the workspace setup page which will allow you to authenticate with your provider:
3141
32- > If you don't require fine-grained access control, it's easier to configure a
33- > GitHub OAuth app!
42+ ``` tf
43+ data "coder_external_auth" "<github|gitlab|azure-devops|bitbucket-cloud|bitbucket-server|other>" {
44+ id = "<USER_DEFINED_ID>"
45+ }
3446
35- 1 . [ Create a GitHub App] ( https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app )
47+ # GitHub Example (CODER_EXTERNAL_AUTH_0_ID="primary-github")
48+ # makes a GitHub authentication token available at data.coder_external_auth.github.access_token
49+ data "coder_external_auth" "github" {
50+ id = "primary-github"
51+ }
3652
37- - Set the callback URL to
38- ` https://coder.example.com/external-auth/USER_DEFINED_ID/callback ` .
39- - Deactivate Webhooks.
40- - Enable fine-grained access to specific repositories or a subset of
41- permissions for security.
53+ ```
4254
43- ![ Register GitHub App ] ( ../images/admin/github-app-register.png )
55+ Inside your Terraform code, you now have access to authentication variables. Reference the documentation for your chosen provider for more information on how to supply it with a token.
4456
45- 2 . Adjust the GitHub App permissions. You can use more or less permissions than
46- are listed here, this is merely a suggestion that allows users to clone
47- repositories:
57+ ### Workspace CLI
4858
49- ![ Adjust GitHub App Permissions ] ( ../images/admin/github-app-permissions.png )
59+ Use [ ` external-auth ` ] ( ../reference/cli/external-auth.md ) in the Coder CLI to access a token within the workspace:
5060
51- | Name | Permission | Description |
52- | ---------------| --------------| --------------------------------------------------------|
53- | Contents | Read & Write | Grants access to code and commit statuses. |
54- | Pull requests | Read & Write | Grants access to create and update pull requests. |
55- | Workflows | Read & Write | Grants access to update files in ` .github/workflows/ ` . |
56- | Metadata | Read-only | Grants access to metadata written by GitHub Apps. |
57- | Members | Read-only | Grants access to organization members and teams. |
61+ ``` shell
62+ coder external-auth < USER_DEFINED_ID> access-token
63+ ```
5864
59- 3 . Install the App for your organization. You may select a subset of
60- repositories to grant access to.
65+ ## Git-provider specific env variables
6166
62- ![ Install GitHub App] ( ../images/admin/github-app-install.png )
67+ ### Azure DevOps
68+
69+ Azure DevOps requires the following environment variables:
6370
6471``` env
65- CODER_EXTERNAL_AUTH_0_ID="USER_DEFINED_ID "
66- CODER_EXTERNAL_AUTH_0_TYPE=github
72+ CODER_EXTERNAL_AUTH_0_ID="primary-azure-devops "
73+ CODER_EXTERNAL_AUTH_0_TYPE=azure-devops
6774CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
75+ # Ensure this value is your "Client Secret", not "App Secret"
6876CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
77+ CODER_EXTERNAL_AUTH_0_AUTH_URL="https://app.vssps.visualstudio.com/oauth2/authorize"
78+ CODER_EXTERNAL_AUTH_0_TOKEN_URL="https://app.vssps.visualstudio.com/oauth2/token"
6979```
7080
71- ## GitHub Enterprise
81+ ### Azure DevOps (via Entra ID)
7282
73- GitHub Enterprise requires the following environment variables:
83+ Azure DevOps (via Entra ID) requires the following environment variables:
7484
7585``` env
76- CODER_EXTERNAL_AUTH_0_ID="primary-github "
77- CODER_EXTERNAL_AUTH_0_TYPE=github
86+ CODER_EXTERNAL_AUTH_0_ID="primary-azure-devops "
87+ CODER_EXTERNAL_AUTH_0_TYPE=azure-devops-entra
7888CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
7989CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
80- CODER_EXTERNAL_AUTH_0_VALIDATE_URL="https://github.example.com/api/v3/user"
81- CODER_EXTERNAL_AUTH_0_AUTH_URL="https://github.example.com/login/oauth/authorize"
82- CODER_EXTERNAL_AUTH_0_TOKEN_URL="https://github.example.com/login/oauth/access_token"
90+ CODER_EXTERNAL_AUTH_0_AUTH_URL="https://login.microsoftonline.com/<TENANT ID>/oauth2/authorize"
8391```
8492
85- ## Bitbucket Server
93+ > Note: Your app registration in Entra ID requires the ` vso.code_write ` scope
94+
95+ ### Bitbucket Server
8696
8797Bitbucket Server requires the following environment variables:
8898
@@ -94,35 +104,50 @@ CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxx
94104CODER_EXTERNAL_AUTH_0_AUTH_URL=https://bitbucket.domain.com/rest/oauth2/latest/authorize
95105```
96106
97- ## Azure DevOps
107+ ### Gitea
98108
99- Azure DevOps requires the following environment variables:
109+ ``` env
110+ CODER_EXTERNAL_AUTH_0_ID="gitea"
111+ CODER_EXTERNAL_AUTH_0_TYPE=gitea
112+ CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxxx
113+ CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
114+ # If self managed, set the Auth URL to your Gitea instance
115+ CODER_EXTERNAL_AUTH_0_AUTH_URL="https://gitea.com/login/oauth/authorize"
116+ ```
117+
118+ The Redirect URI for Gitea should be
119+ ` https://coder.company.org/external-auth/gitea/callback ` .
120+
121+ ### GitHub
122+
123+ <blockquote class =" admonition tip " >
124+
125+ If you don't require fine-grained access control, it's easier to [ configure a GitHub OAuth app] ( #configure-a-github-oauth-app ) .
126+
127+ </blockquote >
100128
101129``` env
102- CODER_EXTERNAL_AUTH_0_ID="primary-azure-devops "
103- CODER_EXTERNAL_AUTH_0_TYPE=azure-devops
130+ CODER_EXTERNAL_AUTH_0_ID="USER_DEFINED_ID "
131+ CODER_EXTERNAL_AUTH_0_TYPE=github
104132CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
105- # Ensure this value is your "Client Secret", not "App Secret"
106133CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
107- CODER_EXTERNAL_AUTH_0_AUTH_URL="https://app.vssps.visualstudio.com/oauth2/authorize"
108- CODER_EXTERNAL_AUTH_0_TOKEN_URL="https://app.vssps.visualstudio.com/oauth2/token"
109134```
110135
111- ## Azure DevOps (via Entra ID)
136+ ### GitHub Enterprise
112137
113- Azure DevOps (via Entra ID) requires the following environment variables:
138+ GitHub Enterprise requires the following environment variables:
114139
115140``` env
116- CODER_EXTERNAL_AUTH_0_ID="primary-azure-devops "
117- CODER_EXTERNAL_AUTH_0_TYPE=azure-devops-entra
141+ CODER_EXTERNAL_AUTH_0_ID="primary-github "
142+ CODER_EXTERNAL_AUTH_0_TYPE=github
118143CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
119144CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
120- CODER_EXTERNAL_AUTH_0_AUTH_URL="https://login.microsoftonline.com/<TENANT ID>/oauth2/authorize"
145+ CODER_EXTERNAL_AUTH_0_VALIDATE_URL="https://github.example.com/api/v3/user"
146+ CODER_EXTERNAL_AUTH_0_AUTH_URL="https://github.example.com/login/oauth/authorize"
147+ CODER_EXTERNAL_AUTH_0_TOKEN_URL="https://github.example.com/login/oauth/access_token"
121148```
122149
123- > Note: Your app registration in Entra ID requires the ` vso.code_write ` scope
124-
125- ## GitLab self-managed
150+ ### GitLab self-managed
126151
127152GitLab self-managed requires the following environment variables:
128153
@@ -138,21 +163,11 @@ CODER_EXTERNAL_AUTH_0_TOKEN_URL="https://gitlab.company.org/oauth/token"
138163CODER_EXTERNAL_AUTH_0_REGEX=gitlab\.company\.org
139164```
140165
141- ## Gitea
142-
143- ``` env
144- CODER_EXTERNAL_AUTH_0_ID="gitea"
145- CODER_EXTERNAL_AUTH_0_TYPE=gitea
146- CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxxx
147- CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
148- # If self managed, set the Auth URL to your Gitea instance
149- CODER_EXTERNAL_AUTH_0_AUTH_URL="https://gitea.com/login/oauth/authorize"
150- ```
166+ ### JFrog Artifactory
151167
152- The Redirect URI for Gitea should be
153- ` https://coder.company.org/external-auth/gitea/callback ` .
168+ Visit the [ JFrog Artifactory] ( ../admin/integrations/jfrog-artifactory.md ) guide for instructions on how to set up for JFrog Artifactory.
154169
155- ## Self-managed git providers
170+ ## Self-managed Git providers
156171
157172Custom authentication and token URLs should be used for self-managed Git
158173provider deployments.
@@ -166,10 +181,6 @@ CODER_EXTERNAL_AUTH_0_REGEX=github\.company\.org
166181
167182> Note: The ` REGEX ` variable must be set if using a custom git domain.
168183
169- ## JFrog Artifactory
170-
171- Visit the [ JFrog Artifactory] ( ../admin/integrations/jfrog-artifactory.md ) guide for instructions on how to set up for JFrog Artifactory.
172-
173184## Custom scopes
174185
175186Optionally, you can request custom scopes:
@@ -178,6 +189,39 @@ Optionally, you can request custom scopes:
178189CODER_EXTERNAL_AUTH_0_SCOPES="repo:read repo:write write:gpg_key"
179190```
180191
192+ ## OAuth provider
193+
194+ ### Configure a GitHub OAuth app
195+
196+ 1 . [ Create a GitHub App] ( https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app )
197+
198+ - Set the callback URL to
199+ ` https://coder.example.com/external-auth/USER_DEFINED_ID/callback ` .
200+ - Deactivate Webhooks.
201+ - Enable fine-grained access to specific repositories or a subset of
202+ permissions for security.
203+
204+ ![ Register GitHub App] ( ../images/admin/github-app-register.png )
205+
206+ 1 . Adjust the GitHub app permissions. You can use more or fewer permissions than
207+ are listed here, this example allows users to clone
208+ repositories:
209+
210+ ![ Adjust GitHub App Permissions] ( ../images/admin/github-app-permissions.png )
211+
212+ | Name | Permission | Description |
213+ | ---------------| --------------| --------------------------------------------------------|
214+ | Contents | Read & Write | Grants access to code and commit statuses. |
215+ | Pull requests | Read & Write | Grants access to create and update pull requests. |
216+ | Workflows | Read & Write | Grants access to update files in ` .github/workflows/ ` . |
217+ | Metadata | Read-only | Grants access to metadata written by GitHub Apps. |
218+ | Members | Read-only | Grants access to organization members and teams. |
219+
220+ 1 . Install the App for your organization. You may select a subset of
221+ repositories to grant access to.
222+
223+ ![ Install GitHub App] ( ../images/admin/github-app-install.png )
224+
181225## Multiple External Providers
182226
183227<blockquote class =" info " >
0 commit comments