Docker: Only switch user if the current user is root (#7654)

* Update entrypoint script for Dockerfile to only switch user if its running as root

Signed-off-by: Rafael Matias <rafael@skyle.net>

* make root user check at the beginning

Signed-off-by: Rafael Matias <rafael@skyle.net>

---------

Signed-off-by: Rafael Matias <rafael@skyle.net>
pull/7672/head
Rafael Matias 2 months ago committed by GitHub
parent 874cba016d
commit 0d63955158
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      besu/src/main/scripts/besu-entry.sh

@ -14,6 +14,14 @@
## SPDX-License-Identifier: Apache-2.0 ## SPDX-License-Identifier: Apache-2.0
## ##
# Construct the command as a single string
COMMAND="/opt/besu/bin/besu $@"
# Check if current user is not root. If not, run the command as is.
if [ "$(id -u)" -ne 0 ]; then
exec /bin/bash -c "$COMMAND"
fi
# Run Besu first to get paths needing permission adjustment # Run Besu first to get paths needing permission adjustment
output=$(/opt/besu/bin/besu --print-paths-and-exit $BESU_USER_NAME "$@") output=$(/opt/besu/bin/besu --print-paths-and-exit $BESU_USER_NAME "$@")
@ -41,9 +49,5 @@ echo "$output" | while IFS=: read -r prefix path accessType; do
fi fi
done done
# Finally, run Besu with the actual arguments passed to the container
# Construct the command as a single string
COMMAND="/opt/besu/bin/besu $@"
# Switch to the besu user and execute the command # Switch to the besu user and execute the command
exec su -s /bin/bash $BESU_USER_NAME -c "$COMMAND" exec su -s /bin/bash "$BESU_USER_NAME" -c "$COMMAND"

Loading…
Cancel
Save