-
Notifications
You must be signed in to change notification settings - Fork 151
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
Implement rootless workloads #2481
Conversation
Not sure what milestone you want to stick this into @tobybellwood? |
I think it's the last component of the 2.0 release? |
discussed in the AIO security meeting:
|
Looking at this a bit more, I think we might be able to keep the group set to non-root, and add root as a supplementary group on openshift. I'll have to do some more research and testing. |
e5af09a
to
55dee24
Compare
Migrating permissions of RWX volumes from some common storage volume provisionersGiven the need to migrate existing workloads, I tried to understand how our current RWX storage provisioners matched permissions between the pod and the storage volume to enable access. Here's what you get when mounting a PVC for a RWX volume with the new non-root pod securityContext from this PR:
nfs-provisioner
AWS efs-provisionerAWS with
Azure fileAKS using the azure-file storageclass, RWX volumes are given 777 permissions and also the group ID given by
GKE nfs-client-provisionerGKE using the nfs-client-provisioner, RWX volumes are simply given 777 permissions.
DiscussionAmazingly, every RWX provisioner I checked uses a different mechanism to give the pod access to the storage. Since existing workloads are running as root we have the problem that e.g.
This is a problem, since So the solution I've come up with is to recursively set group ownership to match the mountpoint, and to give group access permissions. This is basically the same thing the This will:
There is one circumstance I can see where this logic will break, and that is where the volume has been The other problem with this approach is that the initContainer will run on every pod start, which is a lot of overhead for a process which only needs to run once. To mitigate this I'm creating a sentinel file inside the storage volume, which is checked before doing anything in the initContainer. This should mean that the permission change is only done approximately once.
I've manually tested this on EKS and GKE by creating files with broken permissions and letting the initContainer fix them. The Azure file provisioner enforces permissions by ignoring all chown/chmod requests, so the initContainer isn't strictly required:
Future workOnce all workloads are running with the new pod securityContext, the initContainer can be removed. |
ae10bc8
to
8d9f8ab
Compare
After some discussion, this needs a feature flag via environment variable for initial rollout. |
ac25ff3
to
5ba171c
Compare
As this feature can be controlled at the cluster, project, and environment level, I'm setting this as ready for review. Automated testing for projects/environments to assess if they can run rootless with no changes will be left for a future PR. |
e8fe650
to
f35e775
Compare
just for some reference for the future, here is the codechange since k8s 1.12 which changed the behavior to NOT change the persistent storage if it's an RWX mount: |
images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Outdated
Show resolved
Hide resolved
images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Outdated
Show resolved
Hide resolved
images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Outdated
Show resolved
Hide resolved
images/kubectl-build-deploy-dind/helmcharts/nginx-php-persistent/templates/deployment.yaml
Show resolved
Hide resolved
b490b3a
to
597077b
Compare
@Schnitzel @tobybellwood I cleaned this up a lot and simplified it to reduce the changes and hopefully make the logic much clearer. Let me know what you think. |
Specific UID/GID is based on https://github.com/hexops/dockerfile.
The initContainer on the nginx-php-persistent deployment ensures RWX storage has permissions compatible with the pod securityContext. This will: 1. Match the permissions set by all the above StorageClass drivers on the root of the volume. 2. Give the new non-root pod `securityContext` `g+rw` access to all files, and `g+x` on directories. When Pod Security Standards are enabled in Lagoon in future, this initContainer will have to be disabled or removed, since it runs as root.
* update comment to be more descriptive. * only look for global scope Lagoon variables. * update documentation
Checklist
Description
This PR implements rootless workloads on Lagoon, disabled by default, and controlled via feature flags as documented in #2541.
For Openshift 3.11 compatibility we run as a non-root uid, root gid, and non-root
fsGroup
. This also means that no changes are required in lagoon-images.The changes made include:
securityContext
to all pods.initContainer
to the shared storage nginx pod. This will update the ownership of the shared storage volume to the correct permissions going forward. See this comment below for details.This depends on uselagoon/lagoon-charts#235. Once that lands, we can remove 4a4fa5d from this PR.
Closing issues
Partially addresses https://github.com/amazeeio/lagoon/issues/2059.