This is a Traefik middleware plugin that authenticates users with Google OpenID Connect, and then checks that their email address or Google Workspace domain is authorized.
| Option | Default | Required | Description |
|---|---|---|---|
| oidc.clientID | X | OAuth client ID | |
| oidc.clientSecret | X | OAuth client secret | |
| oidc.callbackPath | /oidc/callback | The path where the OIDC provider will redirect the user after authenticating. | |
| oidc.redirectHost | Optional host override for the OIDC redirect URI. Use this to configure a single, central redirect URI for multiple subdomains (e.g., auth.example.com). Requires cookie.domain to be set for cookie sharing. | ||
| oidc.prompt | A space-delimited, case-sensitive list of prompts to present the user. Possible values are: none, consent, select_account. See Google's docs for more info. | ||
| cookie.name | oidc_auth | Name of the cookie. It can be customized to avoid collisions when running multiple instances of the middleware. | |
| cookie.path | / | You can use this to limit the scope of the cookie to a specific path. Defaults to '/'. | |
| cookie.secret | X | Secret is the HMAC key for cookie signing, and helps provide integrity protection for cookies. | |
| cookie.duration | 24h | Validity period for new cookies. Users are granted access for this length of time regardless of changes to user's account in the OIDC provider. Uses the Go time.Duration format. | |
| cookie.insecure | false | Set to true to omit the Secure attribute from cookies. | |
| cookie.sameSite | Lax | SameSite attribute for cookies. Options: Strict, Lax, None. Lax provides CSRF protection while allowing cookies on top-level navigation. | |
| cookie.domain | Domain attribute for cookies. Use this to share cookies across subdomains (e.g., .example.com). Must start with a dot. Required when using oidc.redirectHost. | ||
| authorized.emails | X | List of allowed email addresses. | |
| authorized.domains | X | List of allowed domains. | |
| debug | false | Enable debug logging to stdout. |
X-Forwarded-User
When the middleware proxies a request it adds an X-Fowarded-User header
containing the user's email address. This can be used by the downstream service
to identify the authenticated user.
If you want your JSON access logs to include the user's email address then
configure the access log to retain the X-Forwarded-User header. Here is a
CLI example:
# Adding X-Forwarded-User to JSON access logs.
--accesslog
--accesslog.format=json
--accesslog.fields.headers.names.X-Forwarded-User=keep
The resulting access log will contain a request_X-Forwarded-User field.
See Limiting the Fields/Including Headers for more details.
Static config
# traefik.ymlexperimental:plugins:google-oidc-auth-middleware:moduleName: "github.com/andrewkroh/google-oidc-auth-middleware"# Populate this with the latest release tag.version: vX.Y.Z
Dynamic config
# dynamic.ymlhttp:middlewares:oidc-auth:plugin:google-oidc-auth-middleware:oidc:clientID: example.apps.googleusercontent.comclientSecret: fake-secretcookie:secret: mySecretKeyauthorized:emails:domains:- example.comrouters:my-router:rule: host(`localhost`)service: service-fooentryPoints:- webmiddlewares:- oidc-auth
When protecting multiple subdomains (e.g., app1.example.com, app2.example.com, app3.example.com) under the same parent domain, you can configure a single central redirect URI instead of registering each subdomain individually with your OAuth provider.
This feature requires two settings:
oidc.redirectHost: Set this to a central host that will handle all OIDC callbacks (e.g., auth.example.com)cookie.domain: Set this to share cookies across all subdomains (e.g., .example.com)# dynamic.ymlhttp:middlewares:oidc-auth:plugin:google-oidc-auth-middleware:oidc:clientID: example.apps.googleusercontent.comclientSecret: fake-secretredirectHost: auth.example.com # Central callback hostcallbackPath: /oidc/callbackcookie:secret: mySecretKeydomain: .example.com # Share cookies across *.example.comauthorized:emails:domains:- example.comrouters:# Router for the central callback hostauth-callback:rule: Host(`auth.example.com`) && Path(`/oidc/callback`)service: noop@internalentryPoints:- webmiddlewares:- oidc-auth#tls: ...# Routers for protected subdomainsapp1:rule: Host(`app1.example.com`)service: service-app1entryPoints:- webmiddlewares:- oidc-authapp2:rule: Host(`app2.example.com`)service: service-app2entryPoints:- webmiddlewares:- oidc-authapp3:rule: Host(`app3.example.com`)service: service-app3entryPoints:- webmiddlewares:- oidc-auth
In your Google OAuth console, you only need to register one authorized redirect URI:
https://auth.example.com/oidc/callback
Instead of having to register:
https://app1.example.com/oidc/callbackhttps://app2.example.com/oidc/callbackhttps://app3.example.com/oidc/callbackhttps://app1.example.comredirect_uri=https://auth.example.com/oidc/callbackhttps://auth.example.com/oidc/callbackDomain=.example.com (shared across all subdomains)https://app1.example.com*.example.com)example.com vs example.org) is not supported