Skip to content

Commit

Permalink
Inspec iam gen (#2962)
Browse files Browse the repository at this point in the history
Merged PR #2962.
  • Loading branch information
slevenick authored and modular-magician committed Jan 13, 2020
1 parent ed80aef commit 78a66e7
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/ansible
9 changes: 9 additions & 0 deletions products/iam/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,12 @@ objects:
name: validBeforeTime
description: Key can only be used before this time.
output: true
- !ruby/object:Api::Type::Enum
name: keyType
output: true
description: |
Specifies the type of the key. Possible values include KEY_TYPE_UNSPECIFIED, USER_MANAGED and SYSTEM_MANAGED
values:
- :KEY_TYPE_UNSPECIFIED
- :USER_MANAGED
- :SYSTEM_MANAGED
36 changes: 36 additions & 0 deletions products/iam/inspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2020 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

--- !ruby/object:Provider::Inspec::Config
overrides: !ruby/object:Overrides::ResourceOverrides
Role: !ruby/object:Overrides::Inspec::ResourceOverride
name: CustomRole
base_url: projects/{{project}}/roles?view=FULL
self_link: projects/{{project}}/roles/{{name}}
privileged: true
ServiceAccount: !ruby/object:Overrides::Inspec::ResourceOverride
privileged: true
properties:
name: !ruby/object:Overrides::Inspec::PropertyOverride
override_name: service_account_name
displayName: !ruby/object:Overrides::Inspec::PropertyOverride
override_name: service_account_display_name
uniqueId: !ruby/object:Overrides::Inspec::PropertyOverride
override_name: service_account_id
email: !ruby/object:Overrides::Inspec::PropertyOverride
override_name: service_account_email
ServiceAccountKey: !ruby/object:Overrides::Inspec::ResourceOverride
privileged: true
properties:
name: !ruby/object:Overrides::Inspec::PropertyOverride
override_name: key_name
3 changes: 2 additions & 1 deletion templates/inspec/examples/attributes/external_attributes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ gcp_storage_bucket_object: bucket-with-object
gcp_kms_key_ring_policy_name: kms-key-ring
gcp_kms_crypto_key_name_policy: kms-key
gcp_db_instance_name: my-database
gcp_db_user_name: user-name
gcp_db_user_name: user-name
gcp_project_iam_custom_role_id: admin-role
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% gcp_project_iam_custom_role_id = "#{external_attribute('gcp_project_iam_custom_role_id', doc_generation)}" -%>
describe google_iam_custom_role(project: <%= gcp_project_id -%>, name: <%= gcp_project_iam_custom_role_id -%>) do
it { should exist }
its('stage') { should eq 'GA' }
its('included_permissions') { should eq ["iam.roles.list"] }
end

describe google_iam_custom_role(project: <%= gcp_project_id -%>, name: 'nonexistent') do
it { should_not exist }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.')
gcp_project_iam_custom_role_id = attribute(:gcp_project_iam_custom_role_id, default: '<%= external_attribute('gcp_project_iam_custom_role_id') -%>', description: 'The IAM custom role identifier.')
gcp_enable_privileged_resources = attribute(:gcp_enable_privileged_resources, default:0, description:'Flag to enable privileged resources requiring elevated privileges in GCP.')
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% gcp_project_iam_custom_role_id = "#{external_attribute('gcp_project_iam_custom_role_id', doc_generation)}" -%>
describe google_iam_custom_roles(project: <%= gcp_project_id -%>) do
its('names') { should include "projects/<%= doc_generation ? "project-id" : "\#{gcp_project_id}" -%>/roles/<%= doc_generation ? "role-id" : "\#{gcp_project_iam_custom_role_id}" -%>" }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% gcp_service_account_display_name = "#{external_attribute('gcp_service_account_display_name', doc_generation)}" -%>
describe google_iam_service_account(project: <%= gcp_project_id -%>, name: "<%= doc_generation ? "display-name" : "\#{gcp_service_account_display_name}" -%>@<%= doc_generation ? "project-id" : "\#{gcp_project_id}" -%>.iam.gserviceaccount.com") do
it { should exist }
its('display_name') { should cmp <%= gcp_service_account_display_name -%> }
end

describe google_iam_service_account(project: <%= gcp_project_id -%>, name: "nonexistent@<%= doc_generation ? "project-id" : "\#{gcp_project_id}" -%>.iam.gserviceaccount.com") do
it { should_not exist }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.')
gcp_service_account_display_name = attribute(:gcp_service_account_display_name, default: '<%= external_attribute('gcp_service_account_display_name') -%>', description: 'The IAM service account display name.')
gcp_enable_privileged_resources = attribute(:gcp_enable_privileged_resources, default:0, description:'Flag to enable privileged resources requiring elevated privileges in GCP.')
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% gcp_service_account_display_name = "#{external_attribute('gcp_service_account_display_name', doc_generation)}" -%>
describe google_iam_service_accounts(project: <%= gcp_project_id -%>, name: "<%= doc_generation ? "display-name" : "\#{gcp_service_account_display_name}" -%>@<%= doc_generation ? "project-id" : "\#{gcp_project_id}" -%>.iam.gserviceaccount.com") do
its('service_account_emails') { should include "<%= doc_generation ? "display-name" : "\#{gcp_service_account_display_name}" -%>@<%= doc_generation ? "project-id" : "\#{gcp_project_id}" -%>.iam.gserviceaccount.com" }
its('count') { should be <= 1000 }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% gcp_service_account_display_name = "#{external_attribute('gcp_service_account_display_name', doc_generation)}" -%>
google_iam_service_account_keys(project: <%= gcp_project_id -%>, service_account: "<%= doc_generation ? "display-name" : "\#{gcp_service_account_display_name}" -%>@<%= doc_generation ? "project-id" : "\#{gcp_project_id}" -%>.iam.gserviceaccount.com").key_names.each do |sa_key_name|
describe
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.')
gcp_service_account_display_name = attribute(:gcp_service_account_display_name, default: '<%= external_attribute('gcp_service_account_display_name') -%>', description: 'The IAM service account display name.')
gcp_enable_privileged_resources = attribute(:gcp_enable_privileged_resources, default:0, description:'Flag to enable privileged resources requiring elevated privileges in GCP.')
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%>
<% gcp_service_account_display_name = "#{external_attribute('gcp_service_account_display_name', doc_generation)}" -%>
describe google_iam_service_account_keys(project: <%= gcp_project_id -%>, service_account: "<%= doc_generation ? "display-name" : "\#{gcp_service_account_display_name}" -%>@<%= doc_generation ? "project-id" : "\#{gcp_project_id}" -%>.iam.gserviceaccount.com") do
its('count') { should be <= 1000 }
end

0 comments on commit 78a66e7

Please sign in to comment.