Skip to content

Commit 5b5542c

Browse files
Merge pull request #30355 from rioliu-rh/check-namespace-is-privileged
NO-JIRA: update namespace privilege check to use PSA label
2 parents 11d30d9 + 4babf1d commit 5b5542c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/extended/util/compat_otp/client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ func NewCLIForKubeOpenShift(basename string) *exutil.CLI {
4040

4141
// IsNamespacePrivileged checks if a namespace has privileged SCC
4242
func IsNamespacePrivileged(oc *exutil.CLI, namespace string) (bool, error) {
43-
stdout, err := oc.AsAdmin().Run("get").Args("ns", namespace, "-o", "jsonpath={.metadata.labels.security\\.openshift\\.io/scc\\.podSecurityLabelSync}").Output()
43+
// Check for the Kubernetes Pod Security Admission 'enforce: privileged' label.
44+
// This is the direct confirmation that the namespace's admission controller
45+
// will allow an unrestricted pod (like the one created by 'oc debug node').
46+
stdout, err := oc.AsAdmin().Run("get").Args("ns", namespace, "-o", `jsonpath={.metadata.labels.pod-security\.kubernetes\.io/enforce}`).Output()
47+
4448
if err != nil {
4549
return false, err
4650
}
4751

48-
if strings.Contains(stdout, "false") {
52+
// The namespace is privileged if it explicitly enforces the privileged standard.
53+
if labelValue := strings.TrimSpace(stdout); labelValue == "privileged" {
4954
return true, nil
5055
}
5156

0 commit comments

Comments
 (0)