Skip to content

Commit

Permalink
Docker: Only switch user if the current user is root (hyperledger#7654)
Browse files Browse the repository at this point in the history
* Update entrypoint script for Dockerfile to only switch user if its running as root

Signed-off-by: Rafael Matias <[email protected]>

* make root user check at the beginning

Signed-off-by: Rafael Matias <[email protected]>

---------

Signed-off-by: Rafael Matias <[email protected]>
  • Loading branch information
skylenet authored Sep 23, 2024
1 parent 874cba0 commit 0d63955
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions besu/src/main/scripts/besu-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
## 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
output=$(/opt/besu/bin/besu --print-paths-and-exit $BESU_USER_NAME "$@")

Expand Down Expand Up @@ -41,9 +49,5 @@ echo "$output" | while IFS=: read -r prefix path accessType; do
fi
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
exec su -s /bin/bash $BESU_USER_NAME -c "$COMMAND"
exec su -s /bin/bash "$BESU_USER_NAME" -c "$COMMAND"

0 comments on commit 0d63955

Please sign in to comment.