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

Set securityContext on injected initContainer #1273

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions .chloggen/initcontainer-securitycontext.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Set securityContext on injected initContainer based on existing containers.

# One or more tracking issues related to the change
issues: [1084, 1058]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
13 changes: 13 additions & 0 deletions pkg/instrumentation/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ func (i *sdkInjector) inject(ctx context.Context, insts languageInstrumentations
pod = i.injectCommonEnvVar(otelinst, pod, index)
pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod, index)
}

pod = i.setInitContainerSecurityContext(pod, pod.Spec.Containers[index].SecurityContext)

return pod
}

func (i *sdkInjector) setInitContainerSecurityContext(pod corev1.Pod, securityContext *corev1.SecurityContext) corev1.Pod {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: in the future we may want to rename this to be more generic for other container features we want propagated.

for i, initContainer := range pod.Spec.InitContainers {
if initContainer.Name == initContainerName {
pod.Spec.InitContainers[i].SecurityContext = securityContext
}
}

return pod
}

Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-dotnet/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ spec:
- name: otc-container
initContainers:
- name: opentelemetry-auto-instrumentation
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
status:
phase: Running
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-dotnet/01-install-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ spec:
containers:
- name: myapp
image: docker.io/avadhutp123/aspnetapp@sha256:d2e8d3415f6f12efae0369aa0a9777a58583841fb133f33e10a73adb9fb392da # source code of the application: https://github.com/dotnet/dotnet-docker/tree/main/samples/aspnetapp
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-java-other-ns/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ spec:
- name: otc-container
initContainers:
- name: opentelemetry-auto-instrumentation
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
status:
phase: Running
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-java-other-ns/03-install-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ spec:
containers:
- name: myapp
image: ghcr.io/pavolloffay/spring-petclinic:latest
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-java/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ spec:
- name: otc-container
initContainers:
- name: opentelemetry-auto-instrumentation
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
status:
phase: Running
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-java/01-install-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ spec:
containers:
- name: myapp
image: ghcr.io/pavolloffay/spring-petclinic:latest
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-nodejs/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ spec:
- name: otc-container
initContainers:
- name: opentelemetry-auto-instrumentation
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
status:
phase: Running
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-nodejs/01-install-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ spec:
containers:
- name: myapp
image: ghcr.io/anuraaga/express-hello-world:latest
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-python/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ spec:
- name: otc-container
initContainers:
- name: opentelemetry-auto-instrumentation
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
status:
phase: Running
4 changes: 4 additions & 0 deletions tests/e2e/instrumentation-python/01-install-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ spec:
containers:
- name: myapp
image: ghcr.io/anuraaga/flask-hello-world:latest
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]