git.iko.soy/typeable/oauth2-proxy
on 8cbf921 help sign in
450 lines 23 kB history raw
1---
2layout: default
3title: Auth Configuration
4permalink: /auth-configuration
5nav_order: 2
6---
8## OAuth Provider Configuration
10You will need to register an OAuth application with a Provider (Google, GitHub or another provider), and configure it with Redirect URI(s) for the domain you intend to run `oauth2-proxy` on.
12Valid providers are :
14- [Google](#google-auth-provider) _default_
15- [Azure](#azure-auth-provider)
16- [Facebook](#facebook-auth-provider)
17- [GitHub](#github-auth-provider)
18- [Keycloak](#keycloak-auth-provider)
19- [GitLab](#gitlab-auth-provider)
20- [LinkedIn](#linkedin-auth-provider)
21- [Microsoft Azure AD](#microsoft-azure-ad-provider)
22- [OpenID Connect](#openid-connect-provider)
23- [login.gov](#logingov-provider)
24- [Nextcloud](#nextcloud-provider)
25- [DigitalOcean](#digitalocean-auth-provider)
26- [Bitbucket](#bitbucket-auth-provider)
27- [Gitea](#gitea-auth-provider)
29The provider can be selected using the `provider` configuration value.
31Please note that not all providers support all claims. The `preferred_username` claim is currently only supported by the OpenID Connect provider.
33### Google Auth Provider
35For Google, the registration steps are:
371. Create a new project: https://console.developers.google.com/project
382. Choose the new project from the top right project dropdown (only if another project is selected)
393. In the project Dashboard center pane, choose **"API Manager"**
404. In the left Nav pane, choose **"Credentials"**
415. In the center pane, choose **"OAuth consent screen"** tab. Fill in **"Product name shown to users"** and hit save.
426. In the center pane, choose **"Credentials"** tab.
43 - Open the **"New credentials"** drop down
44 - Choose **"OAuth client ID"**
45 - Choose **"Web application"**
46 - Application name is freeform, choose something appropriate
47 - Authorized JavaScript origins is your domain ex: `https://internal.yourcompany.com`
48 - Authorized redirect URIs is the location of oauth2/callback ex: `https://internal.yourcompany.com/oauth2/callback`
49 - Choose **"Create"**
507. Take note of the **Client ID** and **Client Secret**
52It's recommended to refresh sessions on a short interval (1h) with `cookie-refresh` setting which validates that the account is still authorized.
54#### Restrict auth to specific Google groups on your domain. (optional)
561. Create a service account: https://developers.google.com/identity/protocols/OAuth2ServiceAccount and make sure to download the json file.
572. Make note of the Client ID for a future step.
583. Under "APIs & Auth", choose APIs.
594. Click on Admin SDK and then Enable API.
605. Follow the steps on https://developers.google.com/admin-sdk/directory/v1/guides/delegation#delegate_domain-wide_authority_to_your_service_account and give the client id from step 2 the following oauth scopes:
62```
63https://www.googleapis.com/auth/admin.directory.group.readonly
64https://www.googleapis.com/auth/admin.directory.user.readonly
65```
676. Follow the steps on https://support.google.com/a/answer/60757 to enable Admin API access.
687. Create or choose an existing administrative email address on the Gmail domain to assign to the `google-admin-email` flag. This email will be impersonated by this client to make calls to the Admin SDK. See the note on the link from step 5 for the reason why.
698. Create or choose an existing email group and set that email to the `google-group` flag. You can pass multiple instances of this flag with different groups
70 and the user will be checked against all the provided groups.
719. Lock down the permissions on the json file downloaded from step 1 so only oauth2-proxy is able to read the file and set the path to the file in the `google-service-account-json` flag.
7210. Restart oauth2-proxy.
74Note: The user is checked against the group members list on initial authentication and every time the token is refreshed ( about once an hour ).
76### Azure Auth Provider
781. Add an application: go to [https://portal.azure.com](https://portal.azure.com), choose **"Azure Active Directory"** in the left menu, select **"App registrations"** and then click on **"New app registration"**.
792. Pick a name and choose **"Webapp / API"** as application type. Use `https://internal.yourcompany.com` as Sign-on URL. Click **"Create"**.
803. On the **"Settings"** / **"Properties"** page of the app, pick a logo and select **"Multi-tenanted"** if you want to allow users from multiple organizations to access your app. Note down the application ID. Click **"Save"**.
814. On the **"Settings"** / **"Required Permissions"** page of the app, click on **"Windows Azure Active Directory"** and then on **"Access the directory as the signed in user"**. Hit **"Save"** and then then on **"Grant permissions"** (you might need another admin to do this).
825. On the **"Settings"** / **"Reply URLs"** page of the app, add `https://internal.yourcompanycom/oauth2/callback` for each host that you want to protect by the oauth2 proxy. Click **"Save"**.
836. On the **"Settings"** / **"Keys"** page of the app, add a new key and note down the value after hitting **"Save"**.
847. Configure the proxy with
86```
87 --provider=azure
88 --client-id=<application ID from step 3>
89 --client-secret=<value from step 6>
90```
92Note: When using the Azure Auth provider with nginx and the cookie session store you may find the cookie is too large and doesn't get passed through correctly. Increasing the proxy_buffer_size in nginx or implementing the [redis session storage](configuration/sessions#redis-storage) should resolve this.
94### Facebook Auth Provider
961. Create a new FB App from <https://developers.facebook.com/>
972. Under FB Login, set your Valid OAuth redirect URIs to `https://internal.yourcompany.com/oauth2/callback`
99### GitHub Auth Provider
1011. Create a new project: https://github.com/settings/developers
1022. Under `Authorization callback URL` enter the correct url ie `https://internal.yourcompany.com/oauth2/callback`
104The GitHub auth provider supports two additional ways to restrict authentication to either organization and optional team level access, or to collaborators of a repository. Restricting by these options is normally accompanied with `--email-domain=*`
106NOTE: When `--github-user` is set, the specified users are allowed to login even if they do not belong to the specified org and team or collaborators.
108To restrict by organization only, include the following flag:
110 -github-org="": restrict logins to members of this organisation
112To restrict within an organization to specific teams, include the following flag in addition to `-github-org`:
114 -github-team="": restrict logins to members of any of these teams (slug), separated by a comma
116If you would rather restrict access to collaborators of a repository, those users must either have push access to a public repository or any access to a private repository:
118 -github-repo="": restrict logins to collaborators of this repository formatted as orgname/repo
120If you'd like to allow access to users with **read only** access to a **public** repository you will need to provide a [token](https://github.com/settings/tokens) for a user that has write access to the repository. The token must be created with at least the `public_repo` scope:
122 -github-token="": the token to use when verifying repository collaborators
124To allow a user to login with their username even if they do not belong to the specified org and team or collaborators, separated by a comma
126 -github-user="": allow logins by username, separated by a comma
128If you are using GitHub enterprise, make sure you set the following to the appropriate url:
130 -login-url="http(s)://<enterprise github host>/login/oauth/authorize"
131 -redeem-url="http(s)://<enterprise github host>/login/oauth/access_token"
132 -validate-url="http(s)://<enterprise github host>/api/v3"
134### Keycloak Auth Provider
1361. Create new client in your Keycloak with **Access Type** 'confidental' and **Valid Redirect URIs** 'https://internal.yourcompany.com/oauth2/callback'
1372. Take note of the Secret in the credential tab of the client
1383. Create a mapper with **Mapper Type** 'Group Membership' and **Token Claim Name** 'groups'.
140Make sure you set the following to the appropriate url:
142 -provider=keycloak
143 -client-id=<client you have created>
144 -client-secret=<your client's secret>
145 -login-url="http(s)://<keycloak host>/auth/realms/<your realm>/protocol/openid-connect/auth"
146 -redeem-url="http(s)://<keycloak host>/auth/realms/<your realm>/protocol/openid-connect/token"
147 -validate-url="http(s)://<keycloak host>/auth/realms/<your realm>/protocol/openid-connect/userinfo"
148 -keycloak-group=<user_group>
150The group management in keycloak is using a tree. If you create a group named admin in keycloak you should define the 'keycloak-group' value to /admin.
152### GitLab Auth Provider
154Whether you are using GitLab.com or self-hosting GitLab, follow [these steps to add an application](https://docs.gitlab.com/ce/integration/oauth_provider.html). Make sure to enable at least the `openid`, `profile` and `email` scopes.
156Restricting by group membership is possible with the following option:
158 -gitlab-group="": restrict logins to members of any of these groups (slug), separated by a comma
160If you are using self-hosted GitLab, make sure you set the following to the appropriate URL:
162 -oidc-issuer-url="<your gitlab url>"
164### LinkedIn Auth Provider
166For LinkedIn, the registration steps are:
1681. Create a new project: https://www.linkedin.com/secure/developer
1692. In the OAuth User Agreement section:
170 - In default scope, select r_basicprofile and r_emailaddress.
171 - In "OAuth 2.0 Redirect URLs", enter `https://internal.yourcompany.com/oauth2/callback`
1723. Fill in the remaining required fields and Save.
1734. Take note of the **Consumer Key / API Key** and **Consumer Secret / Secret Key**
175### Microsoft Azure AD Provider
177For adding an application to the Microsoft Azure AD follow [these steps to add an application](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app).
179Take note of your `TenantId` if applicable for your situation. The `TenantId` can be used to override the default `common` authorization server with a tenant specific server.
181### OpenID Connect Provider
183OpenID Connect is a spec for OAUTH 2.0 + identity that is implemented by many major providers and several open source projects. This provider was originally built against CoreOS Dex and we will use it as an example.
1851. Launch a Dex instance using the [getting started guide](https://github.com/coreos/dex/blob/master/Documentation/getting-started.md).
1862. Setup oauth2-proxy with the correct provider and using the default ports and callbacks.
1873. Login with the fixture use in the dex guide and run the oauth2-proxy with the following args:
189```
190 -provider oidc
191 -provider-display-name "My OIDC Provider"
192 -client-id oauth2-proxy
193 -client-secret proxy
194 -redirect-url http://127.0.0.1:4180/oauth2/callback
195 -oidc-issuer-url http://127.0.0.1:5556
196 -cookie-secure=false
197 -email-domain example.com
198```
200The OpenID Connect Provider (OIDC) can also be used to connect to other Identity Providers such as Okta. To configure the OIDC provider for Okta, perform
201the following steps:
203#### Configuring the OIDC Provider with Okta
2051. Log in to Okta using an administrative account. It is suggested you try this in preview first, `example.oktapreview.com`
2062. (OPTIONAL) If you want to configure authorization scopes and claims to be passed on to multiple applications,
207you may wish to configure an authorization server for each application. Otherwise, the provided `default` will work.
208* Navigate to **Security** then select **API**
209* Click **Add Authorization Server**, if this option is not available you may require an additional license for a custom authorization server.
210* Fill out the **Name** with something to describe the application you are protecting. e.g. 'Example App'.
211* For **Audience**, pick the URL of the application you wish to protect: https://example.corp.com
212* Fill out a **Description**
213* Add any **Access Policies** you wish to configure to limit application access.
214* The default settings will work for other options.
215[See Okta documentation for more information on Authorization Servers](https://developer.okta.com/docs/guides/customize-authz-server/overview/)
2163. Navigate to **Applications** then select **Add Application**.
217* Select **Web** for the **Platform** setting.
218* Select **OpenID Connect** and click **Create**
219* Pick an **Application Name** such as `Example App`.
220* Set the **Login redirect URI** to `https://example.corp.com`.
221* Under **General** set the **Allowed grant types** to `Authorization Code` and `Refresh Token`.
222* Leave the rest as default, taking note of the `Client ID` and `Client Secret`.
223* Under **Assignments** select the users or groups you wish to access your application.
2244. Create a configuration file like the following:
226```
227provider = "oidc"
228redirect_url = "https://example.corp.com/oauth2/callback"
229oidc_issuer_url = "https://corp.okta.com/oauth2/abCd1234"
230upstreams = [
231 "https://example.corp.com"
233email_domains = [
234 "corp.com"
236client_id = "XXXXX"
237client_secret = "YYYYY"
238pass_access_token = true
239cookie_secret = "ZZZZZ"
240skip_provider_button = true
241```
243The `oidc_issuer_url` is based on URL from your **Authorization Server**'s **Issuer** field in step 2, or simply https://corp.okta.com
244The `client_id` and `client_secret` are configured in the application settings.
245Generate a unique `client_secret` to encrypt the cookie.
247Then you can start the oauth2-proxy with `./oauth2-proxy --config /etc/example.cfg`
249#### Configuring the OIDC Provider with Okta - localhost
2501. Signup for developer account: https://developer.okta.com/signup/
2512. Create New `Web` Application: https://${your-okta-domain}/dev/console/apps/new
2523. Example Application Settings for localhost:
253 * **Name:** My Web App
254 * **Base URIs:** http://localhost:4180/
255 * **Login redirect URIs:** http://localhost:4180/oauth2/callback
256 * **Logout redirect URIs:** http://localhost:4180/
257 * **Group assignments:** `Everyone`
258 * **Grant type allowed:** `Authorization Code` and `Refresh Token`
2594. Make note of the `Client ID` and `Client secret`, they are needed in a future step
2605. Make note of the **default** Authorization Server Issuer URI from: https://${your-okta-domain}/admin/oauth2/as
2616. Example config file `/etc/localhost.cfg`
262 ```
263 provider = "oidc"
264 redirect_url = "http://localhost:4180/oauth2/callback"
265 oidc_issuer_url = "https://${your-okta-domain}/oauth2/default"
266 upstreams = [
267 "http://0.0.0.0:8080"
268 ]
269 email_domains = [
270 "*"
271 ]
272 client_id = "XXX"
273 client_secret = "YYY"
274 pass_access_token = true
275 cookie_secret = "ZZZ"
276 cookie_secure = false
277 skip_provider_button = true
278 # Note: use the following for testing within a container
279 # http_address = "0.0.0.0:4180"
280 ```
2817. Then you can start the oauth2-proxy with `./oauth2-proxy --config /etc/localhost.cfg`
283### login.gov Provider
285login.gov is an OIDC provider for the US Government.
286If you are a US Government agency, you can contact the login.gov team through the contact information
287that you can find on https://login.gov/developers/ and work with them to understand how to get login.gov
288accounts for integration/test and production access.
290A developer guide is available here: https://developers.login.gov/, though this proxy handles everything
291but the data you need to create to register your application in the login.gov dashboard.
293As a demo, we will assume that you are running your application that you want to secure locally on
294http://localhost:3000/, that you will be starting your proxy up on http://localhost:4180/, and that
295you have an agency integration account for testing.
297First, register your application in the dashboard. The important bits are:
298 * Identity protocol: make this `Openid connect`
299 * Issuer: do what they say for OpenID Connect. We will refer to this string as `${LOGINGOV_ISSUER}`.
300 * Public key: This is a self-signed certificate in .pem format generated from a 2048 bit RSA private key.
301 A quick way to do this is `openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3650 -nodes -subj '/C=US/ST=Washington/L=DC/O=GSA/OU=18F/CN=localhost'`,
302 The contents of the `key.pem` shall be referred to as `${OAUTH2_PROXY_JWT_KEY}`.
303 * Return to App URL: Make this be `http://localhost:4180/`
304 * Redirect URIs: Make this be `http://localhost:4180/oauth2/callback`.
305 * Attribute Bundle: Make sure that email is selected.
307Now start the proxy up with the following options:
308```
309./oauth2-proxy -provider login.gov \
310 -client-id=${LOGINGOV_ISSUER} \
311 -redirect-url=http://localhost:4180/oauth2/callback \
312 -oidc-issuer-url=https://idp.int.identitysandbox.gov/ \
313 -cookie-secure=false \
314 -email-domain=gsa.gov \
315 -upstream=http://localhost:3000/ \
316 -cookie-secret=somerandomstring12341234567890AB \
317 -cookie-domain=localhost \
318 -skip-provider-button=true \
319 -pubjwk-url=https://idp.int.identitysandbox.gov/api/openid_connect/certs \
320 -profile-url=https://idp.int.identitysandbox.gov/api/openid_connect/userinfo \
321 -jwt-key="${OAUTH2_PROXY_JWT_KEY}"
322```
323You can also set all these options with environment variables, for use in cloud/docker environments.
324One tricky thing that you may encounter is that some cloud environments will pass in environment
325variables in a docker env-file, which does not allow multiline variables like a PEM file.
326If you encounter this, then you can create a `jwt_signing_key.pem` file in the top level
327directory of the repo which contains the key in PEM format and then do your docker build.
328The docker build process will copy that file into your image which you can then access by
329setting the `OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem`
330environment variable, or by setting `--jwt-key-file=/etc/ssl/private/jwt_signing_key.pem` on the commandline.
332Once it is running, you should be able to go to `http://localhost:4180/` in your browser,
333get authenticated by the login.gov integration server, and then get proxied on to your
334application running on `http://localhost:3000/`. In a real deployment, you would secure
335your application with a firewall or something so that it was only accessible from the
336proxy, and you would use real hostnames everywhere.
338#### Skip OIDC discovery
340Some providers do not support OIDC discovery via their issuer URL, so oauth2-proxy cannot simply grab the authorization, token and jwks URI endpoints from the provider's metadata.
342In this case, you can set the `--skip-oidc-discovery` option, and supply those required endpoints manually:
344```
345 -provider oidc
346 -client-id oauth2-proxy
347 -client-secret proxy
348 -redirect-url http://127.0.0.1:4180/oauth2/callback
349 -oidc-issuer-url http://127.0.0.1:5556
350 -skip-oidc-discovery
351 -login-url http://127.0.0.1:5556/authorize
352 -redeem-url http://127.0.0.1:5556/token
353 -oidc-jwks-url http://127.0.0.1:5556/keys
354 -cookie-secure=false
355 -email-domain example.com
356```
358### Nextcloud Provider
360The Nextcloud provider allows you to authenticate against users in your
361Nextcloud instance.
363When you are using the Nextcloud provider, you must specify the urls via
364configuration, environment variable, or command line argument. Depending
365on whether your Nextcloud instance is using pretty urls your urls may be of the
366form `/index.php/apps/oauth2/*` or `/apps/oauth2/*`.
368Refer to the [OAuth2
369documentation](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/oauth2.html)
370to setup the client id and client secret. Your "Redirection URI" will be
371`https://internalapp.yourcompany.com/oauth2/callback`.
373```
374 -provider nextcloud
375 -client-id <from nextcloud admin>
376 -client-secret <from nextcloud admin>
377 -login-url="<your nextcloud url>/index.php/apps/oauth2/authorize"
378 -redeem-url="<your nextcloud url>/index.php/apps/oauth2/api/v1/token"
379 -validate-url="<your nextcloud url>/ocs/v2.php/cloud/user?format=json"
380```
382Note: in *all* cases the validate-url will *not* have the `index.php`.
384### DigitalOcean Auth Provider
3861. [Create a new OAuth application](https://cloud.digitalocean.com/account/api/applications)
387 * You can fill in the name, homepage, and description however you wish.
388 * In the "Application callback URL" field, enter: `https://oauth-proxy/oauth2/callback`, substituting `oauth2-proxy` with the actual hostname that oauth2-proxy is running on. The URL must match oauth2-proxy's configured redirect URL.
3892. Note the Client ID and Client Secret.
391To use the provider, pass the following options:
393```
394 --provider=digitalocean
395 --client-id=<Client ID>
396 --client-secret=<Client Secret>
397```
399 Alternatively, set the equivalent options in the config file. The redirect URL defaults to `https://<requested host header>/oauth2/callback`. If you need to change it, you can use the `--redirect-url` command-line option.
401### Bitbucket Auth Provider
4031. [Add a new OAuth consumer](https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html)
404 * In "Callback URL" use `https://<oauth2-proxy>/oauth2/callback`, substituting `<oauth2-proxy>` with the actual hostname that oauth2-proxy is running on.
405 * In Permissions section select:
406 * Account -> Email
407 * Team membership -> Read
408 * Repositories -> Read
4092. Note the Client ID and Client Secret.
411To use the provider, pass the following options:
413```
414 --provider=bitbucket
415 --client-id=<Client ID>
416 --client-secret=<Client Secret>
417```
419The default configuration allows everyone with Bitbucket account to authenticate. To restrict the access to the team members use additional configuration option: `--bitbucket-team=<Team name>`. To restrict the access to only these users who has access to one selected repository use `--bitbucket-repository=<Repository name>`.
422### Gitea Auth Provider
4241. Create a new application: `https://< your gitea host >/user/settings/applications`
4252. Under `Redirect URI` enter the correct URL i.e. `https://<proxied host>/oauth2/callback`
4263. Note the Client ID and Client Secret.
4274. Pass the following options to the proxy:
429```
430 --provider="github"
431 --redirect-url="https://<proxied host>/oauth2/callback"
432 --provider-display-name="Gitea"
433 --client-id="< client_id as generated by Gitea >"
434 --client-secret="< client_secret as generated by Gitea >"
435 --login-url="https://< your gitea host >/login/oauth/authorize"
436 --redeem-url="https://< your gitea host >/login/oauth/access_token"
437 --validate-url="https://< your gitea host >/api/v1"
438```
441## Email Authentication
443To authorize by email domain use `--email-domain=yourcompany.com`. To authorize individual email addresses use `--authenticated-emails-file=/path/to/file` with one email per line. To authorize all email addresses use `--email-domain=*`.
445## Adding a new Provider
447Follow the examples in the [`providers` package]({{ site.gitweb }}/providers/) to define a new
448`Provider` instance. Add a new `case` to
449[`providers.New()`]({{ site.gitweb }}/providers/providers.go) to allow `oauth2-proxy` to use the
450new `Provider`.