fix: add restricted-compliant securityContext to Java init container#360
Open
ab0utbla-k wants to merge 1 commit intoaws:mainfrom
Open
fix: add restricted-compliant securityContext to Java init container#360ab0utbla-k wants to merge 1 commit intoaws:mainfrom
ab0utbla-k wants to merge 1 commit intoaws:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #361
Problem
The Java auto-instrumentation init container (
opentelemetry-auto-instrumentation-java) is created without anysecurityContext, causing pod creation to fail in namespaces enforcingpod-security.kubernetes.io/enforce: restricted.Other languages (NodeJS, Python, DotNet, Apache) are not affected — they all call
setInitContainerSecurityContext, which copies the app container's security context onto the init container.Root Cause
In
pkg/instrumentation/sdk.go,setInitContainerSecurityContextwas commented out for Java to avoid arunAsNonRootconflict with the root-based Java agent image (opentelemetry-operator#2272). However, this left the init container with nosecurityContextat all, violating the restricted Pod Security Standard.Fix
Added a new
setInitContainerRestrictedSecurityContextmethod that applies a minimal restricted-compliantsecurityContextto the Java init container:allowPrivilegeEscalation: falsecapabilities.drop: ["ALL"]seccompProfile.type: RuntimeDefaultIt deliberately omits
runAsNonRootandrunAsUserto avoid the #2272 conflict. The init container only copies a JAR into a shared volume, so it needs no capabilities and the hardcoded minimal context is appropriate.Reproduction
pod-security.kubernetes.io/enforce: restrictedinstrumentation.opentelemetry.io/inject-java: "true"and a restricted-compliantsecurityContextFailedCreateevent on the ReplicaSetTesting
Updated all existing test cases that assert on the Java init container's expected pod spec (3 in
sdk_test.go, 4 inpodmutator_test.go) to include the newsecurityContext. All tests pass.