awspec 0.11.0 → 0.12.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16910d9cda734c86c840666374dc2c4b76879fbb
4
- data.tar.gz: 4155b14d91f07184993c5ae95e7a4145ac00ff04
3
+ metadata.gz: f2ff02288d8cfff552e9cf1211382f75e504247f
4
+ data.tar.gz: 96799ca4d6347c76dbfa421967252f5a6287672c
5
5
  SHA512:
6
- metadata.gz: d2ebfcdabd2c5bc3510d267d8078c103af3342a616af6c73f32eaf1759799eba171b07161d33b31e9e7d38d16887f66663a210dde5ba8e552f850cb9dc62ff55
7
- data.tar.gz: 134eb310c685f2a8fdc7686d54f6b1f2ae85996fc3e2d71f475e8d7e6a332b724c7720454c1598c16802a5371957d031784c5bff722053aac394f87d3ec69c41
6
+ metadata.gz: 4fa8b135318364c8f980bd8f8b8e756f3fe33a19de637b72d47c9ff65529019a562631526dac7a36645e0db959fc26f144449db1348f3a6125c840a53b5636bb
7
+ data.tar.gz: e1e32e85c6959ad7abb85cbb8edd76edf292044e1f1a6eadcafc6196062fef5adfd4d76a7358dc5f2d9ba8a264fc36928d665d2b8315803518179e1ee2964669
data/awspec.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_runtime_dependency 'rspec', '~> 3.0'
23
23
  spec.add_runtime_dependency 'rspec-its'
24
- spec.add_runtime_dependency 'aws-sdk', '~> 2'
24
+ spec.add_runtime_dependency 'aws-sdk', '~> 2.1.20'
25
25
  spec.add_runtime_dependency 'thor'
26
26
  spec.add_runtime_dependency 'activesupport'
27
27
  spec.add_development_dependency 'bundler', '~> 1.9'
@@ -0,0 +1,8 @@
1
+ ### be_allowed_action
2
+
3
+ ```ruby
4
+ describe iam_group('my-iam-group') do
5
+ it { should be_allowed_action('ec2:DescribeInstances') }
6
+ it { should be_allowed_action('s3:Put*').resource_arn('arn:aws:s3:::my-bucket-name/*') }
7
+ end
8
+ ```
@@ -0,0 +1,8 @@
1
+ ### be_allowed_action
2
+
3
+ ```ruby
4
+ describe iam_role('my-iam-role') do
5
+ it { should be_allowed_action('ec2:DescribeInstances') }
6
+ it { should be_allowed_action('s3:Put*').resource_arn('arn:aws:s3:::my-bucket-name/*') }
7
+ end
8
+ ```
@@ -0,0 +1,8 @@
1
+ ### be_allowed_action
2
+
3
+ ```ruby
4
+ describe iam_user('my-iam-user') do
5
+ it { should be_allowed_action('ec2:DescribeInstances') }
6
+ it { should be_allowed_action('s3:Put*').resource_arn('arn:aws:s3:::my-bucket-name/*') }
7
+ end
8
+ ```
@@ -280,6 +280,15 @@ IamUser resource type.
280
280
 
281
281
  ### exist
282
282
 
283
+ ### be_allowed_action
284
+
285
+ ```ruby
286
+ describe iam_user('my-iam-user') do
287
+ it { should be_allowed_action('ec2:DescribeInstances') }
288
+ it { should be_allowed_action('s3:Put*').resource_arn('arn:aws:s3:::my-bucket-name/*') }
289
+ end
290
+ ```
291
+
283
292
  ### have_iam_policy
284
293
 
285
294
  ### belong_to_iam_group
@@ -291,6 +300,15 @@ IamGroup resource type.
291
300
 
292
301
  ### exist
293
302
 
303
+ ### be_allowed_action
304
+
305
+ ```ruby
306
+ describe iam_group('my-iam-group') do
307
+ it { should be_allowed_action('ec2:DescribeInstances') }
308
+ it { should be_allowed_action('s3:Put*').resource_arn('arn:aws:s3:::my-bucket-name/*') }
309
+ end
310
+ ```
311
+
294
312
  ### have_iam_policy
295
313
 
296
314
  ### have_iam_user
@@ -302,6 +320,15 @@ IamRole resource type.
302
320
 
303
321
  ### exist
304
322
 
323
+ ### be_allowed_action
324
+
325
+ ```ruby
326
+ describe iam_role('my-iam-role') do
327
+ it { should be_allowed_action('ec2:DescribeInstances') }
328
+ it { should be_allowed_action('s3:Put*').resource_arn('arn:aws:s3:::my-bucket-name/*') }
329
+ end
330
+ ```
331
+
305
332
  ### have_iam_policy
306
333
 
307
334
  #### its(:path), its(:role_name), its(:role_id), its(:arn), its(:create_date), its(:assume_role_policy_document)
@@ -7,7 +7,7 @@ module Awspec::Generator
7
7
  @type_name = 'IamGroup'
8
8
  @type = Awspec::Type::IamGroup.new('my-iam-group')
9
9
  @ret = @type.resource
10
- @matchers = []
10
+ @matchers = %w(be_allowed_action)
11
11
  @ignore_matchers = []
12
12
  @describes = []
13
13
  end
@@ -7,7 +7,7 @@ module Awspec::Generator
7
7
  @type_name = 'IamRole'
8
8
  @type = Awspec::Type::IamRole.new('my-iam-role')
9
9
  @ret = @type.resource
10
- @matchers = []
10
+ @matchers = %w(be_allowed_action)
11
11
  @ignore_matchers = []
12
12
  @describes = []
13
13
  end
@@ -7,7 +7,7 @@ module Awspec::Generator
7
7
  @type_name = 'IamUser'
8
8
  @type = Awspec::Type::IamUser.new('my-iam-user')
9
9
  @ret = @type.resource
10
- @matchers = %w(belong_to_iam_group)
10
+ @matchers = %w(belong_to_iam_group be_allowed_action)
11
11
  @ignore_matchers = []
12
12
  @describes = []
13
13
  end
@@ -19,6 +19,16 @@ module Awspec::Helper
19
19
  end
20
20
  end
21
21
 
22
+ def select_policy_evaluation_results(policy_arn, action_name, resource_arn = nil)
23
+ options = {
24
+ policy_source_arn: policy_arn,
25
+ action_names: [action_name]
26
+ }
27
+ options[:resource_arns] = [resource_arn] if resource_arn
28
+ res = @iam_client.simulate_principal_policy(options)
29
+ res.evaluation_results
30
+ end
31
+
22
32
  def select_iam_group_by_user_name(user_name)
23
33
  res = @iam_client.list_groups_for_user({
24
34
  user_name: user_name
@@ -16,3 +16,6 @@ require 'awspec/matcher/have_route'
16
16
 
17
17
  # IAM User
18
18
  require 'awspec/matcher/belong_to_iam_group'
19
+
20
+ # IAM User/Group/Role
21
+ require 'awspec/matcher/be_allowed_action'
@@ -0,0 +1,12 @@
1
+ RSpec::Matchers.define :be_allowed_action do |action_name|
2
+ match do |resource|
3
+ results = resource.select_policy_evaluation_results(resource.resource[:arn], action_name, @resource_arn)
4
+ results.find do |result|
5
+ result.eval_decision == 'allowed'
6
+ end
7
+ end
8
+
9
+ chain :resource_arn do |arn|
10
+ @resource_arn = arn
11
+ end
12
+ end
@@ -38,6 +38,19 @@ Aws.config[:iam] = {
38
38
  ],
39
39
  is_truncated: false,
40
40
  marker: nil
41
+ },
42
+ simulate_principal_policy: {
43
+ evaluation_results: [
44
+ {
45
+ eval_action_name: 'ec2:DescribeInstances',
46
+ eval_resource_name: '*',
47
+ eval_decision: 'allowed',
48
+ matched_statements: [
49
+ ]
50
+ }
51
+ ],
52
+ is_truncated: false,
53
+ marker: nil
41
54
  }
42
55
  }
43
56
  }
@@ -18,6 +18,19 @@ Aws.config[:iam] = {
18
18
  ],
19
19
  is_truncated: false,
20
20
  marker: nil
21
+ },
22
+ simulate_principal_policy: {
23
+ evaluation_results: [
24
+ {
25
+ eval_action_name: 'ec2:DescribeInstances',
26
+ eval_resource_name: '*',
27
+ eval_decision: 'allowed',
28
+ matched_statements: [
29
+ ]
30
+ }
31
+ ],
32
+ is_truncated: false,
33
+ marker: nil
21
34
  }
22
35
  }
23
36
  }
@@ -29,6 +29,19 @@ Aws.config[:iam] = {
29
29
  ],
30
30
  is_truncated: false,
31
31
  marker: nil
32
+ },
33
+ simulate_principal_policy: {
34
+ evaluation_results: [
35
+ {
36
+ eval_action_name: 'ec2:DescribeInstances',
37
+ eval_resource_name: '*',
38
+ eval_decision: 'allowed',
39
+ matched_statements: [
40
+ ]
41
+ }
42
+ ],
43
+ is_truncated: false,
44
+ marker: nil
32
45
  }
33
46
  }
34
47
  }
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.11.0'
2
+ VERSION = '0.12.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-14 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2'
47
+ version: 2.1.20
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2'
54
+ version: 2.1.20
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +157,9 @@ files:
157
157
  - bin/awspec
158
158
  - doc/_resource_types/ec2.md
159
159
  - doc/_resource_types/elb.md
160
+ - doc/_resource_types/iam_group.md
161
+ - doc/_resource_types/iam_role.md
162
+ - doc/_resource_types/iam_user.md
160
163
  - doc/_resource_types/lambda.md
161
164
  - doc/_resource_types/rds_db_parameter_group.md
162
165
  - doc/_resource_types/security_group.md
@@ -210,6 +213,7 @@ files:
210
213
  - lib/awspec/helper/finder/vpc.rb
211
214
  - lib/awspec/helper/type.rb
212
215
  - lib/awspec/matcher.rb
216
+ - lib/awspec/matcher/be_allowed_action.rb
213
217
  - lib/awspec/matcher/be_opened.rb
214
218
  - lib/awspec/matcher/belong_to_db_subnet_group.rb
215
219
  - lib/awspec/matcher/belong_to_iam_group.rb