Skip to content

Commit

Permalink
Merge pull request #1852 from Prateeknandle/throttling
Browse files Browse the repository at this point in the history
enabling alert throttling by default
  • Loading branch information
Aryan-sharma11 authored Sep 2, 2024
2 parents a39cd16 + ea90693 commit c8471b1
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci-latest-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ jobs:
- name: Test KubeArmor using Ginkgo
run: |
go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo
make -C tests/k8s_env/
make
working-directory: ./tests/k8s_env
timeout-minutes: 30

- name: Get karmor sysdump
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ jobs:
- name: Test KubeArmor using Ginkgo
run: |
go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo
cd tests/k8s_env
ginkgo --vv --flake-attempts=10 --timeout=10m smoke/
working-directory: ./tests/k8s_env
timeout-minutes: 30

- name: Get karmor sysdump
Expand Down
2 changes: 1 addition & 1 deletion KubeArmor/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func readCmdLineParams() {

stateAgent := flag.Bool(ConfigStateAgent, false, "enabling KubeArmor State Agent client")

alertThrottling := flag.Bool(ConfigAlertThrottling, false, "enabling Alert Throttling")
alertThrottling := flag.Bool(ConfigAlertThrottling, true, "enabling Alert Throttling")

maxAlertPerSec := flag.Int(ConfigMaxAlertPerSec, 10, "Maximum alerts allowed per second")

Expand Down
8 changes: 8 additions & 0 deletions KubeArmor/monitor/systemMonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,21 @@ func (mon *SystemMonitor) UpdateThrottlingConfig() {
if err := mon.BpfConfigMap.Update(uint32(3), uint32(1), cle.UpdateAny); err != nil {
mon.Logger.Errf("Error Updating System Monitor Config Map to enable alert throttling : %s", err.Error())
}
} else {
if err := mon.BpfConfigMap.Update(uint32(3), uint32(0), cle.UpdateAny); err != nil {
mon.Logger.Errf("Error Updating System Monitor Config Map to enable alert throttling : %s", err.Error())
}
}
if err := mon.BpfConfigMap.Update(uint32(4), uint32(cfg.GlobalCfg.MaxAlertPerSec), cle.UpdateAny); err != nil {
mon.Logger.Errf("Error Updating System Monitor Config Map to set max alerts per sec : %s", err.Error())
}
if err := mon.BpfConfigMap.Update(uint32(5), uint32(cfg.GlobalCfg.ThrottleSec), cle.UpdateAny); err != nil {
mon.Logger.Errf("Error Updating System Monitor Config Map to set time interval for dropping subsequent alerts : %s", err.Error())
}
mon.Logger.Printf("Alert Throttling configured {alertThrottling:%v, maxAlertPerSec:%v, throttleSec:%v}",
cfg.GlobalCfg.AlertThrottling,
cfg.GlobalCfg.MaxAlertPerSec,
cfg.GlobalCfg.ThrottleSec)
}

// UpdateNsKeyMap Function
Expand Down
3 changes: 3 additions & 0 deletions KubeArmor/packaging/kubearmor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ hostVisibility: "process,file,network,capabilities"
enableKubeArmorHostPolicy: true
enableKubeArmorVm: false
k8s: false
alertThrottling: true
maxAlertPerSec: 10
throttleSec: 30
3 changes: 3 additions & 0 deletions deployments/get/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,9 @@ func GetKubearmorConfigMap(namespace, name string) *corev1.ConfigMap {
data[cfg.ConfigDefaultCapabilitiesPosture] = "audit"
data[cfg.ConfigDefaultNetworkPosture] = "audit"
data[cfg.ConfigDefaultPostureLogs] = "true"
data[cfg.ConfigAlertThrottling] = "true"
data[cfg.ConfigMaxAlertPerSec] = "10"
data[cfg.ConfigThrottleSec] = "30"

return &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Expand Down
2 changes: 1 addition & 1 deletion deployments/helm/KubeArmor/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ kubearmorConfigMap:
defaultCapabilitiesPosture: audit
defaultNetworkPosture: audit
visibility: process,network
alertThrottling: false
alertThrottling: true
maxAlertPerSec: 10
throttleSec: 30

Expand Down
2 changes: 1 addition & 1 deletion deployments/helm/KubeArmorOperator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ kubearmorConfig:
enableStdOutAlerts: false
enableStdOutMsgs: false
seccompEnabled: true
alertThrottling: false
alertThrottling: true
maxAlertPerSec: 10
throttleSec: 30

Expand Down
2 changes: 1 addition & 1 deletion getting-started/alert_throttling.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Throttling conditions can be configured through the config map, `kubearmor-confi

Three configurable conditions for throttling are:

1. enabling alert throttling, by default alert throttling will not be available. In order to enable throttling we need to set `alertThrottling` to `true`.
1. enabling/disabling alert throttling, by default alert throttling will be enabled. In order to disable throttling we need to set `alertThrottling` to `false`.

2. set the threshold frequency for the alerts generated, by default it is set to `10` alerts(after enabling throttling), which means 10 alerts would be allowed to be generated per second. After the threshold frequency is crossed an alert will be generated which will notify that threshold frequency is crossed and for next few seconds we will not recieve alerts for this container. In order to set threshold frequency we need to set `maxAlertPerSec` to an int value, which decribes the number of maximum alerts that could be generated per sec.

Expand Down
2 changes: 1 addition & 1 deletion pkg/KubeArmorOperator/common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var ConfigMapData = map[string]string{
ConfigDefaultNetworkPosture: "audit",
ConfigVisibility: "process,network,capabilities",
ConfigDefaultPostureLogs: "true",
ConfigAlertThrottling: "false",
ConfigAlertThrottling: "true",
ConfigMaxAlertPerSec: "10",
ConfigThrottleSec: "30",
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/KubeArmorOperator/config/samples/sample-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
enableStdOutAlerts: false
enableStdOutMsgs: false
seccompEnabled: false
alertThrottling: false
alertThrottling: true
maxAlertPerSec: 10
throttleSec: 30
kubearmorImage:
Expand Down

0 comments on commit c8471b1

Please sign in to comment.