Skip to content

Add securityContext support for TargetAllocator#2162

Open
hahakiki2025 wants to merge 3 commits into
open-telemetry:mainfrom
hahakiki2025:topic/yan/update-collector-crd-for-ta
Open

Add securityContext support for TargetAllocator#2162
hahakiki2025 wants to merge 3 commits into
open-telemetry:mainfrom
hahakiki2025:topic/yan/update-collector-crd-for-ta

Conversation

@hahakiki2025

Copy link
Copy Markdown

Currently, when namespace-level privilege is not enabled, deploying TargetAllocator alongside the OpenTelemetry Collector (with enabled=true) fails due to PodSecurity "restricted" policy violations:

  • allowPrivilegeEscalation must be set to false
  • capabilities must drop ["ALL"]

This change adds support for configuring securityContext for the TargetAllocator container, enabling compliant deployments under restricted PodSecurity settings.

Test Steps and Logs

  • Create an OpenTelemetryCollector with TargetAllocator enabled and securityContext configured:
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: collector-with-ta
spec:
  securityContext:
    allowPrivilegeEscalation: false
    capabilities:
      drop:
      - ALL
    runAsNonRoot: true
    seccompProfile:
      type: RuntimeDefault
  mode: statefulset
  targetAllocator:
    enabled: true
    securityContext:
      allowPrivilegeEscalation: false
      capabilities:
        drop:
        - ALL
    podSecurityContext:
      runAsNonRoot: true
      seccompProfile:
        type: RuntimeDefault
  config:
    receivers:
      prometheus:
        config:
          scrape_configs:
          - job_name: 'otel-collector'
            scrape_interval: 10s
            static_configs:
            - targets: [ '0.0.0.0:8888' ]
            metric_relabel_configs:
            - action: labeldrop
              regex: (id|name)
            - action: labelmap
              regex: label_(.+)
              replacement: $$1

    exporters:
      debug: {}

    service:
      pipelines:
        metrics:
          receivers: [prometheus]
          exporters: [debug]
  • Apply the manifest
kubectl apply -f opentelemetry-collector-targetallocator.yml -n test1
  • Verify the TargetAllocator pod is running:
kubectl get pods -n test1 |grep target
collector-with-ta-targetallocator-57986fd8f4-6l9hb   1/1     Running   0          43m
  • Inspect the securityContext of the TargetAllocator container that it's correctly applied:
kubectl get pod <targetallocator-pod> -n test1 -o yaml | yq .spec.containers[].securityContext
allowPrivilegeEscalation: false
capabilities:
  drop:
    - ALL

@hahakiki2025
hahakiki2025 requested review from a team, Allex1 and jvoravong as code owners April 24, 2026 10:50
@linux-foundation-easycla

linux-foundation-easycla Bot commented Apr 24, 2026

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: hahakiki2025 / name: Yan Li (99cc9f2)
  • ✅ login: TylerHelmuth / name: Tyler Helmuth (34a3017)

@TylerHelmuth

Copy link
Copy Markdown
Member

@hahakiki2025 please sign the CLA then I will review the code

@hahakiki2025
hahakiki2025 force-pushed the topic/yan/update-collector-crd-for-ta branch 3 times, most recently from 3da63ab to 99cc9f2 Compare April 30, 2026 10:46
@hahakiki2025

Copy link
Copy Markdown
Author

@hahakiki2025 please sign the CLA then I will review the code

@TylerHelmuth CLA signed, please go ahead, thanks

@TylerHelmuth

Copy link
Copy Markdown
Member

@hahakiki2025 please bump the charts minor version and regenerate the examples with make generate-examples CHARTS=opentelemetry-target-allocator

@hahakiki2025
hahakiki2025 force-pushed the topic/yan/update-collector-crd-for-ta branch from 34a3017 to f5fc8dc Compare May 25, 2026 07:19
@hahakiki2025

Copy link
Copy Markdown
Author

@hahakiki2025 please bump the charts minor version and regenerate the examples with make generate-examples CHARTS=opentelemetry-target-allocator
Hi Tyler,
I'm new contributor to the Opentelemetry Upstream. Regarding the bumping the charts minor version, is it similar to the version bump as this PR? In the PR it bumped the version to 0.112.2 in Chart.yaml and then run make generate-examples for the examples update? thanks

@hahakiki2025

Copy link
Copy Markdown
Author

@hahakiki2025 please bump the charts minor version and regenerate the examples with make generate-examples CHARTS=opentelemetry-target-allocator
Hi Tyler,
I'm new contributor to the Opentelemetry Upstream. Regarding the bumping the charts minor version, is it similar to the version bump as this PR? In the PR it bumped the version to 0.112.2 in Chart.yaml and then run make generate-examples for the examples update? thanks

@TylerHelmuth Done the version bump, please help have a look, thanks!

@hahakiki2025
hahakiki2025 force-pushed the topic/yan/update-collector-crd-for-ta branch from cccafee to ef7f26f Compare May 27, 2026 03:30
@hahakiki2025
hahakiki2025 requested review from atoulme and povilasv May 27, 2026 03:31
@hahakiki2025
hahakiki2025 force-pushed the topic/yan/update-collector-crd-for-ta branch from ef7f26f to 9df63d2 Compare May 28, 2026 08:45
Currently, when namespace-level privilege is not enabled, deploying
TargetAllocator alongside the OpenTelemetry Collector (with `enabled=true`)
fails due to PodSecurity "restricted" policy violations:

- allowPrivilegeEscalation must be set to false
- capabilities must drop ["ALL"]

This change adds support for configuring securityContext for the
TargetAllocator container, enabling compliant deployments under
restricted PodSecurity settings.

Signed-off-by: Yan Li <sherly_lee@163.com>
Signed-off-by: Yan Li <sherly_lee@163.com>
@hahakiki2025
hahakiki2025 force-pushed the topic/yan/update-collector-crd-for-ta branch from ed0b99a to 1464daa Compare June 1, 2026 10:07
@hahakiki2025

Copy link
Copy Markdown
Author

@TylerHelmuth I have rebased the code to resolve the conflicts. Since @atoulme and @povilasv have already approved it, could you please take another look and help merge this when you have a moment? Thank you!

Comment on lines +3369 to +3386
SecurityContext:
properties:
allowPrivilegeEscalation:
type: boolean
capabilities:
properties:
add:
items:
type: string
type: array
x-kubernetes-list-type: atomic
drop:
items:
type: string
type: array
x-kubernetes-list-type: atomic
type: object
type: object

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All the files in this dir are managed via make update-operator-crds. We can't add this manually, it would need to be in the upstream OpenTelemetry Operator CRD

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.

4 participants