-
Notifications
You must be signed in to change notification settings - Fork 115
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
docker image / container runs fine with docker run, but not when deployed to Kubernetes (unprivileged) #123
Comments
Hi @divStar. Currently, Supercronic was developed for our platform which is primarily Docker-focused, so within the K8s landscape isn't something we developed for. After reviewing your specifics I think that this issue comes down to the
Hopefully, that helps you move a little further in your troubleshooting. |
Since I had a bit of trouble finding a full Dockerfile in the beginning, here is a working example for an unprivileged Dockerfile with Supercronic in it: FROM alpine:latest
# Install required packages
RUN apk add --no-cache curl postgresql-client bash diffutils
# Latest releases available at https://github.com/aptible/supercronic/releases
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.2/supercronic-linux-amd64 \
SUPERCRONIC=supercronic-linux-amd64 \
SUPERCRONIC_SHA1SUM=2319da694833c7a147976b8e5f337cd83397d6be
RUN curl -fsSLO "$SUPERCRONIC_URL" \
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
&& chmod +x "$SUPERCRONIC" \
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
# Create a dummy query.sh
RUN mkdir /workdir
RUN echo "#!/bin/bash\necho 'Replace the /workdir/query.sh with your own by mounting it!'" > /workdir/query.sh
RUN chmod +x /workdir/query.sh
# Define a default cron expression
ENV CRON_EXPRESSION "* * * * *"
# Create a startup script that sets up the cron job
RUN echo -e "${CRON_EXPRESSION} /workdir/query.sh > /proc/1/fd/1 2>&1" > /crontab
RUN chmod -R 0777 /workdir
# Create user and group
ENV USER_ID=1337
ENV GROUP_ID=1337
ENV USER_NAME=appuser
ENV GROUP_NAME=appgroup
RUN addgroup -g $GROUP_ID $GROUP_NAME && \
adduser -D --uid $USER_ID --ingroup $GROUP_NAME $USER_NAME
WORKDIR /workdir
USER appuser
# Start cron with the configured expression and run the startup script
#CMD ["/bin/sh", "-c", "./start.sh & crond -l $LOG_LEVEL -f"]
CMD sh -c "id && supercronic /crontab" In my securityContext:
runAsUser: 1337
runAsGroup: 1337
fsGroup: 1337 I am not 100% sure which of the changes did the trick, but it works. Also for those reading: you might want to add / remove particular packages and you might not want Thank you for your help :). |
@turner-aptible I actually do have one more question.
I suppose I could somehow make that line part of the CMD command, but it seems a bit much. Is there a way to have My current solution is: ...
CMD sh -c "id && supercronic <(echo '$(cat "/crontab" | sed "s/\$CRON_EXPRESSION/$(echo "$CRON_EXPRESSION" | sed 's/[\\/]/\\\//')/")')" This replaces the hardcoded |
Hello!
Thank you very much for such a handy tool.
I use the following Dockerfile to build the image:
I run the image/container using the following command from CLI just fine:
docker run -t --init --user 0:0 --cap-drop ALL --security-opt no-new-privileges --read-only --group-add 1 --group-add 2 --group-add 3 --group-add 4 --group-add 6 --group-add 10 --group-add 11 --group-add 20 --group-add 26 --group-add 27 --rm -e CRON_EXPRESSION="* * * * *" -v /.../query.sh:/workdir/query.sh:ro .../cronic-image:1
It also works flawlessly if I do not
group-add
any groups at all and no matter what user I specify (even nobody:nogroup works).The output from
docker run
is about something like this:However: when I deploy it to our Kubernetes cluster, I get the following output from ArgoCD:
Note: in
groups=...
0(root)
is not included when deployed to the Kubernetes cluster, but is very much so if I run it locally usingdocker run...
.I suspect, that the Kubernetes cluster is restricted and we are not supposed to run unprivileged images and containers, but I thought I had made the container work in an unprivileged manner.
Do you happen to have an idea why that is and how to fix it? I really I tried everything I could. Setting
securityContext
along withrunAsUser: ...
andrunAsGroup
, but nothing works. It seems supercronic doesn't have enough permissions to execute/workdir/query.sh
, that I mount...The text was updated successfully, but these errors were encountered: