Skip to content

Commit

Permalink
Merge pull request #150 from oneiro-naut/native-apparmor
Browse files Browse the repository at this point in the history
Add native AppArmor policy support in KubeArmorPolicy
  • Loading branch information
nam-jaehyun authored Jun 14, 2021
2 parents 530306a + 38fc028 commit cc3b39c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions KubeArmor/enforcer/appArmorProfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2221,9 +2221,19 @@ func GenerateProfileBody(enableAuditd bool, oldContentsPreMid, oldConetntsMidPos

fromSources := map[string][]string{}

nativeAppArmorRules := []string{}

// preparation

for _, secPolicy := range securityPolicies {
if len(secPolicy.Spec.Apparmor) > 0 {
scanner := bufio.NewScanner(strings.NewReader(secPolicy.Spec.Apparmor))
for scanner.Scan() {
line := " " + strings.TrimSpace(scanner.Text()) + "\n"
nativeAppArmorRules = append(nativeAppArmorRules, line)
}
}

if len(secPolicy.Spec.Process.MatchPaths) > 0 {
for _, path := range secPolicy.Spec.Process.MatchPaths {
if path.Action == "Allow" || path.Action == "AllowWithAudit" {
Expand Down Expand Up @@ -2468,6 +2478,17 @@ func GenerateProfileBody(enableAuditd bool, oldContentsPreMid, oldConetntsMidPos

profileBody = " ## == POLICY START == ##\n" + bodyFromSource + profileBody + " ## == POLICY END == ##\n"

// body - native apparmor
if len(nativeAppArmorRules) > 0 {
profileBody = profileBody + "\n ## == NATIVE POLICY START == ##\n"
for _, nativeRule := range nativeAppArmorRules {
profileBody = profileBody + nativeRule
}
profileBody = profileBody + " ## == NATIVE POLICY END == ##\n"
}

count = count + len(nativeAppArmorRules)

// foot

profileFoot := " ## == POST START == ##\n" + GenerateProfileFoot() + " ## == POST END == ##\n"
Expand Down Expand Up @@ -2541,6 +2562,12 @@ func (ae *AppArmorEnforcer) GenerateAppArmorProfile(appArmorProfile string, secu
} else if strings.Contains(line, "## == POST END == ##") {
pos = "FOOT"
continue
} else if strings.Contains(line, "## == NATIVE POLICY START == ##") {
pos = "NATIVE-START"
continue
} else if strings.Contains(line, "## == NATIVE POLICY END == ##") {
pos = "NATIVE-END"
continue
}

if pos == "HEAD" {
Expand Down
2 changes: 2 additions & 0 deletions KubeArmor/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ type SecuritySpec struct {
Capabilities CapabilitiesType `json:"capabilities,omitempty"`
Resource ResourceType `json:"resource,omitempty"`

Apparmor string `json:"apparmor,omitempty"`

Action string `json:"action"`
}

Expand Down
2 changes: 2 additions & 0 deletions helm/templates/security.accuknox.com_kubearmorpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ spec:
- AllowWithAudit
- BlockWithAudit
type: string
apparmor:
type: string
capabilities:
properties:
action:
Expand Down
2 changes: 2 additions & 0 deletions pkg/KubeArmorPolicy/api/v1/kubearmorpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ type KubeArmorPolicySpec struct {
Capabilities CapabilitiesType `json:"capabilities,omitempty"`
Resource ResourceType `json:"resource,omitempty"`

Apparmor string `json:"apparmor,omitempty"`

// +kubebuilder:validation:optional
Severity SeverityType `json:"severity,omitempty"`
// +kubebuilder:validation:optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ spec:
- AllowWithAudit
- BlockWithAudit
type: string
apparmor:
type: string
capabilities:
properties:
action:
Expand Down

0 comments on commit cc3b39c

Please # to comment.