-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Deploying manager pod as non-root #1637
Comments
Really thank you for raising it. Wdyt about clone the kube-rbac-proxy project and build an image to be gen as the kb projects ones to test your operator project with a kube-rbac-proxy image that is Regards the changes in #1635 I think we need to check it deeper because: Is it supportable for all k8s versions? Is not it just valid for 1.18 see here? Would it affect the behaviour in order kinds of k8s cluster? How a project with will behaviour in OCP for example? Would it be the best approach to solve the problem for the majority of scenarios? Should it be introduced by default or just documented? |
After changing the base image to
The pod.spec.securityContext.runAsUser API exists as far back as 1.12.x from what I can see
Personally I just found it a little confusing that the manager base image specified nonroot, so should have worked as-is on my nonroot cluster. Now it depends on whether kubebuilder wants to be secure by default at the cost of potentially more queries and issues. I think documentation on this will be needed in either case. |
Hi @harpratap,
Could you please push the PR for kube-rbac-proxy and ping me on it? It is definitely something that we need to do in order to ensure security.
The container cannot have root access because it would be a strong security failure since containers are just processes and then, it means that would be easily possible have root access to the host. Also, I understand that when we do not define the user the cluster it will assign a user with low permissions. Shows that if we do as proposed: securityContext:
runAsUser: 1337 Then it grants more privileged pods when the goal is to be less privileged as possible by default. See the OCP doc. Regards this point in specific I think we should just add by default it if it would be a security recommendation to do be done always which shows not the case. However, please feel free to let me know if I am missing something or if you find any Kubernetes documentation which says the opposite. |
@camilamacedo86 Makes sense. The change on kube-rbac-proxy is here - brancz/kube-rbac-proxy#85 |
Hi @harpratap, Thank you for your reply. See that we should not add the fixed ID. If you look we are using the variable already (we might could remove the user indeed, it is required to check):
Also, for further information check GoogleContainerTools/distroless#235 (comment) In this way, what in POV we need to close this task:
We need to collab to the brancz/kube-rbac-proxy in order to this project provide an image that is distroless and rootless which means that it will be something such as:
We need to update your PR against master in Kubebuidler to use :
As described in: https://kubernetes.io/blog/2016/08/security-best-practices-kubernetes-deployment/ |
@camilamacedo86 Thanks for your changes! Regarding
So if we are defining |
HI @harpratap, Really thank you for your collaboration and patient with. See that I could finish this one: brancz/kube-rbac-proxy#86 and I added the comments for we address your suggestion here in Kube as well. See; #1635. It is great and you had an excellent spot on this one. |
@camilamacedo86 Thanks so much! |
@camilamacedo86 Thanks for working on this. Waiting for update to a rootless image. |
I am closing this one because all changes and fixes required were done. We only need to know is have an As workaround users are able to update their projects manually to use the images provided by https://github.com/brancz/kube-rbac-proxy directly. |
I tried deploying the manager on our K8s platform that doesn't allow root by default but ran into following issues even though there's nothing really in the manager that requires root
I see the following two errors -
Error: container has runAsNonRoot and image will run as root
Error: container has runAsNonRoot and image has non-numeric user (nonroot), cannot verify user is non-root
We use the following podsecuritypolicy to ensure that pods are not running as root -
I believe this is happening because of two reasons -
The kube-rbac-proxy uses root by default, since it is using distroless/static as it's base image - https://github.com/brancz/kube-rbac-proxy/blob/master/Dockerfile#L1 I got this from this comment - RunAs unprivileged user GoogleContainerTools/distroless#235 (comment)
The manager image is using nonroot:nonroot user - https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugin/v2/scaffolds/internal/templates/dockerfile.go#L65
I have made some changes in #1635 which made it work in our cluster with the nonroot accounts.
What versions of software are you using? Specifically, the following are often useful:
kubebuilder version
) and scaffolding version (check yourPROJECT
file) 2.3.1 and v2go.mod
file) v0.6.0kubectl version
against your API server) v1.18.6/kind bug
The text was updated successfully, but these errors were encountered: