Skip to content
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: Only switch user if the current user is root #7654

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading