Skip to content

fix(core): guard WatchConfigChanges endpoint iteration with EndPointsLock#2760

Open
rootp1 wants to merge 1 commit into
kubearmor:mainfrom
rootp1:fix/unorchestrated-config-reload-lock
Open

fix(core): guard WatchConfigChanges endpoint iteration with EndPointsLock#2760
rootp1 wants to merge 1 commit into
kubearmor:mainfrom
rootp1:fix/unorchestrated-config-reload-lock

Conversation

@rootp1

@rootp1 rootp1 commented Jul 10, 2026

Copy link
Copy Markdown

Summary

  • WatchConfigChanges() in KubeArmor/core/unorchestratedUpdates.go iterated dm.EndPoints directly on config reload without holding dm.EndPointsLock, unlike every other access to that slice in the daemon (e.g. kubeUpdate.go).
  • This is an unsynchronized concurrent-access surface between config reload and endpoint-mutating operations (container add/remove, policy update).

Linked Issue

Fixes #2759

What Changed

  • Take dm.EndPointsLock.RLock() to copy dm.EndPoints into a local snapshot, release the lock, then iterate the snapshot to perform per-endpoint posture/visibility updates.
  • Added KubeArmor/core/unorchestratedUpdates_race_test.go, a targeted -race test that runs the fixed snapshot-and-iterate pattern concurrently against goroutines mutating dm.EndPoints under the same lock.

Verification

  • gofmt -l on changed files — passed (no output)
  • GOOS=linux GOARCH=amd64 go build ./core/... — passed
  • GOOS=linux GOARCH=amd64 go vet ./core/... — passed
  • go test ./core/... -run TestConfigReloadEndpointIterationRaceCondition -race — not run: this repo's core package (via KubeArmor/common and KubeArmor/utils/bpflsmprobe) only compiles on Linux (uses Linux-only golang.org/x/sys/unix APIs), and no Linux toolchain/Docker was available in this environment; verified via Linux cross-compilation (build+vet above) instead
  • make gofmt / go-lint (Revive) / go-sec / go-vuln / go test ./... (repo CI, ci-test-go.yml) — not run locally: these require a Linux runner and/or tools (Revive, Gosec, govulncheck) not installed in this environment; will run in upstream CI on this PR

Scope

  • Only KubeArmor/core/unorchestratedUpdates.go and the new test file were changed; no unrelated files were touched.

…Lock

Take a read lock while snapshotting dm.EndPoints before iterating in the
config-reload callback, matching the locking convention used everywhere
else dm.EndPoints is accessed (e.g. kubeUpdate.go). Fixes a data race
between config reload and concurrent endpoint mutations from container
handlers.

Fixes kubearmor#2759

Signed-off-by: rootp1 <arnav.iitr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unorchestrated config reload iterates dm.EndPoints without holding EndPointsLock

1 participant