@@ -36,6 +36,8 @@ def initialize(info = {})
36
36
register_options (
37
37
[
38
38
OptString . new ( 'IAM_USERNAME' , [ false , 'Name of the user to be created (leave empty or unset to use a random name)' , '' ] ) ,
39
+ OptString . new ( 'IAM_PASSWORD' , [ false , 'Password to set for the user to be created (leave empty or unset to use a random name)' , '' ] ) ,
40
+ OptString . new ( 'IAM_GROUPNAME' , [ false , 'Name of the group to be created (leave empty or unset to use a random name)' , '' ] ) ,
39
41
OptBool . new ( 'CREATE_API' , [ true , 'Add access key ID and secret access key to account (API, CLI, and SDK access)' , true ] ) ,
40
42
OptBool . new ( 'CREATE_CONSOLE' , [ true , 'Create an account with a password for accessing the AWS management console' , true ] ) ,
41
43
OptString . new ( 'AccessKeyId' , [ false , 'AWS access key' , '' ] ) ,
@@ -89,19 +91,18 @@ def run
89
91
results [ 'UserName' ] = username
90
92
91
93
# create group
92
- groupname = username
94
+ groupname = datastore [ 'IAM_GROUPNAME' ] . blank? ? username : datastore [ 'IAM_GROUPNAME' ]
93
95
print_status ( "Creating group: #{ groupname } " )
94
96
action = 'CreateGroup'
95
97
doc = call_iam ( creds , 'Action' => action , 'GroupName' => groupname )
96
98
print_results ( doc , action )
97
99
results [ 'GroupName' ] = groupname
98
100
99
101
# create group policy
100
- policyname = username
101
- print_status ( "Creating group policy: #{ policyname } " )
102
+ print_status ( "Creating group policy" )
102
103
pol_doc = datastore [ 'IAM_GROUP_POL' ]
103
104
action = 'PutGroupPolicy'
104
- doc = call_iam ( creds , 'Action' => action , 'GroupName' => groupname , 'PolicyName' => policyname , 'PolicyDocument' => URI . encode ( pol_doc ) )
105
+ doc = call_iam ( creds , 'Action' => action , 'GroupName' => groupname , 'PolicyName' => 'Policy' , 'PolicyDocument' => URI . encode ( pol_doc ) )
105
106
print_results ( doc , action )
106
107
107
108
# add user to group
@@ -123,7 +124,7 @@ def run
123
124
124
125
if datastore [ 'CREATE_CONSOLE' ]
125
126
print_status ( "Creating password for #{ username } " )
126
- password = username
127
+ password = datastore [ 'IAM_PASSWORD' ] . blank? ? Rex :: Text . rand_text_alphanumeric ( 16 ) : datastore [ 'IAM_PASSWORD' ]
127
128
action = 'CreateLoginProfile'
128
129
response = call_iam ( creds , 'Action' => action , 'UserName' => username , 'Password' => password )
129
130
doc = print_results ( response , action )
0 commit comments