miam 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rspec +2 -1
- data/.travis.yml +6 -4
- data/README.md +8 -1
- data/bin/miam +3 -1
- data/lib/miam/client.rb +54 -13
- data/lib/miam/driver.rb +44 -14
- data/lib/miam/dsl/context/role.rb +5 -1
- data/lib/miam/dsl/context.rb +5 -1
- data/lib/miam/dsl/converter.rb +17 -3
- data/lib/miam/exporter.rb +8 -4
- data/lib/miam/password_manager.rb +23 -4
- data/lib/miam/version.rb +1 -1
- data/lib/miam.rb +1 -1
- data/miam.gemspec +3 -4
- data/spec/miam/attach_detach_policy_spec.rb +4 -4
- data/spec/miam/create_spec.rb +3 -3
- data/spec/miam/delete_spec.rb +6 -6
- data/spec/miam/exclude_spec.rb +252 -0
- data/spec/miam/hash_ext_spec.rb +2 -2
- data/spec/miam/ignore_login_profile_spec.rb +3 -3
- data/spec/miam/rename_spec.rb +6 -6
- data/spec/miam/target_spec.rb +185 -0
- data/spec/miam/update_spec.rb +97 -11
- data/spec/spec_helper.rb +5 -2
- metadata +27 -9
data/spec/miam/create_spec.rb
CHANGED
|
@@ -12,7 +12,7 @@ describe 'create' do
|
|
|
12
12
|
context 'when create user and group' do
|
|
13
13
|
let(:dsl) do
|
|
14
14
|
<<-RUBY
|
|
15
|
-
user "bob", :path=>"/
|
|
15
|
+
user "bob", :path=>"/developer/" do
|
|
16
16
|
login_profile :password_reset_required=>true
|
|
17
17
|
|
|
18
18
|
groups(
|
|
@@ -88,7 +88,7 @@ describe 'create' do
|
|
|
88
88
|
let(:expected) do
|
|
89
89
|
{:users=>
|
|
90
90
|
{"bob"=>
|
|
91
|
-
{:path=>"/
|
|
91
|
+
{:path=>"/developer/",
|
|
92
92
|
:groups=>["Admin", "SES"],
|
|
93
93
|
:attached_managed_policies=>[],
|
|
94
94
|
:policies=>
|
|
@@ -184,7 +184,7 @@ describe 'create' do
|
|
|
184
184
|
end
|
|
185
185
|
end
|
|
186
186
|
|
|
187
|
-
user "bob", :path=>"/
|
|
187
|
+
user "bob", :path=>"/developer/" do
|
|
188
188
|
include_template context.user_name
|
|
189
189
|
end
|
|
190
190
|
|
data/spec/miam/delete_spec.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
describe 'delete' do
|
|
2
2
|
let(:dsl) do
|
|
3
3
|
<<-RUBY
|
|
4
|
-
user "bob", :path=>"/
|
|
4
|
+
user "bob", :path=>"/developer/" do
|
|
5
5
|
login_profile :password_reset_required=>true
|
|
6
6
|
|
|
7
7
|
groups(
|
|
@@ -74,7 +74,7 @@ describe 'delete' do
|
|
|
74
74
|
let(:expected) do
|
|
75
75
|
{:users=>
|
|
76
76
|
{"bob"=>
|
|
77
|
-
{:path=>"/
|
|
77
|
+
{:path=>"/developer/",
|
|
78
78
|
:groups=>["Admin", "SES"],
|
|
79
79
|
:attached_managed_policies=>[],
|
|
80
80
|
:policies=>
|
|
@@ -139,7 +139,7 @@ describe 'delete' do
|
|
|
139
139
|
context 'when delete group' do
|
|
140
140
|
let(:delete_group_dsl) do
|
|
141
141
|
<<-RUBY
|
|
142
|
-
user "bob", :path=>"/
|
|
142
|
+
user "bob", :path=>"/developer/" do
|
|
143
143
|
login_profile :password_reset_required=>true
|
|
144
144
|
|
|
145
145
|
groups(
|
|
@@ -351,7 +351,7 @@ describe 'delete' do
|
|
|
351
351
|
context 'when delete instance_profile' do
|
|
352
352
|
let(:delete_instance_profiles_dsl) do
|
|
353
353
|
<<-RUBY
|
|
354
|
-
user "bob", :path=>"/
|
|
354
|
+
user "bob", :path=>"/developer/" do
|
|
355
355
|
login_profile :password_reset_required=>true
|
|
356
356
|
|
|
357
357
|
groups(
|
|
@@ -432,7 +432,7 @@ describe 'delete' do
|
|
|
432
432
|
context 'when delete role' do
|
|
433
433
|
let(:delete_role_dsl) do
|
|
434
434
|
<<-RUBY
|
|
435
|
-
user "bob", :path=>"/
|
|
435
|
+
user "bob", :path=>"/developer/" do
|
|
436
436
|
login_profile :password_reset_required=>true
|
|
437
437
|
|
|
438
438
|
groups(
|
|
@@ -491,7 +491,7 @@ describe 'delete' do
|
|
|
491
491
|
context 'when delete role and instance_profile' do
|
|
492
492
|
let(:delete_role_and_instance_profile_dsl) do
|
|
493
493
|
<<-RUBY
|
|
494
|
-
user "bob", :path=>"/
|
|
494
|
+
user "bob", :path=>"/developer/" do
|
|
495
495
|
login_profile :password_reset_required=>true
|
|
496
496
|
|
|
497
497
|
groups(
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
describe 'exclude option' do
|
|
2
|
+
let(:dsl) do
|
|
3
|
+
<<-RUBY
|
|
4
|
+
user "bob", :path=>"/developer/" do
|
|
5
|
+
login_profile :password_reset_required=>true
|
|
6
|
+
|
|
7
|
+
groups(
|
|
8
|
+
"Admin",
|
|
9
|
+
"SES"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
policy "S3" do
|
|
13
|
+
{"Statement"=>
|
|
14
|
+
[{"Action"=>
|
|
15
|
+
["s3:Get*",
|
|
16
|
+
"s3:List*"],
|
|
17
|
+
"Effect"=>"Allow",
|
|
18
|
+
"Resource"=>"*"}]}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
attached_managed_policies(
|
|
22
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
user "mary", :path=>"/staff/" do
|
|
27
|
+
policy "S3" do
|
|
28
|
+
{"Statement"=>
|
|
29
|
+
[{"Action"=>
|
|
30
|
+
["s3:Get*",
|
|
31
|
+
"s3:List*"],
|
|
32
|
+
"Effect"=>"Allow",
|
|
33
|
+
"Resource"=>"*"}]}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
attached_managed_policies(
|
|
37
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
group "Admin", :path=>"/admin/" do
|
|
42
|
+
policy "Admin" do
|
|
43
|
+
{"Statement"=>[{"Effect"=>"Allow", "Action"=>"*", "Resource"=>"*"}]}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
attached_managed_policies(
|
|
47
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
group "SES", :path=>"/ses/" do
|
|
52
|
+
policy "ses-policy" do
|
|
53
|
+
{"Statement"=>
|
|
54
|
+
[{"Effect"=>"Allow", "Action"=>"ses:SendRawEmail", "Resource"=>"*"}]}
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
attached_managed_policies(
|
|
58
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
role "my-role", :path=>"/any/" do
|
|
63
|
+
instance_profiles(
|
|
64
|
+
"my-instance-profile"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
assume_role_policy_document do
|
|
68
|
+
{"Version"=>"2012-10-17",
|
|
69
|
+
"Statement"=>
|
|
70
|
+
[{"Sid"=>"",
|
|
71
|
+
"Effect"=>"Allow",
|
|
72
|
+
"Principal"=>{"Service"=>"ec2.amazonaws.com"},
|
|
73
|
+
"Action"=>"sts:AssumeRole"}]}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
policy "role-policy" do
|
|
77
|
+
{"Statement"=>
|
|
78
|
+
[{"Action"=>
|
|
79
|
+
["s3:Get*",
|
|
80
|
+
"s3:List*"],
|
|
81
|
+
"Effect"=>"Allow",
|
|
82
|
+
"Resource"=>"*"}]}
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
attached_managed_policies(
|
|
86
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
87
|
+
)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
instance_profile "my-instance-profile", :path=>"/profile/"
|
|
91
|
+
RUBY
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
before(:each) do
|
|
95
|
+
apply { dsl }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context 'when exclude a user' do
|
|
99
|
+
let(:exclude_bob) do
|
|
100
|
+
<<-RUBY
|
|
101
|
+
user "mary", :path=>"/staff/" do
|
|
102
|
+
policy "S3" do
|
|
103
|
+
{"Statement"=>
|
|
104
|
+
[{"Action"=>
|
|
105
|
+
["s3:Get*",
|
|
106
|
+
"s3:List*"],
|
|
107
|
+
"Effect"=>"Allow",
|
|
108
|
+
"Resource"=>"*"}]}
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
attached_managed_policies(
|
|
112
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
group "Admin", :path=>"/admin/" do
|
|
117
|
+
policy "Admin" do
|
|
118
|
+
{"Statement"=>[{"Effect"=>"Allow", "Action"=>"*", "Resource"=>"*"}]}
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
attached_managed_policies(
|
|
122
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
123
|
+
)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
group "SES", :path=>"/ses/" do
|
|
127
|
+
policy "ses-policy" do
|
|
128
|
+
{"Statement"=>
|
|
129
|
+
[{"Effect"=>"Allow", "Action"=>"ses:SendRawEmail", "Resource"=>"*"}]}
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
attached_managed_policies(
|
|
133
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
134
|
+
)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
role "my-role", :path=>"/any/" do
|
|
138
|
+
instance_profiles(
|
|
139
|
+
"my-instance-profile"
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
assume_role_policy_document do
|
|
143
|
+
{"Version"=>"2012-10-17",
|
|
144
|
+
"Statement"=>
|
|
145
|
+
[{"Sid"=>"",
|
|
146
|
+
"Effect"=>"Allow",
|
|
147
|
+
"Principal"=>{"Service"=>"ec2.amazonaws.com"},
|
|
148
|
+
"Action"=>"sts:AssumeRole"}]}
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
policy "role-policy" do
|
|
152
|
+
{"Statement"=>
|
|
153
|
+
[{"Action"=>
|
|
154
|
+
["s3:Get*",
|
|
155
|
+
"s3:List*"],
|
|
156
|
+
"Effect"=>"Allow",
|
|
157
|
+
"Resource"=>"*"}]}
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
attached_managed_policies(
|
|
161
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
162
|
+
)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
instance_profile "my-instance-profile", :path=>"/profile/"
|
|
166
|
+
RUBY
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
subject { client(exclude: [/bob/]) }
|
|
170
|
+
|
|
171
|
+
it do
|
|
172
|
+
updated = apply(subject) { exclude_bob }
|
|
173
|
+
expect(updated).to be_falsey
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
context 'when exclude a group, a role and an instance profile' do
|
|
178
|
+
let(:exclude_admin_and_my) do
|
|
179
|
+
<<-RUBY
|
|
180
|
+
user "bob", :path=>"/developer/" do
|
|
181
|
+
login_profile :password_reset_required=>true
|
|
182
|
+
|
|
183
|
+
groups(
|
|
184
|
+
"Admin",
|
|
185
|
+
"SES"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
policy "S3" do
|
|
189
|
+
{"Statement"=>
|
|
190
|
+
[{"Action"=>
|
|
191
|
+
["s3:Get*",
|
|
192
|
+
"s3:List*"],
|
|
193
|
+
"Effect"=>"Allow",
|
|
194
|
+
"Resource"=>"*"}]}
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
attached_managed_policies(
|
|
198
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
199
|
+
)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
user "mary", :path=>"/staff/" do
|
|
203
|
+
policy "S3" do
|
|
204
|
+
{"Statement"=>
|
|
205
|
+
[{"Action"=>
|
|
206
|
+
["s3:Get*",
|
|
207
|
+
"s3:List*"],
|
|
208
|
+
"Effect"=>"Allow",
|
|
209
|
+
"Resource"=>"*"}]}
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
attached_managed_policies(
|
|
213
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
214
|
+
)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
group "SES", :path=>"/ses/" do
|
|
218
|
+
policy "ses-policy" do
|
|
219
|
+
{"Statement"=>
|
|
220
|
+
[{"Effect"=>"Allow", "Action"=>"ses:SendRawEmail", "Resource"=>"*"}]}
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
attached_managed_policies(
|
|
224
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
225
|
+
)
|
|
226
|
+
end
|
|
227
|
+
RUBY
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
subject { client(exclude: [/Admin/, /^my-/]) }
|
|
231
|
+
|
|
232
|
+
it do
|
|
233
|
+
updated = apply(subject) { exclude_admin_and_my }
|
|
234
|
+
expect(updated).to be_falsey
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
context 'when specifying exclude option in a DSL' do
|
|
239
|
+
let(:exclude_everything) do
|
|
240
|
+
<<-RUBY
|
|
241
|
+
exclude /.*/
|
|
242
|
+
RUBY
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
subject { client(exclude: []) }
|
|
246
|
+
|
|
247
|
+
it do
|
|
248
|
+
updated = apply(subject) { exclude_everything }
|
|
249
|
+
expect(updated).to be_falsey
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
data/spec/miam/hash_ext_spec.rb
CHANGED
|
@@ -2,7 +2,7 @@ describe 'Hash#sort_array!' do
|
|
|
2
2
|
let(:hash) do
|
|
3
3
|
{:users=>
|
|
4
4
|
{"bob"=>
|
|
5
|
-
{:path=>"/
|
|
5
|
+
{:path=>"/developer/",
|
|
6
6
|
:groups=>[],
|
|
7
7
|
:policies=>
|
|
8
8
|
{"S3"=>
|
|
@@ -19,7 +19,7 @@ describe 'Hash#sort_array!' do
|
|
|
19
19
|
let(:expected_hash) do
|
|
20
20
|
{:users=>
|
|
21
21
|
{"bob"=>
|
|
22
|
-
{:path=>"/
|
|
22
|
+
{:path=>"/developer/",
|
|
23
23
|
:groups=>[],
|
|
24
24
|
:policies=>
|
|
25
25
|
{"S3"=>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
describe 'ignore login profile' do
|
|
2
2
|
let(:dsl) do
|
|
3
3
|
<<-RUBY
|
|
4
|
-
user "bob", :path=>"/
|
|
4
|
+
user "bob", :path=>"/developer/" do
|
|
5
5
|
login_profile :password_reset_required=>true
|
|
6
6
|
|
|
7
7
|
policy "S3" do
|
|
@@ -18,7 +18,7 @@ describe 'ignore login profile' do
|
|
|
18
18
|
|
|
19
19
|
let(:update_dsl) do
|
|
20
20
|
<<-RUBY
|
|
21
|
-
user "bob", :path=>"/
|
|
21
|
+
user "bob", :path=>"/developer/" do
|
|
22
22
|
login_profile :password_reset_required=>false
|
|
23
23
|
|
|
24
24
|
policy "S3" do
|
|
@@ -37,7 +37,7 @@ describe 'ignore login profile' do
|
|
|
37
37
|
let(:expected) do
|
|
38
38
|
{:users=>
|
|
39
39
|
{"bob"=>
|
|
40
|
-
{:path=>"/
|
|
40
|
+
{:path=>"/developer/",
|
|
41
41
|
:groups=>[],
|
|
42
42
|
:policies=>
|
|
43
43
|
{"S3"=>
|
data/spec/miam/rename_spec.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
describe 'update' do
|
|
2
2
|
let(:dsl) do
|
|
3
3
|
<<-RUBY
|
|
4
|
-
user "bob", :path=>"/
|
|
4
|
+
user "bob", :path=>"/developer/" do
|
|
5
5
|
login_profile :password_reset_required=>true
|
|
6
6
|
|
|
7
7
|
groups(
|
|
@@ -74,7 +74,7 @@ describe 'update' do
|
|
|
74
74
|
let(:expected) do
|
|
75
75
|
{:users=>
|
|
76
76
|
{"bob"=>
|
|
77
|
-
{:path=>"/
|
|
77
|
+
{:path=>"/developer/",
|
|
78
78
|
:groups=>["Admin", "SES"],
|
|
79
79
|
:attached_managed_policies=>[],
|
|
80
80
|
:policies=>
|
|
@@ -139,7 +139,7 @@ describe 'update' do
|
|
|
139
139
|
context 'when rename user' do
|
|
140
140
|
let(:rename_user_dsl) do
|
|
141
141
|
<<-RUBY
|
|
142
|
-
user "bob2", :path=>"/
|
|
142
|
+
user "bob2", :path=>"/developer/", :renamed_from=>"bob" do
|
|
143
143
|
login_profile :password_reset_required=>true
|
|
144
144
|
|
|
145
145
|
groups(
|
|
@@ -222,7 +222,7 @@ describe 'update' do
|
|
|
222
222
|
context 'when rename group' do
|
|
223
223
|
let(:rename_group_dsl) do
|
|
224
224
|
<<-RUBY
|
|
225
|
-
user "bob", :path=>"/
|
|
225
|
+
user "bob", :path=>"/developer/" do
|
|
226
226
|
login_profile :password_reset_required=>true
|
|
227
227
|
|
|
228
228
|
groups(
|
|
@@ -306,7 +306,7 @@ describe 'update' do
|
|
|
306
306
|
context 'when rename without renamed_from' do
|
|
307
307
|
let(:rename_without_renamed_from_dsl) do
|
|
308
308
|
<<-RUBY
|
|
309
|
-
user "bob2", :path=>"/
|
|
309
|
+
user "bob2", :path=>"/developer/" do
|
|
310
310
|
login_profile :password_reset_required=>true
|
|
311
311
|
|
|
312
312
|
groups(
|
|
@@ -391,7 +391,7 @@ describe 'update' do
|
|
|
391
391
|
context 'when rename role and instance_profile' do
|
|
392
392
|
let(:rename_role_and_instance_profile_dsl) do
|
|
393
393
|
<<-RUBY
|
|
394
|
-
user "bob", :path=>"/
|
|
394
|
+
user "bob", :path=>"/developer/" do
|
|
395
395
|
login_profile :password_reset_required=>true
|
|
396
396
|
|
|
397
397
|
groups(
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
describe 'target option' do
|
|
2
|
+
let(:dsl) do
|
|
3
|
+
<<-RUBY
|
|
4
|
+
user "bob", :path=>"/developer/" do
|
|
5
|
+
login_profile :password_reset_required=>true
|
|
6
|
+
|
|
7
|
+
groups(
|
|
8
|
+
"Admin",
|
|
9
|
+
"SES"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
policy "S3" do
|
|
13
|
+
{"Statement"=>
|
|
14
|
+
[{"Action"=>
|
|
15
|
+
["s3:Get*",
|
|
16
|
+
"s3:List*"],
|
|
17
|
+
"Effect"=>"Allow",
|
|
18
|
+
"Resource"=>"*"}]}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
attached_managed_policies(
|
|
22
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
user "mary", :path=>"/staff/" do
|
|
27
|
+
policy "S3" do
|
|
28
|
+
{"Statement"=>
|
|
29
|
+
[{"Action"=>
|
|
30
|
+
["s3:Get*",
|
|
31
|
+
"s3:List*"],
|
|
32
|
+
"Effect"=>"Allow",
|
|
33
|
+
"Resource"=>"*"}]}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
attached_managed_policies(
|
|
37
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
group "Admin", :path=>"/admin/" do
|
|
42
|
+
policy "Admin" do
|
|
43
|
+
{"Statement"=>[{"Effect"=>"Allow", "Action"=>"*", "Resource"=>"*"}]}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
attached_managed_policies(
|
|
47
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
group "SES", :path=>"/ses/" do
|
|
52
|
+
policy "ses-policy" do
|
|
53
|
+
{"Statement"=>
|
|
54
|
+
[{"Effect"=>"Allow", "Action"=>"ses:SendRawEmail", "Resource"=>"*"}]}
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
attached_managed_policies(
|
|
58
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
role "my-role", :path=>"/any/" do
|
|
63
|
+
instance_profiles(
|
|
64
|
+
"my-instance-profile"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
assume_role_policy_document do
|
|
68
|
+
{"Version"=>"2012-10-17",
|
|
69
|
+
"Statement"=>
|
|
70
|
+
[{"Sid"=>"",
|
|
71
|
+
"Effect"=>"Allow",
|
|
72
|
+
"Principal"=>{"Service"=>"ec2.amazonaws.com"},
|
|
73
|
+
"Action"=>"sts:AssumeRole"}]}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
policy "role-policy" do
|
|
77
|
+
{"Statement"=>
|
|
78
|
+
[{"Action"=>
|
|
79
|
+
["s3:Get*",
|
|
80
|
+
"s3:List*"],
|
|
81
|
+
"Effect"=>"Allow",
|
|
82
|
+
"Resource"=>"*"}]}
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
attached_managed_policies(
|
|
86
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
87
|
+
)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
instance_profile "my-instance-profile", :path=>"/profile/"
|
|
91
|
+
RUBY
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
before(:each) do
|
|
95
|
+
apply { dsl }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context 'when target a user' do
|
|
99
|
+
let(:target_bob) do
|
|
100
|
+
<<-RUBY
|
|
101
|
+
user "bob", :path=>"/developer/" do
|
|
102
|
+
login_profile :password_reset_required=>true
|
|
103
|
+
|
|
104
|
+
groups(
|
|
105
|
+
"Admin",
|
|
106
|
+
"SES"
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
policy "S3" do
|
|
110
|
+
{"Statement"=>
|
|
111
|
+
[{"Action"=>
|
|
112
|
+
["s3:Get*",
|
|
113
|
+
"s3:List*"],
|
|
114
|
+
"Effect"=>"Allow",
|
|
115
|
+
"Resource"=>"*"}]}
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
attached_managed_policies(
|
|
119
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
120
|
+
)
|
|
121
|
+
end
|
|
122
|
+
RUBY
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
subject { client(target: [/bob/]) }
|
|
126
|
+
|
|
127
|
+
it do
|
|
128
|
+
updated = apply(subject) { target_bob }
|
|
129
|
+
expect(updated).to be_falsey
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context 'when target a group, a role and an instance profile' do
|
|
134
|
+
let(:target_admin_and_my) do
|
|
135
|
+
<<-RUBY
|
|
136
|
+
group "Admin", :path=>"/admin/" do
|
|
137
|
+
policy "Admin" do
|
|
138
|
+
{"Statement"=>[{"Effect"=>"Allow", "Action"=>"*", "Resource"=>"*"}]}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
attached_managed_policies(
|
|
142
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
143
|
+
)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
role "my-role", :path=>"/any/" do
|
|
147
|
+
instance_profiles(
|
|
148
|
+
"my-instance-profile"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
assume_role_policy_document do
|
|
152
|
+
{"Version"=>"2012-10-17",
|
|
153
|
+
"Statement"=>
|
|
154
|
+
[{"Sid"=>"",
|
|
155
|
+
"Effect"=>"Allow",
|
|
156
|
+
"Principal"=>{"Service"=>"ec2.amazonaws.com"},
|
|
157
|
+
"Action"=>"sts:AssumeRole"}]}
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
policy "role-policy" do
|
|
161
|
+
{"Statement"=>
|
|
162
|
+
[{"Action"=>
|
|
163
|
+
["s3:Get*",
|
|
164
|
+
"s3:List*"],
|
|
165
|
+
"Effect"=>"Allow",
|
|
166
|
+
"Resource"=>"*"}]}
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
attached_managed_policies(
|
|
170
|
+
"arn:aws:iam::aws:policy/AmazonElastiCacheReadOnlyAccess"
|
|
171
|
+
)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
instance_profile "my-instance-profile", :path=>"/profile/"
|
|
175
|
+
RUBY
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
subject { client(target: [/Admin/, /^my-/]) }
|
|
179
|
+
|
|
180
|
+
it do
|
|
181
|
+
updated = apply(subject) { target_admin_and_my }
|
|
182
|
+
expect(updated).to be_falsey
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|