Skip to content

Commit

Permalink
Handle readonly File violation corner case for Audit mode
Browse files Browse the repository at this point in the history
This commit adds new field ReadOnly to MatchPolicy struct.

Fixes: kubearmor#213

Signed-off-by: Ayush Dwivedi <ayush.dwivedi@accuknox.com>
  • Loading branch information
oneiro-naut committed Jul 28, 2021
1 parent 490bb56 commit 93e36b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions KubeArmor/feeder/policyMatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func (fd *Feeder) newMatchPolicy(policyEnabled int, policyName, src string, mp i
match.Resource = fpt.Path
match.ResourceType = "Path"

match.ReadOnly = fpt.ReadOnly

if policyEnabled == tp.KubeArmorPolicyAudited && strings.HasPrefix(fpt.Action, "Block") {
match.Action = "Audit (" + fpt.Action + ")"
} else {
Expand All @@ -113,6 +115,8 @@ func (fd *Feeder) newMatchPolicy(policyEnabled int, policyName, src string, mp i
match.Resource = fdt.Directory
match.ResourceType = "Directory"

match.ReadOnly = fdt.ReadOnly

if policyEnabled == tp.KubeArmorPolicyAudited && strings.HasPrefix(fdt.Action, "Block") {
match.Action = "Audit (" + fdt.Action + ")"
} else {
Expand All @@ -126,6 +130,8 @@ func (fd *Feeder) newMatchPolicy(policyEnabled int, policyName, src string, mp i
match.Resource = fpt.Pattern
match.ResourceType = "" // to be defined based on the pattern matching syntax

match.ReadOnly = fpt.ReadOnly

if policyEnabled == tp.KubeArmorPolicyAudited && strings.HasPrefix(fpt.Action, "Block") {
match.Action = "Audit (" + fpt.Action + ")"
} else {
Expand Down Expand Up @@ -791,6 +797,12 @@ func (fd *Feeder) UpdateMatchedPolicy(log tp.Log) tp.Log {

log.Type = "MatchedPolicy"
log.Action = secPolicy.Action

if log.Operation == "File" {
if secPolicy.ReadOnly && log.Data != "" && (strings.Contains(log.Data, "O_RDWR") || strings.Contains(log.Data, "O_WRONLY")) {
log.Action = "Audit (Block)"
}
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions KubeArmor/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ type MatchPolicy struct {
Resource string
ResourceType string

Regexp *regexp.Regexp
Native bool
Regexp *regexp.Regexp
Native bool
ReadOnly bool

Action string
}
Expand Down

0 comments on commit 93e36b0

Please sign in to comment.