2018-02-01 03:45:02 +00:00
|
|
|
class AwsIamPolicies < Inspec.resource(1)
|
|
|
|
name 'aws_iam_policies'
|
|
|
|
desc 'Verifies settings for AWS IAM Policies in bulk'
|
2019-03-19 14:17:32 +00:00
|
|
|
example <<~EXAMPLE
|
2018-02-01 03:45:02 +00:00
|
|
|
describe aws_iam_policies do
|
|
|
|
it { should exist }
|
|
|
|
end
|
2019-03-19 14:17:32 +00:00
|
|
|
EXAMPLE
|
2018-02-08 04:26:37 +00:00
|
|
|
supports platform: 'aws'
|
|
|
|
|
|
|
|
include AwsPluralResourceMixin
|
|
|
|
def validate_params(resource_params)
|
|
|
|
unless resource_params.empty?
|
|
|
|
raise ArgumentError, 'aws_iam_policies does not accept resource parameters.'
|
|
|
|
end
|
|
|
|
resource_params
|
|
|
|
end
|
2018-02-01 03:45:02 +00:00
|
|
|
|
|
|
|
# Underlying FilterTable implementation.
|
|
|
|
filter = FilterTable.create
|
2018-06-26 19:14:21 +00:00
|
|
|
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
|
|
|
filter.register_column(:policy_names, field: :policy_name)
|
|
|
|
.register_column(:arns, field: :arn)
|
|
|
|
filter.install_filter_methods_on_resource(self, :table)
|
2018-02-01 03:45:02 +00:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
'IAM Policies'
|
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
def fetch_from_api
|
|
|
|
backend = BackendFactory.create(inspec_runner)
|
2018-03-02 18:45:17 +00:00
|
|
|
@table = []
|
|
|
|
pagination_opts = {}
|
|
|
|
loop do
|
|
|
|
api_result = backend.list_policies(pagination_opts)
|
|
|
|
@table += api_result.policies.map(&:to_h)
|
|
|
|
pagination_opts = { marker: api_result.marker }
|
|
|
|
break unless api_result.is_truncated
|
|
|
|
end
|
2018-02-01 03:45:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class Backend
|
2018-02-08 04:26:37 +00:00
|
|
|
class AwsClientApi < AwsBackendBase
|
2018-02-01 03:45:02 +00:00
|
|
|
BackendFactory.set_default_backend(self)
|
2018-02-08 04:26:37 +00:00
|
|
|
self.aws_client_class = Aws::IAM::Client
|
2018-02-01 03:45:02 +00:00
|
|
|
|
|
|
|
def list_policies(query)
|
2018-02-08 04:26:37 +00:00
|
|
|
aws_service_client.list_policies(query)
|
2018-02-01 03:45:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|