Skip to content

Commit 879aaf1

Browse files
skylenetWolmin
authored andcommitted
Docker: Only switch user if the current user is root (besu-eth#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> Signed-off-by: Wolmin <lamonos123@gmail.com>
1 parent 78f7c62 commit 879aaf1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

besu/src/main/scripts/besu-entry.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
## SPDX-License-Identifier: Apache-2.0
1515
##
1616

17+
# Construct the command as a single string
18+
COMMAND="/opt/besu/bin/besu $@"
19+
20+
# Check if current user is not root. If not, run the command as is.
21+
if [ "$(id -u)" -ne 0 ]; then
22+
exec /bin/bash -c "$COMMAND"
23+
fi
24+
1725
# Run Besu first to get paths needing permission adjustment
1826
output=$(/opt/besu/bin/besu --print-paths-and-exit $BESU_USER_NAME "$@")
1927

@@ -41,9 +49,5 @@ echo "$output" | while IFS=: read -r prefix path accessType; do
4149
fi
4250
done
4351

44-
# Finally, run Besu with the actual arguments passed to the container
45-
# Construct the command as a single string
46-
COMMAND="/opt/besu/bin/besu $@"
47-
4852
# Switch to the besu user and execute the command
49-
exec su -s /bin/bash $BESU_USER_NAME -c "$COMMAND"
53+
exec su -s /bin/bash "$BESU_USER_NAME" -c "$COMMAND"

0 commit comments

Comments
 (0)