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

Adding the possibility to run as an arbitrary user #14

Merged
merged 3 commits into from
Nov 1, 2023
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
42 changes: 42 additions & 0 deletions apache2/bin/start.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
#!/usr/bin/env bash

# Check and read the user and group env vars set by the user
# Save them for later use as they will be overwritten by the next command
if [[ -v APACHE_RUN_USER ]]; then
APACHE_UID=$APACHE_RUN_USER
fi
if [[ -v APACHE_RUN_GROUP ]]; then
APACHE_GUID=$APACHE_RUN_GROUP
fi

# Read the envars for Apache2
source /etc/apache2/envvars

# Run as an arbitrary user / group if the user asked for one. It needs
# to be created first and stripped of the leading #
if [[ -v APACHE_UID ]]; then
export APACHE_RUN_USER=$APACHE_UID
APACHE_UID_TO_CREATE=$(echo $APACHE_UID | sed 's/#//')
if [[ -v APACHE_GUID ]]; then
export APACHE_RUN_GROUP=$APACHE_GUID
APACHE_GUID_TO_CREATE=$(echo $APACHE_GUID | sed 's/#//')
[ $(getent group openconext) ] || groupadd -g $APACHE_GUID_TO_CREATE openconext
[ $(getent passwd openconext) ] || useradd -M -u $APACHE_UID_TO_CREATE -g $APACHE_GUID_TO_CREATE openconext
else
[ $(getent passwd openconext) ] || useradd -M -u $APACHE_UID_TO_CREATE openconext
fi
fi

# Make sure the directories Apache2 needs are owned by the user running the daemon
for dir in \
"$APACHE_RUN_DIR" \
"$APACHE_LOG_DIR" \
"/var/www/html" \
; do \
if [[ -v APACHE_UID_TO_CREATE ]]; then
if [[ -v APACHE_GUID_TO_CREATE ]]; then
chown "$APACHE_UID_TO_CREATE:$APACHE_GUID_TO_CREATE" "$dir";
else
chown "$APACHE_UID_TO_CREATE" "$dir";
fi
else
chown "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir";
fi
chmod 1777 "$dir";
done

# Start Apache2
apache2 -D FOREGROUND