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(throttling): differentiate throttling handling for audit behaviour based on enforcer #1898

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

// 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)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
to a lower bit size type int32 without an upper bound check.
Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
to a lower bit size type int32 without an upper bound check.
log.DroppingAlertsInterval = int32(cfg.GlobalCfg.ThrottleSec)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
to a lower bit size type int32 without an upper bound check.
Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
to a lower bit size type int32 without an upper bound check.
}
}
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
Loading