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

Commit 08f65ec

Browse files
mvanbaakmichaelwittig
authored andcommitted
Deprecate SUDOERSGROUP in favor of SUDOERS_GROUPS (#64)
* Deprecate SUDOERSGROUP in favor of SUDOERS_GROUPS which can now hold a comma seperated list of IAM groups * fix typo in SUDOERS_GROUPS variable name * Use correct variable we set in for group now to fetch users in the SUDOERS_GROUPS
1 parent 6f5b1d7 commit 08f65ec

File tree

5 files changed

+33
-48
lines changed

5 files changed

+33
-48
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ one or more of the following lines:
9393
```
9494
ASSUMEROLE="IAM-role-arn" # IAM Role ARN for multi account. See below for more info
9595
IAM_AUTHORIZED_GROUPS="GROUPNAMES" # Comma seperated list of IAM groups to import
96-
SUDOERSGROUP="GROUPNAME" # IAM group that should have sudo access
96+
SUDOERS_GROUPS="GROUPNAMES" # Comma seperated list of IAM groups that should have sudo access
97+
SUDOERSGROUP="GROUPNAME" # Deprecated! IAM group that should have sudo access. Please use SUDOERS_GROUPS as this variable will be removed in future release.
9798
LOCAL_MARKER_GROUP="iam-synced-users" # Dedicated UNIX group to mark imported users. Used for deleting removed IAM users
9899
LOCAL_GROUPS="GROUPNAMES" # Comma seperated list of UNIX groups to add the users in
99100
USERADD_PROGRAM="/usr/sbin/useradd" # The useradd program to use. defaults to `/usr/sbin/useradd`

aws-ec2-ssh.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
IAM_AUTHORIZED_GROUPS=""
22
LOCAL_MARKER_GROUP="iam-synced-users"
33
LOCAL_GROUPS=""
4-
SUDOERSGROUP=""
4+
SUDOERS_GROUPS=""
55
ASSUMEROLE=""
66

77
# Remove or set to 0 if you are done with configuration

import_users.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ fi
2525
# Specify an IAM group for users who should be given sudo privileges, or leave
2626
# empty to not change sudo access, or give it the value '##ALL##' to have all
2727
# users be given sudo rights.
28+
# DEPRECATED! Use SUDOERS_GROUPS
2829
: ${SUDOERSGROUP:=""}
2930

31+
# Specify a comma seperated list of IAM groups for users who should be given sudo privileges.
32+
# Leave empty to not change sudo access, or give the value '##ALL## to have all users
33+
# be given sudo rights.
34+
: ${SUDOERS_GROUPS:="${SUDOERSGROUP}"}
35+
3036
# Assume a role before contacting AWS IAM to get users and keys.
3137
# This can be used if you define your users in one AWS account, while the EC2
3238
# instance you use this script runs in another.
@@ -92,13 +98,17 @@ function get_local_users() {
9298
| sed "s/,/ /g"
9399
}
94100

95-
# Get IAM users of the group marked with sudo access
101+
# Get IAM users of the groups marked with sudo access
96102
function get_sudoers_users() {
97-
[[ -z "${SUDOERSGROUP}" ]] || [[ "${SUDOERSGROUP}" == "##ALL##" ]] ||
98-
aws iam get-group \
99-
--group-name "${SUDOERSGROUP}" \
100-
--query "Users[].[UserName]" \
101-
--output text
103+
local group
104+
105+
[[ -z "${SUDOERS_GROUPS}" ]] || [[ "${SUDOERS_GROUPS}" == "##ALL##" ]] ||
106+
for group in $(echo "${SUDOERS_GROUPS}" | tr "," " "); do
107+
aws iam get-group \
108+
--group-name "${group}" \
109+
--query "Users[].[UserName]" \
110+
--output text
111+
done
102112
}
103113

104114
# Get the unix usernames of the IAM users within the sudo group
@@ -138,11 +148,11 @@ function create_or_update_local_user() {
138148
/usr/sbin/usermod -a -G "${localusergroups}" "${username}"
139149

140150
# Should we add this user to sudo ?
141-
if [[ ! -z "${SUDOERSGROUP}" ]]
151+
if [[ ! -z "${SUDOERS_GROUPS}" ]]
142152
then
143153
SaveUserFileName=$(echo "${username}" | tr "." " ")
144154
SaveUserSudoFilePath="/etc/sudoers.d/$SaveUserFileName"
145-
if [[ "${SUDOERSGROUP}" == "##ALL##" ]] || echo "${sudousers}" | grep "^${username}\$" > /dev/null
155+
if [[ "${SUDOERS_GROUPS}" == "##ALL##" ]] || echo "${sudousers}" | grep "^${username}\$" > /dev/null
146156
then
147157
echo "${username} ALL=(ALL) NOPASSWD:ALL" > "${SaveUserSudoFilePath}"
148158
else

install.sh

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ Install import_users.sh and authorized_key_commands.
1515
Comma seperated list of IAM groups. Leave empty for all available IAM users
1616
-l group,group Give the users these local UNIX groups
1717
Comma seperated list
18-
-s group Specify an IAM group for users who should be given sudo privileges, or leave
18+
-s group,group Specify IAM group(s) for users who should be given sudo privileges, or leave
1919
empty to not change sudo access, or give it the value '##ALL##' to have all
2020
users be given sudo rights.
21+
Comma seperated list
2122
-p program Specify your useradd program to use.
2223
Defaults to '/usr/sbin/useradd'
2324
-u "useradd args" Specify arguments to use with useradd.
@@ -28,7 +29,7 @@ EOF
2829
}
2930

3031
IAM_GROUPS=""
31-
SUDO_GROUP=""
32+
SUDO_GROUPS=""
3233
LOCAL_GROUPS=""
3334
ASSUME_ROLE=""
3435
USERADD_PROGRAM=""
@@ -45,7 +46,7 @@ do
4546
IAM_GROUPS="$OPTARG"
4647
;;
4748
s)
48-
SUDO_GROUP="$OPTARG"
49+
SUDO_GROUPS="$OPTARG"
4950
;;
5051
l)
5152
LOCAL_GROUPS="$OPTARG"
@@ -85,35 +86,21 @@ cd "$tmpdir/aws-ec2-ssh"
8586
cp authorized_keys_command.sh /opt/authorized_keys_command.sh
8687
cp import_users.sh /opt/import_users.sh
8788

88-
# To control which users are imported/synced, uncomment the line below
89-
# changing GROUPNAMES to a comma seperated list of IAM groups you want to sync.
90-
# You can specify 1 or more groups, comma seperated, without spaces.
91-
# If you leave it blank, all IAM users will be synced.
9289
if [ "${IAM_GROUPS}" != "" ]
9390
then
9491
echo "IAM_AUTHORIZED_GROUPS=\"${IAM_GROUPS}\"" >> /etc/aws-ec2-ssh.conf
9592
fi
9693

97-
# To control which users are given sudo privileges, uncomment the line below
98-
# changing GROUPNAME to either the name of the IAM group for sudo users, or
99-
# to ##ALL## to give all users sudo access. If you leave it blank, no users will
100-
# be given sudo access.
101-
if [ "${SUDO_GROUP}" != "" ]
94+
if [ "${SUDO_GROUPS}" != "" ]
10295
then
103-
echo "SUDOERSGROUP=\"${SUDO_GROUP}\"" >> /etc/aws-ec2-ssh.conf
96+
echo "SUDOERS_GROUPS=\"${SUDO_GROUPS}\"" >> /etc/aws-ec2-ssh.conf
10497
fi
10598

106-
# To control which local groups a user will get, uncomment the line belong
107-
# changing GROUPNAMES to a comma seperated list of local UNIX groups.
108-
# If you live it blank, this setting will be ignored
10999
if [ "${LOCAL_GROUPS}" != "" ]
110100
then
111101
echo "LOCAL_GROUPS=\"${LOCAL_GROUPS}\"" >> /etc/aws-ec2-ssh.conf
112102
fi
113103

114-
# If your IAM users are in another AWS account, put the AssumeRole ARN here.
115-
# replace the word ASSUMEROLEARN with the full arn. eg 'arn:aws:iam::$accountid:role/$role'
116-
# See docs/multiawsaccount.md on how to make this work
117104
if [ "${ASSUME_ROLE}" != "" ]
118105
then
119106
echo "ASSUMEROLE=\"${ASSUME_ROLE}\"" >> /etc/aws-ec2-ssh.conf

showcase.yaml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,17 @@ Resources:
138138
Comma seperated list of IAM groups. Leave empty for all available IAM users
139139
-l group,group Give the users these local UNIX groups
140140
Comma seperated list
141-
-s group Specify an IAM group for users who should be given sudo privileges, or leave
141+
-s group,group Specify IAM group(s) for users who should be given sudo privileges, or leave
142142
empty to not change sudo access, or give it the value '##ALL##' to have all
143143
users be given sudo rights.
144+
Comma seperated list
144145
145146
146147
EOF
147148
}
148149
149150
IAM_GROUPS=""
150-
SUDO_GROUP=""
151+
SUDO_GROUPS=""
151152
LOCAL_GROUPS=""
152153
ASSUME_ROLE=""
153154
@@ -162,7 +163,7 @@ Resources:
162163
IAM_GROUPS="$OPTARG"
163164
;;
164165
s)
165-
SUDO_GROUP="$OPTARG"
166+
SUDO_GROUPS="$OPTARG"
166167
;;
167168
l)
168169
LOCAL_GROUPS="$OPTARG"
@@ -196,35 +197,21 @@ Resources:
196197
cp authorized_keys_command.sh /opt/authorized_keys_command.sh
197198
cp import_users.sh /opt/import_users.sh
198199
199-
# To control which users are imported/synced, uncomment the line below
200-
# changing GROUPNAMES to a comma seperated list of IAM groups you want to sync.
201-
# You can specify 1 or more groups, comma seperated, without spaces.
202-
# If you leave it blank, all IAM users will be synced.
203200
if [ "${IAM_GROUPS}" != "" ]
204201
then
205202
echo "IAM_AUTHORIZED_GROUPS=\"${IAM_GROUPS}\"" >> /etc/aws-ec2-ssh.conf
206203
fi
207204
208-
# To control which users are given sudo privileges, uncomment the line below
209-
# changing GROUPNAME to either the name of the IAM group for sudo users, or
210-
# to ##ALL## to give all users sudo access. If you leave it blank, no users will
211-
# be given sudo access.
212-
if [ "${SUDO_GROUP}" != "" ]
205+
if [ "${SUDO_GROUPS}" != "" ]
213206
then
214-
echo "SUDOERSGROUP=\"${SUDO_GROUP}\"" >> /etc/aws-ec2-ssh.conf
207+
echo "SUDOERS_GROUPS=\"${SUDO_GROUPS}\"" >> /etc/aws-ec2-ssh.conf
215208
fi
216209
217-
# To control which local groups a user will get, uncomment the line belong
218-
# changing GROUPNAMES to a comma seperated list of local UNIX groups.
219-
# If you live it blank, this setting will be ignored
220210
if [ "${LOCAL_GROUPS}" != "" ]
221211
then
222212
echo "LOCAL_GROUPS=\"${LOCAL_GROUPS}\"" >> /etc/aws-ec2-ssh.conf
223213
fi
224214
225-
# If your IAM users are in another AWS account, put the AssumeRole ARN here.
226-
# replace the word ASSUMEROLEARN with the full arn. eg 'arn:aws:iam::$accountid:role/$role'
227-
# See docs/multiawsaccount.md on how to make this work
228215
if [ "${ASSUME_ROLE}" != "" ]
229216
then
230217
echo "ASSUMEROLE=\"${ASSUME_ROLE}\"" >> /etc/aws-ec2-ssh.conf

0 commit comments

Comments
 (0)