Skip to content

Commit

Permalink
redirect logs to alerts based on default posture
Browse files Browse the repository at this point in the history
When KubeArmor is equipped with default posture block/audit each of the telemetry events generated needs to be an alert. This commit introduces changes to the policy matcher to update our logs to implicit block/audit alerts based on the configured default posture.

Ref #595

Signed-off-by: daemon1024 <[email protected]>
  • Loading branch information
daemon1024 committed Feb 14, 2022
1 parent f6115a4 commit 61280ab
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions KubeArmor/feeder/policyMatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,25 @@ func lastString(ss []string) string {
return ss[len(ss)-1]
}

// Update Log Fields based on default posture and visibility configuration and return false if no updates
func setLogFields(action string, visibility bool, log *tp.Log) bool {
if action == "block" {
(*log).Type = "MatchedPolicy"
(*log).PolicyName = "DefaultPosture"
(*log).Action = "Block"
return true
} else if action == "audit" {
(*log).Type = "MatchedPolicy"
(*log).PolicyName = "DefaultPosture"
(*log).Action = "Audit"
return true
} else if visibility {
(*log).Type = "ContainerLog"
return true
}
return false
}

// UpdateMatchedPolicy Function
func (fd *Feeder) UpdateMatchedPolicy(log tp.Log) tp.Log {
allowProcPolicy := ""
Expand Down Expand Up @@ -1008,18 +1027,22 @@ func (fd *Feeder) UpdateMatchedPolicy(log tp.Log) tp.Log {
}
}

if log.ProcessVisibilityEnabled && log.Operation == "Process" {
log.Type = "ContainerLog"
return log
} else if log.FileVisibilityEnabled && log.Operation == "File" {
log.Type = "ContainerLog"
return log
} else if log.NetworkVisibilityEnabled && log.Operation == "Network" {
log.Type = "ContainerLog"
return log
} else if log.CapabilitiesVisibilityEnabled && log.Operation == "Capabilities" {
log.Type = "ContainerLog"
return log
if log.Operation == "Process" {
if setLogFields(cfg.GlobalCfg.DefaultFilePosture, log.ProcessVisibilityEnabled, &log) {
return log
}
} else if log.Operation == "File" {
if setLogFields(cfg.GlobalCfg.DefaultFilePosture, log.FileVisibilityEnabled, &log) {
return log
}
} else if log.Operation == "Network" {
if setLogFields(cfg.GlobalCfg.DefaultNetworkPosture, log.NetworkVisibilityEnabled, &log) {
return log
}
} else if log.Operation == "Capabilities" {
if setLogFields(cfg.GlobalCfg.DefaultCapabilitiesPosture, log.CapabilitiesVisibilityEnabled, &log) {
return log
}
}
} else if log.Type == "MatchedPolicy" {
if log.PolicyEnabled == tp.KubeArmorPolicyAudited {
Expand Down

0 comments on commit 61280ab

Please sign in to comment.