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

Commit 4c111c3

Browse files
mvanbaakmichaelwittig
authored andcommitted
Add logging of adding/deleting users. (#65)
We now log to syslog (auth.info) whenever we add or delete a user. This fixes #62
1 parent 08f65ec commit 4c111c3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

import_users.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ fi
4444
# Possibility to provide custom useradd arguments
4545
: ${USERADD_ARGS:="--create-home --shell /bin/bash"}
4646

47+
function log() {
48+
/usr/bin/logger -i -p auth.info -t aws-ec2-ssh "$@"
49+
}
50+
4751
function setup_aws_credentials() {
4852
local stscredentials
4953
if [[ ! -z "${ASSUMEROLE}" ]]
@@ -142,9 +146,11 @@ function create_or_update_local_user() {
142146
localusergroups="${LOCAL_GROUPS},${LOCAL_MARKER_GROUP}"
143147
fi
144148

145-
id "${username}" >/dev/null 2>&1 \
146-
|| ${USERADD_PROGRAM} ${USERADD_ARGS} "${username}" \
147-
&& /bin/chown -R "${username}:${username}" "$(eval echo ~$username)"
149+
if ! id "${username}" >/dev/null 2>&1; then
150+
${USERADD_PROGRAM} ${USERADD_ARGS} "${username}"
151+
/bin/chown -R "${username}:${username}" "$(eval echo ~$username)"
152+
log "Created new user ${username}"
153+
fi
148154
/usr/sbin/usermod -a -G "${localusergroups}" "${username}"
149155

150156
# Should we add this user to sudo ?
@@ -172,6 +178,7 @@ function delete_local_user() {
172178
sleep 1
173179
# Remove account now that all processes for the user are gone
174180
/usr/sbin/userdel -f -r "${1}"
181+
log "Deleted user ${1}"
175182
}
176183

177184
function clean_iam_username() {

0 commit comments

Comments
 (0)