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

✨ authz: add scopes to default rule resolver #157

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

sttts
Copy link
Member

@sttts sttts commented Dec 21, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds support for a user extra scope key authentication.kcp.io/scopes holding cluster:<name> values. The RBAC rule resolve is extended to handle a non-matching user as not anonymous, not applying to the rules.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Add user info extra scoping info of the shape `authentication.kcp.io/scopes: cluster:<name>,...` to constaint a user to one or multiple certain cluster. Multiple extra values are conjunctive, i.e. their intersection is the allowed scope.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


Comment on lines +35 to +42
if cluster := genericapirequest.ClusterFrom(ctx); cluster != nil {
clusterName = cluster.Name
}

Choose a reason for hiding this comment

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

Dont we need to check for cluster == "" here? else its "" and InSocpe function might get confusing? Mabe check inside InScope and if "" just return false?

Copy link
Member Author

Choose a reason for hiding this comment

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

system:admin logical cluster is empty string.

Copy link

@mjudeikis mjudeikis left a comment

Choose a reason for hiding this comment

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

looks ok

Comment on lines 55 to 80
name: "scoped user to multiple clusters",
info: user.DefaultInfo{Extra: map[string][]string{"authentication.kcp.io/scopes": {"cluster:this", "cluster:another"}}},
cluster: logicalcluster.Name("this"),
want: false,
},

Choose a reason for hiding this comment

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

Should this be true? Multiple clusters, but one I need is included

Copy link
Member Author

Choose a reason for hiding this comment

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

see above. Scoping is not additive.

Comment on lines 70 to 105
scopes := attr.GetExtra()[ScopeExtraKey]
for _, scope := range scopes {
switch {
case strings.HasPrefix(scope, "cluster:"):
if scope != "cluster:"+string(cluster) {
return false
}
default:
// Unknown scope, ignore.
}
}

Choose a reason for hiding this comment

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

Now I think this is wrong. If I have 2 scopes to 2 separate clusters (Im still in scope for both), but as soon as I get evaluated to one of them which is not the one Im targeting now - I get false and deny.

Copy link

@mjudeikis mjudeikis Jan 13, 2025

Choose a reason for hiding this comment

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

scopes:
   cluster:foo
   cluster:bar

InScope(user, bar) and I get false in first check as foo != bar

Copy link
Member Author

Choose a reason for hiding this comment

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

that's intentional. You have a scoped user, and now you evaluate it inside another cluster. Then this user is equivalent to {Name: "system:anonymous", Groups: []string{"system:authenticated"}}.

@sttts sttts force-pushed the sttts-scopes-1.31 branch 2 times, most recently from 6e5c9a2 to 38bf113 Compare January 14, 2025 09:31
@sttts sttts force-pushed the sttts-scopes-1.31 branch from 38bf113 to e7d2b2f Compare January 16, 2025 10:40
@sttts sttts merged commit 350c910 into kcp-dev:kcp-1.31.0 Jan 16, 2025
@sttts sttts deleted the sttts-scopes-1.31 branch January 16, 2025 19:00
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.

2 participants