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

Consider supporting groups instead of single users only and create their tests #351

Open
wants to merge 3 commits into
base: sig-auth-acceptance
Choose a base branch
from

Conversation

ShazaAldawamneh
Copy link

this PR to cover issue: 333

@ShazaAldawamneh ShazaAldawamneh marked this pull request as ready for review January 7, 2025 14:21
@ShazaAldawamneh
Copy link
Author

@stlaz @ibihim can I have your review in this PR please ?

@stlaz
Copy link
Collaborator

stlaz commented Jan 9, 2025

This is an open source project, remove any references to trackers that are not in this repo. If they contain additional context, move it to the GitHub issue you are fixing.

@ShazaAldawamneh ShazaAldawamneh changed the title CNTRLPLANE-63: Consider supporting groups instead of single users only and create their tests Consider supporting groups instead of single users only and create their tests Jan 9, 2025
Copy link
Collaborator

@ibihim ibihim left a comment

Choose a reason for hiding this comment

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

good job

pkg/authorization/static/static.go Outdated Show resolved Hide resolved
pkg/authorization/static/static.go Outdated Show resolved Hide resolved
}

if isAllowed(saConfig.User.Name, userName) &&
if (saConfig.User.Name == "" || isAllowed(saConfig.User.Name, userName)) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the previous solution was sufficient. If there is no config (empty string) for user or any other resourceAttribute, it defaults to true.

The unit tests show those permutations of user / no user, group / no group, allowed.

if len(configGroups) == 0 {
return true
}
configGroupSet := make(map[string]struct{})
Copy link
Collaborator

Choose a reason for hiding this comment

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

A set is a great solution for this. You are always on the safe side that it scales up.

But the configGroupSet slice will never change, and we are initializing it on every request at least once.
We would need to move it out and initialize the configGroupSet in the constructor NewStaticAuthorizer.
The issue is, that the config given to the user to configure it is a slice of strings. This should stay as is, but for working with it we need to turn this into a Set of strings. So you would need to create as struct StaticAuthorizationOptions that contains a slice of strings and can be used by the user and you need to modify the existing StaticAuthorizationConfig to have a Set of strings.
If you create a Set and you don't use the k8s utility package and you do it by hand, it is also good to create struct{}{} as a global variable with a name like noop and reference it, that way you don't initialize it for every entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants