2018-08-30 18:24:56 +00:00
# External OAUTH Authentication
2017-03-08 23:58:34 +00:00
### Overview
The `auth-url` and `auth-signin` annotations allow you to use an external
authentication provider to protect your Ingress resources.
2018-04-29 06:17:29 +00:00
!!! Important
2022-01-17 00:57:28 +00:00
This annotation requires `ingress-nginx-controller v0.9.0` or greater.
2017-03-08 23:58:34 +00:00
### Key Detail
This functionality is enabled by deploying multiple Ingress objects for a single host.
One Ingress object has no special annotations and handles authentication.
Other Ingress objects can then be annotated in such a way that require the user to
authenticate against the first Ingress's endpoint, and can redirect `401` s to the
same endpoint.
Sample:
2017-10-13 13:55:03 +00:00
```yaml
2017-03-08 23:58:34 +00:00
...
metadata:
name: application
annotations:
2018-07-04 09:57:51 +00:00
nginx.ingress.kubernetes.io/auth-url: "https://$host/oauth2/auth"
2018-07-19 06:22:05 +00:00
nginx.ingress.kubernetes.io/auth-signin: "https://$host/oauth2/start?rd=$escaped_request_uri"
2017-03-08 23:58:34 +00:00
...
```
### Example: OAuth2 Proxy + Kubernetes-Dashboard
2019-07-18 06:59:19 +00:00
This example will show you how to deploy [`oauth2_proxy` ](https://github.com/pusher/oauth2_proxy )
2022-01-17 00:57:28 +00:00
into a Kubernetes cluster and use it to protect the Kubernetes Dashboard using GitHub as the OAuth2 provider.
2017-03-08 23:58:34 +00:00
2017-10-13 13:55:03 +00:00
#### Prepare
2017-03-08 23:58:34 +00:00
1. Install the kubernetes dashboard
2022-01-17 00:57:28 +00:00
```console
kubectl create -f https://raw.githubusercontent.com/kubernetes/kops/master/addons/kubernetes-dashboard/v1.10.1.yaml
```
2017-03-08 23:58:34 +00:00
2022-01-17 00:57:28 +00:00
2. Create a [custom GitHub OAuth application ](https://github.com/settings/applications/new )
2017-03-08 23:58:34 +00:00
2022-01-17 00:57:28 +00:00

2017-03-09 14:39:18 +00:00
2022-01-17 00:57:28 +00:00
- Homepage URL is the FQDN in the Ingress rule, like `https://foo.bar.com`
- Authorization callback URL is the same as the base FQDN plus `/oauth2/callback` , like `https://foo.bar.com/oauth2/callback`
2017-03-08 23:58:34 +00:00
2022-01-17 00:57:28 +00:00

2017-03-09 14:39:18 +00:00
2024-01-28 16:32:47 +00:00
3. Configure values in the file [`oauth2-proxy.yaml` ](https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/docs/examples/auth/oauth-external-auth/oauth2-proxy.yaml ) with the values:
2017-03-08 23:58:34 +00:00
2022-01-17 00:57:28 +00:00
- OAUTH2_PROXY_CLIENT_ID with the github `<Client ID>`
- OAUTH2_PROXY_CLIENT_SECRET with the github `<Client Secret>`
- OAUTH2_PROXY_COOKIE_SECRET with value of `python -c 'import os,base64; print(base64.b64encode(os.urandom(16)).decode("ascii"))'`
2024-01-28 16:32:47 +00:00
- (optional, but recommended) OAUTH2_PROXY_GITHUB_USERS with GitHub usernames to allow to login
- `__INGRESS_HOST__` with a valid FQDN (e.g. `foo.bar.com` )
- `__INGRESS_SECRET__` with a Secret with a valid SSL certificate
2017-03-08 23:58:34 +00:00
2024-01-28 16:32:47 +00:00
4. Deploy the oauth2 proxy and the ingress rules by running:
2017-03-08 23:58:34 +00:00
2024-01-28 16:32:47 +00:00
```console
$ kubectl create -f oauth2-proxy.yaml
```
#### Test
Test the integration by accessing the configured URL, e.g. `https://foo.bar.com`



### Example: Vouch Proxy + Kubernetes-Dashboard
This example will show you how to deploy [`Vouch Proxy` ](https://github.com/vouch/vouch-proxy )
into a Kubernetes cluster and use it to protect the Kubernetes Dashboard using GitHub as the OAuth2 provider.
#### Prepare
1. Install the kubernetes dashboard
```console
kubectl create -f https://raw.githubusercontent.com/kubernetes/kops/master/addons/kubernetes-dashboard/v1.10.1.yaml
```
2. Create a [custom GitHub OAuth application ](https://github.com/settings/applications/new )

- Homepage URL is the FQDN in the Ingress rule, like `https://foo.bar.com`
- Authorization callback URL is the same as the base FQDN plus `/oauth2/auth` , like `https://foo.bar.com/oauth2/auth`

3. Configure Vouch Proxy values in the file [`vouch-proxy.yaml` ](https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/docs/examples/auth/oauth-external-auth/vouch-proxy.yaml ) with the values:
- VOUCH_COOKIE_DOMAIN with value of `<Ingress Host>`
- OAUTH_CLIENT_ID with the github `<Client ID>`
- OAUTH_CLIENT_SECRET with the github `<Client Secret>`
- (optional, but recommended) VOUCH_WHITELIST with GitHub usernames to allow to login
- `__INGRESS_HOST__` with a valid FQDN (e.g. `foo.bar.com` )
- `__INGRESS_SECRET__` with a Secret with a valid SSL certificate
2017-03-08 23:58:34 +00:00
2024-01-28 16:32:47 +00:00
4. Deploy Vouch Proxy and the ingress rules by running:
2017-10-13 13:55:03 +00:00
2022-01-17 00:57:28 +00:00
```console
2024-01-28 16:32:47 +00:00
$ kubectl create -f vouch-proxy.yaml
2022-01-17 00:57:28 +00:00
```
2024-01-28 16:32:47 +00:00
#### Test
2017-03-08 23:58:34 +00:00
2024-01-28 16:32:47 +00:00
Test the integration by accessing the configured URL, e.g. `https://foo.bar.com`
2017-03-09 14:39:18 +00:00

2022-01-17 00:57:28 +00:00

2017-03-09 15:09:49 +00:00
