-
Notifications
You must be signed in to change notification settings - Fork 544
Description
Recently, I have been attempting to write the resource list for deploying Kubernetes based on Helm charts. However, during the deployment process, we encountered many compatibility issues related to cloud-native. Now, I will list some issues that I encountered when the rustfs container started the entrypoint using the root user:
In the practice of Kubernetes, to prevent container privilege escalation, it is generally recommended to deploy using non-root users and non-root file systems.
ref: security-context
# pod security context
securityContext:
fsGroup: 1000
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
# container security context
containers:
securityContext:
capabilities:
drop:
- ALL
readOnlyRootFilesystem: falseWhen the rustfs image was built, directories /data and /logs belonging to the root user were already created, with the permission set to 0750. This will result in the inability to use these two directories properly after starting as a non-root user. Because 0750 is reserved for exclusive use by the system.
I noticed that in the startup script of the entrypoint, the uid:1000 user is used to ultimately start the rustfs process. Although this avoids some security risks, the container is still running as root.
My idea is that we should modify the entrypoint startup logic and run the entrypoint script in the Dockerfile without using root privileges at all.
FROM alpine:3.22
RUN <<EOF
groupadd -g 1001 --system rustfs
useradd \
--no-log-init \
--gid 1001 \
--uid 1001 \
--create-home \
--home-dir /rustfs \
rustfs
EOF
# Before exporting the image, switch the container user to a regular user.
USER rustfs
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/bin/rustfs"]