Skip to content

fix: Fix injected sidecar security contexts for runAsNonRoot pods - #101

Closed
Ladas wants to merge 1 commit into
rossoctl:mainfrom
Ladas:fix-sidecar-security-context
Closed

Ladas wants to merge 1 commit into
rossoctl:mainfrom
Ladas:fix-sidecar-security-context

Conversation

@Ladas

@Ladas Ladas commented Feb 6, 2026

Copy link
Copy Markdown

Summary

  • Add SecurityContext to injected sidecar containers to fix CreateContainerConfigError on pods with runAsNonRoot: true
  • kagenti-client-registration: runAsUser: 65534 (nobody), runAsNonRoot: true, drop all capabilities
  • spiffe-helper: Explicitly runAsUser: 0, runAsNonRoot: false (upstream image requires root for SPIRE socket access, documented like proxy-init)

Problem

When the webhook injects the kagenti-client-registration sidecar, it has no SecurityContext. If the pod has runAsNonRoot: true (set by the webhook itself or security policies), the container fails with:

Error: container has runAsNonRoot and image will run as root

Fix

Add explicit SecurityContext to both injected sidecars in container_builder.go, following the pattern already used by the envoy-proxy and proxy-init containers.

Test plan

  • Verify client-registration container starts successfully on pods with runAsNonRoot: true
  • Verify spiffe-helper starts on SPIRE-enabled clusters
  • Run kagenti/kagenti Kind E2E tests with bumped webhook chart

Fixes rossoctl/rossoctl#611

🤖 Generated with Claude Code

The webhook injects sidecar containers without SecurityContext,
causing CreateContainerConfigError on pods with runAsNonRoot: true.

client-registration: Set runAsUser=65534 (nobody), runAsNonRoot=true,
drop all capabilities. The Python registration script does not need
root privileges.

spiffe-helper: Explicitly set runAsUser=0 with runAsNonRoot=false.
The upstream image runs as root and needs socket access. Document
this like the proxy-init container which uses the same pattern.

Fixes rossoctl/rossoctl#611

Signed-off-by: Ladislav Smola <[email protected]>

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Ladislav Smola <[email protected]>
@Ladas Ladas changed the title Fix injected sidecar security contexts for runAsNonRoot pods fix: Fix injected sidecar security contexts for runAsNonRoot pods Feb 6, 2026
@Ladas

Ladas commented Feb 6, 2026

Copy link
Copy Markdown
Author

jsut a try, complete fix is in #100

@Ladas Ladas closed this Feb 7, 2026
esnible added a commit to esnible/cortex that referenced this pull request Sep 10, 2026
The list-shape heuristics did not separate a rekey from an eviction, and
the comment above them asserted a safety property the code lacked.

Reproduced before changing anything. Append evicts only when the count
EXCEEDS max_sessions and evictOldestLocked removes exactly one entry, so
at capacity session rossoctl#101 arriving means one id vanishes and one appears
with the length unchanged. A stale "default" is the prime candidate (it
is spared only while it is activeID). All three guards then passed and
default's 3 events were filed under an unrelated session, SessionID
rewritten — the exact outcome the comment claimed was prevented, in the
case the banner calls "evicted". Not contrived: it is the steady state at
capacity.

CreatedAt is a real discriminator, as the reviewer noted. Store.Rekey
renames in place on the same *entry, so a rekeyed session reports
default's original CreatedAt, while a fresh session gets CreatedAt: now.
Verified end to end rather than by reading: driving the real store
through the JSON encoder and decoding as apiclient does confirms the
rekeyed id preserves the timestamp and a new id does not. rekeyedTo now
gates on that equality, which makes the length and prior-membership
checks redundant — both removed along with soleNewSession/hasSession.

The .Equal() detail is load-bearing and also verified: after a JSON
round trip, == on the same instant returns FALSE while .Equal() returns
true. Using == would have silently disabled migration rather than
failing loudly. Covered by a test that re-parses an RFC3339 timestamp.

Two existing rekey tests were under-specifying the store: they built
summaries with no CreatedAt, which no real rekey produces. Updated to
carry it, so they model what Rekey actually does.

Refs rossoctl#870

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ed Snible <[email protected]>
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.

1 participant