Skip to content

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

…heir tests]

added comment

Refactor group storage structure in status.go to use sets

Optimize group lookup by precomputing GroupSet in NewStaticAuthorizer for O(1) checks.

Update pkg/authorization/static/static.go

Co-authored-by: Krzysztof Ostrowski <[email protected]>

Update pkg/authorization/static/static.go

Co-authored-by: Krzysztof Ostrowski <[email protected]>

imported set
Groups []string `json:"groups,omitempty"`
Name string `json:"name,omitempty"`
Groups []string `json:"groups,omitempty"`
GroupSet set.Set[string]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we split the external, serialized config, and its internal representation?
Make it so that only one of username/group can be specified.

func NewStaticAuthorizer(config []StaticAuthorizationConfig) (*staticAuthorizer, error) {
for _, c := range config {
if c.ResourceRequest != (c.Path == "") {
for c := range config {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we need some internal representation of the config anyway, it might be easier to implement this part as a unionauthorizer.New([]staticAuthorizer{...}) (union authorizer constructor) where each staticAuthorizer in the above mentioned slice represents each element from []StaticAuthorizationConfig here.

That way func (saConfig StaticAuthorizationConfig) Matches(a authorizer.Attributes) bool
changes into
func (sa staticAuthorizer) Authorize(ctx context.Context, a authorizer.Attributes) (authorized authorizer.Decision, reason string, err error).
Each return true changes into authorizer.DecisionAllow and each return false into authorizer.DecisionNoOpinion.

The constructor might then look something like this:

func NewStaticAuthorizer(config []StaticAuthorizationConfig) (authorizer.Authorizer, error) {
   var authorizers []staticAuthorizer
   for _, c := range config {
       authz, err := newStaticAuthorizers(&c)
       // handle error
       authorizers = append(authorizers, authz)
   }
   return unionauthorizer.New(authorizers...)
}

WDYT?

cc @ibihim

Copy link
Collaborator

@ibihim ibihim Feb 24, 2025

Choose a reason for hiding this comment

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

lol. Yes, I agree. This is what I tried to convey. We need an internal and an external representation. The internal one has a Set, the other has a slice of groups potentially.

WRT the I have no strong opinions. We could leave it as is, but why invent our own logic, if we try to satisfy the authorizer interface, right?

return true
}
for _, group := range requestGroups {
if _, exists := saConfig.User.GroupSet[group]; exists {
Copy link
Collaborator

Choose a reason for hiding this comment

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

use the set.Has() method

@stlaz stlaz added the sig-auth-acceptance issues created during review for sig-auth-acceptance label Apr 8, 2025
@ibihim
Copy link
Collaborator

ibihim commented Sep 19, 2025

As this PR is pretty stale, I will take it over, if you don't mind @ShazaAldawamneh

@ibihim
Copy link
Collaborator

ibihim commented Sep 19, 2025

@stlaz, I tried to split options and config, but this looks pretty intense:

f5a229f

It looks like we are adding a lot of complexity to keep the formalities correct. WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sig-auth-acceptance issues created during review for sig-auth-acceptance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants