Skip to content

Commit

Permalink
fix(throttling): differentiate throttling handling for audit behaviou…
Browse files Browse the repository at this point in the history
…r based on enforcer

Signed-off-by: Prateek <[email protected]>
  • Loading branch information
Prateeknandle committed Nov 28, 2024
1 parent bf5d5df commit 9937d9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
14 changes: 14 additions & 0 deletions KubeArmor/feeder/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,20 @@ func (fd *Feeder) PushLog(log tp.Log) {

// gRPC output
if log.Type == "MatchedPolicy" || log.Type == "MatchedHostPolicy" || log.Type == "SystemEvent" {

// checking throttling condition for "Audit" alerts when enforcer is 'eBPF Monitor'
if cfg.GlobalCfg.AlertThrottling && strings.Contains(log.Action, "Audit") && log.Enforcer == "eBPF Monitor" {
nsKey := fd.ContainerNsKey[log.ContainerID]
alert, throttle := fd.ShouldDropAlertsPerContainer(nsKey.PidNs, nsKey.MntNs)
if alert && throttle {
return
} else if alert && !throttle {
log.Operation = "AlertThreshold"
log.Type = "SystemEvent"
log.MaxAlertsPerSec = int32(cfg.GlobalCfg.MaxAlertPerSec)
log.DroppingAlertsInterval = int32(cfg.GlobalCfg.ThrottleSec)
}
}
pbAlert := pb.Alert{}

pbAlert.Timestamp = log.Timestamp
Expand Down
28 changes: 0 additions & 28 deletions KubeArmor/feeder/policyMatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -1741,20 +1741,6 @@ func (fd *Feeder) UpdateMatchedPolicy(log tp.Log) tp.Log {
return tp.Log{}
}

// check for throttling for "Audit" alerts
if cfg.GlobalCfg.AlertThrottling && strings.Contains(log.Action, "Audit") {
nsKey := fd.ContainerNsKey[log.ContainerID]
alert, throttle := fd.ShouldDropAlertsPerContainer(nsKey.PidNs, nsKey.MntNs)
if alert && throttle {
return tp.Log{}
} else if alert && !throttle {
log.Operation = "AlertThreshold"
log.Type = "SystemEvent"
log.MaxAlertsPerSec = int32(cfg.GlobalCfg.MaxAlertPerSec)
log.DroppingAlertsInterval = int32(cfg.GlobalCfg.ThrottleSec)
}
}

return log
}
} else { // host
Expand Down Expand Up @@ -1784,20 +1770,6 @@ func (fd *Feeder) UpdateMatchedPolicy(log tp.Log) tp.Log {
return tp.Log{}
}

// check for throttling for "Audit" alerts
if cfg.GlobalCfg.AlertThrottling && strings.Contains(log.Action, "Audit") {
nsKey := fd.ContainerNsKey[log.ContainerID]
alert, throttle := fd.ShouldDropAlertsPerContainer(nsKey.PidNs, nsKey.MntNs)
if alert && throttle {
return tp.Log{}
} else if alert && !throttle {
log.Operation = "AlertThreshold"
log.Type = "SystemEvent"
log.MaxAlertsPerSec = int32(cfg.GlobalCfg.MaxAlertPerSec)
log.DroppingAlertsInterval = int32(cfg.GlobalCfg.ThrottleSec)
}
}

return log
}
}
Expand Down

0 comments on commit 9937d9d

Please sign in to comment.