Closed gimler closed 3 years ago
I'm really confused why you're doing chmod +s
on your binary, especially if your goal is to run it as non-root? Adding the setuid bit to a binary is specifically for running a binary as root all the time.
Also, in your simplified example, gosu
is overkill, and you just use USER
instead:
...
USER wwwrun
CMD ["cron", "-n"]
If you also run with --security-opt no-new-privileges
then the setuid bit will cause an error instead of just silently running as root, which might be useful for you.
For more help, I'd suggest a dedicated support forum, such as the Docker Community Forums, the Docker Community Slack, or Stack Overflow.
@tianon i was try to keep the code snippet as small as possible, sorry i forgot a comment. the +s was only a try to solve the setuid problem.
# chmod u+s to solve
# setuid: Operation not permitted
i have remove this part.
we can not set the user with USER wwwrun
because we have some init scripts that must be run on container start with root rights.
So the question is how can we fix the setuid: Operation not permitted
error.
with this
chmod u+s /usr/bin/gosu
pciapp@d92314a67613:/usr/local/static/3rd$ gosu -h
error: "gosu" appears to be installed with the 'setuid' bit set, which is an *extremely* insecure and completely unsupported configuration! (what you want instead is likely 'sudo' or 'su')
#ok with this set
export GOSU_PLEASE_LET_ME_BE_COMPLETELY_INSECURE_I_GET_TO_KEEP_ALL_THE_PIECES="I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhäuser Gate. All those moments will be lost in time, like tears in rain. Time to die."
root@dea3a1fa8039:/app# gosu -h
Usage: gosu user-spec command [args]
eg: gosu tianon bash
gosu nobody:root bash -c 'whoami && id'
gosu 1000:1 id
gosu version: 1.17 (go1.18.2 on linux/amd64; gc)
gosu license: Apache-2.0 (full text at https://github.com/tianon/gosu)
ref Disallow installing gosu with setuid @Aug 18, 2021
Please, please, please do not run gosu with setuid; I'm really certain it's the wrong tool for what you're trying to accomplish.
Please, please, please do not run gosu with setuid; I'm really certain it's the wrong tool for what you're trying to accomplish.
It's a trick in some scene, like:
chmod u+s /usr/bin/gosu
with root, or just pre-set with the image.xxapp
for the container in docker/k8s (either with entrypoint and docker/kubectl exec ..)entrypoint.sh: gosu root $cmd
gosu root chmod u-s /usr/bin/gosu
, then exec /app/bin/start.sh
Honestly, properly and securely configuring sudo
is better for that use case. It's literally designed for it.
Another even better answer would be an init container (in k8s).
system: sles 12 sp5
Error:
How can i run the cron as wwwrun?