Skip to content

Add --allowed-group validation on callback endpoint #854

Closed
@vladarts

Description

@vladarts

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.

Thanks!

Activity

JoelSpeed

JoelSpeed commented on Oct 19, 2020

@JoelSpeed
Member

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

NickMeves commented on Oct 19, 2020

@NickMeves
Contributor

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 future EnrichSessionState logic, so all sessions should be completely configured at this point in the flow and ready for authorization.

NickMeves

NickMeves commented on Oct 19, 2020

@NickMeves
Contributor

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.

  • We'll authenticate freely to give you a session (hence callback allowed).
  • Then we'll authorize check the group membership on attempted access to resources.

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 AuthZ

vladarts

vladarts commented on Oct 19, 2020

@vladarts
Author

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

NickMeves commented on Oct 19, 2020

@NickMeves
Contributor

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 from auth URL and redirecting to the sign-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?

vladarts

vladarts commented on Oct 20, 2020

@vladarts
Author

Created a PR: #855
But I did not found a proper place to place tests for this feature.

NickMeves

NickMeves commented on Nov 25, 2020

@NickMeves
Contributor

Fixed in this PR: #797

added a commit that references this issue on Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Add --allowed-group validation on callback endpoint · Issue #854 · oauth2-proxy/oauth2-proxy