mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
Use user primary group if not root (#292)
* Use user primary group if not root * Do not run getent on MacOS * Simplify UID/GID management * Create uid.env if it does not exist * Populate uid.env if it's empty
This commit is contained in:
parent
1ead0af77e
commit
ec89c36ca0
@ -4,10 +4,11 @@ set -e
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
OUTPUT_DIR="../."
|
||||
OUTPUT_DIR=".."
|
||||
if [ $# -gt 0 ]
|
||||
then
|
||||
OUTPUT_DIR=$1
|
||||
mkdir -p $OUTPUT_DIR
|
||||
fi
|
||||
|
||||
COREVERSION="latest"
|
||||
@ -22,16 +23,13 @@ then
|
||||
WEBVERSION=$3
|
||||
fi
|
||||
|
||||
OS="lin"
|
||||
if [ "$(uname)" == "Darwin" ]
|
||||
then
|
||||
OS="mac"
|
||||
fi
|
||||
ENV_DIR="$OUTPUT_DIR/env"
|
||||
|
||||
# Save the installation UID/GID, they could also be manually changed later on if desired
|
||||
LUID="LOCAL_UID=`id -u $USER`"
|
||||
LGID="LOCAL_GID=`getent group docker | cut -d: -f3`"
|
||||
|
||||
mkdir -p $OUTPUT_DIR
|
||||
LGID="LOCAL_GID=`id -g $USER`"
|
||||
mkdir -p $ENV_DIR
|
||||
(echo $LUID; echo $LGID) > $ENV_DIR/uid.env
|
||||
|
||||
LETS_ENCRYPT="n"
|
||||
echo -e -n "${CYAN}(!)${NC} Enter the domain name for your bitwarden instance (ex. bitwarden.company.com): "
|
||||
@ -64,14 +62,8 @@ then
|
||||
fi
|
||||
|
||||
docker pull bitwarden/setup:$COREVERSION
|
||||
if [ $OS == "lin" ]
|
||||
then
|
||||
docker run -it --rm --name setup -v $OUTPUT_DIR:/bitwarden -e $LUID -e $LGID bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -install 1 -domain $DOMAIN -letsencrypt $LETS_ENCRYPT -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
else
|
||||
docker run -it --rm --name setup -v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -install 1 -domain $DOMAIN -letsencrypt $LETS_ENCRYPT -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
fi
|
||||
docker run -it --rm --name setup -v $OUTPUT_DIR:/bitwarden --env-file $ENV_DIR/uid.env bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -install 1 -domain $DOMAIN -letsencrypt $LETS_ENCRYPT -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
|
||||
echo ""
|
||||
echo "Setup complete"
|
||||
|
@ -5,7 +5,7 @@ set -e
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
OUTPUT_DIR="../."
|
||||
OUTPUT_DIR=".."
|
||||
if [ $# -gt 1 ]
|
||||
then
|
||||
OUTPUT_DIR=$2
|
||||
@ -23,16 +23,17 @@ then
|
||||
WEBVERSION=$4
|
||||
fi
|
||||
|
||||
OS="lin"
|
||||
if [ "$(uname)" == "Darwin" ]
|
||||
then
|
||||
OS="mac"
|
||||
fi
|
||||
|
||||
DOCKER_DIR="$OUTPUT_DIR/docker"
|
||||
ENV_DIR="$OUTPUT_DIR/env"
|
||||
LUID="LOCAL_UID=`id -u $USER`"
|
||||
LGID="LOCAL_GID=`getent group docker | cut -d: -f3`"
|
||||
DOCKER_DIR="$OUTPUT_DIR/docker"
|
||||
|
||||
# As in install.sh, save the running UID/GID, they could not exist yet, during an update for example
|
||||
if ! grep -q "^LOCAL_UID=" $ENV_DIR/uid.env 2>/dev/null || ! grep -q "^LOCAL_GID=" $ENV_DIR/uid.env 2>/dev/null
|
||||
then
|
||||
LUID="LOCAL_UID=`id -u $USER`"
|
||||
LGID="LOCAL_GID=`id -g $USER`"
|
||||
mkdir -p $ENV_DIR
|
||||
(echo $LUID; echo $LGID) > $ENV_DIR/uid.env
|
||||
fi
|
||||
|
||||
# Functions
|
||||
|
||||
@ -79,58 +80,30 @@ function updateLetsEncrypt() {
|
||||
|
||||
function updateDatabase() {
|
||||
pullSetup
|
||||
if [ $OS == "lin" ]
|
||||
then
|
||||
docker run -i --rm --name setup --network container:bitwarden-mssql \
|
||||
-v $OUTPUT_DIR:/bitwarden -e $LUID -e $LGID bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -update 1 -db 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
else
|
||||
docker run -i --rm --name setup --network container:bitwarden-mssql \
|
||||
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -update 1 -db 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
fi
|
||||
docker run -i --rm --name setup --network container:bitwarden-mssql \
|
||||
-v $OUTPUT_DIR:/bitwarden --env-file $ENV_DIR/uid.env bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -update 1 -db 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
echo "Database update complete"
|
||||
}
|
||||
|
||||
function update() {
|
||||
pullSetup
|
||||
if [ $OS == "lin" ]
|
||||
then
|
||||
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
|
||||
-e $LUID -e $LGID bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
else
|
||||
docker run -i --rm --name setup \
|
||||
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
fi
|
||||
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
|
||||
--env-file $ENV_DIR/uid.env bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -update 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
}
|
||||
|
||||
function printEnvironment() {
|
||||
pullSetup
|
||||
if [ $OS == "lin" ]
|
||||
then
|
||||
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
|
||||
-e $LUID -e $LGID bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
else
|
||||
docker run -i --rm --name setup \
|
||||
-v $OUTPUT_DIR:/bitwarden bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
fi
|
||||
docker run -i --rm --name setup -v $OUTPUT_DIR:/bitwarden \
|
||||
--env-file $ENV_DIR/uid.env bitwarden/setup:$COREVERSION \
|
||||
dotnet Setup.dll -printenv 1 -os $OS -corev $COREVERSION -webv $WEBVERSION
|
||||
}
|
||||
|
||||
function restart() {
|
||||
dockerComposeDown
|
||||
dockerComposePull
|
||||
updateLetsEncrypt
|
||||
|
||||
if [ $OS == "lin" ]
|
||||
then
|
||||
mkdir -p $ENV_DIR
|
||||
(echo $LUID; echo $LGID) > $ENV_DIR/uid.env
|
||||
fi
|
||||
|
||||
dockerComposeUp
|
||||
dockerPrune
|
||||
printEnvironment
|
||||
|
@ -5,52 +5,27 @@
|
||||
GROUPNAME="bitwarden"
|
||||
USERNAME="bitwarden"
|
||||
|
||||
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
|
||||
LGID=${LOCAL_GID:-999}
|
||||
LUID=${LOCAL_UID:-0}
|
||||
LGID=${LOCAL_GID:-0}
|
||||
|
||||
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
|
||||
LUID=${LOCAL_UID:-999}
|
||||
# Step down from host root to well-known nobody/nogroup user
|
||||
|
||||
# Step down from host root
|
||||
|
||||
if [ $LGID == 0 ]
|
||||
if [ $LUID -eq 0 ]
|
||||
then
|
||||
LGID=999
|
||||
LUID=65534
|
||||
fi
|
||||
if [ $LGID -eq 0 ]
|
||||
then
|
||||
LGID=65534
|
||||
fi
|
||||
|
||||
if [ $LUID == 0 ]
|
||||
then
|
||||
LUID=999
|
||||
fi
|
||||
# Create user and group
|
||||
|
||||
# Create group
|
||||
|
||||
if [ $CURRENTGID ]
|
||||
then
|
||||
if [ "$CURRENTGID" != "$LGID" ]
|
||||
then
|
||||
groupmod -g $LGID $GROUPNAME
|
||||
fi
|
||||
else
|
||||
groupadd -g $LGID $GROUPNAME
|
||||
fi
|
||||
|
||||
# Create user and assign group
|
||||
|
||||
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ]
|
||||
then
|
||||
usermod -u $LUID $USERNAME
|
||||
elif [ $NOUSER == 1 ]
|
||||
then
|
||||
useradd -r -u $LUID -g $GROUPNAME $USERNAME
|
||||
fi
|
||||
|
||||
# Make home directory for user
|
||||
|
||||
if [ ! -d "/home/$USERNAME" ]
|
||||
then
|
||||
mkhomedir_helper $USERNAME
|
||||
fi
|
||||
groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 ||
|
||||
groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1
|
||||
useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 ||
|
||||
usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1
|
||||
mkhomedir_helper $USERNAME
|
||||
|
||||
# The rest...
|
||||
|
||||
@ -63,4 +38,4 @@ chown -R $USERNAME:$GROUPNAME /etc/bitwarden
|
||||
cp /etc/bitwarden/ca-certificates/*.crt /usr/local/share/ca-certificates/ \
|
||||
&& update-ca-certificates
|
||||
|
||||
gosu $USERNAME:$GROUPNAME dotnet /app/Admin.dll
|
||||
exec gosu $USERNAME:$GROUPNAME dotnet /app/Admin.dll
|
||||
|
@ -5,52 +5,27 @@
|
||||
GROUPNAME="bitwarden"
|
||||
USERNAME="bitwarden"
|
||||
|
||||
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
|
||||
LGID=${LOCAL_GID:-999}
|
||||
LUID=${LOCAL_UID:-0}
|
||||
LGID=${LOCAL_GID:-0}
|
||||
|
||||
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
|
||||
LUID=${LOCAL_UID:-999}
|
||||
# Step down from host root to well-known nobody/nogroup user
|
||||
|
||||
# Step down from host root
|
||||
|
||||
if [ $LGID == 0 ]
|
||||
if [ $LUID -eq 0 ]
|
||||
then
|
||||
LGID=999
|
||||
LUID=65534
|
||||
fi
|
||||
if [ $LGID -eq 0 ]
|
||||
then
|
||||
LGID=65534
|
||||
fi
|
||||
|
||||
if [ $LUID == 0 ]
|
||||
then
|
||||
LUID=999
|
||||
fi
|
||||
# Create user and group
|
||||
|
||||
# Create group
|
||||
|
||||
if [ $CURRENTGID ]
|
||||
then
|
||||
if [ "$CURRENTGID" != "$LGID" ]
|
||||
then
|
||||
groupmod -g $LGID $GROUPNAME
|
||||
fi
|
||||
else
|
||||
groupadd -g $LGID $GROUPNAME
|
||||
fi
|
||||
|
||||
# Create user and assign group
|
||||
|
||||
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ]
|
||||
then
|
||||
usermod -u $LUID $USERNAME
|
||||
elif [ $NOUSER == 1 ]
|
||||
then
|
||||
useradd -r -u $LUID -g $GROUPNAME $USERNAME
|
||||
fi
|
||||
|
||||
# Make home directory for user
|
||||
|
||||
if [ ! -d "/home/$USERNAME" ]
|
||||
then
|
||||
mkhomedir_helper $USERNAME
|
||||
fi
|
||||
groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 ||
|
||||
groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1
|
||||
useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 ||
|
||||
usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1
|
||||
mkhomedir_helper $USERNAME
|
||||
|
||||
# The rest...
|
||||
|
||||
@ -63,10 +38,11 @@ mkdir -p /etc/bitwarden/logs
|
||||
mkdir -p /etc/bitwarden/ca-certificates
|
||||
chown -R $USERNAME:$GROUPNAME /etc/bitwarden
|
||||
|
||||
env >> /etc/environment
|
||||
# Sounds like gosu keeps env when switching, but of course cron does not
|
||||
env > /etc/environment
|
||||
cron
|
||||
|
||||
cp /etc/bitwarden/ca-certificates/*.crt /usr/local/share/ca-certificates/ \
|
||||
&& update-ca-certificates
|
||||
|
||||
gosu $USERNAME:$GROUPNAME dotnet /app/Api.dll
|
||||
exec gosu $USERNAME:$GROUPNAME dotnet /app/Api.dll
|
||||
|
@ -5,54 +5,30 @@
|
||||
GROUPNAME="bitwarden"
|
||||
USERNAME="bitwarden"
|
||||
|
||||
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
|
||||
LGID=${LOCAL_GID:-999}
|
||||
LUID=${LOCAL_UID:-0}
|
||||
LGID=${LOCAL_GID:-0}
|
||||
|
||||
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
|
||||
LUID=${LOCAL_UID:-999}
|
||||
# Step down from host root to well-known nobody/nogroup user
|
||||
|
||||
# Step down from host root
|
||||
|
||||
if [ $LGID == 0 ]
|
||||
if [ $LUID -eq 0 ]
|
||||
then
|
||||
LGID=999
|
||||
LUID=65534
|
||||
fi
|
||||
if [ $LGID -eq 0 ]
|
||||
then
|
||||
LGID=65534
|
||||
fi
|
||||
|
||||
if [ $LUID == 0 ]
|
||||
then
|
||||
LUID=999
|
||||
fi
|
||||
# Create user and group
|
||||
|
||||
# Create group
|
||||
|
||||
if [ $CURRENTGID ]
|
||||
then
|
||||
if [ "$CURRENTGID" != "$LGID" ]
|
||||
then
|
||||
groupmod -g $LGID $GROUPNAME
|
||||
fi
|
||||
else
|
||||
groupadd -g $LGID $GROUPNAME
|
||||
fi
|
||||
|
||||
# Create user and assign group
|
||||
|
||||
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ]
|
||||
then
|
||||
usermod -u $LUID $USERNAME
|
||||
elif [ $NOUSER == 1 ]
|
||||
then
|
||||
useradd -r -u $LUID -g $GROUPNAME $USERNAME
|
||||
fi
|
||||
|
||||
# Make home directory for user
|
||||
|
||||
if [ ! -d "/home/$USERNAME" ]
|
||||
then
|
||||
mkhomedir_helper $USERNAME
|
||||
fi
|
||||
groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 ||
|
||||
groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1
|
||||
useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 ||
|
||||
usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1
|
||||
mkhomedir_helper $USERNAME
|
||||
|
||||
# The rest...
|
||||
|
||||
chown -R $USERNAME:$GROUPNAME /app
|
||||
gosu $USERNAME:$GROUPNAME dotnet /app/Icons.dll
|
||||
|
||||
exec gosu $USERNAME:$GROUPNAME dotnet /app/Icons.dll
|
||||
|
@ -5,52 +5,27 @@
|
||||
GROUPNAME="bitwarden"
|
||||
USERNAME="bitwarden"
|
||||
|
||||
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
|
||||
LGID=${LOCAL_GID:-999}
|
||||
LUID=${LOCAL_UID:-0}
|
||||
LGID=${LOCAL_GID:-0}
|
||||
|
||||
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
|
||||
LUID=${LOCAL_UID:-999}
|
||||
# Step down from host root to well-known nobody/nogroup user
|
||||
|
||||
# Step down from host root
|
||||
|
||||
if [ $LGID == 0 ]
|
||||
if [ $LUID -eq 0 ]
|
||||
then
|
||||
LGID=999
|
||||
LUID=65534
|
||||
fi
|
||||
if [ $LGID -eq 0 ]
|
||||
then
|
||||
LGID=65534
|
||||
fi
|
||||
|
||||
if [ $LUID == 0 ]
|
||||
then
|
||||
LUID=999
|
||||
fi
|
||||
# Create user and group
|
||||
|
||||
# Create group
|
||||
|
||||
if [ $CURRENTGID ]
|
||||
then
|
||||
if [ "$CURRENTGID" != "$LGID" ]
|
||||
then
|
||||
groupmod -g $LGID $GROUPNAME
|
||||
fi
|
||||
else
|
||||
groupadd -g $LGID $GROUPNAME
|
||||
fi
|
||||
|
||||
# Create user and assign group
|
||||
|
||||
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ]
|
||||
then
|
||||
usermod -u $LUID $USERNAME
|
||||
elif [ $NOUSER == 1 ]
|
||||
then
|
||||
useradd -r -u $LUID -g $GROUPNAME $USERNAME
|
||||
fi
|
||||
|
||||
# Make home directory for user
|
||||
|
||||
if [ ! -d "/home/$USERNAME" ]
|
||||
then
|
||||
mkhomedir_helper $USERNAME
|
||||
fi
|
||||
groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 ||
|
||||
groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1
|
||||
useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 ||
|
||||
usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1
|
||||
mkhomedir_helper $USERNAME
|
||||
|
||||
# The rest...
|
||||
|
||||
@ -66,4 +41,4 @@ chown -R $USERNAME:$GROUPNAME /app
|
||||
cp /etc/bitwarden/ca-certificates/*.crt /usr/local/share/ca-certificates/ \
|
||||
&& update-ca-certificates
|
||||
|
||||
gosu $USERNAME:$GROUPNAME dotnet /app/Identity.dll
|
||||
exec gosu $USERNAME:$GROUPNAME dotnet /app/Identity.dll
|
||||
|
@ -5,52 +5,27 @@
|
||||
GROUPNAME="bitwarden"
|
||||
USERNAME="bitwarden"
|
||||
|
||||
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
|
||||
LGID=${LOCAL_GID:-999}
|
||||
LUID=${LOCAL_UID:-0}
|
||||
LGID=${LOCAL_GID:-0}
|
||||
|
||||
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
|
||||
LUID=${LOCAL_UID:-999}
|
||||
# Step down from host root to well-known nobody/nogroup user
|
||||
|
||||
# Step down from host root
|
||||
|
||||
if [ $LGID == 0 ]
|
||||
if [ $LUID -eq 0 ]
|
||||
then
|
||||
LGID=999
|
||||
LUID=65534
|
||||
fi
|
||||
if [ $LGID -eq 0 ]
|
||||
then
|
||||
LGID=65534
|
||||
fi
|
||||
|
||||
if [ $LUID == 0 ]
|
||||
then
|
||||
LUID=999
|
||||
fi
|
||||
# Create user and group
|
||||
|
||||
# Create group
|
||||
|
||||
if [ $CURRENTGID ]
|
||||
then
|
||||
if [ "$CURRENTGID" != "$LGID" ]
|
||||
then
|
||||
groupmod -g $LGID $GROUPNAME
|
||||
fi
|
||||
else
|
||||
groupadd -g $LGID $GROUPNAME
|
||||
fi
|
||||
|
||||
# Create user and assign group
|
||||
|
||||
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ]
|
||||
then
|
||||
usermod -u $LUID $USERNAME
|
||||
elif [ $NOUSER == 1 ]
|
||||
then
|
||||
useradd -r -u $LUID -g $GROUPNAME $USERNAME
|
||||
fi
|
||||
|
||||
# Make home directory for user
|
||||
|
||||
if [ ! -d "/home/$USERNAME" ]
|
||||
then
|
||||
mkhomedir_helper $USERNAME
|
||||
fi
|
||||
groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 ||
|
||||
groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1
|
||||
useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 ||
|
||||
usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1
|
||||
mkhomedir_helper $USERNAME
|
||||
|
||||
# The rest...
|
||||
|
||||
@ -58,5 +33,5 @@ chown -R $USERNAME:$GROUPNAME /bitwarden_server
|
||||
mkdir -p /etc/bitwarden/core/attachments
|
||||
chown -R $USERNAME:$GROUPNAME /etc/bitwarden
|
||||
|
||||
gosu $USERNAME:$GROUPNAME dotnet /bitwarden_server/Server.dll \
|
||||
exec gosu $USERNAME:$GROUPNAME dotnet /bitwarden_server/Server.dll \
|
||||
/contentRoot=/etc/bitwarden/core/attachments /webRoot=. /serveUnknown=true
|
||||
|
@ -5,52 +5,27 @@
|
||||
GROUPNAME="bitwarden"
|
||||
USERNAME="bitwarden"
|
||||
|
||||
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
|
||||
LGID=${LOCAL_GID:-999}
|
||||
LUID=${LOCAL_UID:-0}
|
||||
LGID=${LOCAL_GID:-0}
|
||||
|
||||
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
|
||||
LUID=${LOCAL_UID:-999}
|
||||
# Step down from host root to well-known nobody/nogroup user
|
||||
|
||||
# Step down from host root
|
||||
|
||||
if [ $LGID == 0 ]
|
||||
if [ $LUID -eq 0 ]
|
||||
then
|
||||
LGID=999
|
||||
LUID=65534
|
||||
fi
|
||||
if [ $LGID -eq 0 ]
|
||||
then
|
||||
LGID=65534
|
||||
fi
|
||||
|
||||
if [ $LUID == 0 ]
|
||||
then
|
||||
LUID=999
|
||||
fi
|
||||
# Create user and group
|
||||
|
||||
# Create group
|
||||
|
||||
if [ $CURRENTGID ]
|
||||
then
|
||||
if [ "$CURRENTGID" != "$LGID" ]
|
||||
then
|
||||
groupmod -g $LGID $GROUPNAME
|
||||
fi
|
||||
else
|
||||
groupadd -g $LGID $GROUPNAME
|
||||
fi
|
||||
|
||||
# Create user and assign group
|
||||
|
||||
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ]
|
||||
then
|
||||
usermod -u $LUID $USERNAME
|
||||
elif [ $NOUSER == 1 ]
|
||||
then
|
||||
useradd -r -u $LUID -g $GROUPNAME $USERNAME
|
||||
fi
|
||||
|
||||
# Make home directory for user
|
||||
|
||||
if [ ! -d "/home/$USERNAME" ]
|
||||
then
|
||||
mkhomedir_helper $USERNAME
|
||||
fi
|
||||
groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 ||
|
||||
groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1
|
||||
useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 ||
|
||||
usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1
|
||||
mkhomedir_helper $USERNAME
|
||||
|
||||
# The rest...
|
||||
|
||||
@ -63,7 +38,8 @@ chown -R $USERNAME:$GROUPNAME /var/opt/mssql
|
||||
chown $USERNAME:$GROUPNAME /backup-db.sh
|
||||
chown $USERNAME:$GROUPNAME /backup-db.sql
|
||||
|
||||
env >> /etc/environment
|
||||
# Sounds like gosu keeps env when switching, but of course cron does not
|
||||
env > /etc/environment
|
||||
cron
|
||||
|
||||
gosu $USERNAME:$GROUPNAME /opt/mssql/bin/sqlservr
|
||||
exec gosu $USERNAME:$GROUPNAME /opt/mssql/bin/sqlservr
|
||||
|
@ -5,52 +5,27 @@
|
||||
GROUPNAME="bitwarden"
|
||||
USERNAME="bitwarden"
|
||||
|
||||
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
|
||||
LGID=${LOCAL_GID:-999}
|
||||
LUID=${LOCAL_UID:-0}
|
||||
LGID=${LOCAL_GID:-0}
|
||||
|
||||
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
|
||||
LUID=${LOCAL_UID:-999}
|
||||
# Step down from host root to well-known nobody/nogroup user
|
||||
|
||||
# Step down from host root
|
||||
|
||||
if [ $LGID == 0 ]
|
||||
if [ $LUID -eq 0 ]
|
||||
then
|
||||
LGID=999
|
||||
LUID=65534
|
||||
fi
|
||||
if [ $LGID -eq 0 ]
|
||||
then
|
||||
LGID=65534
|
||||
fi
|
||||
|
||||
if [ $LUID == 0 ]
|
||||
then
|
||||
LUID=999
|
||||
fi
|
||||
# Create user and group
|
||||
|
||||
# Create group
|
||||
|
||||
if [ $CURRENTGID ]
|
||||
then
|
||||
if [ "$CURRENTGID" != "$LGID" ]
|
||||
then
|
||||
groupmod -g $LGID $GROUPNAME
|
||||
fi
|
||||
else
|
||||
groupadd -g $LGID $GROUPNAME
|
||||
fi
|
||||
|
||||
# Create user and assign group
|
||||
|
||||
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ]
|
||||
then
|
||||
usermod -u $LUID $USERNAME
|
||||
elif [ $NOUSER == 1 ]
|
||||
then
|
||||
useradd -r -u $LUID -g $GROUPNAME $USERNAME
|
||||
fi
|
||||
|
||||
# Make home directory for user
|
||||
|
||||
if [ ! -d "/home/$USERNAME" ]
|
||||
then
|
||||
mkhomedir_helper $USERNAME
|
||||
fi
|
||||
groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 ||
|
||||
groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1
|
||||
useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 ||
|
||||
usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1
|
||||
mkhomedir_helper $USERNAME
|
||||
|
||||
# The rest...
|
||||
|
||||
@ -65,4 +40,4 @@ chown -R $USERNAME:$GROUPNAME /var/run/nginx.pid
|
||||
chown -R $USERNAME:$GROUPNAME /var/cache/nginx
|
||||
chown -R $USERNAME:$GROUPNAME /var/log/nginx
|
||||
|
||||
gosu $USERNAME:$GROUPNAME nginx -g 'daemon off;'
|
||||
exec gosu $USERNAME:$GROUPNAME nginx -g 'daemon off;'
|
||||
|
@ -172,7 +172,10 @@ SA_PASSWORD=SECRET
|
||||
Helpers.Exec("chmod 600 /bitwarden/env/mssql.override.env");
|
||||
|
||||
// Empty uid env file. Only used on Linux hosts.
|
||||
using(var sw = File.CreateText("/bitwarden/env/uid.env")) { }
|
||||
if(!File.Exists("/bitwarden/env/uid.env"))
|
||||
{
|
||||
using(var sw = File.CreateText("/bitwarden/env/uid.env")) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,52 +5,27 @@
|
||||
GROUPNAME="bitwarden"
|
||||
USERNAME="bitwarden"
|
||||
|
||||
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
|
||||
LGID=${LOCAL_GID:-999}
|
||||
LUID=${LOCAL_UID:-0}
|
||||
LGID=${LOCAL_GID:-0}
|
||||
|
||||
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
|
||||
LUID=${LOCAL_UID:-999}
|
||||
# Step down from host root to well-known nobody/nogroup user
|
||||
|
||||
# Step down from host root
|
||||
|
||||
if [ $LGID == 0 ]
|
||||
if [ $LUID -eq 0 ]
|
||||
then
|
||||
LGID=999
|
||||
LUID=65534
|
||||
fi
|
||||
if [ $LGID -eq 0 ]
|
||||
then
|
||||
LGID=65534
|
||||
fi
|
||||
|
||||
if [ $LUID == 0 ]
|
||||
then
|
||||
LUID=999
|
||||
fi
|
||||
# Create user and group
|
||||
|
||||
# Create group
|
||||
|
||||
if [ $CURRENTGID ]
|
||||
then
|
||||
if [ "$CURRENTGID" != "$LGID" ]
|
||||
then
|
||||
groupmod -g $LGID $GROUPNAME
|
||||
fi
|
||||
else
|
||||
groupadd -g $LGID $GROUPNAME
|
||||
fi
|
||||
|
||||
# Create user and assign group
|
||||
|
||||
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ]
|
||||
then
|
||||
usermod -u $LUID $USERNAME
|
||||
elif [ $NOUSER == 1 ]
|
||||
then
|
||||
useradd -r -u $LUID -g $GROUPNAME $USERNAME
|
||||
fi
|
||||
|
||||
# Make home directory for user
|
||||
|
||||
if [ ! -d "/home/$USERNAME" ]
|
||||
then
|
||||
mkhomedir_helper $USERNAME
|
||||
fi
|
||||
groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 ||
|
||||
groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1
|
||||
useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 ||
|
||||
usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1
|
||||
mkhomedir_helper $USERNAME
|
||||
|
||||
# The rest...
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user