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

OCPBUGS-17164: Fix SELinuxprofile inherit issue #1919

Merged
merged 1 commit into from
Oct 13, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions internal/pkg/translator/obj2cil.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ func Object2CIL(
// all templates must inherit from the system container. Without explicitly
// inheriting from the system container, the policy will not be loaded
// if it uses e.g. net_container or any other template because only the
// container template includes a "process" definition
cilbuilder.WriteString(getCILInheritline(systemContainerInherit))
// container template includes a "process" definition unless it is inhrienting
// another selinuxProfile object because the system container is already being
// inherited in that case.
if len(objInherits) == 0 {
cilbuilder.WriteString(getCILInheritline(systemContainerInherit))
}
for _, inherit := range systemInherits {
if inherit == systemContainerInherit {
// already appended above
Expand All @@ -52,7 +56,7 @@ func Object2CIL(
cilbuilder.WriteString(getCILInheritline(inherit))
}
for _, inherit := range objInherits {
cilbuilder.WriteString(getCILInheritline(inherit.GetPolicyUsage()))
cilbuilder.WriteString(getCILInheritline(inherit.GetPolicyName()))
}
if sp.Spec.Permissive {
cilbuilder.WriteString(typePermissive)
Expand Down
16 changes: 14 additions & 2 deletions internal/pkg/translator/obj2cil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestObject2CIL(t *testing.T) {
name string
profile *selxv1alpha2.SelinuxProfile
wantMatches []string
doNotMatch []string
inheritsys []string
inheritobjs []selxv1alpha2.SelinuxProfileObject
}{
Expand Down Expand Up @@ -178,8 +179,11 @@ func TestObject2CIL(t *testing.T) {
},
wantMatches: []string{
"\\(block test-selinux-recording-nginx_default",
"\\(blockinherit foo_default.process\\)",
"\\(allow process http_port_t \\( tcp_socket \\(.*name_bind.*\\)\\)\\)\n",
"\\(blockinherit foo_default\\)",
"\\(allow process http_port_t \\( tcp_socket \\(.*name_bind.*\\)\\)\\)\\n",
},
doNotMatch: []string{
"\\(blockinherit container\\)",
},
inheritobjs: []selxv1alpha2.SelinuxProfileObject{
&selxv1alpha2.SelinuxProfile{
Expand Down Expand Up @@ -315,6 +319,14 @@ func TestObject2CIL(t *testing.T) {
t.Errorf("The generated CIL didn't match expectation.\nExpected match for: %s\nGenerated CIL: %s", wantMatch, got)
}
}
for _, doNotMatch := range tt.doNotMatch {
matched, err := regexp.MatchString(doNotMatch, got)
if err != nil {
t.Errorf("Error matching parsed CIL to expected result: %s", err)
} else if matched {
t.Errorf("The generated CIL matched expectation.\nExpected no match for: %s\nGenerated CIL: %s", doNotMatch, got)
}
}
})
}
}
Loading