Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/webhooks/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ func amIAdmin(request admissionctl.Request) bool {
}
}

// Allow osd-admin user only when it's in the cluster-admins group
// This is specifically for OpenShift CI e2e tests
// Note: This is a security trade-off - we're allowing this specific combination
// for e2e test compatibility. In production OSD clusters, customers cannot
// create users with the cluster-admins group as it's managed by OAuth.
if request.UserInfo.Username == "osd-admin" && slices.Contains(request.UserInfo.Groups, "cluster-admins") {
return true
}

return false
}

Expand Down
34 changes: 34 additions & 0 deletions pkg/webhooks/namespace/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,3 +1162,37 @@ func TestGetURI(t *testing.T) {
t.Fatalf("Hook URI does not begin with a /")
}
}

// TestE2EAdminUser tests the e2e test user exemption
func TestE2EAdminUser(t *testing.T) {
tests := []namespaceTestSuites{
{
// osd-admin with cluster-admins group should be allowed (for CI e2e tests)
testID: "e2e-osd-admin-with-cluster-admins",
targetNamespace: "kube-system",
username: "osd-admin",
userGroups: []string{"cluster-admins", "system:authenticated:oauth", "system:authenticated"},
operation: admissionv1.Create,
shouldBeAllowed: true,
},
{
// osd-admin without cluster-admins group should be denied
testID: "osd-admin-without-cluster-admins",
targetNamespace: "kube-system",
username: "osd-admin",
userGroups: []string{"system:authenticated:oauth", "system:authenticated"},
operation: admissionv1.Create,
shouldBeAllowed: false,
},
{
// Different user with cluster-admins should still be denied (cluster-admins exemption was removed)
testID: "other-user-with-cluster-admins",
targetNamespace: "kube-system",
username: "some-other-user",
userGroups: []string{"cluster-admins", "system:authenticated:oauth", "system:authenticated"},
operation: admissionv1.Create,
shouldBeAllowed: false,
},
}
runNamespaceTests(t, tests)
}