|
| 1 | +# Authentication |
| 2 | + |
| 3 | +. |
| 4 | + |
| 5 | +By default, Coder is accessible via password authentication. Coder does not |
| 6 | +recommend using password authentication in production, and recommends using an |
| 7 | +authentication provider with properly configured multi-factor authentication |
| 8 | +(MFA). It is your responsibility to ensure the auth provider enforces MFA |
| 9 | +correctly. |
| 10 | + |
| 11 | +The following steps explain how to set up GitHub OAuth or OpenID Connect. |
| 12 | + |
| 13 | +## GitHub |
| 14 | + |
| 15 | +### Step 1: Configure the OAuth application in GitHub |
| 16 | + |
| 17 | +First, |
| 18 | +[register a GitHub OAuth app](https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app/). |
| 19 | +GitHub will ask you for the following Coder parameters: |
| 20 | + |
| 21 | +- **Homepage URL**: Set to your Coder deployments |
| 22 | + [`CODER_ACCESS_URL`](../cli/server.md#--access-url) (e.g. |
| 23 | + `https://coder.domain.com`) |
| 24 | +- **User Authorization Callback URL**: Set to `https://coder.domain.com` |
| 25 | + |
| 26 | +> Note: If you want to allow multiple coder deployments hosted on subdomains |
| 27 | +> e.g. coder1.domain.com, coder2.domain.com, to be able to authenticate with the |
| 28 | +> same GitHub OAuth app, then you can set **User Authorization Callback URL** to |
| 29 | +> the `https://domain.com` |
| 30 | +
|
| 31 | +Note the Client ID and Client Secret generated by GitHub. You will use these |
| 32 | +values in the next step. |
| 33 | + |
| 34 | +Coder will need permission to access user email addresses. Find the "Account |
| 35 | +Permissions" settings for your app and select "read-only" for "Email addresses". |
| 36 | + |
| 37 | +### Step 2: Configure Coder with the OAuth credentials |
| 38 | + |
| 39 | +Navigate to your Coder host and run the following command to start up the Coder |
| 40 | +server: |
| 41 | + |
| 42 | +```shell |
| 43 | +coder server --oauth2-github-allow-signups=true --oauth2-github-allowed-orgs="your-org" --oauth2-github-client-id="8d1...e05" --oauth2-github-client-secret="57ebc9...02c24c" |
| 44 | +``` |
| 45 | + |
| 46 | +> For GitHub Enterprise support, specify the |
| 47 | +> `--oauth2-github-enterprise-base-url` flag. |
| 48 | +
|
| 49 | +Alternatively, if you are running Coder as a system service, you can achieve the |
| 50 | +same result as the command above by adding the following environment variables |
| 51 | +to the `/etc/coder.d/coder.env` file: |
| 52 | + |
| 53 | +```env |
| 54 | +CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS=true |
| 55 | +CODER_OAUTH2_GITHUB_ALLOWED_ORGS="your-org" |
| 56 | +CODER_OAUTH2_GITHUB_CLIENT_ID="8d1...e05" |
| 57 | +CODER_OAUTH2_GITHUB_CLIENT_SECRET="57ebc9...02c24c" |
| 58 | +``` |
| 59 | + |
| 60 | +**Note:** To allow everyone to signup using GitHub, set: |
| 61 | + |
| 62 | +```env |
| 63 | +CODER_OAUTH2_GITHUB_ALLOW_EVERYONE=true |
| 64 | +``` |
| 65 | + |
| 66 | +Once complete, run `sudo service coder restart` to reboot Coder. |
| 67 | + |
| 68 | +If deploying Coder via Helm, you can set the above environment variables in the |
| 69 | +`values.yaml` file as such: |
| 70 | + |
| 71 | +```yaml |
| 72 | +coder: |
| 73 | + env: |
| 74 | + - name: CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS |
| 75 | + value: "true" |
| 76 | + - name: CODER_OAUTH2_GITHUB_CLIENT_ID |
| 77 | + value: "533...des" |
| 78 | + - name: CODER_OAUTH2_GITHUB_CLIENT_SECRET |
| 79 | + value: "G0CSP...7qSM" |
| 80 | + # If setting allowed orgs, comment out CODER_OAUTH2_GITHUB_ALLOW_EVERYONE and its value |
| 81 | + - name: CODER_OAUTH2_GITHUB_ALLOWED_ORGS |
| 82 | + value: "your-org" |
| 83 | + # If allowing everyone, comment out CODER_OAUTH2_GITHUB_ALLOWED_ORGS and it's value |
| 84 | + #- name: CODER_OAUTH2_GITHUB_ALLOW_EVERYONE |
| 85 | + # value: "true" |
| 86 | +``` |
| 87 | + |
| 88 | +To upgrade Coder, run: |
| 89 | + |
| 90 | +```shell |
| 91 | +helm upgrade <release-name> coder-v2/coder -n <namespace> -f values.yaml |
| 92 | +``` |
| 93 | + |
| 94 | +> We recommend requiring and auditing MFA usage for all users in your GitHub |
| 95 | +> organizations. This can be enforced from the organization settings page in the |
| 96 | +> "Authentication security" sidebar tab. |
| 97 | +
|
| 98 | +## OpenID Connect |
| 99 | + |
| 100 | +The following steps through how to integrate any OpenID Connect provider (Okta, |
| 101 | +Active Directory, etc.) to Coder. |
| 102 | + |
| 103 | +### Step 1: Set Redirect URI with your OIDC provider |
| 104 | + |
| 105 | +Your OIDC provider will ask you for the following parameter: |
| 106 | + |
| 107 | +- **Redirect URI**: Set to `https://coder.domain.com/api/v2/users/oidc/callback` |
| 108 | + |
| 109 | +### Step 2: Configure Coder with the OpenID Connect credentials |
| 110 | + |
| 111 | +Navigate to your Coder host and run the following command to start up the Coder |
| 112 | +server: |
| 113 | + |
| 114 | +```shell |
| 115 | +coder server --oidc-issuer-url="https://issuer.corp.com" --oidc-email-domain="your-domain-1,your-domain-2" --oidc-client-id="533...des" --oidc-client-secret="G0CSP...7qSM" |
| 116 | +``` |
| 117 | + |
| 118 | +If you are running Coder as a system service, you can achieve the same result as |
| 119 | +the command above by adding the following environment variables to the |
| 120 | +`/etc/coder.d/coder.env` file: |
| 121 | + |
| 122 | +```env |
| 123 | +CODER_OIDC_ISSUER_URL="https://issuer.corp.com" |
| 124 | +CODER_OIDC_EMAIL_DOMAIN="your-domain-1,your-domain-2" |
| 125 | +CODER_OIDC_CLIENT_ID="533...des" |
| 126 | +CODER_OIDC_CLIENT_SECRET="G0CSP...7qSM" |
| 127 | +``` |
| 128 | + |
| 129 | +Once complete, run `sudo service coder restart` to reboot Coder. |
| 130 | + |
| 131 | +If deploying Coder via Helm, you can set the above environment variables in the |
| 132 | +`values.yaml` file as such: |
| 133 | + |
| 134 | +```yaml |
| 135 | +coder: |
| 136 | + env: |
| 137 | + - name: CODER_OIDC_ISSUER_URL |
| 138 | + value: "https://issuer.corp.com" |
| 139 | + - name: CODER_OIDC_EMAIL_DOMAIN |
| 140 | + value: "your-domain-1,your-domain-2" |
| 141 | + - name: CODER_OIDC_CLIENT_ID |
| 142 | + value: "533...des" |
| 143 | + - name: CODER_OIDC_CLIENT_SECRET |
| 144 | + value: "G0CSP...7qSM" |
| 145 | +``` |
| 146 | +
|
| 147 | +To upgrade Coder, run: |
| 148 | +
|
| 149 | +```shell |
| 150 | +helm upgrade <release-name> coder-v2/coder -n <namespace> -f values.yaml |
| 151 | +``` |
| 152 | + |
| 153 | +## OIDC Claims |
| 154 | + |
| 155 | +When a user logs in for the first time via OIDC, Coder will merge both the |
| 156 | +claims from the ID token and the claims obtained from hitting the upstream |
| 157 | +provider's `userinfo` endpoint, and use the resulting data as a basis for |
| 158 | +creating a new user or looking up an existing user. |
| 159 | + |
| 160 | +To troubleshoot claims, set `CODER_VERBOSE=true` and follow the logs while |
| 161 | +signing in via OIDC as a new user. Coder will log the claim fields returned by |
| 162 | +the upstream identity provider in a message containing the string |
| 163 | +`got oidc claims`, as well as the user info returned. |
| 164 | + |
| 165 | +> **Note:** If you need to ensure that Coder only uses information from the ID |
| 166 | +> token and does not hit the UserInfo endpoint, you can set the configuration |
| 167 | +> option `CODER_OIDC_IGNORE_USERINFO=true`. |
| 168 | +
|
| 169 | +### Email Addresses |
| 170 | + |
| 171 | +By default, Coder will look for the OIDC claim named `email` and use that value |
| 172 | +for the newly created user's email address. |
| 173 | + |
| 174 | +If your upstream identity provider users a different claim, you can set |
| 175 | +`CODER_OIDC_EMAIL_FIELD` to the desired claim. |
| 176 | + |
| 177 | +> **Note** If this field is not present, Coder will attempt to use the claim |
| 178 | +> field configured for `username` as an email address. If this field is not a |
| 179 | +> valid email address, OIDC logins will fail. |
| 180 | +
|
| 181 | +### Email Address Verification |
| 182 | + |
| 183 | +Coder requires all OIDC email addresses to be verified by default. If the |
| 184 | +`email_verified` claim is present in the token response from the identity |
| 185 | +provider, Coder will validate that its value is `true`. If needed, you can |
| 186 | +disable this behavior with the following setting: |
| 187 | + |
| 188 | +```env |
| 189 | +CODER_OIDC_IGNORE_EMAIL_VERIFIED=true |
| 190 | +``` |
| 191 | + |
| 192 | +> **Note:** This will cause Coder to implicitly treat all OIDC emails as |
| 193 | +> "verified", regardless of what the upstream identity provider says. |
| 194 | +
|
| 195 | +### Usernames |
| 196 | + |
| 197 | +When a new user logs in via OIDC, Coder will by default use the value of the |
| 198 | +claim field named `preferred_username` as the the username. |
| 199 | + |
| 200 | +If your upstream identity provider uses a different claim, you can set |
| 201 | +`CODER_OIDC_USERNAME_FIELD` to the desired claim. |
| 202 | + |
| 203 | +> **Note:** If this claim is empty, the email address will be stripped of the |
| 204 | +> domain, and become the username (e.g. `example@coder.com` becomes `example`). |
| 205 | +> To avoid conflicts, Coder may also append a random word to the resulting |
| 206 | +> username. |
| 207 | +
|
| 208 | +## OIDC Login Customization |
| 209 | + |
| 210 | +If you'd like to change the OpenID Connect button text and/or icon, you can |
| 211 | +configure them like so: |
| 212 | + |
| 213 | +```env |
| 214 | +CODER_OIDC_SIGN_IN_TEXT="Sign in with Gitea" |
| 215 | +CODER_OIDC_ICON_URL=https://gitea.io/images/gitea.png |
| 216 | +``` |
| 217 | + |
| 218 | +To change the icon and text above the OpenID Connect button, see application |
| 219 | +name and logo url in [appearance](./appearance.md) settings. |
| 220 | + |
| 221 | +## Disable Built-in Authentication |
| 222 | + |
| 223 | +To remove email and password login, set the following environment variable on |
| 224 | +your Coder deployment: |
| 225 | + |
| 226 | +```env |
| 227 | +CODER_DISABLE_PASSWORD_AUTH=true |
| 228 | +``` |
| 229 | + |
| 230 | +## SCIM (enterprise) |
| 231 | + |
| 232 | +Coder supports user provisioning and deprovisioning via SCIM 2.0 with header |
| 233 | +authentication. Upon deactivation, users are |
| 234 | +[suspended](./users.md#suspend-a-user) and are not deleted. |
| 235 | +[Configure](./configure.md) your SCIM application with an auth key and supply it |
| 236 | +the Coder server. |
| 237 | + |
| 238 | +```env |
| 239 | +CODER_SCIM_API_KEY="your-api-key" |
| 240 | +``` |
| 241 | + |
| 242 | +## TLS |
| 243 | + |
| 244 | +If your OpenID Connect provider requires client TLS certificates for |
| 245 | +authentication, you can configure them like so: |
| 246 | + |
| 247 | +```env |
| 248 | +CODER_TLS_CLIENT_CERT_FILE=/path/to/cert.pem |
| 249 | +CODER_TLS_CLIENT_KEY_FILE=/path/to/key.pem |
| 250 | +``` |
0 commit comments