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(apparmor): fix apparmor profile generation logic #987

Merged
merged 1 commit into from
Nov 15, 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
6 changes: 0 additions & 6 deletions KubeArmor/enforcer/appArmorProfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,6 @@ func (ae *AppArmorEnforcer) GenerateProfileBody(securityPolicies []tp.SecurityPo
ae.Logger.Errf("Error while copying global rules to local profile for %s: %s", source, err.Error())
continue
}
for proc, config := range profile.ProcessPaths {
add := checkIfGlobalRuleToBeAdded(proc, val.ProcessPaths)
if add {
newval.ProcessPaths[proc] = config
}
}
for file, config := range profile.FilePaths {
add := checkIfGlobalRuleToBeAdded(file, val.FilePaths)
if add {
Expand Down
34 changes: 27 additions & 7 deletions KubeArmor/enforcer/appArmorTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const BaseTemplate = `
#include <tunables/global>
{{- $ctx := .}}
{{- $regex := ".*?(\\[|\\*|\\+|\\?|\\$|\\|)+.*"}}
{{- $fromSourceList := list }}
{{- range $source, $data := .FromSource }}
{{- $fromSourceList = append $fromSourceList $source}}
{{- end }}

## == Dispatcher profile START == ##
profile {{.Name}} flags=(attach_disconnected,mediate_deleted) {
Expand Down Expand Up @@ -141,8 +145,8 @@ profile {{.Name}} flags=(attach_disconnected,mediate_deleted) {
{{- range $source, $value := $.FromSource}}
profile {{$.Name}}-{{$source}} {
{{$source}} rix,
{{ template "pre-section" $value }}
{{template "file-section" $value}}
{{template "pre-section" $value }}
{{template "file-section" $value}}
## == DISPATCHER START == ##
{{- range $value, $data := .ProcessPaths}}
{{- $suffix := ""}}
Expand All @@ -162,11 +166,27 @@ profile {{$.Name}}-{{$source}} {

{{- if $data.Allow}}
{{- if eq $suffix "" }}
{{- if $data.OwnerOnly}}
owner {{$value}} px -> {{$.Name}}-{{$value}},
{{- else}}
{{$value}} px -> {{$.Name}}-{{$value}},
{{- end}}
{{- if has $value $fromSourceList }}
{{- if $data.OwnerOnly}}
owner {{$value}} px -> {{$.Name}}-{{$value}},
{{- else}}
{{$value}} px -> {{$.Name}}-{{$value}},
{{- end}}
{{- else}}
{{- if $data.OwnerOnly}}
owner {{$value}} cx,
{{- else}}
{{$value}} cx,
profile {{$value}} {
{{$value}} rix,
{{template "pre-section" $ctx}}
{{template "file-section" $ctx}}
{{template "network-section" $ctx}}
{{template "capabilities-section" $ctx}}
{{template "post-section" }}
}
{{- end}}
{{- end}}
{{- end}}
{{- end}}
{{- end}}
Expand Down