Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Add ability to config user deletion program and arguments #156

Merged
merged 1 commit into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ LOCAL_MARKER_GROUP="iam-synced-users" # Dedicated UNIX group to mark im
LOCAL_GROUPS="GROUPNAMES" # Comma seperated list of UNIX groups to add the users in
USERADD_PROGRAM="/usr/sbin/useradd" # The useradd program to use. defaults to `/usr/sbin/useradd`
USERADD_ARGS="--create-home --shell /bin/bash" # Arguments for the useradd program. defaults to `--create-home --shell /bin/bash`
USERDEL_PROGRAM="/usr/sbin/userdel" # The userdel program to use. defaults to `/usr/sbin/userdel`
USERDEL_ARGS="--force --remove" # Arguments for the userdel program. defaults to `--force --remove`
```

The LOCAL_MARKER_GROUP will be created if it does not exist. BEWARE: DO NOT add any manually created users
Expand Down
9 changes: 8 additions & 1 deletion import_users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ fi
# Possibility to provide custom useradd arguments
: ${USERADD_ARGS:="--user-group --create-home --shell /bin/bash"}

# Possibility to provide a custom userdel program
: ${USERDEL_PROGRAM:="/usr/sbin/userdel"}

# Possibility to provide custom userdel arguments
: ${USERDEL_ARGS:="--force --remove"}

# Initizalize INSTANCE variable
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
Expand Down Expand Up @@ -211,7 +217,8 @@ function delete_local_user() {
/usr/bin/pkill -9 -u "${1}" || true
sleep 1
# Remove account now that all processes for the user are gone
/usr/sbin/userdel -f -r "${1}"
${USERDEL_PROGRAM} ${USERDEL_ARGS} "${1}"

log "Deleted user ${1}"
}

Expand Down
22 changes: 21 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ LOCAL_GROUPS=""
ASSUME_ROLE=""
USERADD_PROGRAM=""
USERADD_ARGS=""
USERDEL_PROGRAM=""
USERDEL_ARGS=""
RELEASE="master"

while getopts :hva:i:l:s:p:u:r: opt
while getopts :hva:i:l:s:p:u:d:f:r: opt
do
case $opt in
h)
Expand Down Expand Up @@ -72,6 +74,12 @@ do
u)
USERADD_ARGS="$OPTARG"
;;
d)
USERDEL_PROGRAM="$OPTARG"
;;
f)
USERDEL_ARGS="$OPTARG"
;;
r)
RELEASE="$OPTARG"
;;
Expand All @@ -93,6 +101,8 @@ export LOCAL_GROUPS
export ASSUME_ROLE
export USERADD_PROGRAM
export USERADD_ARGS
export USERDEL_PROGRAM
export USERDEL_ARGS

# check if AWS CLI exists
if ! [ -x "$(which aws)" ]; then
Expand Down Expand Up @@ -147,6 +157,16 @@ then
echo "USERADD_ARGS=\"${USERADD_ARGS}\"" >> $MAIN_CONFIG_FILE
fi

if [ "${USERDEL_PROGRAM}" != "" ]
then
echo "USERDEL_PROGRAM=\"${USERDEL_PROGRAM}\"" >> $MAIN_CONFIG_FILE
fi

if [ "${USERDEL_ARGS}" != "" ]
then
echo "USERDEL_ARGS=\"${USERDEL_ARGS}\"" >> $MAIN_CONFIG_FILE
fi

./install_configure_selinux.sh

./install_configure_sshd.sh
Expand Down