Skip to content

Commit 3652a0b

Browse files
committed
Add OIDC docs + examples
1 parent 68c3299 commit 3652a0b

File tree

4 files changed

+82
-11
lines changed

4 files changed

+82
-11
lines changed

README.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# Traefik Forward Auth [![Build Status](https://travis-ci.org/thomseddon/traefik-forward-auth.svg?branch=master)](https://travis-ci.org/thomseddon/traefik-forward-auth) [![Go Report Card](https://goreportcard.com/badge/github.com/thomseddon/traefik-forward-auth)](https://goreportcard.com/report/github.com/thomseddon/traefik-forward-auth) ![Docker Pulls](https://img.shields.io/docker/pulls/thomseddon/traefik-forward-auth.svg) [![GitHub release](https://img.shields.io/github/release/thomseddon/traefik-forward-auth.svg)](https://GitHub.com/thomseddon/traefik-forward-auth/releases/)
33

44

5-
A minimal forward authentication service that provides Google oauth based login and authentication for the [traefik](https://github.com/containous/traefik) reverse proxy/load balancer.
5+
A minimal forward authentication service that provides OAuth/SSO login and authentication for the [traefik](https://github.com/containous/traefik) reverse proxy/load balancer.
66

77
## Why?
88

99
- Seamlessly overlays any http service with a single endpoint (see: `url-path` in [Configuration](#configuration))
10+
- Supports multiple providers including Google and OpenID Connect (supported by Azure, Github, Salesforce etc.)
1011
- Supports multiple domains/subdomains by dynamically generating redirect_uri's
1112
- Allows authentication to be selectively applied/bypassed based on request parameters (see `rules` in [Configuration](#configuration)))
1213
- Supports use of centralised authentication host/redirect_uri (see `auth-host` in [Configuration](#configuration)))
@@ -19,7 +20,7 @@ A minimal forward authentication service that provides Google oauth based login
1920
- [Usage](#usage)
2021
- [Simple](#simple)
2122
- [Advanced](#advanced)
22-
- [OAuth Configuration](#oauth-configuration)
23+
- [Provider Setup](#provider-setup)
2324
- [Configuration](#configuration)
2425
- [Overview](#overview)
2526
- [Option Details](#option-details)
@@ -46,7 +47,7 @@ v2 was released in June 2019, whilst this is fully backwards compatible, a numbe
4647

4748
#### Simple:
4849

49-
See below for instructions on how to setup your [OAuth Configuration](#oauth-configuration).
50+
See below for instructions on how to setup your [Provider Setup](#provider-setup).
5051

5152
docker-compose.yml:
5253

@@ -65,8 +66,8 @@ services:
6566
traefik-forward-auth:
6667
image: thomseddon/traefik-forward-auth:2
6768
environment:
68-
- CLIENT_ID=your-client-id
69-
- CLIENT_SECRET=your-client-secret
69+
- PROVIDERS_GOOGLE_CLIENT_ID=your-client-id
70+
- PROVIDERS_GOOGLE_CLIENT_SECRET=your-client-secret
7071
- SECRET=something-random
7172
- INSECURE_COOKIE=true # Example assumes no https, do not use in production
7273

@@ -98,14 +99,24 @@ Please see the examples directory for a more complete [docker-compose.yml](https
9899

99100
Also in the examples directory is [docker-compose-auth-host.yml](https://github.com/thomseddon/traefik-forward-auth/blob/master/examples/docker-compose-auth-host.yml) which shows how to configure a central auth host, along with some other options.
100101

101-
#### OAuth Configuration
102+
#### Provider Setup
103+
104+
##### Google
102105

103106
Head to https://console.developers.google.com and make sure you've switched to the correct email account.
104107

105108
Create a new project then search for and select "Credentials" in the search bar. Fill out the "OAuth Consent Screen" tab.
106109

107110
Click "Create Credentials" > "OAuth client ID". Select "Web Application", fill in the name of your app, skip "Authorized JavaScript origins" and fill "Authorized redirect URIs" with all the domains you will allow authentication from, appended with the `url-path` (e.g. https://app.test.com/_oauth)
108111

112+
You must set the `providers.google.client-id` and `providers.google.client-secret` config options.
113+
114+
##### OpenID Connect
115+
116+
Any provider that supports OpenID Connect 1.0 can be configured via the OIDC config options below.
117+
118+
You must set the `providers.oidc.issuer-url`, `providers.oidc.client-id` and `providers.oidc.client-secret` config options.
119+
109120
## Configuration
110121

111122
### Overview
@@ -126,18 +137,24 @@ Application Options:
126137
--cookie-name= Cookie Name (default: _forward_auth) [$COOKIE_NAME]
127138
--csrf-cookie-name= CSRF Cookie Name (default: _forward_auth_csrf) [$CSRF_COOKIE_NAME]
128139
--default-action=[auth|allow] Default action (default: auth) [$DEFAULT_ACTION]
140+
--default-provider=[google|oidc] Default provider (default: google) [$DEFAULT_PROVIDER]
129141
--domain= Only allow given email domains, can be set multiple times [$DOMAIN]
130142
--lifetime= Lifetime in seconds (default: 43200) [$LIFETIME]
131143
--url-path= Callback URL Path (default: /_oauth) [$URL_PATH]
132144
--secret= Secret used for signing (required) [$SECRET]
133145
--whitelist= Only allow given email addresses, can be set multiple times [$WHITELIST]
134-
--rule.<name>.<param>= Rule definitions, param can be: "action" or "rule"
146+
--rule.<name>.<param>= Rule definitions, param can be: "action", "rule" or "provider"
135147
136148
Google Provider:
137149
--providers.google.client-id= Client ID [$PROVIDERS_GOOGLE_CLIENT_ID]
138150
--providers.google.client-secret= Client Secret [$PROVIDERS_GOOGLE_CLIENT_SECRET]
139151
--providers.google.prompt= Space separated list of OpenID prompt options [$PROVIDERS_GOOGLE_PROMPT]
140152
153+
OIDC Provider:
154+
--providers.oidc.issuer-url= Issuer URL [$PROVIDERS_OIDC_ISSUER_URL]
155+
--providers.oidc.client-id= Client ID [$PROVIDERS_OIDC_CLIENT_ID]
156+
--providers.oidc.client-secret= Client Secret [$PROVIDERS_OIDC_CLIENT_SECRET]
157+
141158
Help Options:
142159
-h, --help Show this help message
143160
```
@@ -210,6 +227,12 @@ All options can be supplied in any of the following ways, in the following prece
210227

211228
Default: `auth` (i.e. all requests require authentication)
212229

230+
- `default-provider`
231+
232+
Set the default provider to use for authentication, this can be overridden within [rules](#rules). Valid options are currently `google` or `oidc`.
233+
234+
Default: `google`
235+
213236
- `domain`
214237

215238
When set, only users matching a given domain will be permitted to access.
@@ -253,6 +276,9 @@ All options can be supplied in any of the following ways, in the following prece
253276
- `action` - same usage as [`default-action`](#default-action), supported values:
254277
- `auth` (default)
255278
- `allow`
279+
- `provider` - same usage as [`default-provider`](#default-provider), supported values:
280+
- `google`
281+
- `oidc`
256282
- `rule` - a rule to match a request, this uses traefik's v2 rule parser for which you can find the documentation here: https://docs.traefik.io/v2.0/routing/routers/#rule, supported values are summarised here:
257283
- ``Headers(`key`, `value`)``
258284
- ``HeadersRegexp(`key`, `regexp`)``
@@ -265,14 +291,19 @@ All options can be supplied in any of the following ways, in the following prece
265291

266292
For example:
267293
```
294+
# Allow requests that being with `/api/public` and contain the `Content-Type` header with a value of `application/json`
268295
rule.1.action = allow
269296
rule.1.rule = PathPrefix(`/api/public`) && Headers(`Content-Type`, `application/json`)
270297
298+
# Allow requests that have the exact path `/public`
271299
rule.two.action = allow
272300
rule.two.rule = Path(`/public`)
273-
```
274301
275-
In the above example, the first rule would allow requests that begin with `/api/public` and contain the `Content-Type` header with a value of `application/json`. It would also allow requests that had the exact path `/public`.
302+
# Use OpenID Connect provider (must be configured) for requests that begin with `/github`
303+
rule.oidc.action = auth
304+
rule.oidc.provider = oidc
305+
rule.oidc.rule = PathPrefix(`/github`)
306+
```
276307

277308
## Concepts
278309

examples/docker-compose-oidc.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: '3'
2+
3+
services:
4+
traefik:
5+
image: traefik:1.7
6+
command: -c /traefik.toml
7+
ports:
8+
- "8085:80"
9+
- "8086:8080"
10+
networks:
11+
- traefik
12+
volumes:
13+
- ./traefik.toml:/traefik.toml
14+
- /var/run/docker.sock:/var/run/docker.sock
15+
16+
whoami1:
17+
image: emilevauge/whoami
18+
networks:
19+
- traefik
20+
labels:
21+
- "traefik.backend=whoami"
22+
- "traefik.enable=true"
23+
- "traefik.frontend.rule=Host:whoami.localhost.com"
24+
25+
traefik-forward-auth:
26+
build: ../
27+
environment:
28+
- DEFAULT_PROVIDER=oidc
29+
- PROVIDERS_OIDC_ISSUER_URL=https://login.microsoftonline.com/{tenant}
30+
- PROVIDERS_OIDC_CLIENT_ID=your-client-id
31+
- PROVIDERS_OIDC_CLIENT_SECRET=your-client-secret
32+
- SECRET=something-random
33+
- INSECURE_COOKIE=true
34+
- DOMAIN=yourcompany.com
35+
- LOG_LEVEL=debug
36+
networks:
37+
- traefik
38+
39+
networks:
40+
traefik:

examples/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3'
22

33
services:
44
traefik:
5-
image: traefik
5+
image: traefik:1.7
66
command: -c /traefik.toml --logLevel=DEBUG
77
ports:
88
- "8085:80"

internal/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Config struct {
3838
Whitelist CommaSeparatedList `long:"whitelist" env:"WHITELIST" description:"Only allow given email addresses, can be set multiple times"`
3939

4040
Providers provider.Providers `group:"providers" namespace:"providers" env-namespace:"PROVIDERS"`
41-
Rules map[string]*Rule `long:"rule.<name>.<param>" description:"Rule definitions, param can be: \"action\" or \"rule\""`
41+
Rules map[string]*Rule `long:"rule.<name>.<param>" description:"Rule definitions, param can be: \"action\", \"rule\" or \"provider\""`
4242

4343
// Filled during transformations
4444
Secret []byte `json:"-"`

0 commit comments

Comments
 (0)