Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set traefik with OAuth2 authentication

I'm using traefik as a reverse proxy. I want to set OAuth2 authentication for a entry point. In the document, I found the Forward Authentication which I think may be useful for this. But the document is just too simple

This configuration will first forward the request to http://authserver.com/auth.

If the response code is 2XX, access is granted and the original request is performed. Otherwise, the response from the authentication server is returned.

I've no idea how can I achieve authentication OAuth2 within a forwarding? I've tried oauth2_proxy but didn't find a solution.
In this issue/comment guybrush provided a solution. But that, in fact, was a double reverse proxys.

like image 327
kehao Avatar asked Jun 12 '18 15:06

kehao


People also ask

How do I configure OAuth?

Configure OAuth consent & register your appComplete the app registration form, then click Save and Continue. If you're creating an app for use outside of your Google Workspace organization, click Add or Remove Scopes. Add and verify the authorization scopes required by your app, then click Save and Continue.

What is Traefik forward Auth?

A minimal forward authentication service that provides OAuth/SSO login and authentication for the traefik reverse proxy/load balancer.

Does OAuth2 support Active Directory?

Azure Active Directory (Azure AD) supports all OAuth 2.0 flows.


2 Answers

I've recently built an app for this: https://github.com/thomseddon/traefik-forward-auth

It uses Forward Authentication, as you mentioned, and uses Google OAuth to authenticate users.

There's an example Docker Compose setup here: https://github.com/thomseddon/traefik-forward-auth/blob/master/examples/docker-compose.yml. See the traefik.toml file to see how Traefik is configured to point at the app.

Let me know if it is helpful!

like image 185
Thom Seddon Avatar answered Sep 21 '22 21:09

Thom Seddon


Instead of trying to make Traefik support your case, let Traefik do what it does best and instead use Keycloak Gatekeeper for authentication (and potentially authorization).

This would change your setup from

Client -- Traefik -- Service

to

Client -- Traefik -- Gatekeeper -- Service

This means that both Traefik and Gatekeeper act as reverse proxy.

It's incredibly simple to model complex auth setups with this approach. One potential drawback is however the additional RP layer, so for high performance setups this may not be an ideal solution.

Note that Gatekeeper can work with any OIDC compatible IdP, so you don't have to run Keycloak to use it.

like image 40
theDmi Avatar answered Sep 22 '22 21:09

theDmi