Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filter sso groups based on regex #11774

Merged
merged 11 commits into from
Sep 10, 2023

Conversation

basanthjenuhb
Copy link
Contributor

@basanthjenuhb basanthjenuhb commented Sep 8, 2023

Fixes #10153 #9530

Motivation

  • Currently users logging in via SSO with lot of groups, exceed the 4KB Cookie limit
  • This happens because we send the full set of claims as part of cookie
  • Adding capability to filter sso groups matching a regex.
  • This would eliminate all SSO groups which won't be used in SSO RBAC and reduce the number of groups in the authorization cookie

Modifications

  • Add a property filterGroupsRegex in SSO config
  • Filter groups based on the property

Verification

  • Tested locally with filterGroupsRegex

Example usage:

scopes:
- groups
- email
- profile
rbac:
  enabled: true
filterGroupsRegex:
- ".*argowf.*"

bjenuhb added 2 commits September 8, 2023 09:09
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
config/sso.go Outdated
@@ -21,6 +21,7 @@ type SSOConfig struct {
CustomGroupClaimName string `json:"customGroupClaimName,omitempty"`
UserInfoPath string `json:"userInfoPath,omitempty"`
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
FilterSSOGroupsRegex string `json:"filterSSOGroupsRegex,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FilterSSOGroupsRegex string `json:"filterSSOGroupsRegex,omitempty"`
FilterGroupsRegex string `json:"filterGroupsRegex,omitempty"`

"SSO" is redundant here as this is a field of SSOConfig

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would an allowlist of groups suffice as well? Or is a regex necessary for the amount of relevant groups?

server/auth/sso/sso.go Outdated Show resolved Hide resolved
@basanthjenuhb
Copy link
Contributor Author

basanthjenuhb commented Sep 8, 2023

Would an allowlist of groups suffice as well? Or is a regex necessary for the amount of relevant groups?

Reason for regex is to be able to add groups dynamically. And be able to filter our groups which will be relevant for argo SSO rbac. And reduce number of groups to bring the cookie size below 4kb

with allowlist we would need to update config and restart everytime we want to add a new group

Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
Copy link
Contributor

@juliev0 juliev0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. So, for a given cluster there would be only one particular regex that can be matched, right? I wonder if we should make it an array of regex?

Copy link
Member

@sarabala1979 sarabala1979 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sarabala1979
Copy link
Member

@basanthjenuhb Can you add the document for this?
@terrytangyuan can we include this feature in v3.5?

@basanthjenuhb
Copy link
Contributor Author

Good idea. So, for a given cluster there would be only one particular regex that can be matched, right? I wonder if we should make it an array of regex?

yeah
we could make it an array
but wanted to keep it simple and see how it works out for us
we can take it up as an enhancement after we see this one’s usage

@basanthjenuhb
Copy link
Contributor Author

@basanthjenuhb Can you add the document for this? @terrytangyuan can we include this feature in v3.5?

#11778

Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, for a given cluster there would be only one particular regex that can be matched, right? I wonder if we should make it an array of regex?

Julie brings up a good point here

we could make it an array
but wanted to keep it simple and see how it works out for us
we can take it up as an enhancement after we see this one’s usage

Adding a feature afterward is a bit easier said than done -- there would then be two features that need to be maintained for backward-compatibility.

If we can get ahead of a problem now, it would certainly aid maintainability

@agilgur5
Copy link
Member

agilgur5 commented Sep 8, 2023

with allowlist we would need to update config

correct. that is not necessarily a bad thing though. I'm not opposed to regex but there is a security trade-off.

restart everytime we want to add a new group

there is a separate issue to improve that: #10970

bjenuhb added 2 commits September 8, 2023 21:51
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
@agilgur5
Copy link
Member

agilgur5 commented Sep 8, 2023

So, for a given cluster there would be only one particular regex that can be matched, right? I wonder if we should make it an array of regex?

Julie brings up a good point here

Wait a minute, maybe I spoke too soon. This is a regex after all, you can do "or" conditions within a regex. Would that suffice? That would actually be simpler than having to tell users whether the array is "or" vs. "and"

Sorry I haven't been home all day, responded from my phone. Apologies if this results in rework 🙇
Will take a closer look later. Also want to check how Dex handles this case

@juliev0
Copy link
Contributor

juliev0 commented Sep 8, 2023

Wait a minute, maybe I spoke too soon. This is a regex after all, you can do "or" conditions within a regex. Would that suffice? That would actually be simpler than having to tell users whether the array is "or" vs. "and"

You're right. Just looked that up. It's more doable than I thought it was.

@basanthjenuhb
Copy link
Contributor Author

basanthjenuhb commented Sep 9, 2023

Wait a minute, maybe I spoke too soon. This is a regex after all, you can do "or" conditions within a regex. Would that suffice? That would actually be simpler than having to tell users whether the array is "or" vs. "and"

yes, I had looked it up
regex does support OR. it would look like (.*patternA.*|.*patternB.*), although doable, its just not very clean compared to

filterGroupsRegex:
- ".*patternA.*"
- ".*patternB.*"

I would prefer list over single regex if the idea is to support multiple patterns.
anyways, let me know your preference. Will make the changes accordingly

Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
@juliev0
Copy link
Contributor

juliev0 commented Sep 9, 2023

I would prefer list over single regex if the idea is to support multiple patterns. anyways, let me know your preference. Will make the changes accordingly

I agree if you’re open to changing it. Thanks

@basanthjenuhb
Copy link
Contributor Author

basanthjenuhb commented Sep 9, 2023

I agree if you’re open to changing it. Thanks

already did

Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's some stylistic issues in the code (it was spliced in between another block of related code), see below

server/auth/sso/sso.go Show resolved Hide resolved
server/auth/sso/sso.go Show resolved Hide resolved
@agilgur5
Copy link
Member

agilgur5 commented Sep 9, 2023

I agree if you’re open to changing it. Thanks

I don't have too strong an opinion on this so long as the documentation makes clear that the list is "OR"'d together. Otherwise it may be ambiguous to users. I mentioned this in my docs review

A singular regex does not have any ambiguity; that would be the main benefit (also simpler code)

@@ -280,6 +293,18 @@ func (s *sso) HandleCallback(w http.ResponseWriter, r *http.Request) {
return
}
}
if s.filterGroupsRegex != nil && len(s.filterGroupsRegex) > 0 {
var filteredGroups []string
Copy link
Member

@agilgur5 agilgur5 Sep 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be great if the provider could do this logic so that the response from it is not so large, but it does not seem there is a uniform provider interface for that.

There is a related Dex issue on this (dexidp/dex#1476) and generalizing it was basically closed out due to provider-specific nuances.

So I think there may be no way around filtering in the Server code unfortunately.

If a user has an IdP proxy like Dex though, they can do this group filter logic within Dex. As we get into more complex scenarios like these, we may want to consider limiting the scope of the internal implementation and forwarding users to Dex et al instead.

bjenuhb added 2 commits September 10, 2023 03:29
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
server/auth/sso/sso.go Outdated Show resolved Hide resolved
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for iterating on this!

@juliev0 juliev0 merged commit 477b3ca into argoproj:master Sep 10, 2023
24 checks passed
@terrytangyuan
Copy link
Member

@terrytangyuan can we include this feature in v3.5?

@sarabala1979 Sorry just saw it. Let's discuss this in the next contributors meeting on v3.5 release strategy. #11381

terrytangyuan pushed a commit that referenced this pull request Oct 19, 2023
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
Co-authored-by: bjenuhb <Basanth_JenuHB@intuit.com>
dpadhiar pushed a commit to dpadhiar/argo-workflows that referenced this pull request May 9, 2024
Signed-off-by: bjenuhb <Basanth_JenuHB@intuit.com>
Co-authored-by: bjenuhb <Basanth_JenuHB@intuit.com>
Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>
@agilgur5 agilgur5 added this to the v3.4.x patches milestone Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SSO does not work for users with a lot of groups due to exceeding max browser cookie size limit
5 participants