Skip to content

Commit b5ea847

Browse files
committed
Fix amIAdmin function to correctly check admin group membership
The amIAdmin function had a logic bug where it was checking if a single group name existed in the user's group list, rather than checking if any of the user's groups matched the allowed admin groups. This caused the webhook to incorrectly deny requests from users in the cluster-admins group. This fixes the e2e test failures in openshift/origin endpoint admission tests where the admin client was being denied access to privileged namespaces. OCPBUGS-62642
1 parent 3031ecc commit b5ea847

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/webhooks/namespace/namespace.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,22 @@ func NewWebhook() *NamespaceWebhook {
321321
}
322322

323323
func amIAdmin(request admissionctl.Request) bool {
324-
amISREAdmin := false
325-
amIClusterAdmin := false
324+
// Check if user is a cluster admin by username
325+
if utils.SliceContains(request.UserInfo.Username, clusterAdminUsers) {
326+
return true
327+
}
326328

327-
if utils.SliceContains(request.UserInfo.Username, clusterAdminUsers) || utils.SliceContains(clusterAdminGroup, request.UserInfo.Groups) {
328-
amIClusterAdmin = true
329+
// Check if user is in cluster-admins group
330+
if utils.SliceContains(clusterAdminGroup, request.UserInfo.Groups) {
331+
return true
329332
}
330333

334+
// Check if user is in any SRE admin groups
331335
for _, group := range sreAdminGroups {
332336
if utils.SliceContains(group, request.UserInfo.Groups) {
333-
amISREAdmin = true
334-
break
337+
return true
335338
}
336339
}
337340

338-
return (amIClusterAdmin || amISREAdmin)
341+
return false
339342
}

0 commit comments

Comments
 (0)