1
1
# External Authentication
2
2
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
+
3
9
To 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 :
5
11
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/ )
9
12
- [ Azure DevOps] ( https://learn.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops )
10
13
- [ 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 )
11
20
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:
14
24
15
25
``` env
16
26
CODER_EXTERNAL_AUTH_0_ID="<USER_DEFINED_ID>"
17
27
CODER_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>
20
30
21
- # Optionally, configure a custom display name and icon
31
+ # Optionally, configure a custom display name and icon:
22
32
CODER_EXTERNAL_AUTH_0_DISPLAY_NAME="Google Calendar"
23
33
CODER_EXTERNAL_AUTH_0_DISPLAY_ICON="https://mycustomicon.com/google.svg"
24
34
```
25
35
26
36
The ` 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.
29
39
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:
31
41
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
+ }
34
46
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
+ }
36
52
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
+ ```
42
54
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.
44
56
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
48
58
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:
50
60
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
+ ```
58
64
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
61
66
62
- ![ Install GitHub App] ( ../images/admin/github-app-install.png )
67
+ ### Azure DevOps
68
+
69
+ Azure DevOps requires the following environment variables:
63
70
64
71
``` 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
67
74
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
75
+ # Ensure this value is your "Client Secret", not "App Secret"
68
76
CODER_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"
69
79
```
70
80
71
- ## GitHub Enterprise
81
+ ### Azure DevOps (via Entra ID)
72
82
73
- GitHub Enterprise requires the following environment variables:
83
+ Azure DevOps (via Entra ID) requires the following environment variables:
74
84
75
85
``` 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
78
88
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
79
89
CODER_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"
83
91
```
84
92
85
- ## Bitbucket Server
93
+ > Note: Your app registration in Entra ID requires the ` vso.code_write ` scope
94
+
95
+ ### Bitbucket Server
86
96
87
97
Bitbucket Server requires the following environment variables:
88
98
@@ -94,35 +104,50 @@ CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxx
94
104
CODER_EXTERNAL_AUTH_0_AUTH_URL=https://bitbucket.domain.com/rest/oauth2/latest/authorize
95
105
```
96
106
97
- ## Azure DevOps
107
+ ### Gitea
98
108
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 >
100
128
101
129
``` 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
104
132
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
105
- # Ensure this value is your "Client Secret", not "App Secret"
106
133
CODER_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"
109
134
```
110
135
111
- ## Azure DevOps (via Entra ID)
136
+ ### GitHub Enterprise
112
137
113
- Azure DevOps (via Entra ID) requires the following environment variables:
138
+ GitHub Enterprise requires the following environment variables:
114
139
115
140
``` 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
118
143
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
119
144
CODER_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"
121
148
```
122
149
123
- > Note: Your app registration in Entra ID requires the ` vso.code_write ` scope
124
-
125
- ## GitLab self-managed
150
+ ### GitLab self-managed
126
151
127
152
GitLab self-managed requires the following environment variables:
128
153
@@ -138,21 +163,11 @@ CODER_EXTERNAL_AUTH_0_TOKEN_URL="https://gitlab.company.org/oauth/token"
138
163
CODER_EXTERNAL_AUTH_0_REGEX=gitlab\.company\.org
139
164
```
140
165
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
151
167
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.
154
169
155
- ## Self-managed git providers
170
+ ## Self-managed Git providers
156
171
157
172
Custom authentication and token URLs should be used for self-managed Git
158
173
provider deployments.
@@ -166,10 +181,6 @@ CODER_EXTERNAL_AUTH_0_REGEX=github\.company\.org
166
181
167
182
> Note: The ` REGEX ` variable must be set if using a custom git domain.
168
183
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
-
173
184
## Custom scopes
174
185
175
186
Optionally, you can request custom scopes:
@@ -178,6 +189,39 @@ Optionally, you can request custom scopes:
178
189
CODER_EXTERNAL_AUTH_0_SCOPES="repo:read repo:write write:gpg_key"
179
190
```
180
191
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
+
181
225
## Multiple External Providers
182
226
183
227
<blockquote class =" info " >
0 commit comments