-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(acl): preserve user permissions across namespaces #9812
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,8 +148,17 @@ func (cache *AclCache) Update(ns uint64, groups []acl.Group) { | |
| AclCachePtr.predPerms[k] = v | ||
| } | ||
|
|
||
| for k, v := range userPredPerms { | ||
| AclCachePtr.userPredPerms[k] = v | ||
| // User IDs are namespace-local, so the same ID can exist in multiple namespaces. Merge the | ||
| // namespaced predicates instead of replacing permissions collected from another namespace. | ||
| for userID, newPerms := range userPredPerms { | ||
| perms, found := AclCachePtr.userPredPerms[userID] | ||
| if !found { | ||
| perms = make(map[string]int32) | ||
| AclCachePtr.userPredPerms[userID] = perms | ||
| } | ||
| for predicate, permission := range newPerms { | ||
| perms[predicate] = permission | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The merge itself is correct, and this is pre-existing rather than something you introduced. But the new write loop widens it, so it's worth knowing about.
Delete-vs-iterate was already there. Insert-vs-iterate is the nastier form, because a grow/rehash mid-iteration is what trips Go's unrecoverable Cheap to close while you're in here: func (cache *AclCache) GetUserPredPerms(userId string) map[string]int32 {
cache.RLock()
defer cache.RUnlock()
perms := make(map[string]int32, len(cache.userPredPerms[userId]))
for pred, perm := range cache.userPredPerms[userId] {
perms[pred] = perm
}
return perms
}While you're there, |
||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Low priority, and pre-existing: once a user's last permission in their only namespace is cleared, the entry sticks around forever with an empty inner map. The merge branch doesn't prune it either. One line at the end of the loop: if len(perms) == 0 {
delete(AclCachePtr.userPredPerms, userID)
}Callers behave the same either way, since |
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking design note, since what you have is correct.
The collision is possible at all because
userPredPermsis keyed by bare user ID while every value key is namespace-qualified. Keying the outer map byx.NamespaceAttr(ns, userID)would remove it at the source, and take two costs with it that this change slightly worsens:RefreshACLscallsUpdateonce per namespace, so a full refresh is O(namespaces x total entries).authorizePredsnow iterates a user's predicates across all namespaces to buildallowedPreds, andexpand(_all_)builds a hash map over that slice on every query. For a user ID present in many namespaces (common in multi-tenant setups) that grows linearly with namespace count.authorizePredsalready hasns := userData.namespacein hand, soGetUserPredPerms(ns, userId)should be a fairly contained change. Happy to take it as a follow-up if you'd rather keep this PR tight.