-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Multiple Sub Domains #237
Comments
One "simple" way to do this is to run two instances of oauth2_proxy, which use the same cookie-secret and both set cookie-domain to |
OK and just so I am clear, if I had 10 domains I wanted to protect I would need 10 instances of oauth2_proxy? Is there a "complicated" way? I was wondering whether oauth2_proxy can look at the domain that is coming in and make a "smart" decision on which upstream to forward to based on that? I presume the oauth (i.e google) only needs one redirect-url but oauth2_proxy would need one redirect url for each sub domain app, and therefore you would need multiple google apps and multiple access/secret keys etc etc etc? |
@ploxiln does oauth2_proxy pass the domain to nginx in your example there? For instance if nginx is listening on port 5180 for third_subdomain.website.com will that be passed on by oauth2_proxy? If so thats great! |
By default, yes it does. (Or, the |
Hi @ploxiln
It all works until the very last step, when the user is logged in, it always sends them to |
oauth2_proxy does not get upstream from the nginx config. Those That's a rather complicated nginx config, which I have seen other people post examples similar to, but it's not at all what I was suggesting. |
Oh right... |
Really trying to avoid giving a specific nginx config example, but ok, here's what I was suggesting:
The No request rewriting to stash hostname in path and get it back out again should be necessary! No special oauth path handling should be necessary! oauth2_proxy will either do the oauth or do the proxying as appropriate. It's a proxy for the actual service. It looks like the services which oauth2_proxy is proxying to are on different IPs, so I just want to clarify that those IPs/ports should not be publicly accessible, otherwise oauth2_proxy can be trivially bypassed. |
@ploxiln Or have I missed the point again? EDIT: I did try the above
However that leaves me in a loop, going back to the login page. EDIT 2: The more I think about it that cant work as then the hostname is incorrect as to which internal app to pass the client to. I notice on google console when setting up the callback Google side, you can set multiple redirect_urls, so does that mean you need multiple in the proxy aswell? |
On the google side you can set up multiple allowed redirect_urls. The authenticating application specifies, during the oauth exchange, what redirect_url is for that exchange, and google will only allow it if it's in the list of allowed redirect_urls. For this example, you'll need two allowed redirect_urls in that list, one for each application domain. There should be no extra nginx location blocks specifically for |
OK excellent, so according to the documentation, if I don't specify I.e its being set to the localhost for some reason. I can see that |
It turns out you do need |
Sweet I think that worked. Thanks, I can probably dig a bit.... EDIT:
So is that to say nginx isnt listening on 5180 or something? I have turned selinux off for the time being... |
In nginx, multiple server blocks can use the same port, and nginx can decide which server block to use for that request based on the hostname. Try to confirm that nginx is listening on port 5180 (and is on the same server as oauth2_proxy of course). |
sweet i cracked it. I'll write up a summary of the above and post here. Its might be quite useful for others who want to protect multiple applications |
Hey guys, I have tried configuring oauth2_proxy to do this, but I get a 400 Bad Request The plain HTTP request was sent to HTTPS port oauth2_proxy is configured using...
and the NGINX is configured....
I feel like I am almost there, but I just can't get it figured out. Thanks! |
Something is sending a plain-http request to a port expecting https. Look in nginx and oauth2_proxy logs for a hint as to where exactly this is happening, then you might be able to figure out which side is confused. BTW this is odd: |
hey @amlwwalker did you find out the final working version, can you share your config, thanks |
I was able to do this setup using the great documentation of https://github.com/18F/hub/blob/master/deploy/SSO.md I had to adjust the redirect: -location "~^/(?<target_host>[^/]+).18f.gov/(?<remaining_uri>.*)$" {
- rewrite ^ $scheme://$target_host$remaining_uri;
+location "~^/(?<target_host>[^/]+).company.com/(?<remaining_uri>.*)$" {
+ rewrite ^ $scheme://$target_host.company.com$remaining_uri;
} |
Hello, Sorry to say that but the solution with the nginx upstream and rewrite rule is a mess... We tried to protect 5 backend applications with oauth2_proxy and the nginx conf is very unmaintainable. |
Hi All, Old issue, but here's how I solved this using auth_request and no funky rewriting: Nginx config (all in one block + lots of duplication to make it easy to follow):
And these are the relevant options we're using to run oauth2_proxy:
Cheers, |
@blakemartin How do you go around not setting |
@nardeas - apologies, I missed this somehow. Got around it by using auth_request within the nginx config and letting nginx handle all the subdomain logic. |
@blakemartin can you please post a template on how you are using auth_request, i am getting infinite login loop. |
@KaustubhKhati - I posted an example config above. Please give that a try; if you're still having issues I can email you. |
Can this be used to handle multiple sub domains at once?
For instance, if Nginx is used to route x.company.com and y.company.com can this be used as authentication for both, and on successful auth it passes the connection to the right application? I can see you can have multiple upstreams, but it looks like you can only have one
redirect-url
The text was updated successfully, but these errors were encountered: