-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for a list of Whitelisted domains #464
Conversation
main.go
Outdated
@@ -43,6 +44,7 @@ func main() { | |||
flagSet.Bool("ssl-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS") | |||
|
|||
flagSet.Var(&emailDomains, "email-domain", "authenticate emails with the specified domain (may be given multiple times). Use * to authenticate any email") | |||
flagSet.Var(&whitelistDomains, "whitelist-domains", "allowed domains for redirection after authentication") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the variable is plural, but the option name string should be singular "whitelist-domain"
because it will be used like --whitelist-domain=.first.com --whitelist-domain=.second.com
oauthproxy.go
Outdated
redirect = strings.TrimPrefix(redirect, "https://") | ||
redirect = strings.Split(redirect, "/")[0] | ||
for _, domain := range p.whitelistDomains { | ||
if strings.HasSuffix(redirect, domain) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is repetitive with the case above. You could consider using url.Parse()
You could also consider protecting users from a silly mistake by only doing a suffix match if the whitelisted domain starts with .
, otherwise doing an exact match.
e9c9e0a
to
2652c23
Compare
@ploxiln I have addressed your feedback and rebased onto the current master branch. Thanks for your comments |
This looks like a reasonable implementation to me. I'm not a maintainer though, I just try to help out. I think we'll have to wait for @hlhendy's judgement. The test failures appear to not be related, they're in TestValidatorOverwriteEmailListVia... One other thing that is typically asked of PRs in this project is that you squash down your commits into one. |
It would be nice if you could add support for setting it though the env also |
@bouk Happy to add environment support, looks to me like I just need to add an However it looks at the moment as if the environment loader can only load strings where this needs to load a list of strings, unless I've missed something? Lines 31 to 33 in d75f626
|
The underlying library has support for string slices, so adding the appropriate tag should just work |
main.go
Outdated
@@ -43,6 +44,7 @@ func main() { | |||
flagSet.Bool("ssl-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS") | |||
|
|||
flagSet.Var(&emailDomains, "email-domain", "authenticate emails with the specified domain (may be given multiple times). Use * to authenticate any email") | |||
flagSet.Var(&whitelistDomains, "whitelist-domain", "allowed domains for redirection after authentication") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/whitelist-domain/whitelist-domains/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See "email-domain" just above. It's singular because you specify one at a time: --whitelist-domain=first.com --whitelist-domain=second.com
options.go
Outdated
@@ -32,6 +32,7 @@ type Options struct { | |||
AuthenticatedEmailsFile string `flag:"authenticated-emails-file" cfg:"authenticated_emails_file"` | |||
AzureTenant string `flag:"azure-tenant" cfg:"azure_tenant"` | |||
EmailDomains []string `flag:"email-domain" cfg:"email_domains"` | |||
WhitelistDomains []string `flag:"whitelist-domains" cfg:"whitelist_domains"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If https://github.com/bitly/oauth2_proxy/pull/464/files#r161420105, then s/flag:"whitelist-domains/flag:"whitelist-domain/
oauth2_proxy -whitelist-domain=localhost
2018/01/15 02:13:20 options.go:74: ERROR: flag "whitelist-domains" does not exist
panic: ERROR: flag "whitelist-domains" does not exist
goroutine 1 [running]:
log.Panicf(0x90f438, 0x1d, 0xc420035ca0, 0x1, 0x1)
/usr/local/go/src/log/log.go:333 +0xda
github.com/mreiferson/go-options.Resolve(0x86e180, 0xc420086e00, 0xc4200f2360, 0xc42006f200)
/go/src/github.com/mreiferson/go-options/options.go:74 +0xb11
main.main()
/go/src/github.com/bitly/oauth2_proxy/main.go:103 +0x146b
I've pushed a commit that fixes the panic identified by @Quentin-M and adds the ability to set the whitelist domains from the environment with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
What's the plan for this PR? It solves the exact issue we've been fighting when attempting to use the oauth2_proxy as part of our k8s ingress infrastructure. |
@smitchelus Pretty sure it'll get merged. In the meantime: https://hub.docker.com/r/qmachu/oauth2_proxy/ |
@smitchelus I'm hoping this PR will get merged soon and I've also raised another PR that might interest you given your running K8s. #534 Adds support for the The two PRs combined make the proxy perfect for authentication across multiple K8s clusters |
Thanks for the update @JoelSpeed, @Quentin-M, and thanks for the image link as well. I've built it locally to confirm it worked for our scenario, but obviously look forward to getting it into an official release soon. |
@Quentin-M, just now getting back to this. I tried pulling your image |
@smitchelus try |
Good thought, but no dice: |
@smitchelus I've just built an image and tested the flag from this PR, try this image |
Thanks @JoelSpeed! I appreciate the help. |
Here is what I use fwiw:
|
First of all thanks for this PR! Would really like to just have a single oauth2 proxy for several internal applications :) I'm using nginx as described in the readme to handle authentication using the
The whole flow through my OAuth provider (GitHub) works and the redirect url is being passed correctly in the Am I doing something wrong? Could it be because of the different domain name? |
@simonvanderveldt What values do you have for |
Migration from Bitly to Pusher
Release 3.0.0
ce2c25b
to
d795222
Compare
Now that @pusher have taken over the repository maintenance, I am closing this in favour of pusher#15 |
I wrote this on Friday to fix #399
Tidied it up this morning and went to create PR noticing #461 had been created.
I think this better fixes #399 as it looks for domain suffixes rather than explicit domains which I think was the point of the discussion.
Take from this what you will