I want to add a wireguard sidecar container to prometheus stack installed via helm chart such that I can fetch client connected via vpn. I'm using the helm chart from prometheus-community/kube-prometheus-stack with modified values.yml. To integrate wireguard I added a wireguard container in the values.yml like this:
...
containers:
- name: "wireguard"
image: "lscr.io/linuxserver/wireguard:latest"
volumeMounts:
- name: wireguard-config
mountPath: /config
readOnly: true
- name: wireguard-run
mountPath: /run
securityContext:
runAsGroup: 0
runAsUser: 0
privileged: true
capabilities:
add:
- NET_ADMIN
- SYS_MODULE
but when I start the containers, I get the following error:
Normal Pulled 4s kubelet Successfully pulled image "lscr.io/linuxserver/wireguard:latest" in 500.578587ms
Warning Failed 3s (x3 over 4s) kubelet Error: container's runAsUser breaks non-root policy (pod: "XX", container: wireguard)
Normal Pulled 3s kubelet Successfully pulled image "lscr.io/linuxserver/wireguard:latest" in 456.879479ms
As wireguard needs to be able to change network interfaces, it needs the root privileges. If I don't run the container with root privileges I get the following:
...
SOME OTHER PERMISSION ERROS
s6-supervise (child): fatal: unable to exec run: Permission denied
s6-supervise coredns: warning: unable to spawn ./run - waiting 10 seconds
s6-supervise (child): fatal: unable to exec run: Permission denied
s6-supervise wireguard: warning: unable to spawn ./run - waiting 10 seconds
s6-supervise coredns: warning: unable to spawn ./run - waiting 10 seconds
What I tried is modifying the podSecurityPolicy to allow running containers as root in the prometheus values.yml. I was hoping that I could simply run the container as root (for testing at least):
podSecurityPolicy:
allowedCapabilities:
- runAsUser: RunAsAny
- NET_ADMIN
- SYS_MODULE
allowedHostPaths: []
volumes: []
This didn't change anything (am I doing this correctly?)
How would I allow running a sidecar container as root? Or is there a way to run wireguard without root priv?