kuberneteskubernetes-helmkubernetes-podsecurity-contextsidecar

Can a sidecar container of a pod detect the user of the application container and use the same?


I have defined a sidecar container in a common.tpl file in my helm charts. This sidecar container is included in numerous pods in which different users are used.

I was wondering if there is a way to define as user in the sidecar container the user of the application container. As a result in each pod the same user will be used for both my application and my sidecar container.

I was imagining something like the below:

- name: sidecar_container
  image: sidecar_image:01
  imagePullPolicy: IfNotPresent
  securityContext:
    runAsUser: {{ some_variable_that_indicates_to_the_application's_container_user }}

Is there an option like that?


Solution

  • You can define the "SecurityContext" at Pod level , which means it will be applied to all containers inside the pod.

    Pod security context