Skip to content

Commit ee1829b

Browse files
EdwardAngertChristopherJTrentmatifali
authored
docs: update external auth to better explain process (coder#16027)
- adds to @ChristopherJTrent's PR coder#15970 > Adds more information on how to add external auth, including docker-compose and docker CLI examples and terraform code for template integration. - general edits and improvements to the external-auth doc [preview](https://coder.com/docs/@15970-external-auth-update/admin/external-auth) --------- Co-authored-by: Christopher Trent <[email protected]> Co-authored-by: Muhammad Atif Ali <[email protected]>
1 parent 8fb7832 commit ee1829b

File tree

2 files changed

+147
-105
lines changed

2 files changed

+147
-105
lines changed

docs/admin/external-auth.md

+121-77
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,98 @@
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+
39
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:
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
1626
CODER_EXTERNAL_AUTH_0_ID="<USER_DEFINED_ID>"
1727
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>
2030
21-
# Optionally, configure a custom display name and icon
31+
# Optionally, configure a custom display name and icon:
2232
CODER_EXTERNAL_AUTH_0_DISPLAY_NAME="Google Calendar"
2333
CODER_EXTERNAL_AUTH_0_DISPLAY_ICON="https://mycustomicon.com/google.svg"
2434
```
2535

2636
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.
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
6774
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
75+
# Ensure this value is your "Client Secret", not "App Secret"
6876
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"
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
7888
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
7989
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"
8391
```
8492

85-
## Bitbucket Server
93+
> Note: Your app registration in Entra ID requires the `vso.code_write` scope
94+
95+
### Bitbucket Server
8696

8797
Bitbucket Server requires the following environment variables:
8898

@@ -94,35 +104,50 @@ CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxx
94104
CODER_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
104132
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
105-
# Ensure this value is your "Client Secret", not "App Secret"
106133
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"
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
118143
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
119144
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"
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

127152
GitLab self-managed requires the following environment variables:
128153

@@ -138,21 +163,11 @@ CODER_EXTERNAL_AUTH_0_TOKEN_URL="https://gitlab.company.org/oauth/token"
138163
CODER_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

157172
Custom authentication and token URLs should be used for self-managed Git
158173
provider 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

175186
Optionally, you can request custom scopes:
@@ -178,6 +189,39 @@ Optionally, you can request custom scopes:
178189
CODER_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">

docs/admin/setup/index.md

+26-28
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ a wildcard subdomain that resolves to Coder (e.g. `*.coder.example.com`).
5252
If you are providing TLS certificates directly to the Coder server, either
5353

5454
1. Use a single certificate and key for both the root and wildcard domains.
55-
2. Configure multiple certificates and keys via
55+
1. Configure multiple certificates and keys via
5656
[`coder.tls.secretNames`](https://github.com/coder/coder/blob/main/helm/coder/values.yaml)
5757
in the Helm Chart, or
5858
[`--tls-cert-file`](../../reference/cli/server.md#--tls-cert-file) and
@@ -78,29 +78,27 @@ working directory prior to step 1.
7878

7979
1. Create the TLS secret in your Kubernetes cluster
8080

81-
```shell
82-
kubectl create secret tls coder-tls -n <coder-namespace> --key="tls.key" --cert="tls.crt"
83-
```
81+
```shell
82+
kubectl create secret tls coder-tls -n <coder-namespace> --key="tls.key" --cert="tls.crt"
83+
```
8484

85-
> You can use a single certificate for the both the access URL and wildcard
86-
> access URL. The certificate CN must match the wildcard domain, such as
87-
> `*.example.coder.com`.
85+
You can use a single certificate for the both the access URL and wildcard access URL. The certificate CN must match the wildcard domain, such as `*.example.coder.com`.
8886

8987
1. Reference the TLS secret in your Coder Helm chart values
9088

91-
```yaml
92-
coder:
93-
tls:
94-
secretName:
95-
- coder-tls
96-
97-
# Alternatively, if you use an Ingress controller to terminate TLS,
98-
# set the following values:
99-
ingress:
100-
enable: true
101-
secretName: coder-tls
102-
wildcardSecretName: coder-tls
103-
```
89+
```yaml
90+
coder:
91+
tls:
92+
secretName:
93+
- coder-tls
94+
95+
# Alternatively, if you use an Ingress controller to terminate TLS,
96+
# set the following values:
97+
ingress:
98+
enable: true
99+
secretName: coder-tls
100+
wildcardSecretName: coder-tls
101+
```
104102
105103
## PostgreSQL Database
106104
@@ -116,7 +114,7 @@ the PostgreSQL interactive terminal), output the connection URL with the
116114
following command:
117115

118116
```console
119-
coder server postgres-builtin-url
117+
$ coder server postgres-builtin-url
120118
psql "postgres://coder@localhost:49627/coder?sslmode=disable&password=feU...yI1"
121119
```
122120

@@ -126,13 +124,13 @@ To migrate from the built-in database to an external database, follow these
126124
steps:
127125

128126
1. Stop your Coder deployment.
129-
2. Run `coder server postgres-builtin-serve` in a background terminal.
130-
3. Run `coder server postgres-builtin-url` and copy its output command.
131-
4. Run `pg_dump <built-in-connection-string> > coder.sql` to dump the internal
127+
1. Run `coder server postgres-builtin-serve` in a background terminal.
128+
1. Run `coder server postgres-builtin-url` and copy its output command.
129+
1. Run `pg_dump <built-in-connection-string> > coder.sql` to dump the internal
132130
database to a file.
133-
5. Restore that content to an external database with
131+
1. Restore that content to an external database with
134132
`psql <external-connection-string> < coder.sql`.
135-
6. Start your Coder deployment with
133+
1. Start your Coder deployment with
136134
`CODER_PG_CONNECTION_URL=<external-connection-string>`.
137135

138136
## Configuring Coder behind a proxy
@@ -144,7 +142,7 @@ To configure Coder behind a corporate proxy, set the environment variables
144142
## External Authentication
145143

146144
Coder supports external authentication via OAuth2.0. This allows enabling
147-
integrations with git providers, such as GitHub, GitLab, and Bitbucket etc.
145+
integrations with Git providers, such as GitHub, GitLab, and Bitbucket.
148146

149147
External authentication can also be used to integrate with external services
150148
like JFrog Artifactory and others.
@@ -154,5 +152,5 @@ more information.
154152

155153
## Up Next
156154

157-
- [Learn how to setup and manage templates](../templates/index.md)
155+
- [Setup and manage templates](../templates/index.md)
158156
- [Setup external provisioners](../provisioners.md)

0 commit comments

Comments
 (0)