From 982d4fe8dde1f4e8046b3c03028545156b8d3f70 Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:31:40 +0530 Subject: [PATCH] Automatically generated by magic modules for service: iam and resource: Projects__serviceAccounts__key. This commit includes the following changes: - Singular Resource ERB File - Plural Resource ERB File - Terraform configuration - api.yaml configuration for product iam and resource Projects__serviceAccounts__key Signed-off-by: Samir <85890442+sa-progress@users.noreply.github.com> --- mmv1/products/iam/api.yaml | 90 ++++++++++++++++++- ...google_iam_project_service_account_key.erb | 19 ++++ ...project_service_account_key_attributes.erb | 3 + ...oogle_iam_project_service_account_keys.erb | 5 ++ .../configuration/mm-attributes.yml | 11 +++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_key.erb create mode 100644 mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_key_attributes.erb create mode 100644 mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_keys.erb diff --git a/mmv1/products/iam/api.yaml b/mmv1/products/iam/api.yaml index 9a7b00df2..4587887b0 100644 --- a/mmv1/products/iam/api.yaml +++ b/mmv1/products/iam/api.yaml @@ -195,4 +195,92 @@ objects: - !ruby/object:Api::Type::Boolean name: 'deleted' description: The current deleted state of the role - output: true \ No newline at end of file + output: true + + + - !ruby/object:Api::Resource + name: ProjectServiceAccountKey + base_url: '{{name}}/keys' + self_link: '{{name}}' + references: !ruby/object:Api::Resource::ReferenceLinks + guides: + 'Official Documentation': + api: 'https://cloud.google.com/iam/docs' + async: !ruby/object:Api::OpAsync + operation: !ruby/object:Api::OpAsync::Operation + path: 'name' + base_url: '{op_id}' + wait_ms: 1000 + result: !ruby/object:Api::OpAsync::Result + path: 'response' + resource_inside_response: true + status: !ruby/object:Api::OpAsync::Status + path: 'done' + complete: True + allowed: + - True + - False + error: !ruby/object:Api::OpAsync::Error + path: 'error' + message: 'message' + description: |- + Represents a service account key. A service account has two sets of key-pairs: user-managed, and system-managed. User-managed key-pairs can be created and deleted by users. Users are responsible for rotating these keys periodically to ensure security of their service accounts. Users retain the private key of these key-pairs, and Google retains ONLY the public key. System-managed keys are automatically rotated by Google, and are used for signing for a maximum of two weeks. The rotation process is probabilistic, and usage of the new key will gradually ramp up and down over the key's lifetime. If you cache the public key set for a service account, we recommend that you update the cache every 15 minutes. User-managed keys can be added and removed at any time, so it is important to update the cache frequently. For Google-managed keys, Google will publish a key at least 6 hours before it is first used for signing and will keep publishing it for at least 6 hours after it was last used for signing. Public keys for all service accounts are also published at the OAuth2 Service Account API. + properties: + + - !ruby/object:Api::Type::String + name: 'name' + description: | + The resource name of the service account key in the following format `projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}/keys/{key}`. + - !ruby/object:Api::Type::Enum + name: 'privateKeyType' + description: | + The output format for the private key. Only provided in `CreateServiceAccountKey` responses, not in `GetServiceAccountKey` or `ListServiceAccountKey` responses. Google never exposes system-managed private keys, and never retains user-managed private keys. + values: + - :TYPE_UNSPECIFIED + - :TYPE_PKCS12_FILE + - :TYPE_GOOGLE_CREDENTIALS_FILE + - !ruby/object:Api::Type::Enum + name: 'keyAlgorithm' + description: | + Specifies the algorithm (and possibly key size) for the key. + values: + - :KEY_ALG_UNSPECIFIED + - :KEY_ALG_RSA_1024 + - :KEY_ALG_RSA_2048 + - !ruby/object:Api::Type::String + name: 'privateKeyData' + description: | + The private key data. Only provided in `CreateServiceAccountKey` responses. Make sure to keep the private key data secure because it allows for the assertion of the service account identity. When base64 decoded, the private key data can be used to authenticate with Google API client libraries and with gcloud auth activate-service-account. + - !ruby/object:Api::Type::String + name: 'publicKeyData' + description: | + The public key data. Only provided in `GetServiceAccountKey` responses. + - !ruby/object:Api::Type::String + name: 'validAfterTime' + description: | + The key can be used after this timestamp. + - !ruby/object:Api::Type::String + name: 'validBeforeTime' + description: | + The key can be used before this timestamp. For system-managed key pairs, this timestamp is the end time for the private key signing operation. The public key could still be used for verification for a few hours after this time. + - !ruby/object:Api::Type::Enum + name: 'keyOrigin' + description: | + The key origin. + values: + - :ORIGIN_UNSPECIFIED + - :USER_PROVIDED + - :GOOGLE_PROVIDED + - !ruby/object:Api::Type::Enum + name: 'keyType' + description: | + The key type. + values: + - :KEY_TYPE_UNSPECIFIED + - :USER_MANAGED + - :SYSTEM_MANAGED + - !ruby/object:Api::Type::Boolean + name: 'disabled' + description: | + The key status. + diff --git a/mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_key.erb b/mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_key.erb new file mode 100644 index 000000000..e5a7f55b1 --- /dev/null +++ b/mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_key.erb @@ -0,0 +1,19 @@ +<% gcp_project_id = "#{external_attribute(pwd, 'gcp_project_id', doc_generation)}" -%> +<% project_service_account_key = grab_attributes(pwd)['project_service_account_key'] -%> +describe google_iam_project_service_account_key(name: <%= doc_generation ? "' #{project_service_account_key['name']}'":"project_service_account_key['name']" -%>) do + it { should exist } + its('name') { should cmp <%= doc_generation ? "'#{project_service_account_key['name']}'" : "project_service_account_key['name']" -%> } + its('private_key_type') { should cmp <%= doc_generation ? "'#{project_service_account_key['private_key_type']}'" : "project_service_account_key['private_key_type']" -%> } + its('key_algorithm') { should cmp <%= doc_generation ? "'#{project_service_account_key['key_algorithm']}'" : "project_service_account_key['key_algorithm']" -%> } + its('private_key_data') { should cmp <%= doc_generation ? "'#{project_service_account_key['private_key_data']}'" : "project_service_account_key['private_key_data']" -%> } + its('public_key_data') { should cmp <%= doc_generation ? "'#{project_service_account_key['public_key_data']}'" : "project_service_account_key['public_key_data']" -%> } + its('valid_after_time') { should cmp <%= doc_generation ? "'#{project_service_account_key['valid_after_time']}'" : "project_service_account_key['valid_after_time']" -%> } + its('valid_before_time') { should cmp <%= doc_generation ? "'#{project_service_account_key['valid_before_time']}'" : "project_service_account_key['valid_before_time']" -%> } + its('key_origin') { should cmp <%= doc_generation ? "'#{project_service_account_key['key_origin']}'" : "project_service_account_key['key_origin']" -%> } + its('key_type') { should cmp <%= doc_generation ? "'#{project_service_account_key['key_type']}'" : "project_service_account_key['key_type']" -%> } + +end + +describe google_iam_project_service_account_key(name: "does_not_exit") do + it { should_not exist } +end \ No newline at end of file diff --git a/mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_key_attributes.erb b/mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_key_attributes.erb new file mode 100644 index 000000000..92cd0ab69 --- /dev/null +++ b/mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_key_attributes.erb @@ -0,0 +1,3 @@ +gcp_project_id = input(:gcp_project_id, value: '<%= external_attribute(pwd, 'gcp_project_id') -%>', description: 'The GCP project identifier.') + + project_service_account_key = input('project_service_account_key', value: <%= JSON.pretty_generate(grab_attributes(pwd)['project_service_account_key']) -%>, description: 'project_service_account_key description') \ No newline at end of file diff --git a/mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_keys.erb b/mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_keys.erb new file mode 100644 index 000000000..a4f33409b --- /dev/null +++ b/mmv1/templates/inspec/examples/google_iam_project_service_account_key/google_iam_project_service_account_keys.erb @@ -0,0 +1,5 @@ +<% gcp_project_id = "#{external_attribute(pwd, 'gcp_project_id', doc_generation)}" -%> + <% project_service_account_key = grab_attributes(pwd)['project_service_account_key'] -%> + describe google_iam_project_service_account_keys(name: <%= doc_generation ? "' #{project_service_account_key['name']}'":"project_service_account_key['name']" -%>) do + it { should exist } + end \ No newline at end of file diff --git a/mmv1/templates/inspec/tests/integration/configuration/mm-attributes.yml b/mmv1/templates/inspec/tests/integration/configuration/mm-attributes.yml index 9e0d36471..9a13024e2 100644 --- a/mmv1/templates/inspec/tests/integration/configuration/mm-attributes.yml +++ b/mmv1/templates/inspec/tests/integration/configuration/mm-attributes.yml @@ -958,3 +958,14 @@ project_secret: service_connection: parent : "value_parent" + +project_service_account_key: + name : "value_name" + private_key_type : "value_privatekeytype" + key_algorithm : "value_keyalgorithm" + private_key_data : "value_privatekeydata" + public_key_data : "value_publickeydata" + valid_after_time : "value_validaftertime" + valid_before_time : "value_validbeforetime" + key_origin : "value_keyorigin" + key_type : "value_keytype" \ No newline at end of file