|
46 | 46 | // specialGroups specify groups with special meaning kcp. Lower privilege (= lower number)
|
47 | 47 | // cannot impersonate higher privilege levels.
|
48 | 48 | specialGroups = map[string]privilege{
|
49 |
| - authorizationbootstrap.SystemMastersGroup: superPrivileged, |
50 |
| - authorizationbootstrap.SystemKcpAdminGroup: priviledged, |
51 |
| - user.AllAuthenticated: authenticated, |
| 49 | + authorizationbootstrap.SystemMastersGroup: superPrivileged, |
| 50 | + authorizationbootstrap.SystemLogicalClusterAdmin: priviledged, |
| 51 | + authorizationbootstrap.SystemExternalLogicalClusterAdmin: priviledged, |
| 52 | + authorizationbootstrap.SystemKcpWorkspaceBootstrapper: priviledged, |
| 53 | + authorizationbootstrap.SystemKcpAdminGroup: priviledged, |
| 54 | + user.AllAuthenticated: authenticated, |
52 | 55 | }
|
53 | 56 | )
|
54 | 57 |
|
@@ -177,33 +180,20 @@ func WithImpersonationScoping(handler http.Handler) http.Handler {
|
177 | 180 | })
|
178 | 181 | }
|
179 | 182 |
|
180 |
| -// maxUserPrivilege returns the highest privilege level found among the user's groups. |
181 |
| -func maxUserPrivilege(userGroups []string) privilege { |
182 |
| - max := unprivileged |
183 |
| - for _, g := range userGroups { |
184 |
| - if p, found := specialGroups[g]; found && p > max { |
185 |
| - max = p |
| 183 | +// validImpersonation checks if a user can impersonate all requested groups. |
| 184 | +func validImpersonation(existingGroups, requestedGroups []string) bool { |
| 185 | + for _, g := range existingGroups { |
| 186 | + if g == authorizationbootstrap.SystemMastersGroup { |
| 187 | + return true |
186 | 188 | }
|
187 | 189 | }
|
188 |
| - return max |
189 |
| -} |
190 | 190 |
|
191 |
| -// validImpersonation checks if a user can impersonate all requested groups. |
192 |
| -func validImpersonation(userGroups, requestedGroups []string) bool { |
193 |
| - userMax := maxUserPrivilege(userGroups) |
194 |
| - |
195 |
| - // Case 1: User is requesting to impersonate a group with higher privilege. |
| 191 | + existing := sets.New(existingGroups...) |
196 | 192 | for _, g := range requestedGroups {
|
197 |
| - if userMax < specialGroups[g] { |
198 |
| - return false |
| 193 | + if specialGroups[g] != unprivileged && !existing.Has(g) { |
| 194 | + return false // only impersonate non-unprivileged groups the user already has. |
199 | 195 | }
|
200 | 196 | }
|
201 |
| - // Case 2: User is requesting to impersonate a `system:authenticated` group without having the group itself and not being privileged. |
202 |
| - // This is very much academic, as all users reaching this point will have the `system:authenticated` group or be privileged. |
203 |
| - if sets.New(requestedGroups...).Has(user.AllAuthenticated) && |
204 |
| - !(sets.New(userGroups...).HasAny(user.AllAuthenticated, authorizationbootstrap.SystemMastersGroup, authorizationbootstrap.SystemKcpAdminGroup)) { |
205 |
| - return false |
206 |
| - } |
207 | 197 |
|
208 | 198 | return true
|
209 | 199 | }
|
0 commit comments