Skip to content
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

Fix SELinux PodSecurity message when only user or role are set #113111

Merged
merged 1 commit into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -137,12 +137,12 @@ func seLinuxOptions_1_0(podMetadata *metav1.ObjectMeta, podSpec *corev1.PodSpec)
pluralize("type", "types", len(badTypes)),
joinQuote(badTypes.List()),
))
if setUser {
badData = append(badData, "user may not be set")
}
if setRole {
badData = append(badData, "role may not be set")
}
}
if setUser {
badData = append(badData, "user may not be set")
}
if setRole {
badData = append(badData, "role may not be set")
}

return CheckResult{
Expand Down
Expand Up @@ -118,6 +118,42 @@ func TestSELinuxOptions(t *testing.T) {
expectReason: `seLinuxOptions`,
expectDetail: `containers "d", "e", "f" set forbidden securityContext.seLinuxOptions: type "bar"; user may not be set; role may not be set`,
},
{
name: "bad type",
pod: &corev1.Pod{Spec: corev1.PodSpec{
SecurityContext: &corev1.PodSecurityContext{
SELinuxOptions: &corev1.SELinuxOptions{
Type: "bad",
},
},
}},
expectReason: `seLinuxOptions`,
expectDetail: `pod set forbidden securityContext.seLinuxOptions: type "bad"`,
},
{
name: "bad user",
pod: &corev1.Pod{Spec: corev1.PodSpec{
SecurityContext: &corev1.PodSecurityContext{
SELinuxOptions: &corev1.SELinuxOptions{
User: "bad",
},
},
}},
expectReason: `seLinuxOptions`,
expectDetail: `pod set forbidden securityContext.seLinuxOptions: user may not be set`,
},
{
name: "bad role",
pod: &corev1.Pod{Spec: corev1.PodSpec{
SecurityContext: &corev1.PodSecurityContext{
SELinuxOptions: &corev1.SELinuxOptions{
Role: "bad",
},
},
}},
expectReason: `seLinuxOptions`,
expectDetail: `pod set forbidden securityContext.seLinuxOptions: role may not be set`,
},
}

for _, tc := range tests {
Expand Down