Skip to content

Commit

Permalink
Add google authenticator and select root, and can change default user…
Browse files Browse the repository at this point in the history
…name
ChangwooLim committed Sep 1, 2024
1 parent 093f442 commit ee9a296
Showing 3 changed files with 80 additions and 6 deletions.
13 changes: 9 additions & 4 deletions create_user.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#!/bin/bash

if [ $# -ne 2 ]; then
echo "Usage: $0 <username> <password>"
if [ $# -ne 3 ]; then
echo "Usage: $0 <username> <password> <root>"
echo "<root> should be 'yes' to add the user to the sudoers group, or 'no' to skip."
exit 1
fi

USERNAME=$1
PASSWORD=$2
IS_ROOT=$3

# Add the user and set the password
useradd -m -s /bin/bash $USERNAME
echo "$USERNAME:$PASSWORD" | chpasswd

# Add the user to sudoers
usermod -aG sudo $USERNAME
# Optionally add the user to sudoers
if [ "$IS_ROOT" == "yes" ]; then
usermod -aG sudo $USERNAME
echo "User $USERNAME added to the sudoers group."
fi

# Create shiny directory for the user
mkdir -p /home/$USERNAME/ShinyApps
21 changes: 19 additions & 2 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ RUN apt-get update && apt-get install -y \
curl \
git \
build-essential \
locales
locales \
vim

# Install supervisord
RUN apt-get install -y supervisor
@@ -48,7 +49,23 @@ COPY create_user.sh /usr/local/bin/create_user.sh
COPY shiny-server.conf /etc/shiny-server/shiny-server.conf

RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/create_user.sh
RUN /usr/local/bin/create_user.sh limcw limcw

# Define argument for username and password with default values
ARG USERNAME=limcw
ARG PASSWORD=limcw

# Create the user with specified username and password
RUN /usr/local/bin/create_user.sh ${USERNAME} ${PASSWORD} yes

# Define an argument for using Google Authenticator
ARG USE_GOOGLE_AUTHENTICATOR=false

# If USE_GOOGLE_AUTHENTICATOR is true, copy and run the google-authenticator script
RUN if [ "$USE_GOOGLE_AUTHENTICATOR" = "true" ]; then \
cp /path/to/google-authenticator.sh /usr/local/bin/google-authenticator.sh && \
chmod +x /usr/local/bin/google-authenticator.sh && \
/usr/local/bin/google-authenticator.sh; \
fi

# Copy supervisord configuration
COPY supervisord.conf /etc/supervisord.conf
52 changes: 52 additions & 0 deletions google-authenticator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

apt-get update
apt-get install -y libpam-google-authenticator

# Define the paths for the files to be modified or created
PAM_FILE="/etc/pam.d/rstudio"
RSTUDIO_CONF="/etc/rstudio/rserver.conf"

# Create the /etc/pam.d/rstudio file if it does not exist and add the necessary lines
if [ ! -f "$PAM_FILE" ]; then
echo "Creating $PAM_FILE"
{
echo "auth required pam_google_authenticator.so"
echo "@include common-account"
echo "@include common-session"
} > "$PAM_FILE"
else
echo "Modifying $PAM_FILE"
if ! grep -q "auth required pam_google_authenticator.so" "$PAM_FILE"; then
echo "Adding auth required pam_google_authenticator.so to $PAM_FILE"
echo "auth required pam_google_authenticator.so" >> "$PAM_FILE"
fi
if ! grep -q "@include common-account" "$PAM_FILE"; then
echo "Adding @include common-account to $PAM_FILE"
echo "@include common-account" >> "$PAM_FILE"
fi
if ! grep -q "@include common-session" "$PAM_FILE"; then
echo "Adding @include common-session to $PAM_FILE"
echo "@include common-session" >> "$PAM_FILE"
fi
fi

# Create the /etc/rstudio/rserver.conf file if it does not exist and add the necessary lines
if [ ! -f "$RSTUDIO_CONF" ]; then
echo "Creating $RSTUDIO_CONF"
{
echo "# Server Configuration File"
echo "auth-pam-require-password-prompt=0"
} > "$RSTUDIO_CONF"
else
echo "Modifying $RSTUDIO_CONF"
if ! grep -q "# Server Configuration File" "$RSTUDIO_CONF"; then
echo "# Server Configuration File" >> "$RSTUDIO_CONF"
fi
if ! grep -q "auth-pam-require-password-prompt=0" "$RSTUDIO_CONF"; then
echo "Adding auth-pam-require-password-prompt=0 to $RSTUDIO_CONF"
echo "auth-pam-require-password-prompt=0" >> "$RSTUDIO_CONF"
fi
fi

echo "Configuration completed successfully."

0 comments on commit ee9a296

Please sign in to comment.