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

ERROR controller-runtime.controller - Privileged containers are not allowed spec.containers[1].securityContext.privileged #792

Closed
mssanjay opened this issue Sep 6, 2021 · 16 comments
Labels
question Further information is requested stale

Comments

@mssanjay
Copy link

mssanjay commented Sep 6, 2021

Describe the bug
Controller is unable to create runner pods. I see error as below

2021-09-06T22:15:37.929Z ERROR controller-runtime.controller Reconciler error {"controller": "runner-controller", "request": "gha-runner-controller/example-runner", "error": "pods "example-runner" is forbidden: PodSecurityPolicy: unable to admit pod: [spec.containers[1].securityContext.privileged: Invalid value: true: Privileged containers are not allowed spec.containers[1].securityContext.privileged: Invalid value: true: Privileged containers are not allowed]"}

Checks
Manager logs shows below error

Privileged containers are not allowed spec.containers[1].securityContext.privileged

To Reproduce
Disable Previleged Pods in the cluster

Expected behavior
Runner Pod created

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • Controller Version - 0.18.2
  • Deployment Method [e.g. Helm and Kustomize ] - Helm
  • Helm Chart Version [e.g. 0.11.0, if applicable] -

Additional context
Add any other context about the problem here.

@mumoshu
Copy link
Collaborator

mumoshu commented Sep 6, 2021

@mssanjay Hey! Just curious but what do you want me to do? The information provided by you says that you got the error due to that you created some PSP to disallow privileged pods in your cluster. Then, there might be no way to make actions runners work.

Perhaps anyone could try to integrate rootless docker into actions-runner-controller, but I'm not going to do that myself anytime soon. If you could, I'll gladly review your work!

@mumoshu mumoshu added the invalid This doesn't seem right label Sep 6, 2021
@mssanjay
Copy link
Author

mssanjay commented Sep 7, 2021

@mumoshu Our corporate policy does not allow Privileged pods in our cluster. Hence the policy is in place. Also, I am using the image "docker:dind-rootless" which I thought is a rootless docker. So I am not sure why this error. Thanks for the update!

@mumoshu
Copy link
Collaborator

mumoshu commented Sep 7, 2021

@mssanjay Ah, good to know that there's now rootless version of the official dind image!

Well, actions-runner-controller mostly hardcodes privileged: true. But you can maybe try setting securityContext.seLinuxOptions to non-nil to make it privileged: false.

https://github.com/actions-runner-controller/actions-runner-controller/blob/14564c7b8e0ad7adadcb18a41a15f831b580f931/controllers/runner_controller.go#L805-L812

If it doesn't work, I'd suggest trying the canary image of actions-runner-controller that has a brand new feature called Runner Sets. Perhaps you can overwrite privileged setting for docker container with it. Something like:

apiVersion: actions.summerwind.dev/v1alpha1
kind: RunnerSet
metadata:
  name: example
spec:
  ephemeral: false
  replicas: 2
  repository: mumoshu/actions-runner-controller-ci
  # Other mandatory fields from StatefulSet
  selector:
    matchLabels:
      app: example
  serviceName: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: docker
        privileged: false

@mumoshu mumoshu added question Further information is requested and removed invalid This doesn't seem right labels Sep 7, 2021
@stale
Copy link

stale bot commented Oct 7, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 7, 2021
@rajbos
Copy link
Contributor

rajbos commented Oct 12, 2021

I had the same thing (preparing to add PSP that will disallow privileged containers). I suspect it will work for the dind container, but the deployment will always need a privileged container since it spins up new pods?

Anyway, I've tried using a mimimal seLinuxOptions since that should set the privileged to false. Unfortunately applying this setup still runs the dind containers as privileged:

# runner-deployment.yaml
apiVersion: actions.summerwind.dev/v1alpha1
kind: RunnerDeployment
metadata:
  name: xxx-gh-runner-deployment
spec:
  template:
    spec:
      organization: xxx-gh
      labels:
        - xxx-gh-org
        - k8s

      securityContext:
        seLinuxOptions:
          # level: "s0"
          # role: "system_r"
          # type: "super_t"
          # user: "system_u"
       privileged: false

I've no clue what proper values could be for the level / role / type / user, I have tried that the values above, but still the same result.

Note: I'm checking the privileged status with this command, which returns true:

kubectl get pod xxx-gh-runner-deployment-mzfx9-rj9rs -o json | jq -r '.spec.containers[].securityContext'

Note: I had to modify the official dind:rootless images by adding an extra folder. The image can be found here in my public package feed.

@mumoshu
Copy link
Collaborator

mumoshu commented Oct 12, 2021

If anyone could come up with a working changeset that enables you to run runners w/ dind-rootless w/o privileged, I'd be happy to review it :)

@stale stale bot closed this as completed Oct 26, 2021
@elebioda
Copy link

elebioda commented Nov 2, 2021

@mumoshu Our corporate policy does not allow Privileged pods in our cluster. Hence the policy is in place. Also, I am using the image "docker:dind-rootless" which I thought is a rootless docker. So I am not sure why this error. Thanks for the update!

rootless docker still requires privileged set to true

@rajbos
Copy link
Contributor

rajbos commented Nov 2, 2021

The controller still spins up both containers (the runner and the dind container) in the pod with --priviledged, which I haven't found a way to change @elebioda. Hence the error. Using a different image (dind-rootless) doesn't matter then, they're still spin up as privileged :-).

@elebioda
Copy link

elebioda commented Nov 2, 2021

@rajbos gotcha. Sadly, I am just having to disable the dind sidecar and use the runner for any workflow that holds no container actions... which is slim to none...

@mumoshu
Copy link
Collaborator

mumoshu commented Nov 4, 2021

@elebioda Thanks for sharing! That's absolutely sad news to hear.

I'm now wondering if we could use rootless podman via a docker alias instead. I heard podman has docker-compatible CLI and it works without root. I hope it doesn't require privileges :)

@florenciacomuzzi
Copy link

florenciacomuzzi commented Nov 20, 2021

I am seeing a similar error because I am running on a GKE Autopilot cluster which does not allow privileged pods:

2021-11-20T20:54:50.284Z        ERROR   actions-runner-controller.runner        Failed to create pod resource   {"runner": "actions-runner-system/example-runnerdeploy-lbdgs-pxdtk", "error": "admission webhook \"policycontrollerv2.common-webhooks.networking.gke.io\" denied the request: GKE Policy Controller rejected the request because it violates one or more policies: {\"[denied by autogke-disallow-privilege]\":[\"container docker is privileged; not allowed in Autopilot\"]}"}

@mumoshu
Copy link
Collaborator

mumoshu commented Nov 21, 2021

I've researched this a bit.

The bad news is that the state-of-the-art looks like we still need (1)a rootful container or alike to run a dockerd(with root or non-root user, with or without priv) in the runner pod to run (2)action and service containers(requested by your GitHub Actions workflow).

(1) can be a runc container, a sysbox container, a firecracker VM, etc and (2) is usually a docker container, podman container(e.g. if you do ailas docker=podman in our runner's entrypoint.sh.

I believe we have been discussing about alternatives in (2) so far. But my theory says that we'd need to find one in (1), which isn't trivial and also out of the scope of actions-runner-controller.

The good news is:

I haven't considered using other container runtimes like firecracker and kata container yet. In theory, it should be able to run any privileged containers safely inside a VM as a container. But I'm not sure if they are tested against our use-case. If anyone could give it a try and share your experience, it would be super helpful!

@roshvin
Copy link

roshvin commented May 5, 2022

Hi , even we are looking for running DinD in non-privileged mode . since our CaaS policy wont allow running any container as root.
Do you have any working solution or recommendation.

@jinalshah
Copy link

I am seeing a similar error because I am running on a GKE Autopilot cluster which does not allow privileged pods:

2021-11-20T20:54:50.284Z        ERROR   actions-runner-controller.runner        Failed to create pod resource   {"runner": "actions-runner-system/example-runnerdeploy-lbdgs-pxdtk", "error": "admission webhook \"policycontrollerv2.common-webhooks.networking.gke.io\" denied the request: GKE Policy Controller rejected the request because it violates one or more policies: {\"[denied by autogke-disallow-privilege]\":[\"container docker is privileged; not allowed in Autopilot\"]}"}

@flopotok did you ever manage to get this working on GKE Autopilot? As I've been running into the same issues.

@tedchang77
Copy link

We don't use docker inside our actions workflow. Is it possible to add a runner configuration where we can specify privileged: false?

@mumoshu
Copy link
Collaborator

mumoshu commented Jun 21, 2022

Hey. Yep see #1383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

8 participants