-
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
Add support for running Docker container as non-root user #1891
Conversation
Hi @knadh for people using mount volumes there will be a impact, since their files For people using local filesystems / mount volumes they would need to change the ownership of their files at filesystem level before updating, by doing something similar to: chown -R 1001:1001 /path/to/volume For people using Kubernetes they would been to update their deployment specifying the new apiVersion: v1
kind: Pod
metadata:
name: listmonk
spec:
containers:
- name: listmonk
image: listmonk/listmonk
securityContext:
runAsUser: 1001
runAsGroup: 1001 Lastly if people are using Kubernetes and Persistent Volume Claims (PVCs) they would been to change they file ownership and permissions of their files, they could do it by hand but I would recommend using a In the example bellow I'm running a InitContainer apiVersion: v1
kind: Pod
metadata:
name: listmonk
spec:
initContainers:
- name: init-permissions
image: busybox
command: ["sh", "-c", "chown -R 1001:1001 /path/to/mount"]
volumeMounts:
- name: listmonk-uploads
mountPath: /path/to/mount
containers:
- name: listmonk
image: listmonk/listmonk
securityContext:
runAsUser: 1001
runAsGroup: 1001
volumeMounts:
- name: listmonk-uploads
mountPath: /path/to/mount
volumes:
- name: listmonk-uploads
persistentVolumeClaim:
claimName: listmonk-pvc @knadh This pull-request assumes that you would try to keep things simple and avoid me introducing complexity to the docker image run process. But if you allow I can create a
With a bit of magic on the side of the |
Hi @lmmendes. Please add the script to ensure backwards compatibility. |
@knadh I'm going to place this pull-request in Or if you wish just close the pull-request and I will open a new one once done. |
Closing this pull-request in favor of #1892 that implements a different approach to solve the problem and ensures backwards comparability as requested. |
This pull request introduces the capability to run the listmonk Docker container as non-root user by specifying the
UID
andGID
through environment variables.The following changes have been made:
Dockerfile
to create a non-root user (app
) and group (app
) using the specifiedUID=1001
andGID=1001
.UID
andGID
, with the option to override them using build arguments:docker build --build-arg UID=2001 --build-arg GID=2001 -t listmonk .
Advantages:
Breaking changes
Impacts for people running previous versions (using root, before non root user
UID
andGID
)UID
andGID
) may result in permission errors when the non-root user tries to access these files.UID
andGID
.Testing
Built the project using
Tested running the docker
arm64
locally without issues.Future work
spec.securityContext.runAsUser
,spec.securityContext.runAsGroup
includingspec.containers[*].securityContext.allowPrivilegeEscalation=false
in his deployment to close the loop once this pull-request gets accepted.