Description
In current master commit 420a34f there is a problem with the callback
endpoint - it does not validate --allowed-group
.
Looks like string https://github.com/oauth2-proxy/oauth2-proxy/blob/master/oauthproxy.go#L858:
if p.Validator(session.Email) && p.provider.ValidateGroup(session.Email) {
Should be replaced with
if p.Validator(session.Email) && p.provider.ValidateGroup(session.Email) && p.validateGroups(session.Groups) {
There is also a problem: I compiled with this change, got 403 error. If I press Reload page - I see 500 status code.
Expected Behavior
Return a 403 error on /callback endpoint if token does not contain the group.
Current Behavior
Circular redirect with the following configuration:
nginx.ingress.kubernetes.io/auth-signin: https://oauth2.subdomain.example.net/oauth2/start?rd=https://$host$escaped_request_uri
nginx.ingress.kubernetes.io/auth-url: https://oauth2.subdomain.example.net/oauth2/auth
Workaround
Use sign_in
url instead of start
url for auth-signin
nginx.ingress.kubernetes.io/auth-signin: https://oauth2.subdomain.example.net/oauth2/sign_in?rd=https://$host$escaped_request_uri
nginx.ingress.kubernetes.io/auth-url: https://oauth2.subdomain.example.net/oauth2/auth
but user will always see sign_in page and will not see 403 error.
Possible Solution
Add --allowed-group
validation on /callback endpoint
Your Environment
nginx with auth_request (Kubernetes nginx_ingress) + Keycloak but configured to use as oidc provider instead of native keycloak provider.
- Version used: 420a34f
Thanks!
Activity
JoelSpeed commentedon Oct 19, 2020
I think you're right, we are checking the groups when loading the session but not when creating it, we need both I think.
@NickMeves I know you were heavily involved in reviewing the changes for the group additions, do you know if this was something that was skipped deliberately or was this just missed?
NickMeves commentedon Oct 19, 2020
Provider
ValidateGroup
is a Google provider only method, no other Provider implemented that method. We looked at it originally in the Groups PR, but it taking in an Email made it very focused on Google's use case.I completely removed it in this refactor: #797
Let me look and see if groups validation is needed in general in the callback though. I think you might be right, this is after the
redeemCode
and futureEnrichSessionState
logic, so all sessions should be completely configured at this point in the flow and ready for authorization.NickMeves commentedon Oct 19, 2020
Hmmmm - we did have a discussion about how this whole process works in a world where existing sessions were provisioned, but then the oauth2-proxy configuration changes (and added or removed required groups).
I'll need to think through if that scenario merits anyone getting a session & authZ check on group membership being a later stage.
I think with the current design of this refactor I'm working #797 - I view AuthN & AuthZ as split paradigms.
This might lend itself better to a future world where the AuthZ is more configurable on a per route basis. If
userinfo
actually gave Groups back (#850) -- I could see that being handy for endusers to debug why they AuthN but fail AuthZvladarts commentedon Oct 19, 2020
I am not good in authorization processes but want to propose: After user reached a callback page and he has no access to it - he should be redirected to different path without any GET params to make page reload possible and safe (without re-validation of already checked and non-valid token)
NickMeves commentedon Oct 19, 2020
I see the circular redirect concerns in the subrequest K8s ingress annotation design (that I don't think would happen in traditional upstream deployments, they would get the
401 Unauthorized
on the redirect URL directly -- rather than Nginx catching that fromauth
URL and redirecting to thesign-in
annotation URL).I think for that reason alone, you are right -- for Global group/role based Authorization, we should perform this authorization on the callback.
Do you want to try making a PR with the fix?
callback
endpoint #855vladarts commentedon Oct 20, 2020
Created a PR: #855
But I did not found a proper place to place tests for this feature.
NickMeves commentedon Nov 25, 2020
Fixed in this PR: #797
feat:add higress automatic https (oauth2-proxy#854)