repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
simplymadeapps/simple_scheduler
https://github.com/simplymadeapps/simple_scheduler/blob/fac50a8119736f1df3ddabb2aeef33efd000902e/lib/simple_scheduler/scheduler_job.rb
lib/simple_scheduler/scheduler_job.rb
# frozen_string_literal: true module SimpleScheduler # Active Job class that queues jobs defined in the config file. class SchedulerJob < ActiveJob::Base def perform load_config queue_future_jobs end private # Returns the path of the Simple Scheduler configuration file. # @return [String] def config_path ENV.fetch("SIMPLE_SCHEDULER_CONFIG", "config/simple_scheduler.yml") end # Load the global scheduler config from the YAML file. def load_config @config = YAML.safe_load(ERB.new(File.read(config_path)).result) @queue_ahead = @config["queue_ahead"] || Task::DEFAULT_QUEUE_AHEAD_MINUTES @queue_name = @config["queue_name"] || "default" @time_zone = @config["tz"] || Time.zone.tzinfo.name @config.delete("queue_ahead") @config.delete("queue_name") @config.delete("tz") end # Queue each of the future jobs into Sidekiq from the defined tasks. def queue_future_jobs tasks.each do |task| # Schedule the new run times using the future job wrapper. new_run_times = task.future_run_times - task.existing_run_times new_run_times.each do |time| SimpleScheduler::FutureJob.set(queue: @queue_name, wait_until: time) .perform_later(task.params, time.to_i) end end end # The array of tasks loaded from the config YAML. # @return [Array<SimpleScheduler::Task] def tasks @config.map do |task_name, options| task_params = options.symbolize_keys task_params[:queue_ahead] ||= @queue_ahead task_params[:name] = task_name task_params[:tz] ||= @time_zone Task.new(task_params) end end end end
ruby
MIT
fac50a8119736f1df3ddabb2aeef33efd000902e
2026-01-04T17:46:19.163745Z
false
simplymadeapps/simple_scheduler
https://github.com/simplymadeapps/simple_scheduler/blob/fac50a8119736f1df3ddabb2aeef33efd000902e/lib/simple_scheduler/railtie.rb
lib/simple_scheduler/railtie.rb
# frozen_string_literal: true module SimpleScheduler # Load the rake task into the Rails app class Railtie < Rails::Railtie rake_tasks do load File.join(File.dirname(__FILE__), "../tasks/simple_scheduler_tasks.rake") end end end
ruby
MIT
fac50a8119736f1df3ddabb2aeef33efd000902e
2026-01-04T17:46:19.163745Z
false
simplymadeapps/simple_scheduler
https://github.com/simplymadeapps/simple_scheduler/blob/fac50a8119736f1df3ddabb2aeef33efd000902e/lib/simple_scheduler/future_job.rb
lib/simple_scheduler/future_job.rb
# frozen_string_literal: true module SimpleScheduler # Active Job class that wraps the scheduled job and determines if the job # should still be run based on the scheduled time and when the job expires. class FutureJob < ActiveJob::Base # An error class that is raised if a job does not run because the run time is # too late when compared to the scheduled run time. # @!attribute run_time # @return [Time] The actual run time # @!attribute scheduled_time # @return [Time] The scheduled run time # @!attribute task # @return [SimpleScheduler::Task] The expired task class Expired < StandardError attr_accessor :run_time, :scheduled_time, :task end rescue_from Expired, with: :handle_expired_task # Perform the future job as defined by the task. # @param task_params [Hash] The params from the scheduled task # @param scheduled_time [Integer] The epoch time for when the job was scheduled to be run def perform(task_params, scheduled_time) @task = Task.new(task_params) @scheduled_time = Time.at(scheduled_time).in_time_zone(@task.time_zone) raise Expired if expired? queue_task end # Delete all future jobs created by Simple Scheduler from the `Sidekiq::ScheduledSet`. def self.delete_all Task.scheduled_set.each do |job| job.delete if job.display_class == "SimpleScheduler::FutureJob" end end private # The duration between the scheduled run time and actual run time that # will cause the job to expire. Expired jobs will not be executed. # @return [ActiveSupport::Duration] def expire_duration split_duration = @task.expires_after.split(".") duration = split_duration[0].to_i duration_units = split_duration[1] duration.send(duration_units) end # Returns whether or not the job has expired based on the time # between the scheduled run time and the current time. # @return [Boolean] def expired? return false if @task.expires_after.blank? expire_duration.from_now(@scheduled_time) < Time.now.in_time_zone(@task.time_zone) end # Handle the expired task by passing the task and run time information # to a block that can be creating in a Rails initializer file. def handle_expired_task(exception) exception.run_time = Time.now.in_time_zone(@task.time_zone) exception.scheduled_time = @scheduled_time exception.task = @task SimpleScheduler.expired_task_blocks.each do |block| block.call(exception) end end # The name of the method used to queue the task's job or worker. # @return [Symbol] def perform_method if @task.job_class.included_modules.include?(Sidekiq::Worker) :perform_async else :perform_later end end # Queue the task with the scheduled time if the job allows. def queue_task if @task.job_class.instance_method(:perform).arity.zero? @task.job_class.send(perform_method) else @task.job_class.send(perform_method, @scheduled_time.to_i) end end end end
ruby
MIT
fac50a8119736f1df3ddabb2aeef33efd000902e
2026-01-04T17:46:19.163745Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.10-networking.rb
controls/3.10-networking.rb
# Copyright 2025 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Use Identity Aware Proxy (IAP) to Ensure Only Traffic From Google IP Addresses are Allowed' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.10' control_abbrev = 'networking' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Use Identity Aware Proxy (IAP) to Ensure Only Traffic From Google IP Addresses are Allowed" desc 'IAP authenticates the user requests to your apps via a Google single sign in. You can then manage these users with permissions to control access. It is recommended to use both IAP permissions and firewalls to restrict this access to your apps with sensitive information.' desc 'rationale', 'IAP ensure that access to VMs is controlled by authenticating incoming requests. Access to your apps and the VMs should be restricted by firewall rules that allow only the proxy IAP IP addresses contained in the 35.235.240.0/20 subnet. Otherwise, unauthenticated requests can be made to your apps. To ensure that load balancing works correctly health checks should also be allowed.' tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-1'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/iap' ref 'GCP Docs', url: 'https://cloud.google.com/iap/docs/load-balancer-howto' ref 'GCP Docs', url: 'https://cloud.google.com/load-balancing/docs/health-checks' ref 'GCP Docs', url: 'https://cloud.google.com/blog/products/identity-security/cloud-iap-enables-context-aware-access-to-vms-via-ssh-and-rdp-without-bastion-hosts' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/6.06-db.rb
controls/6.06-db.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That Cloud SQL Database Instances Do Not Have Public IPs' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '6.6' control_abbrev = 'db' sql_cache = CloudSQLCache(project: gcp_project_id) control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure That Cloud SQL Database Instances Do Not Have Public IPs" desc 'It is recommended to configure Second Generation Sql instance to use private IPs instead of public IPs.' desc 'rationale', "To lower the organization's attack surface, Cloud SQL databases should not have public IPs. Private IPs provide improved network security and lower latency for your application." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-1'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/configure-private-ip' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/private-ip' ref 'GCP Docs', url: 'https://cloud.google.com/resource-manager/docs/organization-policy/org-policy-constraints' ref 'GCP Docs', url: 'https://console.cloud.google.com/iam-admin/orgpolicies/sql-restrictPublicIp' if sql_cache.instance_names.empty? impact 'none' describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end else sql_cache.instance_names.each do |db| sql_cache.instance_objects[db].ip_addresses.each do |ip_address| describe "[#{gcp_project_id}] CloudSQL #{db}" do subject { ip_address } its('type') { should_not include('PRIMARY') } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/7.03-bq.rb
controls/7.03-bq.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that a default customer-managed encryption key (CMEK) is specified for all BigQuery data sets' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '7.3' control_abbrev = 'storage' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure that a default customer-managed encryption key (CMEK) is specified for all BigQuery data sets" desc 'BigQuery by default encrypts the data as rest by employing Envelope Encryption using Google managed cryptographic keys. The data is encrypted using the data encryption keys and data encryption keys themselves are further encrypted using key encryption keys. This is seamless and do not require any additional input from the user. However, if you want to have greater control, Customer-managed encryption keys (CMEK) can be used as encryption key management solution for BigQuery Data Sets.' desc 'rationale', 'BigQuery by default encrypts the data as rest by employing Envelope Encryption using Google managed cryptographic keys. This is seamless and does not require any additional input from the user. For greater control over the encryption, customer-managed encryption keys (CMEK) can be used as encryption key management solution for BigQuery Data Sets. Setting a Default Customer-managed encryption key (CMEK) for a data set ensure any tables created in future will use the specified CMEK if none other is provided.' tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-1'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/bigquery/docs/customer-managed-encryption' if google_bigquery_datasets(project: gcp_project_id).ids.empty? impact 'none' describe "[#{gcp_project_id}] does not have BigQuery Datasets, this test is Not Applicable." do skip "[#{gcp_project_id}] does not have BigQuery Datasets" end else google_bigquery_datasets(project: gcp_project_id).ids.each do |name| describe "[#{gcp_project_id}] BigQuery Dataset #{name} should use customer-managed encryption keys (CMEK)" do subject { google_bigquery_dataset(project: gcp_project_id, name: name.split(':').last).default_encryption_configuration } its('kms_key_name') { should_not eq nil } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.10-vms.rb
controls/4.10-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That App Engine Applications Enforce HTTPS Connections (Manual)' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.10' control_abbrev = 'vms' # Though App Engine, keeping consistent with section control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure That App Engine Applications Enforce HTTPS Connections (Manual)" desc 'In order to maintain the highest level of security all connections to an application should be secure by default.' desc 'rationale', 'Insecure HTTP connections maybe subject to eavesdropping which can expose sensitive data. All connections to appengine will automatically be redirected to the HTTPS endpoint ensuring that all connections are secured by TLS.' tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[] # Add relevant NIST controls if any in future ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP App Engine Docs', url: 'https://cloud.google.com/appengine/docs/standard/python3/config/appref' ref 'GCP App Engine Docs (Flexible)', url: 'https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.02-iam.rb
controls/1.02-iam.rb
# controls/1.02-iam.rb (assuming 1.02 is the actual file name) # Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that multi-factor authentication is enabled for all non-service accounts' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.2' # This should match the actual control ID control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that multi-factor authentication is enabled for all non-service accounts" desc 'Setup multi-factor authentication for Google Cloud Platform accounts.' desc 'rationale', 'Multi-factor authentication requires more than one mechanism to authenticate a user. This secures user logins from attackers exploiting stolen or weak credentials.' desc 'notes', 'This control generally requires manual verification because InSpec does not directly query user MFA status from Cloud Identity or Google Workspace. Verification steps are provided in the references.' tag cis_scored: false # Keep this as false tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['IA-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/solutions/securing-gcp-account-u2f' ref 'GCP Docs', url: 'https://support.google.com/accounts/answer/185839' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.06-logging.rb
controls/2.06-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure log metric filter and alerts exists for Custom Role changes' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.6' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure log metric filter and alerts exists for Custom Role changes" desc 'It is recommended that a metric filter and alarm be established for changes to Identity and Access Management (IAM) role creation, deletion and updating activities.' desc 'rationale', 'Google Cloud IAM provides predefined roles that give granular access to specific Google Cloud Platform resources and prevent unwanted access to other resources. However, to cater to organization-specific needs, Cloud IAM also provides the ability to create custom roles. Project owners and administrators with the Organization Role Administrator role or the IAM Role Administrator role can create custom roles. Monitoring role creation, deletion and updating activities will help in identifying any over-privileged role at early stages.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-3 AU-12] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/logs-based-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/custom-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/alerts/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/reference/tools/gcloud-logging' ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/understanding-custom-roles' log_filter = 'resource.type=audited_resource AND protoPayload.methodName="google.iam.admin.v1.CreateRole" OR protoPayload.methodName="google.iam.admin.v1.DeleteRole" OR protoPayload.methodName="google.iam.admin.v1.UpdateRole"' describe "[#{gcp_project_id}] Custom Role changes filter" do subject { google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter) } it { should exist } end google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter).metric_types.each do |metrictype| describe.one do filter = "metric.type=\"#{metrictype}\" resource.type=\"audited_resource\"" google_project_alert_policies(project: gcp_project_id).where(policy_enabled_state: true).policy_names.each do |policy| condition = google_project_alert_policy_condition(policy: policy, filter: filter) describe "[#{gcp_project_id}] Custom Role changes alert policy" do subject { condition } it { should exist } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.03-networking.rb
controls/3.03-networking.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that DNSSEC is enabled for Cloud DNS' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.3' control_abbrev = 'networking' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that DNSSEC is enabled for Cloud DNS" desc 'Cloud Domain Name System (DNS) is a fast, reliable and cost-effective domain name system that powers millions of domains on the internet. Domain Name System Security Extensions (DNSSEC) in Cloud DNS enables domain owners to take easy steps to protect their domains against DNS hijacking and man-in-the-middle and other attacks.' desc 'rationale', 'Domain Name System Security Extensions (DNSSEC) adds security to the DNS protocol by enabling DNS responses to be validated. Having a trustworthy DNS that translates a domain name like www.example.com into its associated IP address is an increasingly important building block of today’s web-based applications. Attackers can hijack this process of domain/IP lookup and redirect users to a malicious site through DNS hijacking and man-in-the-middle attacks. DNSSEC helps mitigate the risk of such attacks by cryptographically signing DNS records. As a result, it prevents attackers from issuing fake DNS responses that may misdirect browsers to nefarious websites.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CM-6'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloudplatform.googleblog.com/2017/11/DNSSEC-now-available-in-Cloud-DNS.html' ref 'GCP Docs', url: 'https://cloud.google.com/dns/dnssec-config#enabling' ref 'GCP Docs', url: 'https://cloud.google.com/dns/dnssec' managed_zone_names = google_dns_managed_zones(project: gcp_project_id).where(visibility: 'public').zone_names if managed_zone_names.empty? impact 'none' describe "[#{gcp_project_id}] does not have DNS Zones with Public visibility. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have DNS Zones with Public visibility." end else managed_zone_names.each do |dnszone| describe "[#{gcp_project_id}] DNS Zone [#{dnszone}] with DNSSEC" do subject { google_dns_managed_zone(project: gcp_project_id, zone: dnszone) } its('dnssec_config.state') { should cmp 'on' } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.04-vms.rb
controls/4.04-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure oslogin is enabled for a Project' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.4' control_abbrev = 'vms' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure oslogin is enabled for a Project" desc 'Enabling OS login binds SSH certificates to IAM users and facilitates effective SSH certificate management.' desc 'rationale', 'Enabling osLogin ensures that SSH keys used to connect to instances are mapped with IAM users. Revoking access to IAM user will revoke all the SSH keys associated with that particular user. It facilitates centralized and automated SSH key pair management which is useful in handling cases like response to compromised SSH key pairs and/or revocation of external/third-party/Vendor users.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/instances/managing-instance-access' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/instances/managing-instance-access#enable_oslogin' describe "[#{gcp_project_id}]" do subject { google_compute_project_info(project: gcp_project_id) } it { should have_enabled_oslogin } end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.04-iam.rb
controls/1.04-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that there are only GCP-managed service account keys for each service account' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.4' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that there are only GCP-managed service account keys for each service account" desc 'User managed service account should not have user managed keys.' desc 'rationale', 'Anyone who has access to the keys will be able to access resources through the service account. GCP-managed keys are used by Cloud Platform services such as App Engine and Compute Engine. These keys cannot be downloaded. Google will keep the keys and automatically rotate them on an approximately weekly basis. User-managed keys are created, downloadable, and managed by users. They expire 10 years from creation. For user-managed keys, user have to take ownership of key management activities which includes: - Key storage - Key distribution - Key revocation - Key rotation - Protecting the keys from unauthorized users - Key recovery Even after owners precaution, keys can be easily leaked by common development malpractices like checking keys into the source code or leaving them in Downloads directory, or accidentally leaving them on support blogs/channels. It is recommended to prevent use of User-managed service account keys.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/understanding-service-accounts#managing_service_account_keys' ref 'GCP Docs', url: 'https://cloud.google.com/resource-manager/docs/organization-policy/restricting-service-accounts' # Use google_service_accounts instead of the custom cache. google_service_accounts(project: gcp_project_id).service_account_emails.each do |service_account| # Use google_service_account_keys to get key types directly. keys = google_service_account_keys(project: gcp_project_id, service_account: service_account) describe "[#{gcp_project_id}] Service Account: #{service_account}" do subject { keys } it 'should not have user-managed keys' do expect(keys.key_types).to_not include('USER_MANAGED') end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.15-logging.rb
controls/2.15-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title "Ensure 'Access Approval' is 'Enabled'" gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.15' control_abbrev = 'logging' # Retaining 'logging' as per existing convention for this section control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure 'Access Approval' is 'Enabled'" desc "GCP Access Approval enables you to require your organizations' explicit approval whenever Google support try to access your projects. You can then select users within your organization who can approve these requests through giving them a security role in IAM. All access requests display which Google Employee requested them in an email or Pub/Sub message that you can choose to Approve. This adds an additional control and logging of who in your organization approved/denied these requests." desc 'rationale', "Controlling access to your information is one of the foundations of information security. Google Employees do have access to your organizations' projects for support reasons. With Access Approval, organizations can then be certain that their information is accessed by only approved Google Personnel. Note: To use Access Approval your organization will need have enabled Access Transparency and have at one of the following support level: Enhanced or Premium. There will be subscription costs associated with these support levels, as well as increased storage costs for storing the logs. There may also be a potential delay in support times if approval is not granted promptly." tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[] # Add relevant NIST controls if any in future ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-approval/docs' ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-approval/docs/overview' ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-approval/docs/quickstart-custom-key' ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-approval/docs/supported-services' ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-approval/docs/view-historical-requests' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.02-networking.rb
controls/3.02-networking.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure Legacy Networks Do Not Exist for Older Projects' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.2' control_abbrev = 'networking' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure Legacy Networks Do Not Exist for Older Projects" desc 'In order to prevent use of legacy networks, a project should not have a legacy network configured. As of now, Legacy Networks are gradually being phased out, and you can no longer create projects with them. This recommendation is to check older projects to ensure that they are not using Legacy Networks.' desc 'rationale', 'Legacy networks have a single network IPv4 prefix range and a single gateway IP address for the whole network. The network is global in scope and spans all cloud regions. Subnetworks cannot be created in a legacy network and are unable to switch from legacy to auto or custom subnet networks. Legacy networks can have an impact for high network traffic projects and are subject to a single point of contention or failure.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CM-6'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/networking#creating_a_legacy_network' ref 'GCP Docs', url: 'https://cloud.google.com/vpc/docs/using-legacy#deleting_a_legacy_network' network_names = google_compute_networks(project: gcp_project_id).network_names if network_names.empty? describe "[#{gcp_project_id}] does not have any networks. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have any networks." end else google_compute_networks(project: gcp_project_id).network_names.each do |network| describe "[#{gcp_project_id}] Network [#{network}] " do subject { google_compute_network(project: gcp_project_id, name: network) } it { should_not be_legacy } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.01-networking.rb
controls/3.01-networking.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That the Default Network Does Not Exist in a Project' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.1' control_abbrev = 'networking' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure That the Default Network Does Not Exist in a Project" desc 'To prevent use of default network, a project should not have a default network.' desc 'rationale', "The default network has a preconfigured network configuration and automatically generates the following insecure firewall rules: - default-allow-internal: Allows ingress connections for all protocols and ports among instances in the network. - default-allow-ssh: Allows ingress connections on TCP port 22(SSH) from any source to any instance in the network. - default-allow-rdp: Allows ingress connections on TCP port 3389(RDP) from any source to any instance in the network. - default-allow-icmp: Allows ingress ICMP traffic from any source to any instance in the network. These automatically created firewall rules do not get audit logged by default. Furthermore, the default network is an auto mode network, which means that its subnets use the same predefined range of IP addresses, and as a result, it's not possible to use Cloud VPN or VPC Network Peering with the default network. Based on organization security and networking requirements, the organization should create a new network and delete the default network." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CM-6'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/networking#firewall_rules' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/reference/latest/networks/insert' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/reference/latest/networks/delete' ref 'GCP Docs', url: 'https://cloud.google.com/vpc/docs/firewall-rules-logging' ref 'GCP Docs', url: 'https://cloud.google.com/vpc/docs/vpc#default-network' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/compute/networks/delete' describe "[#{gcp_project_id}] Subnets" do subject { google_compute_networks(project: gcp_project_id) } its('network_names') { should_not include 'default' } end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.09-iam.rb
controls/1.09-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that Cloud KMS cryptokeys are not anonymously or publicly accessible' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.9' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure that Cloud KMS cryptokeys are not anonymously or publicly accessible" desc 'It is recommended that the IAM policy on Cloud KMS cryptokeys should restrict anonymous and/or public access.' desc 'rationale', 'Granting permissions to allUsers or allAuthenticatedUsers allows anyone to access the dataset. Such access might not be desirable if sensitive data is stored at the location. In this case, ensure that anonymous and/or public access to a Cloud KMS cryptokey is not allowed.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/kms/keys/remove-iam-policy-binding' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/kms/keys/set-iam-policy' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/kms/keys/get-iam-policy' ref 'GCP Docs', url: 'https://cloud.google.com/kms/docs/object-hierarchy#key_resource_id' # Get all "normal" regions and add dual/multi regions locations = google_compute_regions(project: gcp_project_id).region_names locations << 'global' << 'asia' << 'europe' << 'us' << 'eur4' << 'nam4' kms_cache = KMSKeyCache(project: gcp_project_id, locations: locations) # Ensure that keys aren't publicly accessible locations.each do |location| if kms_cache.kms_key_ring_names[location].empty? describe "[#{gcp_project_id}] does not contain any key rings in [#{location}]. This test is Not Applicable." do skip "[#{gcp_project_id}] does not contain any key rings in [#{location}]" end else kms_cache.kms_key_ring_names[location].each do |keyring| if kms_cache.kms_crypto_keys[location][keyring].empty? describe "[#{gcp_project_id}] key ring [#{keyring}] does not contain any cryptographic keys. This test is Not Applicable." do skip "[#{gcp_project_id}] key ring [#{keyring}] does not contain any cryptographic keys" end else kms_cache.kms_crypto_keys[location][keyring].each do |keyname| if google_kms_crypto_key_iam_policy(project: gcp_project_id, location: location, key_ring_name: keyring, crypto_key_name: keyname).bindings.nil? describe "[#{gcp_project_id}] key ring [#{keyring}] key [#{keyname}] does not have any IAM bindings. This test is Not Applicable." do skip "[#{gcp_project_id}] key ring [#{keyring}] key [#{keyname}] does not have any IAM bindings" end else impact 'medium' google_kms_crypto_key_iam_policy(project: gcp_project_id, location: location, key_ring_name: keyring, crypto_key_name: keyname).bindings.each do |binding| describe binding do its('members') { should_not include 'allUsers' } its('members') { should_not include 'allAuthenticatedUsers' } end end end end end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/6.07-db.rb
controls/6.07-db.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That Cloud SQL Database Instances Are Configured With Automated Backups' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '6.7' control_abbrev = 'db' sql_cache = CloudSQLCache(project: gcp_project_id) control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure That Cloud SQL Database Instances Are Configured With Automated Backups" desc 'It is recommended to have all SQL database instances set to enable automated backups.' desc 'rationale', 'Backups provide a way to restore a Cloud SQL instance to recover lost data or recover from a problem with that instance. Automated backups need to be set for any instance that contains data that should be protected from loss or damage. This recommendation is applicable for SQL Server, PostgreSql, MySql generation 1 and MySql generation 2 instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CP-9'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/backup-recovery/backups' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/backup-recovery/backups' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/sqlserver/backup-recovery/backups' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/backup-recovery/backing-up' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/backup-recovery/backing-up' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/sqlserver/backup-recovery/backing-up' if sql_cache.instance_names.empty? impact 'none' describe "[#{gcp_project_id}] does not have any CloudSQL instances, this test is Not Applicable" do skip "[#{gcp_project_id}] does not have any CloudSQL instances" end else sql_cache.instance_names.each do |db| describe "[#{gcp_project_id}] CloudSQL #{db} should have automated backups enabled and have a start time" do subject { sql_cache.instance_objects[db].settings.backup_configuration } its('enabled') { should cmp true } its('start_time') { should_not eq '' } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.07-networking.rb
controls/3.07-networking.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that RDP access is restricted from the internet' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.7' control_abbrev = 'networking' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure that RDP access is restricted from the internet" desc 'GCP Firewall Rules are specific to a VPC Network. Each rule either allows or denies traffic when its conditions are met. Its conditions allow users to specify the type of traffic, such as ports and protocols, and the source or destination of the traffic, including IP addresses, subnets, and instances. Firewall rules are defined at the VPC network level and are specific to the network in which they are defined. The rules themselves cannot be shared among networks. Firewall rules only support IPv4 traffic. When specifying a source for an ingress rule or a destination for an egress rule by address, an IPv4 address or IPv4 block in CIDR notation can be used. Generic (0.0.0.0/0) incoming traffic from the Internet to a VPC or VM instance using RDP on Port 3389 can be avoided.' desc 'rationale', 'GCP Firewall Rules within a VPC Network. These rules apply to outgoing (egress) traffic from instances and incoming (ingress) traffic to instances in the network. Egress and ingress traffic flows are controlled even if the traffic stays within the network (for example, instance-to-instance communication). For an instance to have outgoing Internet access, the network must have a valid Internet gateway route or custom route whose destination IP is specified. This route simply defines the path to the Internet, to avoid the most general (0.0.0.0/0) destination IP Range specified from the Internet through RDP with the default Port 3389. Generic access from the Internet to a specific IP Range should be restricted.' tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[CM-7 CA-3 SC-7] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/vpc/docs/firewalls#blockedtraffic' ref 'GCP Docs', url: 'https://cloud.google.com/blog/products/identity-security/cloud-iap-enables-context-aware-access-to-vms-via-ssh-and-rdp-without-bastion-hosts' google_compute_firewalls(project: gcp_project_id).where(firewall_direction: 'INGRESS').firewall_names.each do |firewall_name| describe "[#{gcp_project_id}] #{firewall_name}" do subject { google_compute_firewall(project: gcp_project_id, name: firewall_name) } it 'Should not allow RDP from 0.0.0.0/0' do expect(subject.allowed_rdp? && (subject.allow_ip_ranges? ['0.0.0.0/0'])).to be false end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.08-logging.rb
controls/2.08-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That the Log Metric Filter and Alerts Exist for VPC Network Route Changes' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.8' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure That the Log Metric Filter and Alerts Exist for VPC Network Route Changes" desc 'It is recommended that a metric filter and alarm be established for Virtual Private Cloud (VPC) network route changes.' desc 'rationale', "Google Cloud Platform (GCP) routes define the paths network traffic takes from a VM instance to another destination. The other destination can be inside the organization VPC network (such as another VM) or outside of it. Every route consists of a destination and a next hop. Traffic whose destination IP is within the destination range is sent to the next hop for delivery. Monitoring changes to route tables will help ensure that all VPC traffic flows through an expected path." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-3 AU-12] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/logs-based-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/custom-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/alerts/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/reference/tools/gcloud-logging' ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/access-control/iam' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/beta/logging/metrics/create' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/alpha/monitoring/policies/create' log_filter = 'resource.type=global AND jsonPayload.event_subtype="compute.routes.delete" OR jsonPayload.event_subtype="compute.routes.insert"' describe "[#{gcp_project_id}] VPC Route changes filter" do subject { google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter) } it { should exist } end google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter).metric_types.each do |metrictype| describe.one do filter = "metric.type=\"#{metrictype}\" resource.type=\"global\"" google_project_alert_policies(project: gcp_project_id).where(policy_enabled_state: true).policy_names.each do |policy| condition = google_project_alert_policy_condition(policy: policy, filter: filter) describe "[#{gcp_project_id}] VPC Route changes alert policy" do subject { condition } it { should exist } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.04-networking.rb
controls/3.04-networking.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that RSASHA1 is not used for key-signing key in Cloud DNS DNSSEC' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.4' control_abbrev = 'networking' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure that RSASHA1 is not used for key-signing key in Cloud DNS DNSSEC" desc 'NOTE: Currently, the SHA1 algorithm has been removed from general use by Google, and, if being used, needs to be whitelisted on a project basis by Google and will also, therefore, require a Google Cloud support contract. DNSSEC algorithm numbers in this registry may be used in CERT RRs. Zone signing (DNSSEC) and transaction security mechanisms (SIG(0) and TSIG) make use of particular subsets of these algorithms. The algorithm used for key signing should be a recommended one and it should be strong.' desc 'rationale', 'Domain Name System Security Extensions (DNSSEC) algorithm numbers in this registry may be used in CERT RRs. Zonesigning (DNSSEC) and transaction security mechanisms (SIG(0) and TSIG) make use of particular subsets of these algorithms. The algorithm used for key signing should be a recommended one and it should be strong. When enabling DNSSEC for a managed zone, or creating a managed zone with DNSSEC, the user can select the DNSSEC signing algorithms and the denial-of-existence type. Changing the DNSSEC settings is only effective for a managed zone if DNSSEC is not already enabled. If there is a need to change the settings for a managed zone where it has been enabled, turn DNSSEC off and then re-enable it with different settings.' tag cis_scored: false tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CM-6'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/dns/dnssec-advanced#advanced_signing_options' managed_zone_names = google_dns_managed_zones(project: gcp_project_id).zone_names if managed_zone_names.empty? describe "[#{gcp_project_id}] does not have DNS Zones. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have DNS Zones." end else managed_zone_names.each do |dnszone| zone = google_dns_managed_zone(project: gcp_project_id, zone: dnszone) if zone.visibility == 'private' describe "[#{gcp_project_id}] DNS zone #{dnszone} has private visibility. This test is not applicable for private zones." do skip "[#{gcp_project_id}] DNS zone #{dnszone} has private visibility." end elsif zone.dnssec_config.state == 'on' zone.dnssec_config.default_key_specs.select { |spec| spec.key_type == 'keySigning' }.each do |spec| impact 'medium' describe "[#{gcp_project_id}] DNS Zone [#{dnszone}] with DNSSEC key-signing" do subject { spec } its('algorithm') { should_not cmp 'RSASHA1' } its('algorithm') { should_not cmp nil } end end else impact 'medium' describe "[#{gcp_project_id}] DNS Zone [#{dnszone}] DNSSEC" do subject { 'off' } it { should cmp 'on' } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.04-logging.rb
controls/2.04-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure Log Metric Filter and Alerts Exist for Project Ownership Assignments/Changes' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.4' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure Log Metric Filter and Alerts Exist for Project Ownership Assignments/Changes" desc "In order to prevent unnecessary project ownership assignments to users/service-accounts and further misuses of projects and resources, all roles/Owner assignments should be monitored. Members (users/Service-Accounts) with role assignment to primitive role roles/owner are Project Owners. Project Owner has all the privileges on a project it belongs to. These can be summarized as below: - All viewer permissions on All GCP Services part within the project - Permissions for actions that modify state of All GCP Services within the project - Manage roles and permissions for a project and all resources within the project - Set up billing for a project Granting owner role to a member (user/Service-Account) will allow members to modify the IAM policy. Therefore grant the owner role only if the member has a legitimate purpose to manage the IAM policy. This is because as project IAM policy contains sensitive access control data and having a minimal set of users manage it will simplify any auditing that you may have to do." desc 'rationale', "Project Ownership Having highest level of privileges on a project, to avoid misuse of project resources project ownership assignment/change actions mentioned should be monitored and alerted to concerned recipients. - Sending project ownership Invites - Acceptance/Rejection of project ownership invite by user - Adding `role\owner` to a user/service-account - Removing a user/Service account from `role\owner`" tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-12'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/logs-based-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/custom-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/alerts/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/reference/tools/gcloud-logging' log_filter = 'resource.type=audited_resource AND (protoPayload.serviceName="cloudresourcemanager.googleapis.com") AND (ProjectOwnership OR projectOwnerInvitee) OR (protoPayload.serviceData.policyDelta.bindingDeltas.action="REMOVE" AND protoPayload.serviceData.policyDelta.bindingDeltas.role="roles/owner") OR (protoPayload.serviceData.policyDelta.bindingDeltas.action="ADD" AND protoPayload.serviceData.policyDelta.bindingDeltas.role="roles/owner")' describe "[#{gcp_project_id}] Project Ownership changes filter" do subject { google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter) } it { should exist } end google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter).metric_types.each do |metrictype| describe.one do filter = "metric.type=\"#{metrictype}\" resource.type=\"audited_resource\"" google_project_alert_policies(project: gcp_project_id).where(policy_enabled_state: true).policy_names.each do |policy| condition = google_project_alert_policy_condition(policy: policy, filter: filter) describe "[#{gcp_project_id}] Project Ownership changes alert policy" do subject { condition } it { should exist } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.10-iam.rb
controls/1.10-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure KMS Encryption Keys Are Rotated Within a Period of 90 Days' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.10' control_abbrev = 'iam' kms_rotation_period_seconds = input('kms_rotation_period_seconds') control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure KMS Encryption Keys Are Rotated Within a Period of 90 Days" desc "Google Cloud Key Management Service stores cryptographic keys in a hierarchical structure designed for useful and elegant access control management. The format for the rotation schedule depends on the client library that is used. For the gcloud command-line tool, the next rotation time must be in ISO or RFC3339 format, and the rotation period must be in the form INTEGER[UNIT], where units can be one of seconds (s), minutes (m), hours (h) or days (d)." desc 'rationale', "Set a key rotation period and starting time. A key can be created with a specified rotation period, which is the time between when new key versions are generated automatically. A key can also be created with a specified next rotation time. A key is a named object representing a cryptographic key used for a specific purpose. The key material, the actual bits used for encryption, can change over time as new key versions are created. A key is used to protect some corpus of data. A collection of files could be encrypted with the same key and people with decrypt permissions on that key would be able to decrypt those files. Therefore, it's necessary to make sure the rotation period is set to a specific time." tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/kms/docs/key-rotation#frequency_of_key_rotation' ref 'GCP Docs', url: 'https://cloud.google.com/kms/docs/re-encrypt-data' # Get all "normal" regions and add dual/multi regions locations = google_compute_regions(project: gcp_project_id).region_names locations << 'global' << 'asia' << 'europe' << 'us' << 'eur4' << 'nam4' kms_cache = KMSKeyCache(project: gcp_project_id, locations: locations) # Ensure KMS keys autorotate 90d or less locations.each do |location| if kms_cache.kms_key_ring_names[location].empty? describe "[#{gcp_project_id}] does not contain any key rings in [#{location}]. This test is Not Applicable." do skip "[#{gcp_project_id}] does not contain any key rings in [#{location}]" end else kms_cache.kms_key_ring_names[location].each do |keyring| if kms_cache.kms_crypto_keys[location][keyring].empty? describe "[#{gcp_project_id}] key ring [#{keyring}] does not contain any cryptographic keys. This test is Not Applicable." do skip "[#{gcp_project_id}] key ring [#{keyring}] does not contain any cryptographic keys" end else kms_cache.kms_crypto_keys[location][keyring].each do |keyname| key = google_kms_crypto_key(project: gcp_project_id, location: location, key_ring_name: keyring, name: keyname) next unless key.purpose == 'ENCRYPT_DECRYPT' && key.primary_state == 'ENABLED' impact 'medium' describe "[#{gcp_project_id}] #{key.crypto_key_name}" do subject { key } its('rotation_period') { should_not eq nil } unless key.rotation_period.nil? rotation_period_int = key.rotation_period.delete_suffix('s').to_i it "should have a lower or equal rotation period than #{kms_rotation_period_seconds}" do expect(rotation_period_int).to be <= kms_rotation_period_seconds end its('next_rotation_time') { should be <= (Time.now + kms_rotation_period_seconds) } end end end end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.14-logging.rb
controls/2.14-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title "Ensure 'Access Transparency' is 'Enabled'" gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') # org_id = input('org_id') # Potentially for future use if InSpec resource becomes available control_id = '2.14' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure 'Access Transparency' is 'Enabled'" desc 'GCP Access Transparency provides audit logs for all actions that Google personnel take in your Google Cloud resources.' desc 'rationale', "Controlling access to your information is one of the foundations of information security. Given that Google Employees do have access to your organizations' projects for support reasons, you should have logging in place to view who, when, and why your information is being accessed. To use Access Transparency your organization will need to have at one of the following support level: Premium, Enterprise, Platinum, or Gold. There will be subscription costs associated with support, as well as increased storage costs for storing the logs." tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[] # Add relevant NIST controls if any in future ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-transparency/docs/overview' ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-transparency/docs/enable' ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-transparency/docs/reading-logs' ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-transparency/docs/reading-logs#justification_reason_codes' ref 'GCP Docs', url: 'https://cloud.google.com/cloud-provider-access-management/access-transparency/docs/supported-services' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.01-vms.rb
controls/4.01-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title ' Ensure that instances are not configured to use the default service account ' gcp_project_id = input('gcp_project_id') gce_zones = input('gce_zones') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.1' control_abbrev = 'vms' gce_instances = GCECache(project: gcp_project_id, gce_zones: gce_zones).gce_instances_cache control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that instances are not configured to use the default compute engine service account with full access to all Cloud APIs" desc 'To support principle of least privileges and prevent potential privilege escalation it is recommended that instances are not assigned to default service account Compute Engine default service account' desc 'rationale', 'The default Compute Engine service account has the Editor role on the project, which allows read and write access to most Google Cloud Services. To defend against privilege escalations if your VM is compromised and prevent an attacker from gaining access to all of your project, it is recommended to not use the default Compute Engine service account. Instead, you should create a new service account and assigning only the permissions needed by your instance.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AC-2 AC-6] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/access/service-accounts' project_number = google_project(project: gcp_project_id).project_number gce_instances.each do |instance| next if instance[:name] =~ /^gke-/ google_compute_instance(project: gcp_project_id, zone: instance[:zone], name: instance[:name]).service_accounts.each do |serviceaccount| describe "VM #{instance[:name]} should not include the default compute engine service account" do subject { serviceaccount.email } it { should_not include("#{project_number}-compute@developer.gserviceaccount.com") } end end end if gce_instances.empty? impact 'none' describe "[#{gcp_project_id}] No Google Compute Engine instances were found. This test is Not Applicable." do skip "[#{gcp_project_id}] No Google Compute Engine instances were found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/5.01-storage.rb
controls/5.01-storage.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that Cloud Storage bucket is not anonymously or publicly accessible' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '5.1' control_abbrev = 'storage' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure that Cloud Storage bucket is not anonymously or publicly accessible" desc 'It is recommended that IAM policy on Cloud Storage bucket does not allows anonymous or public access.' desc 'rationale', 'Allowing anonymous or public access grants permissions to anyone to access bucket content. Such access might not be desired if you are storing any sensitive data. Hence, ensure that anonymous or public access to a bucket is not allowed.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AC-2 CA-3] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/access-control/iam-reference' ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/access-control/making-data-public' ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/gsutil/commands/iam' storage_buckets = google_storage_buckets(project: gcp_project_id).bucket_names storage_buckets.each do |bucket| google_storage_bucket_iam_bindings(bucket: bucket).iam_binding_roles.each do |role| describe "[#{gcp_project_id}] GCS Bucket #{bucket}, Role: #{role}" do subject { google_storage_bucket_iam_binding(bucket: bucket, role: role) } its('members') { should_not include 'allUsers' } its('members') { should_not include 'allAuthenticatedUsers' } end end end if storage_buckets.empty? impact 'none' describe "[#{gcp_project_id}] No Google Storage Buckets were found. This test is Not Applicable." do skip "[#{gcp_project_id}] No Google Storage Buckets were found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.07-vms.rb
controls/4.07-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure VM disks for critical VMs are encrypted with CustomerSupplied Encryption Keys (CSEK)' gcp_project_id = input('gcp_project_id') gce_zones = input('gce_zones') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.7' control_abbrev = 'vms' gce_instances = GCECache(project: gcp_project_id, gce_zones: gce_zones).gce_instances_cache control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure VM disks for critical VMs are encrypted with CustomerSupplied Encryption Keys (CSEK)" desc 'Customer-Supplied Encryption Keys (CSEK) are a feature in Google Cloud Storage and Google Compute Engine. If you supply your own encryption keys, Google uses your key to protect the Google-generated keys used to encrypt and decrypt your data. By default, Google Compute Engine encrypts all data at rest. Compute Engine handles and manages this encryption for you without any additional actions on your part. However, if you wanted to control and manage this encryption yourself, you can provide your own encryption keys.' desc 'rationale', "By default, Google Compute Engine encrypts all data at rest. Compute Engine handles and manages this encryption for you without any additional actions on your part. However, if you wanted to control and manage this encryption yourself, you can provide your own encryption keys. If you provide your own encryption keys, Compute Engine uses your key to protect the Google-generated keys used to encrypt and decrypt your data. Only users who can provide the correct key can use resources protected by a customer-supplied encryption key. Google does not store your keys on its servers and cannot access your protected data unless you provide the key. This also means that if you forget or lose your key, there is no way for Google to recover the key or to recover any data encrypted with the lost key. At least business critical VMs should have VM disks encrypted with CSEK." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-1'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/disks/customer-supplied-encryption#encrypt_a_new_persistent_disk_with_your_own_keys' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/reference/rest/v1/disks/get' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/disks/customer-supplied-encryption#key_file' gce_instances.each do |instance| next if instance[:name] =~ /^gke-/ describe "[#{gcp_project_id}] Instance #{instance[:zone]}/#{instance[:name]}" do subject { google_compute_instance(project: gcp_project_id, zone: instance[:zone], name: instance[:name]) } it { should have_disks_encrypted_with_csek } end end if gce_instances.empty? impact 'none' describe "[#{gcp_project_id}] No Google Compute Engine instances were found. This test is Not Applicable." do skip "[#{gcp_project_id}] No Google Compute Engine instances were found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.13-logging.rb
controls/2.13-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure Cloud Asset Inventory Is Enabled' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.13' control_abbrev = 'logging' # As per existing structure, though control is about Asset Inventory control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure Cloud Asset Inventory Is Enabled" desc "GCP Cloud Asset Inventory is services that provides a historical view of GCP resources and IAM policies through a time-series database. The information recorded includes metadata on Google Cloud resources, metadata on policies set on Google Cloud projects or resources, and runtime information gathered within a Google Cloud resource. Cloud Asset Inventory Service (CAIS) API enablement is not required for operation of the service, but rather enables the mechanism for searching/exporting CAIS asset data directly." desc 'rationale', "The GCP resources and IAM policies captured by GCP Cloud Asset Inventory enables security analysis, resource change tracking, and compliance auditing. It is recommended GCP Cloud Asset Inventory be enabled for all GCP projects." tag cis_scored: false tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[] # Add relevant NIST controls if any in future ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/asset-inventory/docs' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.08-networking.rb
controls/3.08-networking.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that VPC Flow Logs is Enabled for Every Subnet in a VPC Network' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.8' control_abbrev = 'networking' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure that VPC Flow Logs is Enabled for Every Subnet in a VPC Network" desc "Flow Logs is a feature that enables users to capture information about the IP traffic going to and from network interfaces in the organization's VPC Subnets. Once a flow log is created, the user can view and retrieve its data in Stackdriver Logging. It is recommended that Flow Logs be enabled for every business-critical VPC subnet." desc 'rationale', "VPC networks and subnetworks not reserved for internal HTTP(S) load balancing provide logically isolated and secure network partitions where GCP resources can be launched. When Flow Logs are enabled for a subnet, VMs within that subnet start reporting on all Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) flows. Each VM samples the TCP and UDP flows it sees, inbound and outbound, whether the flow is to or from another VM, a host in the on-premises datacenter, a Google service, or a host on the Internet. If two GCP VMs are communicating, and both are in subnets that have VPC Flow Logs enabled, both VMs report the flows. Flow Logs supports the following use cases: - Network monitoring - Understanding network usage and optimizing network traffic expenses - Network forensics - Real-time security analysis Flow Logs provide visibility into network traffic for each VM inside the subnet and can be used to detect anomalous traffic or provide insight during security workflows. The Flow Logs must be configured such that all network traffic is logged, the interval of logging is granular to provide detailed information on the connections, no logs are filtered, and metadata to facilitate investigations are included." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-12 SI-4] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/vpc/docs/using-flow-logs#enabling_vpc_flow_logging' ref 'GCP Docs', url: 'https://cloud.google.com/vpc/' google_compute_regions(project: gcp_project_id).region_names.each do |region| google_compute_subnetworks(project: gcp_project_id, region: region).subnetwork_names.each do |subnet| subnet_obj = google_compute_subnetwork(project: gcp_project_id, region: region, name: subnet) if subnet_obj.purpose == 'INTERNAL_HTTPS_LOAD_BALANCER' # filter subnets for internal HTTPs Load Balancing describe "[#{gcp_project_id} #{region}/#{subnet}] does not support VPC Flow Logs. This test is Not Applicable." do skip "[#{gcp_project_id} #{region}/#{subnet}] does not support VPC Flow Logs." end else describe "[#{gcp_project_id}] #{region}/#{subnet}" do subject { subnet_obj } if subnet_obj.methods.include?(:log_config) == true it 'should have logging enabled' do expect(subnet_obj.log_config.enable).to be true end end end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.16-logging.rb
controls/2.16-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure Logging is enabled for HTTP(S) Load Balancer' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.16' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure Logging is enabled for HTTP(S) Load Balancer" desc 'Logging enabled on a HTTPS Load Balancer will show all network traffic and its destination.' desc 'rationale', 'Logging will allow you to view HTTPS network traffic to your web applications. On high use systems with a high percentage sample rate, the logging file may grow to high capacity in a short amount of time. Ensure that the sample rate is set appropriately so that storage costs are not exorbitant.' tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[] # Add relevant NIST controls if any in future ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/load-balancing/' ref 'GCP Docs', url: 'https://cloud.google.com/load-balancing/docs/https/https-logging-monitoring#gcloud:-global-mode' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/compute/backend-services/' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.08-iam.rb
controls/1.08-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that Separation of duties is enforced while assigning service account related roles to users' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.8' control_abbrev = 'iam' iam_bindings_cache = IAMBindingsCache(project: gcp_project_id) control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure that Separation of duties is enforced while assigning service account related roles to users" desc "It is recommended that the principle of 'Separation of Duties' is enforced while assigning service-account related roles to users." desc 'rationale', "The built-in/predefined IAM role Service Account admin allows the user/identity to create, delete, and manage service account(s). The built-in/predefined IAM role Service Account User allows the user/identity (with adequate privileges on Compute and App Engine) to assign service account(s) to Apps/Compute Instances. Separation of duties is the concept of ensuring that one individual does not have all necessary permissions to be able to complete a malicious action. In Cloud IAM - service accounts, this could be an action such as using a service account to access resources that user should not normally have access to. Separation of duties is a business control typically used in larger organizations, meant to help avoid security or privacy incidents and errors. It is considered best practice. No user should have Service Account Admin and Service Account User roles assigned at the same time." tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AC-2 AC-3] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/service-accounts' ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/understanding-roles' ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/granting-roles-to-service-accounts' sa_admins = iam_bindings_cache.iam_bindings['roles/iam.serviceAccountAdmin'] if sa_admins.nil? || sa_admins.members.count.zero? describe "[#{gcp_project_id}] does not contain users with roles/serviceAccountAdmin. This test is Not Applicable." do skip "[#{gcp_project_id}] does not contain users with roles/serviceAccountAdmin" end elsif iam_bindings_cache.iam_bindings['roles/iam.serviceAccountUser'].nil? describe "[#{gcp_project_id}] does not contain users with roles/serviceAccountUser. This test is Not Applicable." do skip "[#{gcp_project_id}] does not contain users with roles/serviceAccountUser" end else impact 'medium' describe "[#{gcp_project_id}] roles/serviceAccountUser" do subject { iam_bindings_cache.iam_bindings['roles/iam.serviceAccountUser'] } sa_admins.members.each do |sa_admin| its('members.to_s') { should_not match sa_admin } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/7.02-bq.rb
controls/7.02-bq.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that all BigQuery tables are encrypted with customer-managed encryption key (CMEK)' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '7.2' control_abbrev = 'storage' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure that all BigQuery tables are encrypted with customer-managed encryption key (CMEK)" desc 'BigQuery by default encrypts the data as rest by employing Envelope Encryption using Google managed cryptographic keys. The data is encrypted using the data encryption keys and data encryption keys themselves are further encrypted using key encryption keys. This is seamless and do not require any additional input from the user. However, if you want to have greater control, Customer-managed encryption keys (CMEK) can be used as encryption key management solution for BigQuery Data Sets. If CMEK is used, the CMEK is used to encrypt the data encryption keys instead of using google-managed encryption keys.' desc 'rationale', 'BigQuery by default encrypts the data as rest by employing Envelope Encryption using Google managed cryptographic keys. This is seamless and does not require any additional input from the user. For greater control over the encryption, customer-managed encryption keys (CMEK) can be used as encryption key management solution for BigQuery tables. The CMEK is used to encrypt the data encryption keys instead of using google-managed encryption keys. BigQuery stores the table and CMEK association and the encryption/decryption is done automatically. Applying the Default Customer-managed keys on BigQuery data sets ensures that all the new tables created in the future will be encrypted using CMEK but existing tables need to be updated to use CMEK individually.' tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-1'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/bigquery/docs/customer-managed-encryption' if google_bigquery_datasets(project: gcp_project_id).ids.empty? impact 'none' describe "[#{gcp_project_id}] does not have BigQuery Datasets, this test is Not Applicable." do skip "[#{gcp_project_id}] does not have BigQuery Datasets" end else google_bigquery_datasets(project: gcp_project_id).ids.each do |dataset_full_id| dataset_id = dataset_full_id.split(':', 2).last tables = google_bigquery_tables(project: gcp_project_id, dataset: dataset_id).table_references if tables.empty? describe "[#{gcp_project_id}] BigQuery Dataset #{dataset_id} has no tables, this test is Not Applicable." do skip "[#{gcp_project_id}] BigQuery Dataset #{dataset_id} has no tables" end else tables.each do |table_reference| describe "[#{gcp_project_id}] BigQuery Table #{table_reference.table_id} should use customer-managed encryption keys (CMEK)" do subject { google_bigquery_table(project: gcp_project_id, dataset: dataset_id, name: table_reference.table_id).encryption_configuration } its('kms_key_name') { should_not eq nil } end end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.03-logging.rb
controls/2.03-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That Retention Policies on Cloud Storage Buckets Used for Exporting Logs Are Configured Using Bucket Lock' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.3' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure That Retention Policies on Cloud Storage Buckets Used for Exporting Logs Are Configured Using Bucket Lock" desc 'Enabling retention policies on log buckets will protect logs stored in cloud storage buckets from being overwritten or accidentally deleted. It is recommended to set up retention policies and configure Bucket Lock on all storage buckets that are used as log sinks.' desc 'rationale', "Logs can be exported by creating one or more sinks that include a log filter and a destination. As Cloud Logging receives new log entries, they are compared against each sink. If a log entry matches a sink's filter, then a copy of the log entry is written to the destination. Sinks can be configured to export logs in storage buckets. It is recommended to configure a data retention policy for these cloud storage buckets and to lock the data retention policy; thus permanently preventing the policy from being reduced or removed. This way, if the system is ever compromised by an attacker or a malicious insider who wants to cover their tracks, the activity logs are definitely preserved for forensics and security investigations." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-6'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/bucket-lock' ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/using-bucket-lock' if google_logging_project_sinks(project: gcp_project_id).where(destination: /storage.googleapis.com/).destinations.empty? describe "[#{gcp_project_id}] does not have logging sinks configured." do subject { google_logging_project_sinks(project: gcp_project_id).where(destination: /storage.googleapis.com/).destinations } it { should_not be_empty } end else google_logging_project_sinks(project: gcp_project_id).where(destination: /storage.googleapis.com/).destinations.each do |sink| bucket = sink.split('/').last describe "[#{gcp_project_id}] Logging bucket #{bucket} retention policy Bucket Lock status" do subject { google_storage_bucket(name: bucket).retention_policy } its('is_locked') { should be true } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.17-iam.rb
controls/1.17-iam.rb
# Copyright 2025 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure Secrets are Not Stored in Cloud Functions Environment Variables by Using Secret Manager' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.17' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure Secrets are Not Stored in Cloud Functions Environment Variables by Using Secret Manager" desc 'Google Cloud Functions allow you to host serverless code that is executed when an event is triggered, without the requiring the management a host operating system. These functions can also store environment variables to be used by the code that may contain authentication or other information that needs to remain confidential.' desc 'rationale', 'It is recommended to use the Secret Manager, because environment variables are stored unencrypted, and accessible for all users who have access to the code.' tag cis_scored: false tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-28'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/functions/docs/configuring/env-var#managing_secrets' ref 'GCP Docs', url: 'https://cloud.google.com/secret-manager/docs/overview' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/7.04-bq.rb
controls/7.04-bq.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure all data in BigQuery has been classified' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '7.4' control_abbrev = 'storage' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure all data in BigQuery has been classified" desc 'BigQuery tables can contain sensitive data that for security purposes should be discovered, monitored, classified, and protected. Google Clouds Sensitive Data Protection tools can automatically provide data classification of all BigQuery data across an organization.' desc 'rationale', 'Using a cloud service or 3rd party software to continuously monitor and automate the process of data discovery and classification for BigQuery tables is an important part of protecting the data. Sensitive Data Protection is a fully managed data protection and data privacy platform that uses machine learning and pattern matching to discover and classify sensitive data in Google Cloud.' tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/dlp/docs/data-profiles' ref 'GCP Docs', url: 'https://cloud.google.com/dlp/docs/analyze-data-profiles' ref 'GCP Docs', url: 'https://cloud.google.com/dlp/docs/data-profiles-remediation' ref 'GCP Docs', url: 'https://cloud.google.com/dlp/docs/send-profiles-to-scc' ref 'GCP Docs', url: 'https://cloud.google.com/dlp/docs/profile-org-folder#chronicle' ref 'GCP Docs', url: 'https://cloud.google.com/dlp/docs/profile-org-folder#publish-pubsub' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/6.02-db.rb
controls/6.02-db.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that Cloud SQL database Instances are secure' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') log_min_messages = input('log_min_messages') log_min_error_statement = input('log_min_error_statement') log_error_verbosity = input('log_error_verbosity') log_statement = input('log_statement') control_id = '6.2' control_abbrev = 'db' sql_cache = CloudSQLCache(project: gcp_project_id) sql_instance_names = sql_cache.instance_names # 6.2.1 sub_control_id = "#{control_id}.1" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'Log_error_verbosity’ Database Flag for Cloud SQL PostgreSQL Instance Is Set to 'DEFAULT’ or Stricter" desc 'The log_error_verbosity flag controls the verbosity/details of messages logged. Valid values are: • TERSE • DEFAULT • VERBOSE TERSE excludes the logging of DETAIL, HINT, QUERY, and CONTEXT error information. VERBOSE output includes the SQLSTATE error code, source code file name, function name, and line number that generated the error. Ensure an appropriate value is set to \'DEFAULT\' or stricter.' desc 'rationale', 'Auditing helps in troubleshooting operational problems and also permits forensic analysis. If log_error_verbosity is not set to the correct value, too many details or too few details may be logged. This flag should be configured with a value of \'DEFAULT\' or stricter. This recommendation is applicable to PostgreSQL database instances.' tag cis_scored: true tag cis_level: 2 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/flags' ref 'GCP Docs', url: 'https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-ERROR-VERBOSITY' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'POSTGRES' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'log_error_verbosity' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'log_error_verbosity' set to #{log_error_verbosity} " do subject { flag } its('name') { should cmp 'log_error_verbosity' } its('value') { should cmp log_error_verbosity } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end # 6.2.2 sub_control_id = "#{control_id}.2" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure that the 'Log_connections’ database flag for cloud SQL PostgreSQL instance is set to 'on’" desc 'Enabling the log_connections setting causes each attempted connection to the server to be logged, along with successful completion of client authentication. This parameter cannot be changed after the session starts.' desc 'rationale', "PostgreSQL does not log attempted connections by default. Enabling the log_connections setting will create log entries for each attempted connection as well as successful completion of client authentication which can be useful in troubleshooting issues and to determine any unusual connection attempts to the server. This recommendation is applicable to PostgreSQL database instances." tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/flags' ref 'GCP Docs', url: 'https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-CONNECTIONS' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'POSTGRES' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'log_connections' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'log_connections' set to 'on' " do subject { flag } its('name') { should cmp 'log_connections' } its('value') { should cmp 'on' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end # 6.2.3 sub_control_id = "#{control_id}.3" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure that the 'Log_disconnections’ database flag for cloud SQL PostgreSQL instance is set to 'on’" desc 'Enabling the log_disconnections setting logs the end of each session, including the session duration.' desc 'rationale', "PostgreSQL does not log session details such as duration and session end by default. Enabling the log_disconnections setting will create log entries at the end of each session which can be useful in troubleshooting issues and determine any unusual activity across a time period. The log_disconnections and log_connections work hand in hand and generally, the pair would be enabled/disabled together. This recommendation is applicable to PostgreSQL database instances." tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/flags' ref 'GCP Docs', url: 'https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-DISCONNECTIONS' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'POSTGRES' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'log_disconnections' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'log_disconnections' set to 'on' " do subject { flag } its('name') { should cmp 'log_disconnections' } its('value') { should cmp 'on' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end # 6.2.4 sub_control_id = "#{control_id}.4" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'Log_statement’ database flag for cloud SQL PostgreSQL instance is set appropriately" desc "The value of log_statement flag determined the SQL statements that are logged. Valid values are: • none • ddl • mod • all The value ddl logs all data definition statements. The value mod logs all ddl statements, plus data-modifying statements. The statements are logged after a basic parsing is done and statement type is determined, thus this does not logs statements with errors. When using extended query protocol, logging occurs after an Execute message is received and values of the Bind parameters are included. A value of 'ddl' is recommended unless otherwise directed by your organizations logging policy." desc 'rationale', "Auditing helps in forensic analysis. If log_statement is not set to the correct value, too many statements may be logged leading to issues in finding the relevant information from the logs, or too few statements may be logged with relevant information missing from the logs. Setting log_statement to align with your organizations security and logging policies facilitates later auditing and review of database activities. This recommendation is applicable to PostgreSQL database instances." tag cis_scored: true tag cis_level: 2 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/flags' ref 'GCP Docs', url: 'https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-STATEMENT' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'POSTGRES' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'log_duration' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'log_duration' set to 'on' " do subject { flag } its('name') { should cmp 'log_duration' } its('value') { should cmp 'on' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end # 6.2.4 sub_control_id = "#{control_id}.4" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'log_statement' database flag for Cloud SQL PostgreSQL instance is set appropriately" desc 'The value of log_statement flag determined the SQL statements that are logged. Valid values are: - none - ddl - mod - all The value ddl logs all data definition statements. The value mod logs all ddl statements, plus data-modifying statements. The statements are logged after a basic parsing is done and statement type is determined, thus this does not logs statements with errors. When using extended query protocol, logging occurs after an Execute message is received and values of the Bind parameters are included. A value of \'ddl\' is recommended unless otherwise directed by your organization\'s logging policy.' desc 'rationale', 'Auditing helps in troubleshooting operational problems and also permits forensic analysis. If log_statement is not set to the correct value, too many statements may be logged leading to issues in finding the relevant information from the logs, or too few statements may be logged with relevant information missing from the logs. Setting log_statement to align with your organization\'s security and logging policies facilitates later auditing and review of database activities. This recommendation is applicable to PostgreSQL database instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/flags' ref 'GCP Docs', url: 'https://www.postgresql.org/docs/current/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'POSTGRES' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'log_statement' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'log_statement' set to #{log_statement} " do subject { flag } its('name') { should cmp 'log_statement' } its('value') { should cmp log_statement } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end # 6.2.5 sub_control_id = "#{control_id}.5" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure that the 'Log_min_messages’ flag for a cloud SQL PostgreSQL instance is set at minimum to 'warning'" desc 'The log_min_messages flag defines the minimum message severity level that is considered as an error statement. Messages for error statements are logged with the SQL statement. Valid values include (from lowest to highest severity) DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each severity level includes the subsequent levels mentioned above. ERROR is considered the best practice setting. Changes should only be made in accordance with the organizations logging policy' desc 'rationale', "Auditing helps in troubleshooting operational problems and also permits forensic analysis. If log_min_messages is not set to the correct value, messages may not be classified as error messages appropriately. Setting the threshold to 'Warning' will log messages for the most needed error messages. This recommendation is applicable to PostgreSQL database instances." tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/flags' ref 'GCP Docs', url: 'https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-MIN-MESSAGES' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'POSTGRES' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'log_min_messages' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'log_min_messages' set to #{log_min_messages}" do subject { flag } its('name') { should cmp 'log_min_messages' } its('value') { should cmp log_min_messages } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end # 6.2.6 sub_control_id = "#{control_id}.6" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'Log_min_error_statement’ database flag for cloud SQL PostgreSQL instance is set to 'Error’ or stricter" desc 'The log_min_error_statement flag defines the minimum message severity level that are considered as an error statement. Messages for error statements are logged with the SQL statement. Valid values include (from lowest to highest severity) DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each severity level includes the subsequent levels mentioned above. Ensure a value of ERROR or stricter is set.' desc 'rationale', 'Auditing helps in troubleshooting operational problems and also permits forensic analysis. If log_min_error_statement is not set to the correct value, messages may not be classified as error messages appropriately. Considering general log messages as error messages would make is difficult to find actual errors and considering only stricter severity levels as error messages may skip actual errors to log their SQL statements. The log_min_error_statement flag should be set to ERROR or stricter. This recommendation is applicable to PostgreSQL database instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/flags' ref 'GCP Docs', url: 'https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-MIN-ERROR-STATEMENT' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'POSTGRES' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'log_min_error_statement' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'log_min_error_statement' set to #{log_min_error_statement}" do subject { flag } its('name') { should cmp 'log_min_error_statement' } its('value') { should cmp log_min_error_statement } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database" end end end if sql_instance_names.empty? impact 'none' describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end # 6.2.7 sub_control_id = "#{control_id}.7" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure That the 'Log_min_duration_statement’ Database Flag for Cloud SQL PostgreSQL Instance Is Set to '-1' (Disabled)" desc 'The log_min_duration_statement flag defines the minimum amount of execution time of a statement in milliseconds where the total duration of the statement is logged. Ensure that log_min_duration_statement is disabled, i.e., a value of -1 is set.' desc 'rationale', 'Logging SQL statements may include sensitive information that should not be recorded in logs. This recommendation is applicable to PostgreSQL database instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/flags' ref 'GCP Docs', url: 'https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'POSTGRES' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'log_min_duration_statement' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'log_min_duration_statement' set to '-1' " do subject { flag } its('name') { should cmp 'log_min_duration_statement' } its('value') { should cmp '-1' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end # 6.2.8 sub_control_id = "#{control_id}.8" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure That 'cloudsql.enable_pgaudit' Database Flag for each Cloud Sql Postgresql Instance Is Set to 'on' For Centralized Logging" desc 'Ensure cloudsql.enable_pgaudit database flag for Cloud SQL PostgreSQL instance is set to on to allow for centralized logging.' desc 'rationale', 'As numerous other recommendations in this section consist of turning on flags for logging purposes, your organization will need a way to manage these logs. You may have a solution already in place. If you do not, consider installing and enabling the open source pgaudit extension within PostgreSQL and enabling its corresponding flag of cloudsql.enable_pgaudit. This flag and installing the extension enables database auditing in PostgreSQL through the open-source pgAudit extension. This extension provides detailed session and object logging to comply with government, financial, & ISO standards and provides auditing capabilities to mitigate threats by monitoring security events on the instance. Enabling the flag and settings later in this recommendation will send these logs to Google Logs Explorer so that you can access them in a central location. to This recommendation is applicable only to PostgreSQL database instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AU-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/flags#list-flags-postgres' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/pg-audit#enable-auditing-flag' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/pg-audit#customizing-database-audit-logging' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/audit/configure-data-access#config-console-enable' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'POSTGRES' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'enable_pgaudit' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'enable_pgaudit' set to 'on'" do subject { flag } its('name') { should cmp 'enable_pgaudit' } its('value') { should cmp 'on' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a PostgreSQL database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.01-iam.rb
controls/1.01-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that corporate login credentials are used' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.1' control_abbrev = 'iam' # Initialize the IAMBindingsCache outside the control for efficiency # This resource likely holds the IAM bindings for the project. iam_bindings_cache = IAMBindingsCache(project: gcp_project_id) control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure that corporate login credentials are used" desc 'Use corporate login credentials instead of personal accounts, such as Gmail accounts.' desc 'rationale', "It is recommended fully-managed corporate Google accounts be used for increased visibility, auditing, and controlling access to Cloud Platform resources. Email accounts based outside of the user's organization, such as personal accounts, should not be used for business purposes." tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/docs/enterprise/best-practices-for-enterprise-organizations#use_corporate_login_credentials' org_domain = nil project_parent = google_project(project: gcp_project_id).parent if project_parent.nil? # This project is likely a standalone project with no organization parent. # In this scenario, checking corporate login credentials might not be applicable # or you might need a different way to define the 'corporate domain'. # For now, we'll skip if no parent is found. describe "Project #{gcp_project_id} has no organization or folder parent." do skip 'Cannot determine corporate domain. Skipping check for corporate login credentials.' end else case project_parent.type when 'organization' org_id = project_parent.id org_resource = google_organization(name: "organizations/#{org_id}") if org_resource.exists? org_domain = org_resource.display_name else # Fallback if organization resource doesn't exist or is inaccessible describe "Could not retrieve organization details for ID: #{org_id}." do skip 'Cannot determine corporate domain. Skipping check for corporate login credentials.' end end when 'folder' current_folder_id = project_parent.id found_organization = false # Loop upwards until an organization is found or we run out of parents while current_folder_id folder_resource = google_resourcemanager_folder(name: "folders/#{current_folder_id}") if folder_resource.exists? # rubocop:disable Metrics/BlockNesting parent_name = folder_resource.parent # This will be like "folders/123" or "organizations/456" if parent_name.include?('organizations/') org_id = parent_name.sub('organizations/', '') org_resource = google_organization(name: "organizations/#{org_id}") if org_resource.exists? org_domain = org_resource.display_name found_organization = true break # Exit loop once organization is found else # Organization parent exists but cannot be retrieved describe "Could not retrieve organization details for ID: #{org_id} (parent of folder #{current_folder_id})." do skip 'Cannot determine corporate domain. Skipping check for corporate login credentials.' end break # Exit loop as we hit an issue end elsif parent_name.include?('folders/') current_folder_id = parent_name.sub('folders/', '') # Move up to the next folder else # Unexpected parent type for a folder describe "Unexpected parent type '#{parent_name}' for folder #{current_folder_id}." do skip 'Cannot determine corporate domain. Skipping check for corporate login credentials.' end break # Exit loop end else # Folder resource itself doesn't exist or is inaccessible describe "Folder resource 'folders/#{current_folder_id}' not found or inaccessible." do skip 'Cannot determine corporate domain. Skipping check for corporate login credentials.' end break # Exit loop end end unless found_organization describe "Could not find an organization parent for project #{gcp_project_id} through its folder hierarchy." do skip 'Cannot determine corporate domain. Skipping check for corporate login credentials.' end end else # Handle other potential parent types (e.g., `None` for standalone projects, or future types) describe "Project #{gcp_project_id} has an unsupported parent type: #{project_parent.type}." do skip 'Cannot determine corporate domain. Skipping check for corporate login credentials.' end end end # Proceed with IAM checks only if org_domain was successfully determined if org_domain.nil? describe 'Corporate domain could not be determined.' do skip 'Skipping IAM member checks as corporate domain is unknown.' end else iam_bindings_cache.iam_binding_roles.each do |role| iam_bindings_cache.iam_bindings[role].members.each do |member| # Skip service accounts next if member.to_s.end_with?('.gserviceaccount.com') # Skip allUsers and allAuthenticatedUsers next if %w[allUsers allAuthenticatedUsers].include?(member.to_s) describe "[#{gcp_project_id}] [Role:#{role}] Its member #{member}" do subject { member.to_s } # Using `should not match` for personal accounts implies any non-corporate domain # If the intent is strictly to allow ONLY corporate domains, then `should match` # but usually the goal is to exclude personal ones. it { should match(/@#{Regexp.escape(org_domain)}/) } # Use Regexp.escape for safety end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.16-iam.rb
controls/1.16-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure Essential Contacts is Configured for Organization' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.16' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure Essential Contacts is Configured for Organization" desc 'It is recommended that Essential Contacts is configured to designate email addresses for Google Cloud services to notify of important technical or security information.' desc 'rationale', 'Many Google Cloud services, such as Cloud Billing, send out notifications to share important information with Google Cloud users. By default, these notifications are sent to members with certain Identity and Access Management (IAM) roles. With Essential Contacts, you can customize who receives notifications by providing your own list of contacts.' tag cis_scored: false tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CP-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/resource-manager/docs/managing-notification-contacts' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.06-vms.rb
controls/4.06-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that IP forwarding is not enabled on Instances' gcp_project_id = input('gcp_project_id') gce_zones = input('gce_zones') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.6' control_abbrev = 'vms' gce_instances = GCECache(project: gcp_project_id, gce_zones: gce_zones).gce_instances_cache control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that IP forwarding is not enabled on Instances" desc "Compute Engine instance cannot forward a packet unless the source IP address of the packet matches the IP address of the instance. Similarly, GCP won't deliver a packet whose destination IP address is different than the IP address of the instance receiving the packet. However, both capabilities are required if you want to use instances to help route packets. Forwarding of data packets should be disabled to prevent data loss or information disclosure." desc 'rationale', "Compute Engine instance cannot forward a packet unless the source IP address of the packet matches the IP address of the instance. Similarly, GCP won't deliver a packet whose destination IP address is different than the IP address of the instance receiving the packet. However, both capabilities are required if you want to use instances to help route packets. To enable this source and destination IP check, disable the canIpForward field, which allows an instance to send and receive packets with non-matching destination or source IPs." tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[CM-6 CM-8] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/networking#canipforward' gce_instances.each do |instance| next if instance[:name] =~ /^gke-/ gce = google_compute_instance(project: gcp_project_id, zone: instance[:zone], name: instance[:name]) describe.one do describe "[#{gcp_project_id}] Instance #{instance[:zone]}/#{instance[:name]}" do subject { gce } its('can_ip_forward') { should be false } end describe "[#{gcp_project_id}] Instance #{instance[:zone]}/#{instance[:name]} ip-forwarding disabled" do subject { gce } it { should exist } end end end if gce_instances.empty? impact 'none' describe "[#{gcp_project_id}] No Google Compute Engine instances were found. This test is Not Applicable." do skip "[#{gcp_project_id}] No Google Compute Engine instances were found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.05-logging.rb
controls/2.05-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That the Log Metric Filter and Alerts Exist for Audit Configuration Changes' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.5' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure That the Log Metric Filter and Alerts Exist for Audit Configuration Changes" desc "Google Cloud Platform (GCP) services write audit log entries to the Admin Activity and Data Access logs to help answer the questions of, 'who did what, where, and when?' within GCP projects. Cloud audit logging records information includes the identity of the API caller, the time of the API call, the source IP address of the API caller, the request parameters, and the response elements returned by GCP services. Cloud audit logging provides a history of GCP API calls for an account, including API calls made via the console, SDKs, command-line tools, and other GCP services." desc 'rationale', 'Admin activity and data access logs produced by cloud audit logging enable security analysis, resource change tracking, and compliance auditing. Configuring the metric filter and alerts for audit configuration changes ensures the recommended state of audit configuration is maintained so that all activities in the project are audit-able at any point in time.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-3 AU-12] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/logs-based-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/custom-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/alerts/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/reference/tools/gcloud-logging' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/audit/configure-data-access#getiampolicy-setiampolicy' log_filter = 'resource.type=audited_resource AND protoPayload.methodName="SetIamPolicy" AND protoPayload.serviceData.policyDelta.auditConfigDeltas:*' describe "[#{gcp_project_id}] Audit configuration changes filter" do subject { google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter) } it { should exist } end google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter).metric_types.each do |metrictype| describe.one do filter = "metric.type=\"#{metrictype}\" resource.type=\"audited_resource\"" google_project_alert_policies(project: gcp_project_id).where(policy_enabled_state: true).policy_names.each do |policy| condition = google_project_alert_policy_condition(policy: policy, filter: filter) describe "[#{gcp_project_id}] Audit configuration changes alert policy" do subject { condition } it { should exist } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.03-vms.rb
controls/4.03-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title "Ensure 'Block Project-wide SSH keys' is enabled for VM instances" gcp_project_id = input('gcp_project_id') gce_zones = input('gce_zones') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.3' control_abbrev = 'vms' gce_instances = GCECache(project: gcp_project_id, gce_zones: gce_zones).gce_instances_cache control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure 'Block Project-wide SSH keys' enabled for VM instances" desc 'It is recommended to user Instance specific SSH key(s) instead of using common/shared project-wide SSH key(s) to access Instances.' desc 'rationale', 'Project-wide SSH keys are stored in Compute/Project-meta-data. Project wide SSH keys can be used to login into all the instances within project. Using project-wide SSH keys eases the SSH key management but if compromised, poses the security risk which can impact all the instances within project. It is recommended to use Instance specific SSH keys which can limit the attack surface if the SSH keys are compromised.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys' gce_instances.each do |instance| next if instance[:name] =~ /^gke-/ describe "[#{gcp_project_id}] Instance #{instance[:zone]}/#{instance[:name]}" do subject { google_compute_instance(project: gcp_project_id, zone: instance[:zone], name: instance[:name]) } its('block_project_ssh_keys') { should be true } end end if gce_instances.empty? impact 'none' describe "[#{gcp_project_id}] No Google Compute Engine instances were found. This test is Not Applicable." do skip "[#{gcp_project_id}] No Google Compute Engine instances were found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.05-iam.rb
controls/1.05-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that ServiceAccount has no Admin privileges.' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.5' control_abbrev = 'iam' iam_bindings_cache = IAMBindingsCache(project: gcp_project_id) control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that ServiceAccount has no Admin privileges." desc "A service account is a special Google account that belongs to an application or a VM, instead of to an individual end-user. The application uses the service account to call the service's Google API so that users aren't directly involved. It's recommended not to use admin access for ServiceAccount." desc 'rationale', "Service accounts represent service-level security of the Resources (application or a VM) which can be determined by the roles assigned to it. Enrolling ServiceAccount with Admin rights gives full access to an assigned application or a VM. A ServiceAccount Access holder can perform critical actions like delete, update change settings, etc. without user intervention. For this reason, it's recommended that service accounts not have Admin rights." tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/iam/service-accounts/' ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/understanding-roles' ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/understanding-service-accounts' iam_bindings_cache.iam_bindings.keys.grep(/admin/i).each do |role| role_bindings = iam_bindings_cache.iam_bindings[role] if role_bindings.members.nil? impact 'none' describe "[#{gcp_project_id}] Role bindings for role [#{role}] do not contain any members. This test is Not Applicable." do skip "[#{gcp_project_id}] role bindings for role [#{role}] do not contain any members." end else describe "[#{gcp_project_id}] Admin role [#{role}]" do subject { role_bindings } its('members') { should_not include(/@[a-z][a-z0-9|-]{4,28}[a-z].iam.gserviceaccount.com/) } end end end iam_bindings_cache.iam_bindings.keys.grep(%r{roles/editor}).each do |role| members_in_scope = [] iam_bindings_cache.iam_bindings[role].members.each do |member| next if member.include? '@containerregistry.iam.gserviceaccount.com' members_in_scope.push(member) end describe "[#{gcp_project_id}] Project Editor Role" do subject { members_in_scope } it { should_not include(/@[a-z][a-z0-9|-]{4,28}[a-z].iam.gserviceaccount.com/) } end end iam_bindings_cache.iam_bindings.keys.grep(%r{roles/owner}).each do |role| describe "[#{gcp_project_id}] Project Owner Role" do subject { iam_bindings_cache.iam_bindings[role] } its('members') { should_not include(/@[a-z][a-z0-9|-]{4,28}[a-z].iam.gserviceaccount.com/) } end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.05-vms.rb
controls/4.05-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title "Ensure 'Enable connecting to serial ports' is not enabled for VM Instance" gcp_project_id = input('gcp_project_id') gce_zones = input('gce_zones') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.5' control_abbrev = 'vms' gce_instances = GCECache(project: gcp_project_id, gce_zones: gce_zones).gce_instances_cache control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure 'Enable connecting to serial ports' is not enabled for VM Instance" desc "Interacting with a serial port is often referred to as the serial console, which is similar to using a terminal window, in that input and output is entirely in text mode and there is no graphical interface or mouse support. If you enable the interactive serial console on an instance, clients can attempt to connect to that instance from any IP address. Therefore interactive serial console support should be disabled." desc 'rationale', "A virtual machine instance has four virtual serial ports. Interacting with a serial port is similar to using a terminal window, in that input and output is entirely in text mode and there is no graphical interface or mouse support. The instance's operating system, BIOS, and other system-level entities often write output to the serial ports, and can accept input such as commands or answers to prompts. Typically, these system-level entities use the first serial port (port 1) and serial port 1 is often referred to as the serial console. The interactive serial console does not support IP-based access restrictions such as IP whitelists. If you enable the interactive serial console on an instance, clients can attempt to connect to that instance from any IP address. This allows anybody to connect to that instance if they know the correct SSH key, username, project ID, zone, and instance name. Therefore interactive serial console support should be disabled." tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CM-7'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/instances/interacting-with-serial-console' gce_instances.each do |instance| describe "[#{gcp_project_id}] Instance #{instance[:zone]}/#{instance[:name]}" do subject { google_compute_instance(project: gcp_project_id, zone: instance[:zone], name: instance[:name]) } it { should have_serial_port_disabled } end end if gce_instances.empty? impact 'none' describe "[#{gcp_project_id}] No Google Compute Engine instances were found. This test is Not Applicable." do skip "[#{gcp_project_id}] No Google Compute Engine instances were found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.05-networking.rb
controls/3.05-networking.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That RSASHA1 Is Not Used for the Zone-Signing Key in Cloud DNS DNSSEC' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.5' control_abbrev = 'networking' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure That RSASHA1 Is Not Used for the Zone-Signing Key in Cloud DNS DNSSEC" desc 'NOTE: Currently, the SHA1 algorithm has been removed from general use by Google, and, if being used, needs to be whitelisted on a project basis by Google and will also, therefore, require a Google Cloud support contract. DNSSEC algorithm numbers in this registry may be used in CERT RRs. Zone signing (DNSSEC) and transaction security mechanisms (SIG(0) and TSIG) make use of particular subsets of these algorithms. The algorithm used for key signing should be a recommended one and it should be strong.' desc 'rationale', "DNSSEC algorithm numbers in this registry may be used in CERT RRs. Zone signing (DNSSEC) and transaction security mechanisms (SIG(0) and TSIG) make use of particular subsets of these algorithms. The algorithm used for key signing should be a recommended one and it should be strong. When enabling DNSSEC for a managed zone, or creating a managed zone with DNSSEC, the DNSSEC signing algorithms and the denial-of-existence type can be selected. Changing the DNSSEC settings is only effective for a managed zone if DNSSEC is not already enabled. If the need exists to change the settings for a managed zone where it has been enabled, turn DNSSEC off and then re-enable it with different settings." tag cis_scored: false tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CM-6'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/dns/dnssec-advanced#advanced_signing_options' managed_zone_names = google_dns_managed_zones(project: gcp_project_id).zone_names if managed_zone_names.empty? describe "[#{gcp_project_id}] does not have DNS Zones. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have DNS Zones." end else managed_zone_names.each do |dnszone| zone = google_dns_managed_zone(project: gcp_project_id, zone: dnszone) if zone.visibility == 'private' describe "[#{gcp_project_id}] DNS zone #{dnszone} has private visibility. This test is not applicable for private zones." do skip "[#{gcp_project_id}] DNS zone #{dnszone} has private visibility." end elsif zone.dnssec_config.state == 'on' zone.dnssec_config.default_key_specs.select { |spec| spec.key_type == 'zoneSigning' }.each do |spec| impact 'medium' describe "[#{gcp_project_id}] DNS Zone [#{dnszone}] with DNSSEC zone-signing" do subject { spec } its('algorithm') { should_not cmp 'RSASHA1' } its('algorithm') { should_not cmp nil } end end else impact 'medium' describe "[#{gcp_project_id}] DNS Zone [#{dnszone}] DNSSEC" do subject { 'off' } it { should cmp 'on' } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/6.04-db.rb
controls/6.04-db.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That the Cloud SQL Database Instance Requires All Incoming Connections To Use SSL' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '6.4' control_abbrev = 'db' sql_cache = CloudSQLCache(project: gcp_project_id) sql_instance_names = sql_cache.instance_names control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure That the Cloud SQL Database Instance Requires All Incoming Connections To Use SSL" desc 'It is recommended to enforce all incoming connections to SQL database instance to use SSL.' desc 'rationale', 'SQL database connections if successfully trapped (MITM); can reveal sensitive data like credentials, database queries, query outputs etc. For security, it is recommended to always use SSL encryption when connecting to your instance. This recommendation is applicable for Postgresql, MySql generation 1, MySql generation 2 and SQL Server 2017 instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[SC-1 SC-8] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/configure-ssl-instance/' if sql_instance_names.empty? impact 'none' describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end else sql_instance_names.each do |db| describe "[#{gcp_project_id}] CloudSQL #{db}" do subject { sql_cache.instance_objects[db] } it { should have_ip_configuration_require_ssl } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.01-logging.rb
controls/2.01-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That Cloud Audit Logging Is Configured Properly' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.1' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure That Cloud Audit Logging Is Configured Properly" desc 'It is recommended that Cloud Audit Logging is configured to track all admin activities and read, write access to user data.' desc 'rationale', "Cloud Audit Logging maintains two audit logs for each project and organization: Admin Activity nd Data Access. 1. Admin Activity logs contain log entries for API calls or other administrative actions that modify the configurati n or metadata of resources. Admin Activity audit logs are enabled for all services and cannot be configured. 2. Data Access audit logs record API calls that create, modify, or read user-provided data. These are disabled by de ault and should be enabled. There are three kinds of Data Access audit log information: - Admin read: Records operations that read metadata or configuration information. Admin Activity audit logs recor writes of metadata and configuration information which cannot be disabled. - Data read: Records operations that read user-provided data. - Data write: Records operations that write user-provided data. It is recommended to have effective default audit config configured in such a way that: 1. logtype is set to DATA_READ (to logs user activity tracking) and DATA_WRITES (to log changes/tampering to user data) 2. audit config is enabled for all the services supported by Data Access audit logs feature 3. Logs should be captured for all users. i.e. there are no exempted users in any of the audit config section. This will ensure overriding audit config will not contradict the requirement." tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-6 AU-12] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/audit/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/audit/configure-data-access' describe google_project_logging_audit_config(project: gcp_project_id) do its('default_types') { should include 'DATA_READ' } its('default_types') { should include 'DATA_WRITE' } it { should_not have_default_exempted_members } end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.09-vms.rb
controls/4.09-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That Compute Instances Do Not Have Public IP Addresses (Automated)' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.09' control_abbrev = 'vms' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure That Compute Instances Do Not Have Public IP Addresses (Automated)" desc 'Compute instances should not be configured to have external IP addresses. Removing the external IP address from your Compute instance may cause some applications to stop working.' desc 'rationale', "To reduce your attack surface, Compute instances should not have public IP addresses. Instead, instances should be configured behind load balancers, to minimize the instance's exposure to the internet." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[] # Add relevant NIST controls if any in future ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/load-balancing/docs/backend-service#backends_and_external_ip_addresses' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/instances/connecting-advanced#sshbetweeninstances' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/instances/connecting-to-instance' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address#unassign_ip' ref 'GCP Docs', url: 'https://cloud.google.com/resource-manager/docs/organization-policy/org-policy-constraints' ref 'Organization Policy', url: 'https://console.cloud.google.com/orgpolicies/compute-vmExternalIpAccess' # control_id and control_abbrev are already defined above instances_found = false google_compute_zones(project: gcp_project_id).zone_names.each do |zone_name| google_compute_instances(project: gcp_project_id, zone: zone_name) .where { instance_name !~ /^gke-/ } .where(status: 'RUNNING') .instance_names.each do |instance_name| instances_found = true describe "[#{gcp_project_id}] Instance: #{instance_name} in Zone: #{zone_name}" do subject { google_compute_instance(project: gcp_project_id, zone: zone_name, name: instance_name) } it 'should not have an external IP assigned' do subject.network_interfaces.each do |iface| has_external_ip = iface.access_configs&.any? { |ac| !ac.nat_ip.nil? && !ac.nat_ip.empty? } expect(has_external_ip).to be_falsey end end end end end unless instances_found describe "[#{control_abbrev.upcase}] #{control_id} - No Non-GKE Running Instances Found" do skip 'No non-GKE running compute instances were found in the project, this control is Not Applicable.' end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.09-networking.rb
controls/3.09-networking.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure No HTTPS or SSL Proxy Load Balancers Permit SSL Policies With Weak Cipher Suites' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.9' control_abbrev = 'networking' gcp_https_proxies = google_compute_target_https_proxies(project: gcp_project_id).names gcp_ssl_policies = google_compute_ssl_policies(project: gcp_project_id).names control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure No HTTPS or SSL Proxy Load Balancers Permit SSL Policies With Weak Cipher Suites" desc 'Secure Sockets Layer (SSL) policies determine what port Transport Layer Security (TLS) features clients are permitted to use when connecting to load balancers. To prevent usage of insecure features, SSL policies should use (a) at least TLS 1.2 with the MODERN profile; or (b) the RESTRICTED profile, because it effectively requires clients to use TLS 1.2 regardless of the chosen minimum TLS version; or (3) a CUSTOM profile that does not support any of the following features: TLS_RSA_WITH_AES_128_GCM_SHA256 TLS_RSA_WITH_AES_256_GCM_SHA384 TLS_RSA_WITH_AES_128_CBC_SHA TLS_RSA_WITH_AES_256_CBC_SHA TLS_RSA_WITH_3DES_EDE_CBC_SHA' desc 'rationale', 'Load balancers are used to efficiently distribute traffic across multiple servers. Both SSL proxy and HTTPS load balancers are external load balancers, meaning they distribute traffic from the Internet to a GCP network. GCP customers can configure load balancer SSL policies with a minimum TLS version (1.0, 1.1, or 1.2) that clients can use to establish a connection, along with a profile (Compatible, Modern, Restricted, or Custom) that specifies permissible cipher suites. To comply with users using outdated protocols, GCP load balancers can be configured to permit insecure cipher suites. In fact, the GCP default SSL policy uses a minimum TLS version of 1.0 and a Compatible profile, which allows the widest range of insecure cipher suites. As a result, it is easy for customers to configure a load balancer without even knowing that they are permitting outdated cipher suites.' tag cis_scored: false tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-1'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/load-balancing/docs/use-ssl-policies' ref 'GCP Docs', url: 'https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-52r.pdf' # All load balancers have custom/strong TLS profiles set gcp_https_proxies.each do |proxy| describe "[#{gcp_project_id}] HTTPS Proxy: #{proxy}" do subject { google_compute_target_https_proxy(project: gcp_project_id, name: proxy) } it 'should have a custom SSL policy configured' do expect(subject.ssl_policy).to_not cmp(nil) end end end # Ensure SSL Policies use strong TLS gcp_ssl_policies.each do |policy| case google_compute_ssl_policy(project: gcp_project_id, name: policy).profile when 'MODERN' describe "[#{gcp_project_id}] SSL Policy: #{policy}" do subject { google_compute_ssl_policy(project: gcp_project_id, name: policy) } it 'should minimally require TLS 1.2' do expect(subject.min_tls_version).to cmp('TLS_1_2') end end when 'RESTRICTED' describe "[#{gcp_project_id}] SSL Policy: #{policy} profile should be RESTRICTED" do subject { google_compute_ssl_policy(project: gcp_project_id, name: policy).profile } it { should cmp 'RESTRICTED' } end when 'CUSTOM' describe "[#{gcp_project_id}] SSL Policy: #{policy} profile CUSTOM should not contain these cipher suites [TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_3DES_EDE_CBC_SHA] " do subject { google_compute_ssl_policy(project: gcp_project_id, name: policy) } its('custom_features') { should_not be_in %w[TLS_RSA_WITH_AES_128_GCM_SHA256 TLS_RSA_WITH_AES_256_GCM_SHA384 TLS_RSA_WITH_AES_128_CBC_SHA TLS_RSA_WITH_AES_256_CBC_SHA TLS_RSA_WITH_3DES_EDE_CBC_SHA] } end end end if gcp_https_proxies.empty? && gcp_ssl_policies.empty? impact 'none' describe "[#{gcp_project_id}] No HTTPS or SSL proxy load balancers found. This test is Not Applicable." do skip "[#{gcp_project_id}] No HTTPS or SSL proxy load balancers found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.11-logging.rb
controls/2.11-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That the Log Metric Filter and Alerts Exist for SQL Instance Configuration Changes' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.11' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure log metric filter and alerts exists for SQL instance configuration changes" desc 'It is recommended that a metric filter and alarm be established for SQL instance configuration changes.' desc 'rationale', "Monitoring changes to SQL instance configuration changes may reduce the time needed to detect and correct misconfigurations done on the SQL server. Below are a few of the configurable options which may the impact security posture of an SQL instance: - Enable auto backups and high availability: Misconfiguration may adversely impact business continuity, disaster recovery, and high availability - Authorize networks: Misconfiguration may increase exposure to untrusted networks" tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-3 AU-12] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/logs-based-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/custom-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/alerts/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/reference/tools/gcloud-logging' ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/overview' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/postgres/' log_filter = 'resource.type=audited_resource AND protoPayload.methodName="cloudsql.instances.update"' describe "[#{gcp_project_id}] Cloud SQL changes filter" do subject { google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter) } it { should exist } end google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter).metric_types.each do |metrictype| describe.one do filter = "metric.type=\"#{metrictype}\" resource.type=\"audited_resource\"" google_project_alert_policies(project: gcp_project_id).where(policy_enabled_state: true).policy_names.each do |policy| condition = google_project_alert_policy_condition(policy: policy, filter: filter) describe "[#{gcp_project_id}] Cloud SQL changes alert policy" do subject { condition } it { should exist } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.07-logging.rb
controls/2.07-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That the Log Metric Filter and Alerts Exist for VPC Network Firewall Rule Changes' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.7' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure That the Log Metric Filter and Alerts Exist for VPC Network Firewall Rule Changes" desc 'It is recommended that a metric filter and alarm be established for Virtual Private Cloud (VPC) Network Firewall rule changes.' desc 'rationale', 'Monitoring for Create or Update Firewall rule events gives insight to network access changes and may reduce the time it takes to detect suspicious activity.' tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-3 AU-12] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/logs-based-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/custom-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/alerts/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/reference/tools/gcloud-logging' ref 'GCP Docs', url: 'https://cloud.google.com/vpc/docs/firewalls' log_filter = 'resource.type=global AND jsonPayload.event_subtype="compute.firewalls.patch" OR jsonPayload.event_subtype="compute.firewalls.insert"' describe "[#{gcp_project_id}] VPC FW Rule changes filter" do subject { google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter) } it { should exist } end google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter).metric_types.each do |metrictype| describe.one do filter = "metric.type=\"#{metrictype}\" resource.type=\"global\"" google_project_alert_policies(project: gcp_project_id).where(policy_enabled_state: true).policy_names.each do |policy| condition = google_project_alert_policy_condition(policy: policy, filter: filter) describe "[#{gcp_project_id}] VPC FW Rule changes alert policy" do subject { condition } it { should exist } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.11-iam.rb
controls/1.11-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that Separation of duties is enforced while assigning KMS related roles to users' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.11' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that Separation of duties is enforced while assigning KMS related roles to users" desc "It is recommended that the principle of 'Separation of Duties' is enforced while assigning KMS related roles to users." desc 'rationale', "The built-in/predefined IAM role Cloud KMS Admin allows the user/identity to create, delete, and manage service account(s). The built-in/predefined IAM role Cloud KMS CryptoKey Encrypter/Decrypter allows the user/identity (with adequate privileges on concerned resources) to encrypt and decrypt data at rest using an encryption key(s). The built-in/predefined IAM role Cloud KMS CryptoKey Encrypter allows the user/identity (with adequate privileges on concerned resources) to encrypt data at rest using an encryption key(s). The built-in/predefined IAM role Cloud KMS CryptoKey Decrypter allows the user/identity (with adequate privileges on concerned resources) to decrypt data at rest using an encryption key(s). Separation of duties is the concept of ensuring that one individual does not have all necessary permissions to be able to complete a malicious action. In Cloud KMS, this could be an action such as using a key to access and decrypt data a user should not normally have access to. Separation of duties is a business control typically used in larger organizations, meant to help avoid security or privacy incidents and errors. It is considered best practice. No user(s) should have Cloud KMS Admin and any of the Cloud KMS CryptoKey Encrypter/Decrypter, Cloud KMS CryptoKey Encrypter, Cloud KMS CryptoKey Decrypter roles assigned at the same time." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AC-2 AC-3 AC-6] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/kms/docs/separation-of-duties' kms_admins = google_project_iam_binding(project: gcp_project_id, role: 'roles/cloudkms.admin') if kms_admins.members.nil? || kms_admins.members.count.zero? impact 'none' describe "[#{gcp_project_id}] does not have users with roles/CloudKMSAdmin. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have users with roles/CloudKMSAdmin" end else describe "[#{gcp_project_id}] roles/cloudkms.cryptoKeyEncrypter" do subject { google_project_iam_binding(project: gcp_project_id, role: 'roles/cloudkms.cryptoKeyEncrypter') } kms_admins.members.each do |kms_admin| its('members.to_s') { should_not match kms_admin } end end describe "[#{gcp_project_id}] roles/cloudkms.cryptoKeyDecrypter" do subject { google_project_iam_binding(project: gcp_project_id, role: 'roles/cloudkms.cryptoKeyDecrypter') } kms_admins.members.each do |kms_admin| its('members.to_s') { should_not match kms_admin } end end describe "[#{gcp_project_id}] roles/cloudkms.cryptoKeyEncrypterDecrypter" do subject { google_project_iam_binding(project: gcp_project_id, role: 'roles/cloudkms.cryptoKeyEncrypterDecrypter') } kms_admins.members.each do |kms_admin| its('members.to_s') { should_not match kms_admin } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.12-iam.rb
controls/1.12-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure API Keys Only Exist for Active Services' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.12' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure API Keys Only Exist for Active Services" desc 'API Keys should only be used for services in cases where other authentication methods are unavailable. Unused keys with their permissions in tact may still exist within a project. Keys are insecure because they can be viewed publicly, such as from within a browser, or they can be accessed on a device where the key resides. It is recommended to use standard authentication flow instead.' desc 'rationale', "To avoid the security risk in using API keys, it is recommended to use standard authentication flow instead. Security risks involved in using API-Keys appear below: - API keys are simple encrypted strings - API keys do not identify the user or the application making the API request - API keys are typically accessible to clients, making it easy to discover and steal an API key" tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/docs/authentication/api-keys' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/services/api-keys/list' ref 'GCP Docs', url: 'https://cloud.google.com/docs/authentication' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/services/api-keys/delete' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.15-iam.rb
controls/1.15-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure API Keys Are Rotated Every 90 Days' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.15' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure API keys are rotated every 90 days" desc 'API Keys should only be used for services in cases where other authentication methods are unavailable. If they are in use it is recommended to rotate API keys every 90 days.' desc 'rationale', "Security risks involved in using API-Keys are listed below: - API keys are simple encrypted strings - API keys do not identify the user or the application making the API request - API keys are typically accessible to clients, making it easy to discover and steal an API key Because of these potential risks, Google recommends using the standard authentication flow instead of API Keys. However, there are limited cases where API keys are more appropriate. For example, if there is a mobile application that needs to use the Google Cloud Translation API, but doesn't otherwise need a backend server, API keys are the simplest way to authenticate to that API. Once a key is stolen, it has no expiration, meaning it may be used indefinitely unless the project owner revokes or regenerates the key. Rotating API keys will reduce the window of opportunity for an access key that is associated with a compromised or terminated account to be used. API keys should be rotated to ensure that data cannot be accessed with an old key that might have been lost, cracked, or stolen." tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.13-iam.rb
controls/1.13-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure API Keys Are Restricted To Use by Only Specified Hosts and Apps' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.13' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure API Keys Are Restricted To Use by Only Specified Hosts and Apps" desc 'API Keys should only be used for services in cases where other authentication methods are unavailable. In this case, unrestricted keys are insecure because they can be viewed publicly, such as from within a browser, or they can be accessed on a device where the key resides. It is recommended to restrict API key usage to trusted hosts, HTTP referrers and apps. It is recommended to use the more secure standard authentication flow instead.' desc 'rationale', "Security risks involved in using API-Keys appear below: - API keys are simple encrypted strings - API keys do not identify the user or the application making the API request - API keys are typically accessible to clients, making it easy to discover and steal an API key In light of these potential risks, Google recommends using the standard authentication flow instead of API keys. However, there are limited cases where API keys are more appropriate. For example, if there is a mobile application that needs to use the Google Cloud Translation API, but doesn't otherwise need a backend server, API keys are the simplest way to authenticate to that API. In order to reduce attack vectors, API-Keys can be restricted only to trusted hosts, HTTP referrers and applications." tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/docs/authentication/api-keys' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/services/api-keys/list' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/services/api-keys/update' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/6.01-db.rb
controls/6.01-db.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that MySql database instances are secure.' # title 'Ensure that MySql database instance does not allow anyone to connect with administrative privileges.' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '6.1' control_abbrev = 'db' sql_cache = CloudSQLCache(project: gcp_project_id) sql_instance_names = sql_cache.instance_names # 6.1.1 sub_control_id = "#{control_id}.1" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure that MySql database instance does not allow anyone to connect with administrative privileges." desc "It is recommended to set a password for the administrative user (root by default) to prevent unauthorized access to the SQL database instances. This recommendation is applicable only for MySQL Instances. PostgreSQL does not offer any setting for No Password from the cloud console." desc 'rationale', 'At the time of MySQL Instance creation, not providing an administrative password allows anyone to connect to the SQL database instance with administrative privileges. The root password should be set to ensure only authorized users have these privileges.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['IA-5'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/create-manage-users' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/create-instance' describe 'This control is not scored' do skip 'This control is not scored' end end # 6.1.2 sub_control_id = "#{control_id}.2" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'Skip_show_database’ database flag for cloud SQL MySQL instance is set to 'On’" desc 'It is recommended to set skip_show_database database flag for Cloud SQL Mysql instance to on' desc 'rationale', "skip_show_database database flag prevents people from using the SHOW DATABASES statement if they do not have the SHOW DATABASES privilege. This can improve security if you have concerns about users being able to see databases belonging to other users. Its effect depends on the SHOW DATABASES privilege: If the variable value is ON, the SHOW DATABASES statement is permitted only to users who have the SHOW DATABASES privilege, and the statement displays all database names. If the value is OFF, SHOW DATABASES is permitted to all users, but displays the names of only those databases for which the user has the SHOW DATABASES or other privilege. This recommendation is applicable to Mysql database instances." tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/flags' ref 'GCP Docs', url: 'https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_skip_show_database' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'MYSQL' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'skip_show_database' describe flag do its('name') { should cmp 'skip_show_database' } its('value') { should cmp 'on' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a MySQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a MySQL database" end end end if sql_instance_names.empty? describe 'There are no Cloud SQL Instances in this project. This test is Not Applicable.' do skip 'There are no Cloud SQL Instances in this project' end end end # 6.1.3 sub_control_id = "#{control_id}.3" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure that the 'Local_infile’ database flag for a cloud SQL MySQL instance is set to 'off’" desc 'It is recommended to set the local_infile database flag for a Cloud SQL MySQL instance to off.' desc 'rationale', "The local_infile flag controls the server-side LOCAL capability for LOAD DATA statements. Depending on the local_infile setting, the server refuses or permits local data loading by clients that have LOCAL enabled on the client side. To explicitly cause the server to refuse LOAD DATA LOCAL statements (regardless of how client programs and libraries are configured at build time or runtime), start mysqld with local_infile disabled. local_infile can also be set at runtime. Due to security issues associated with the local_infile flag, it is recommended to disable it. This recommendation is applicable to MySQL database instances." tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-1'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/flags' ref 'GCP Docs', url: 'https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_local_infile' ref 'GCP Docs', url: 'https://dev.mysql.com/doc/refman/5.7/en/load-data-local.html' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'MYSQL' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'local_infile' describe flag do its('name') { should cmp 'local_infile' } its('value') { should cmp 'off' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a MySQL database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a MySQL database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/3.06-networking.rb
controls/3.06-networking.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that SSH access is restricted from the internet' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '3.6' control_abbrev = 'networking' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure that SSH access is restricted from the internet" desc 'GCP Firewall Rules are specific to a VPC Network. Each rule either allows or denies traffic when its conditions are met. Its conditions allow the user to specify the type of traffic, such as ports and protocols, and the source or destination of the traffic, including IP addresses, subnets, and instances. Firewall rules are defined at the VPC network level and are specific to the network in which they are defined. The rules themselves cannot be shared among networks. Firewall rules only support IPv4 traffic. When specifying a source for an ingress rule or a destination for an egress rule by address, only an IPv4 address or IPv4 block in CIDR notation can be used. Generic (0.0.0.0/0) incoming traffic from the internet to VPC or VM instance using SSH on Port 22 can be avoided.' desc 'rationale', 'GCP Firewall Rules within a VPC Network apply to outgoing (egress) traffic from instances and incoming (ingress) traffic to instances in the network. Egress and ingress traffic flows are controlled even if the traffic stays within the network (for example, instance-to-instance communication). For an instance to have outgoing Internet access, the network must have a valid Internet gateway route or custom route whose destination IP is specified. This route simply defines the path to the Internet, to avoid the most general (0.0.0.0/0) destination IP Range specified from the Internet through SSH with the default Port 22. Generic access from the Internet to a specific IP Range needs to be restricted.' tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[CM-7 CA-3 SC-7] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/vpc/docs/firewalls#blockedtraffic' ref 'GCP Docs', url: 'https://cloud.google.com/blog/products/identity-security/cloud-iap-enables-context-aware-access-to-vms-via-ssh-and-rdp-without-bastion-hosts' google_compute_firewalls(project: gcp_project_id).where(firewall_direction: 'INGRESS').firewall_names.each do |firewall_name| describe "[#{gcp_project_id}] #{firewall_name}" do subject { google_compute_firewall(project: gcp_project_id, name: firewall_name) } it 'should not allow SSH from 0.0.0.0/0' do expect(subject.allowed_ssh? && (subject.allow_ip_ranges? ['0.0.0.0/0'])).to be false end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/8.01-dp.rb
controls/8.01-dp.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that Dataproc Cluster is encrypted using Customer-Managed Encryption Key' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '8.1' control_abbrev = 'dataproc' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that Dataproc Cluster is encrypted using Customer-Managed Encryption Key" desc 'When you use Dataproc, cluster and job data is stored on Persistent Disks (PDs) associated with the Compute Engine VMs in your cluster and in a Cloud Storage staging bucket. This PD and bucket data is encrypted using a Google-generated data encryption key (DEK) and key encryption key (KEK). The CMEK feature allows you to create, use, and revoke the key encryption key (KEK). Google still controls the data encryption key (DEK).' desc 'rationale', 'Cloud services offer the ability to protect data related to those services using encryption keys managed by the customer within Cloud KMS. These encryption keys are called customer-managed encryption keys (CMEK). When you protect data in Google Cloud services with CMEK, the CMEK key is within your control.' tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-28'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/docs/security/encryption/default-encryption' # Fetch all available compute regions # This uses a helper method or a direct gcloud command execution # You might need to add a helper function in your libraries or execute a shell command # For simplicity, let's assume you have a way to get all regions. # A common way is to use a custom InSpec resource or shell out to gcloud. # Example using a placeholder for dynamic region discovery (you'd implement this) # In a real scenario, you might use `command('gcloud compute regions list --format="value(name)"').stdout.strip.split("\n")` # but directly executing `gcloud` within an InSpec resource's `initialize` or `filter` # methods can be tricky due to execution context and dependencies. # A better approach is to define a custom InSpec resource that wraps these gcloud calls. # For now, let's manually list some common regions, or pass them as an input if fixed. # If you need to make this fully dynamic without hardcoding, you would likely need a # custom InSpec resource that uses the Google Cloud SDK for Ruby to list regions. # For demonstration, let's use a hardcoded list of common regions. # In a real-world, dynamic scenario, you'd integrate a resource like `google_compute_regions` # or run a `gcloud` command to get the list. all_gcp_regions = google_compute_regions(project: gcp_project_id).region_names found_clusters = [] all_gcp_regions.each do |region| clusters_in_region = google_dataproc_clusters(project: gcp_project_id, region: region) found_clusters.concat(clusters_in_region.cluster_names.map { |name| { name: name, region: region } }) if clusters_in_region.cluster_names.any? rescue Inspec::Exceptions::ResourceFailed => e # This will catch errors if the Dataproc API isn't enabled in a region, # or if there are other region-specific issues. # You can log this for debugging if needed: # puts "Could not list clusters in region #{region}: #{e.message}" end if found_clusters.empty? describe "No Dataproc clusters found in project '#{gcp_project_id}' across all common regions." do subject { found_clusters } it { should be_empty } end else found_clusters.each do |cluster_info| cluster_name = cluster_info[:name] cluster_region = cluster_info[:region] cluster = google_dataproc_cluster(project: gcp_project_id, name: cluster_name, region: cluster_region) describe "[#{gcp_project_id}] Dataproc Cluster: #{cluster_name} in region #{cluster_region}" do subject { cluster } its('encryption_config.gce_pd_kms_key_name') { should_not be_nil } its('encryption_config.gce_pd_kms_key_name') { should_not be_empty } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.12-vms.rb
controls/4.12-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure the Latest Operating System Updates Are Installed On Your Virtual Machines in All Projects (Manual)' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.12' control_abbrev = 'vms' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure the Latest Operating System Updates Are Installed On Your Virtual Machines in All Projects (Manual)" desc 'Google Cloud Virtual Machines have the ability via an OS Config agent API to periodically (about every 10 minutes) report OS inventory data. A patch compliance API periodically reads this data, and cross references metadata to determine if the latest updates are installed. This is not the only Patch Management solution available to your organization and you should weigh your needs before committing to using this method. Most Operating Systems require a restart or changing critical resources to apply the updates. Using the Google Cloud VM manager for its OS Patch management will incur additional costs for each VM managed by it.' desc 'rationale', 'Keeping virtual machine operating systems up to date is a security best practice. Using this service will simplify this process.' tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[] # Add relevant NIST controls if any in future ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs - Manage OS', url: 'https://cloud.google.com/compute/docs/manage-os' ref 'GCP Docs - OS Patch Management', url: 'https://cloud.google.com/compute/docs/os-patch-management' ref 'GCP Docs - VM Manager', url: 'https://cloud.google.com/compute/docs/vm-manager' ref 'GCP Docs - OS Details VM Manager', url: 'https://cloud.google.com/compute/docs/images/os-details#vm-manager' ref 'GCP Docs - VM Manager Pricing', url: 'https://cloud.google.com/compute/docs/vm-manager#pricing' ref 'GCP Docs - Verify Setup', url: 'https://cloud.google.com/compute/docs/troubleshooting/vm-manager/verify-setup' ref 'GCP Docs - View OS Details', url: 'https://cloud.google.com/compute/docs/instances/view-os-details#view-data-tools' ref 'GCP Docs - Create Patch Job', url: 'https://cloud.google.com/compute/docs/os-patch-management/create-patch-job' ref 'GCP Docs - Setup NAT', url: 'https://cloud.google.com/nat/docs/set-up-network-address-translation' ref 'GCP Docs - Private Google Access', url: 'https://cloud.google.com/vpc/docs/configure-private-google-access' ref 'CIS Workbench Ref', url: 'https://workbench.cisecurity.org/sections/811638/recommendations/1334335' ref 'GCP Docs - OS Agent Install', url: 'https://cloud.google.com/compute/docs/manage-os#agent-install' ref 'GCP Docs - Verify SA Enabled', url: 'https://cloud.google.com/compute/docs/troubleshooting/vm-manager/verify-setup#service-account-enabled' ref 'GCP Docs - OS Patch Dashboard', url: 'https://cloud.google.com/compute/docs/os-patch-management#use-dashboard' ref 'GCP Docs - Verify Metadata Enabled', url: 'https://cloud.google.com/compute/docs/troubleshooting/vm-manager/verify-setup#metadata-enabled' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/7.01-bq.rb
controls/7.01-bq.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That BigQuery datasets are not anonymously or publicly accessible' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '7.1' control_abbrev = 'storage' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'high' title "[#{control_abbrev.upcase}] Ensure That BigQuery datasets are not anonymously or publicly accessible" desc 'It is recommended that the IAM policy on BigQuery datasets does not allow anonymous and/or public access.' desc 'rationale', 'Granting permissions to allUsers or allAuthenticatedUsers allows anyone to access the dataset. Such access might not be desirable if sensitive data is being stored in the dataset. Therefore, ensure that anonymous and/or public access to a dataset is not allowed.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/bigquery/docs/dataset-access-controls' if google_bigquery_datasets(project: gcp_project_id).ids.empty? impact 'none' describe "[#{gcp_project_id}] does not have BigQuery Datasets, this test is Not Applicable." do skip "[#{gcp_project_id}] does not have BigQuery Datasets" end else google_bigquery_datasets(project: gcp_project_id).ids.each do |name| google_bigquery_dataset(project: gcp_project_id, name: name.split(':').last).access.each do |access| describe "[#{gcp_project_id}] BigQuery Dataset #{name} should not be anonymously or publicly accessible," do subject { access } its('iam_member') { should_not cmp 'allUsers' } its('special_group') { should_not cmp 'allAuthenticatedUsers' } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/5.02-storage.rb
controls/5.02-storage.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that Cloud Storage buckets have uniform bucket-level access enabled' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '5.2' control_abbrev = 'storage' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that Cloud Storage buckets have uniform bucket-level access enabled" desc 'It is recommended that uniform bucket-level access is enabled on Cloud Storage buckets.' desc 'rationale', "It is recommended to use uniform bucket-level access to unify and simplify how you grant access to your Cloud Storage resources. Cloud Storage offers two systems for granting users permission to access your buckets and objects: Cloud Identity and Access Management (Cloud IAM) and Access Control Lists (ACLs).These systems act in parallel - in order for a user to access a Cloud Storage resource, only one of the systems needs to grant the user permission. Cloud IAM is used throughout Google Cloud and allows you to grant a variety of permissions at the bucket and project levels. ACLs are used only by Cloud Storage and have limited permission options, but they allow you to grant permissions on a per-object basis. In order to support a uniform permissioning system, Cloud Storage has uniform bucket-level access. Using this feature disables ACLs for all Cloud Storage resources: access to Cloud Storage resources then is granted exclusively through Cloud IAM. Enabling uniform bucket-level access guarantees that if a Storage bucket is not publicly accessible, no object in the bucket is publicly accessible either." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/uniform-bucket-level-access' ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/using-uniform-bucket-level-access' ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/setting-org-policies#uniform-bucket' storage_buckets = google_storage_buckets(project: gcp_project_id).bucket_names storage_buckets.each do |bucket| uniform_bucket_level_access = google_storage_bucket(name: bucket).acl.nil? describe "[#{gcp_project_id}] GCS Bucket #{bucket}" do it 'should have uniform bucket-level access enabled' do expect(uniform_bucket_level_access).to be true end end end if storage_buckets.empty? impact 'none' describe "[#{gcp_project_id}] No Google Storage Buckets were found. This test is Not Applicable." do skip "[#{gcp_project_id}] No Google Storage Buckets were found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.10-logging.rb
controls/2.10-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That the Log Metric Filter and Alerts Exist for Cloud Storage IAM Permission Changes' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.10' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure That the Log Metric Filter and Alerts Exist for Cloud Storage IAM Permission Changes" desc 'It is recommended that a metric filter and alarm be established for Cloud Storage Bucket IAM changes.' desc 'rationale', 'Monitoring changes to cloud storage bucket permissions may reduce the time needed to detect and correct permissions on sensitive cloud storage buckets and objects inside the bucket.' tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-3 AU-12] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/logs-based-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/custom-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/alerts/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/reference/tools/gcloud-logging' ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/overview' ref 'GCP Docs', url: 'https://cloud.google.com/storage/docs/access-control/iam-roles' log_filter = 'resource.type=gcs_bucket AND protoPayload.methodName="storage.setIamPermissions"' describe "[#{gcp_project_id}] Cloud Storage changes filter" do subject { google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter) } it { should exist } end google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter).metric_types.each do |metrictype| describe.one do filter = "metric.type=\"#{metrictype}\" resource.type=\"gcs_bucket\"" google_project_alert_policies(project: gcp_project_id).where(policy_enabled_state: true).policy_names.each do |policy| condition = google_project_alert_policy_condition(policy: policy, filter: filter) describe "[#{gcp_project_id}] Cloud Storage changes alert policy" do subject { condition } it { should exist } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.07-iam.rb
controls/1.07-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure user-managed/external keys for service accounts are rotated every 90 days or less' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.7' control_abbrev = 'iam' sa_key_older_than_seconds = input('sa_key_older_than_seconds') service_account_cache = ServiceAccountCache(project: gcp_project_id) control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure user-managed/external keys for service accounts are rotated every 90 days or less" desc 'Service Account keys consist of a key ID (Private_key_Id) and Private key, which are used to sign programmatic requests users make to Google cloud services accessible to that particular service account. It is recommended that all Service Account keys are regularly rotated.' desc 'rationale', "Rotating Service Account keys will reduce the window of opportunity for an access key that is associated with a compromised or terminated account to be used. Service Account keys should be rotated to ensure that data cannot be accessed with an old key that might have been lost, cracked, or stolen. Each service account is associated with a key pair managed by Google Cloud Platform (GCP). It is used for service-to-service authentication within GCP. Google rotates the keys daily. GCP provides the option to create one or more user-managed (also called external key pairs) key pairs for use from outside GCP (for example, for use with Application Default Credentials). When a new key pair is created, the user is required to download the private key (which is not retained by Google). With external keys, users are responsible for keeping the private key secure and other management operations such as key rotation. External keys can be managed by the IAM API, gcloud command-line tool, or the Service Accounts page in the Google Cloud Platform Console. GCP facilitates up to 10 external service account keys per service account to facilitate key rotation." tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/understanding-service-accounts#managing_service_account_keys' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/iam/service-accounts/keys/list' ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/service-accounts' service_account_cache.service_account_emails.each do |sa_email| # First, get all user-managed keys for the current service account user_managed_keys_for_sa = service_account_cache.service_account_keys[sa_email].where { key_type == 'USER_MANAGED' } # Then, filter for only the enabled ones among them (where 'disabled' attribute is false) enabled_user_managed_keys = user_managed_keys_for_sa.where { !disabled } if enabled_user_managed_keys.count > 0 impact 'medium' describe "[#{gcp_project_id}] Enabled user-managed ServiceAccount Keys for #{sa_email} older than #{sa_key_older_than_seconds} seconds" do # Now, for the actual check: filter the *enabled* keys for those older than the specified time subject { enabled_user_managed_keys.where { (Time.now - sa_key_older_than_seconds > valid_after_time) } } it { should_not exist } end else describe "[#{gcp_project_id}] ServiceAccount [#{sa_email}] does not have enabled user-managed keys. This test is Not Applicable." do skip "[#{gcp_project_id}] ServiceAccount [#{sa_email}] does not have enabled user-managed keys." end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/6.03-db.rb
controls/6.03-db.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that Cloud SQL Server database Instances are secure' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '6.3' control_abbrev = 'db' sql_cache = CloudSQLCache(project: gcp_project_id) sql_instance_names = sql_cache.instance_names # 6.3.1 sub_control_id = "#{control_id}.1" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'external scripts enabled' Database Flag for Cloud SQL SQL Server Instance Is Set to 'off'" desc 'It is recommended to set external scripts enabled database flag for Cloud SQL SQL Server instance to off' desc 'rationale', 'external scripts enabled enable the execution of scripts with certain remote language extensions. This property is OFF by default. When Advanced Analytics Services is installed, setup can optionally set this property to true. As the External Scripts Enabled feature allows scripts external to SQL such as files located in an R library to be executed, which could adversely affect the security of the system, hence this should be disabled. This recommendation is applicable to SQL Server database instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CM-7'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/external-scripts-enabled-server-configuration-option?view=sql-server-ver15' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/sqlserver/flags' ref 'GCP Docs', url: 'https://docs.microsoft.com/en-us/sql/advanced-analytics/concepts/security?view=sql-server-ver15' ref 'GCP Docs', url: 'https://www.stigviewer.com/stig/ms_sql_server_2016_instance/2018-03-09/finding/V-79347' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'SQLSERVER' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'external scripts enabled' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'external scripts enabled' set to 'off' " do subject { flag } its('name') { should cmp 'external scripts enabled' } its('value') { should cmp 'off' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a SQL Server database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a SQL Server database" end end end if sql_instance_names.empty? describe 'There are no Cloud SQL Instances in this project. This test is Not Applicable.' do skip 'There are no Cloud SQL Instances in this project' end end end # 6.3.2 sub_control_id = "#{control_id}.2" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'cross db ownership chaining' Database Flag for Cloud SQL SQL Server Instance Is Set to 'off'" desc 'It is recommended to set cross db ownership chaining database flag for Cloud SQL SQL Server instance to off. This flag is deprecated for all SQL Server versions in CGP. Going forward, you cant set its value to on. However, if you have this flag enabled, we strongly recommend that you either remove the flag from your database or set it to off. For cross-database access, use the Microsoft tutorial for signing stored procedures with a certificate.' desc 'rationale', 'Use the cross db ownership for chaining option to configure cross-database ownership chaining for an instance of Microsoft SQL Server. This server option allows you to control cross-database ownership chaining at the database level or to allow cross-database ownership chaining for all databases. Enabling cross db ownership is not recommended unless all of the databases hosted by the instance of SQL Server must participate in cross-database ownership chaining and you are aware of the security implications of this setting. This recommendation is applicable to SQL Server database instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/sqlserver/flags' ref 'GCP Docs', url: 'https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/cross-db-ownership-chaining-server-configuration-option?view=sql-server-ver15' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'SQLSERVER' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'cross db ownership chaining' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'cross db ownership chaining' set to 'off' " do subject { flag } its('name') { should cmp 'cross db ownership chaining' } its('value') { should cmp 'off' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a SQL Server database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a SQL Server database" end end end if sql_instance_names.empty? impact 'none' describe 'There are no Cloud SQL Instances in this project. This test is Not Applicable.' do skip 'There are no Cloud SQL Instances in this project' end end end # 6.3.3 sub_control_id = "#{control_id}.3" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'user Connections' Database Flag for Cloud SQL SQL Server Instance Is Set to a Non-limiting Value" desc 'It is recommended to check the user connections for a Cloud SQL SQL Server instance to ensure that it is not artificially limiting connections.' desc 'rationale', 'The user connections option specifies the maximum number of simultaneous user connections that are allowed on an instance of SQL Server. The actual number of user connections allowed also depends on the version of SQL Server that you are using, and also the limits of your application or applications and hardware. SQL Server allows a maximum of 32,767 user connections. Because user connections is by default a self-configuring value, with SQL Server adjusting the maximum number of user connections automatically as needed, up to the maximum value allowable. For example, if only 10 users are logged in, 10 user connection objects are allocated. In most cases, you do not have to change the value for this option. The default is 0, which means that the maximum (32,767) user connections are allowed. However if there is a number defined here that limits connections, SQL Server will not allow anymore above this limit. If the connections are at the limit, any new requests will be dropped, potentially causing lost data or outages for those using the database.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/sqlserver/flags' ref 'GCP Docs', url: 'https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-user-connections-server-configuration-option?view=sql-server-ver15' ref 'GCP Docs', url: 'https://www.stigviewer.com/stig/ms_sql_server_2016_instance/2018-03-09/finding/V-79119' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'SQLSERVER' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'user connections' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'user connections' set to #{user_connections} " do subject { flag } its('name') { should cmp 'user connections' } its('value') { should cmp user_connections } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a SQL Server database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a SQL Server database" end end end if sql_instance_names.empty? describe 'There are no Cloud SQL Instances in this project. This test is Not Applicable.' do skip 'There are no Cloud SQL Instances in this project' end end end # 6.3.4 sub_control_id = "#{control_id}.4" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'user options' Database Flag for Cloud SQL SQL Server Instance Is Not Configured" desc 'The user options option specifies global defaults for all users. A list of default query processing options is established for the duration of a users work session. The user options option allows you to change the default values of the SET options (if the servers default settings are not appropriate). A user can override these defaults by using the SET statement. You can configure user options dynamically for new logins. After you change the setting of user options, new login sessions use the new setting; current login sessions are not affected. This recommendation is applicable to SQL Server database instances.' desc 'rationale', 'It is recommended that, user options database flag for Cloud SQL SQL Server instance should not be configured. A user can override these defaults set with user options by using the SET statement. Some of these features/options could adversely affect the security of the system if enabled.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CM-6'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/sqlserver/flags' ref 'GCP Docs', url: 'https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-user-options-server-configuration-option?view=sql-server-ver15' ref 'GCP Docs', url: 'https://www.stigviewer.com/stig/ms_sql_server_2016_instance/2018-03-09/finding/V-79335' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'SQLSERVER' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'user options' describe "[#{gcp_project_id} , #{db} ] should not have database flag 'user options' configured" do subject { false } it { should be true } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a SQL Server database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a SQL Server database" end end end if sql_instance_names.empty? describe 'There are no Cloud SQL Instances in this project. This test is Not Applicable.' do skip 'There are no Cloud SQL Instances in this project' end end end # 6.3.5 sub_control_id = "#{control_id}.5" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'remote access' Database Flag for Cloud SQL SQL Server Instance Is Set to 'off'" desc 'It is recommended to set remote access database flag for Cloud SQL SQL Server instance to off.' desc 'rationale', 'The remote access option controls the execution of stored procedures from local or remote servers on which instances of SQL Server are running. This default value for this option is 1. This grants permission to run local stored procedures from remote servers or remote stored procedures from the local server. To prevent local stored procedures from being run from a remote server or remote stored procedures from being run on the local server, this must be disabled. The Remote Access option controls the execution of local stored procedures on remote servers or remote stored procedures on local server. Remote access functionality can be abused to launch a Denial-of-Service (DoS) attack on remote servers by off-loading query processing to a target, hence this should be disabled. This recommendation is applicable to SQL Server database instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['CM-7'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/sqlserver/flags' ref 'GCP Docs', url: 'https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-remote-access-server-configuration-option?view=sql-server-ver15' ref 'GCP Docs', url: 'https://www.stigviewer.com/stig/ms_sql_server_2016_instance/2018-03-09/finding/V-79337' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'SQLSERVER' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'remote access' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'remote access' set to 'off' " do subject { flag } its('name') { should cmp 'remote access' } its('value') { should cmp 'off' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a SQL Server database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a SQL Server database" end end end if sql_instance_names.empty? describe 'There are no Cloud SQL Instances in this project. This test is Not Applicable.' do skip 'There are no Cloud SQL Instances in this project' end end end # 6.3.6 sub_control_id = "#{control_id}.6" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure '3625 (trace flag)' Database Flag for all Cloud SQL SQL Server Instances Is Set to 'on'" desc 'It is recommended to set 3625 (trace flag) database flag for Cloud SQL SQL Server instance to on.' desc 'rationale', 'Microsoft SQL Trace Flags are frequently used to diagnose performance issues or to debug stored procedures or complex computer systems, but they may also be recommended by Microsoft Support to address behavior that is negatively impacting a specific workload. All documented trace flags and those recommended by Microsoft Support are fully supported in a production environment when used as directed. 3625(trace log) Limits the amount of information returned to users who are not members of the sysadmin fixed server role, by masking the parameters of some error messages using \'******\'. Setting this in a Google Cloud flag for the instance allows for security through obscurity and prevents the disclosure of sensitive information, hence this is recommended to set this flag globally to on to prevent the flag having been left off, or changed by bad actors. This recommendation is applicable to SQL Server database instances.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-1'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/sqlserver/flags' ref 'GCP Docs', url: 'https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql?view=sql-server-ver15#trace-flags' ref 'GCP Docs', url: 'https://github.com/ktaranov/sqlserver-kit/blob/master/SQL%20Server%20Trace%20Flag.md' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'SQLSERVER' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == '3625' describe "[#{gcp_project_id} , #{db} ] should have a database flag '3625' set to 'off' " do subject { flag } its('name') { should cmp '3625' } its('value') { should cmp 'off' } end end end end else impact 'none' describe "[#{gcp_project_id}] [#{db}] is not a SQL Server database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a SQL Server database" end end end if sql_instance_names.empty? describe 'There are no Cloud SQL Instances in this project. This test is Not Applicable.' do skip 'There are no Cloud SQL Instances in this project' end end end # 6.3.7 sub_control_id = "#{control_id}.7" control "cis-gcp-#{sub_control_id}-#{control_abbrev}" do impact 'none' title "[#{control_abbrev.upcase}] Ensure 'contained database authentication' Database Flag for Cloud SQL SQL Server Instance Is Set to 'off'" desc 'A contained database includes all database settings and metadata required to define the database and has no configuration dependencies on the instance of the Database Engine where the database is installed. Users can connect to the database without authenticating a login at the Database Engine level. Isolating the database from the Database Engine makes it possible to easily move the database to another instance of SQL Server. Contained databases have some unique threats that should be understood and mitigated by SQL Server Database Engine administrators. Most of the threats are related to the USER WITH PASSWORD authentication process, which moves the authentication boundary from the Database Engine level to the database level, hence this is recommended not to enable this flag. This recommendation is applicable to SQL Server database instances.' desc 'rationale', 'When contained databases are enabled, database users with the ALTER ANY USER permission, such as members of the db_owner and db_accessadmin database roles, can grant access to databases and by doing so, grant access to the instance of SQL Server. This means that control over access to the server is no longer limited to members of the sysadmin and securityadmin fixed server role, and logins with the server level CONTROL SERVER and ALTER ANY LOGIN permission. It is recommended to set contained database authentication database flag for Cloud SQL on the SQL Server instance to off.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: sub_control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-3'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/sqlserver/flags' ref 'GCP Docs', url: 'https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/contained-database-authentication-server-configuration-option?view=sql-server-ver15' ref 'GCP Docs', url: 'https://docs.microsoft.com/en-us/sql/relational-databases/databases/security-best-practices-with-contained-databases?view=sql-server-ver15' sql_instance_names.each do |db| if sql_cache.instance_objects[db].database_version.include? 'SQLSERVER' impact 'medium' if sql_cache.instance_objects[db].settings.database_flags.nil? describe "[#{gcp_project_id} , #{db} ] does not any have database flags." do subject { false } it { should be true } end else describe.one do sql_cache.instance_objects[db].settings.database_flags.each do |flag| next unless flag.name == 'contained database authentication' describe "[#{gcp_project_id} , #{db} ] should have a database flag 'contained database authentication' set to 'off' " do subject { flag } its('name') { should cmp 'contained database authentication' } its('value') { should cmp 'off' } end end end end else describe "[#{gcp_project_id}] [#{db}] is not a SQL Server database. This test is Not Applicable." do skip "[#{gcp_project_id}] [#{db}] is not a SQL Server database" end end end if sql_instance_names.empty? describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.02-logging.rb
controls/2.02-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that sinks are configured for all Log entries' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.2' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure that sinks are configured for all Log entries" desc 'It is recommended to create a sink that will export copies of all the log entries. This can help aggregate logs from multiple projects and export them to a Security Information and Event Management (SIEM).' desc 'rationale', 'Log entries are held in Cloud Logging. To aggregate logs, export them to a SIEM. To keep them longer, it is recommended to set up a log sink. Exporting involves writing a filter that selects the log entries to export, and choosing a destination in Cloud Storage, BigQuery, or Cloud Pub/Sub. The filter and destination are held in an object called a sink. To ensure all log entries are exported to sinks, ensure that there is no filter configured for a sink. Sinks can be created in projects, organizations, folders, and billing accounts.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-4 AU-12] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/reference/tools/gcloud-logging' ref 'GCP Docs', url: 'https://cloud.google.com/logging/quotas' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/export/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/export/using_exported_logs' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/export/configure_export_v2' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/export/aggregated_exports' ref 'GCP Docs', url: 'https://cloud.google.com/sdk/gcloud/reference/beta/logging/sinks/list' empty_filter_sinks = [] google_logging_project_sinks(project: gcp_project_id).names.each do |sink_name| empty_filter_sinks.push(sink_name) if google_logging_project_sink(project: gcp_project_id, name: sink_name).filter.nil? end describe "[#{gcp_project_id}] Project level Log sink with an empty filter" do subject { empty_filter_sinks } it 'is expected to exist' do expect(empty_filter_sinks.count).to be_positive end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.09-logging.rb
controls/2.09-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That the Log Metric Filter and Alerts Exist for VPC Network Changes' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.9' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure That the Log Metric Filter and Alerts Exist for VPC Network Changes" desc 'It is recommended that a metric filter and alarm be established for Virtual Private Cloud (VPC) network changes.' desc 'rationale', "It is possible to have more than one VPC within a project. In addition, it is also possible to create a peer connection between two VPCs enabling network traffic to route between VPCs. Monitoring changes to a VPC will help ensure VPC traffic flow is not getting impacted." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AU-3 AU-12] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/logs-based-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/custom-metrics/' ref 'GCP Docs', url: 'https://cloud.google.com/monitoring/alerts/' ref 'GCP Docs', url: 'https://cloud.google.com/logging/docs/reference/tools/gcloud-logging' ref 'GCP Docs', url: 'https://cloud.google.com/vpc/docs/overview' log_filter = 'resource.type=audited_resource AND jsonPayload.event_subtype="compute.networks.insert" OR jsonPayload.event_subtype="compute.networks.patch" OR jsonPayload.event_subtype="compute.networks.delete" OR jsonPayload.event_subtype="compute.networks.removePeering" OR jsonPayload.event_subtype="compute.networks.addPeering"' describe "[#{gcp_project_id}] VPC Network changes filter" do subject { google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter) } it { should exist } end google_project_metrics(project: gcp_project_id).where(metric_filter: log_filter).metric_types.each do |metrictype| describe.one do filter = "metric.type=\"#{metrictype}\" resource.type=\"audited_resource\"" google_project_alert_policies(project: gcp_project_id).where(policy_enabled_state: true).policy_names.each do |policy| condition = google_project_alert_policy_condition(policy: policy, filter: filter) describe "[#{gcp_project_id}] VPC Network changes alert policy" do subject { condition } it { should exist } end end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.06-iam.rb
controls/1.06-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that IAM users are not assigned Service Account User role at project level' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.6' control_abbrev = 'iam' iam_bindings_cache = IAMBindingsCache(project: gcp_project_id) control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that IAM users are not assigned Service Account User role at project level" desc 'It is recommended to assign the Service Account User (iam.serviceAccountUser) and Service Account Token Creator (iam.serviceAccountTokenCreator) roles to a user for a specific service account rather than assigning the role to a user at project level.' desc 'rationale', "A service account is a special Google account that belongs to an application or a virtual machine (VM), instead of to an individual end-user. Application/VM-Instance uses the service account to call the service's Google API so that users aren't directly involved. In addition to being an identity, a service account is a resource that has IAM policies attached to it. These policies determine who can use the service account. Users with IAM roles to update the App Engine and Compute Engine instances (such as App Engine Deployer or Compute Instance Admin) can effectively run code as the service accounts used to run these instances, and indirectly gain access to all the resources for which the service accounts have access. Similarly, SSH access to a Compute Engine instance may also provide the ability to execute code as that instance/Service account. Based on business needs, there could be multiple user-managed service accounts configured for a project. Granting the iam.serviceAccountUser or iam.serviceAccountTokenCreator roles to a user for a project gives the user access to all service accounts in the project, including service accounts that may be created in the future. This can result in elevation of privileges by using service accounts and corresponding Compute Engine instances. In order to implement least privileges best practices, IAM users should not be assigned the Service Account User or Service Account Token Creator roles at the project level. Instead, these roles should be assigned to a user for a specific service account, giving that user access to the service account. The Service Account User allows a user to bind a service account to a long-running job service, whereas the Service Account Token Creator role allows a user to directly impersonate (or assert) the identity of a service account." tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AC-2 AC-3] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/service-accounts' ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/granting-roles-to-service-accounts' ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/understanding-roles' ref 'GCP Docs', url: 'https://cloud.google.com/iam/docs/granting-changing-revoking-access' ref 'GCP Docs', url: 'https://console.cloud.google.com/iam-admin/iam' describe "[#{gcp_project_id}] A project-level binding of ServiceAccountUser" do subject { iam_bindings_cache.iam_bindings['roles/iam.serviceAccountUser'] } it { should eq nil } end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.08-vms.rb
controls/4.08-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure Compute instances are launched with Shielded VM enabled' gcp_project_id = input('gcp_project_id') gce_zones = input('gce_zones') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.8' control_abbrev = 'vms' gce_instances = GCECache(project: gcp_project_id, gce_zones: gce_zones).gce_instances_cache control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure Compute instances are launched with Shielded VM enabled" desc 'To defend against against advanced threats and ensure that the boot loader and firmware on your VMs are signed and untampered, it is recommended that Compute instances are launched with Shielded VM enabled.' desc 'rationale', "Shielded VMs are virtual machines (VMs) on Google Cloud Platform hardened by a set of security controls that help defend against rootkits and bootkits. Shielded VM offers verifiable integrity of your Compute Engine VM instances, so you can be confident your instances haven't been compromised by boot- or kernel-level malware or rootkits. Shielded VM's verifiable integrity is achieved through the use of Secure Boot, virtual trusted platform module (vTPM)-enabled Measured Boot, and integrity monitoring. Shielded VM instances run firmware which is signed and verified using Google's Certificate Authority, ensuring that the instance's firmware is unmodified and establishing the root of trust for Secure Boot. Integrity monitoring helps you understand and make decisions about the state of your VM instances and the Shielded VM vTPM enables Measured Boot by performing the measurements needed to create a known good boot baseline, called the integrity policy baseline. The integrity policy baseline is used for comparison with measurements from subsequent VM boots to determine if anything has changed. Secure Boot helps ensure that the system only runs authentic software by verifying the digital signature of all boot components, and halting the boot process if signature verification fails." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['SC-1'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/instances/modifying-shielded-vm' ref 'GCP Docs', url: 'https://cloud.google.com/shielded-vm' ref 'GCP Docs', url: 'https://cloud.google.com/security/shielded-cloud/shielded-vm#organization-policy-constraint' gce_instances.each do |instance| instance_object = google_compute_instance(project: gcp_project_id, zone: instance[:zone], name: instance[:name]) describe "[#{gcp_project_id}] Instance #{instance[:zone]}/#{instance[:name]}" do if instance_object.shielded_instance_config.nil? it 'should have a shielded instance config' do expect(false).to be true end else it 'should have secure boot enabled' do expect(instance_object.shielded_instance_config.enable_secure_boot).to be true end it 'should have integrity monitoring enabled' do expect(instance_object.shielded_instance_config.enable_integrity_monitoring).to be true end it 'should have virtual trusted platform module (vTPM) enabled' do expect(instance_object.shielded_instance_config.enable_vtpm).to be true end end end end if gce_instances.empty? impact 'none' describe "[#{gcp_project_id}] No Google Compute Engine instances were found. This test is Not Applicable." do skip "[#{gcp_project_id}] No Google Compute Engine instances were found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.02-vms.rb
controls/4.02-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that instances are not configured to use the default service account with full access to all Cloud APIs' gcp_project_id = input('gcp_project_id') gce_zones = input('gce_zones') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '4.2' control_abbrev = 'vms' gce_instances = GCECache(project: gcp_project_id, gce_zones: gce_zones).gce_instances_cache control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that instances are not configured to use the default service account with full access to all Cloud APIs" desc 'To support principle of least privileges and prevent potential privilege escalation it is recommended that instances are not assigned to default service account Compute Engine default service account with Scope Allow full access to all Cloud APIs.' desc 'rationale', "Along with ability to optionally create, manage and use user managed custom service accounts, Google Compute Engine provides default service account Compute Engine default service account for an instances to access necessary cloud services. Project Editor role is assigned to Compute Engine default service account hence, This service account has almost all capabilities over all cloud services except billing. However, when Compute Engine default service account assigned to an instance it can operate in 3 scopes. 1. Allow default access: Allows only minimum access required to run an Instance (Least Privileges) 2. Allow full access to all Cloud APIs: Allow full access to all the cloud APIs/Services (Too much access) 3. Set access for each API: Allows Instance administrator to choose only those APIs that are needed to perform specific business functionality expected by instance When an instance is configured with Compute Engine default service account with Scope Allow full access to all Cloud APIs, based on IAM roles assigned to the user(s) accessing Instance, it may allow user to perform cloud operations/API calls that user is not supposed to perform leading to successful privilege escalation." tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[AC-2 AC-6] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances' ref 'GCP Docs', url: 'https://cloud.google.com/compute/docs/access/service-accounts' project_number = google_project(project: gcp_project_id).project_number gce_instances.each do |instance| next if instance[:name] =~ /^gke-/ google_compute_instance(project: gcp_project_id, zone: instance[:zone], name: instance[:name]).service_accounts.each do |serviceaccount| next if serviceaccount.email != "#{project_number}-compute@developer.gserviceaccount.com" describe "[#{gcp_project_id}] Instance #{instance[:zone]}/#{instance[:name]}" do subject { serviceaccount.scopes } it { should_not include 'https://www.googleapis.com/auth/cloud-platform' } end end end if gce_instances.empty? impact 'none' describe "[#{gcp_project_id}] No Google Compute Engine instances were found. This test is Not Applicable." do skip "[#{gcp_project_id}] No Google Compute Engine instances were found" end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/6.05-db.rb
controls/6.05-db.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That Cloud SQL Database Instances Do Not Implicitly Whitelist All Public IP Addresses' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '6.5' control_abbrev = 'db' sql_cache = CloudSQLCache(project: gcp_project_id) sql_instance_names = sql_cache.instance_names control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure That Cloud SQL Database Instances Do Not Implicitly Whitelist All Public IP Addresses" desc 'Database Server should accept connections only from trusted Network(s)/IP(s) and restrict access from public IP addresses.' desc 'rationale', 'To minimize attack surface on a Database server instance, only trusted/known and required IP(s) should be white-listed to connect to it. An authorized network should not have IPs/networks configured to \'0.0.0.0/0\' which will allow access to the instance from anywhere in the world. Note that authorized networks apply only to instances with public IPs.' tag cis_scored: true tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[SC-1 AC-3] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/configure-ip' ref 'GCP Docs', url: 'https://console.cloud.google.com/iam-admin/orgpolicies/sql-restrictAuthorizedNetworks' ref 'GCP Docs', url: 'https://cloud.google.com/resource-manager/docs/organization-policy/org-policy-constraints' ref 'GCP Docs', url: 'https://cloud.google.com/sql/docs/mysql/connection-org-policy' if sql_instance_names.empty? impact 'none' describe "[#{gcp_project_id}] does not have CloudSQL instances. This test is Not Applicable." do skip "[#{gcp_project_id}] does not have CloudSQL instances." end else sql_instance_names.each do |db| describe "[#{gcp_project_id}] CloudSQL #{db}" do subject { sql_cache.instance_objects[db].settings.ip_configuration.authorized_networks } it { should_not include('0.0.0.0/0') } end end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.14-iam.rb
controls/1.14-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure API Keys Are Restricted to Only APIs That Application Needs Access' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.14' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure API keys are restricted to only APIs that application needs access" desc 'API keys are insecure because they can be viewed publicly, such as from within a browser, or they can be accessed on a device where the key resides. It is recommended to restrict API keys to use (call) only APIs required by an application.' desc 'rationale', "Security risks involved in using API-Keys are below: - API keys are a simple encrypted strings - API keys do not identify the user or the application making the API request - API keys are typically accessible to clients, making it easy to discover and steal an API key Because of this Google recommend using the standard authentication flow instead. However, there are limited cases where API keys are more appropriate. For example, if there is a mobile application that needs to use the Google Cloud Translation API, but doesn't otherwise need a back-end server, API keys are the simplest way to authenticate to that API. In order to reduce attack surface by providing least privileges, API-Keys can be restricted to use (call) only APIs required by an application." tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['AC-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/docs/authentication/api-keys' ref 'GCP Docs', url: 'https://cloud.google.com/apis/docs/overview' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/4.11-vms.rb
controls/4.11-vms.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That Compute Instances Have Confidential Computing Enabled (Automated)' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') supported_confidential_vm_types = input('supported_confidential_vm_types', value: /^(n2d|c2d|n3d)/, description: 'Regex for machine types supporting Confidential Computing. N2D, C2D (AMD SEV). N3D (AMD SEV-SNP). T2D (Intel TDX) might also be relevant if supported by InSpec resources.') control_id = '4.11' control_abbrev = 'vms' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure That Compute Instances Have Confidential Computing Enabled (Automated)" desc 'Google Cloud encrypts data at-rest and in-transit, but customer data must be decrypted for processing. Confidential Computing is a breakthrough technology that encrypts data in-use while it is being processed. Confidential Computing environments keep data encrypted in memory and elsewhere outside the central processing unit (CPU). Confidential VMs leverage hardware-based memory encryption technologies... Customer data will stay encrypted while it is used, indexed, queried, or trained on. Encryption keys are generated by and reside solely in dedicated hardware and are not exportable, enhancing isolation and security. Built-in hardware optimizations ensure Confidential Computing workloads experience minimal to no significant performance penalties.' desc 'rationale', "Confidential Computing enables customers' sensitive code and other data encrypted in memory during processing. Google does not have access to the encryption keys. Confidential VM can help alleviate concerns about risk related to either dependency on Google infrastructure or Google insiders' access to customer data in the clear." tag cis_scored: true tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[] # Add relevant NIST controls if any in future ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/compute/confidential-vm/docs/creating-cvm-instance' ref 'GCP Docs', url: 'https://cloud.google.com/compute/confidential-vm/docs/about-cvm' ref 'GCP Docs', url: 'https://cloud.google.com/confidential-computing' ref 'Google Cloud Blog', url: 'https://cloud.google.com/blog/products/identity-security/introducing-google-cloud-confidential-computing-with-confidential-vms' ref 'Supported Configurations', url: 'https://cloud.google.com/confidential-computing/confidential-vm/docs/supported-configurations' ref 'Pricing', url: 'https://cloud.google.com/compute/confidential-vm/pricing' # control_id and control_abbrev are already defined above # supported_confidential_vm_types is defined as an input above instances_found = false google_compute_zones(project: gcp_project_id).zone_names.each do |zone_name| google_compute_instances(project: gcp_project_id, zone: zone_name) .where(status: 'RUNNING') .where { machine_type.match(supported_confidential_vm_types) } # Filter for machine types that *can* support it .instance_names.each do |instance_name| instances_found = true describe "[#{gcp_project_id}] Confidential VM: #{instance_name} in Zone: #{zone_name}" do subject { google_compute_instance(project: gcp_project_id, zone: zone_name, name: instance_name).confidential_instance_config } its('enable_confidential_compute') { should be true } end end end unless instances_found describe "[#{control_abbrev.upcase}] #{control_id} - No Running Instances of Supported Machine Types Found" do skip 'No running compute instances of machine types supporting Confidential Computing (e.g., N2D, C2D, N3D) were found in the project. This control is Not Applicable or requires manual verification for instances not matching the filter.' end end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/2.12-logging.rb
controls/2.12-logging.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure That Cloud DNS Logging Is Enabled for All VPC Networks' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '2.12' control_abbrev = 'logging' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'low' title "[#{control_abbrev.upcase}] Ensure That Cloud DNS Logging Is Enabled for All VPC Networks" desc 'Cloud DNS logging records the queries from the name servers within your VPC to Stackdriver. Logged queries can come from Compute Engine VMs, GKE containers, or other GCP resources provisioned within the VPC.' desc 'rationale', "Security monitoring and forensics cannot depend solely on IP addresses from VPC flow logs, especially when considering the dynamic IP usage of cloud resources, HTTP virtual host routing, and other technology that can obscure the DNS name used by a client from the IP address. Monitoring of Cloud DNS logs provides visibility to DNS names requested by the clients within the VPC. These logs can be monitored for anomalous domain names, evaluated against threat intelligence, and Note: For full capture of DNS, firewall must block egress UDP/53 (DNS) and TCP/443 (DNS over HTTPS) to prevent client from using external DNS name server for resolution." tag cis_scored: false tag cis_level: 1 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: %w[] # Add relevant NIST controls if any in future ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/dns/docs/monitoring' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
GoogleCloudPlatform/inspec-gcp-cis-benchmark
https://github.com/GoogleCloudPlatform/inspec-gcp-cis-benchmark/blob/40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e/controls/1.03-iam.rb
controls/1.03-iam.rb
# Copyright 2019 The inspec-gcp-cis-benchmark Authors # # 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 # # https://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. title 'Ensure that Security Key Enforcement is enabled for all admin accounts' gcp_project_id = input('gcp_project_id') cis_version = input('cis_version') cis_url = input('cis_url') control_id = '1.3' control_abbrev = 'iam' control "cis-gcp-#{control_id}-#{control_abbrev}" do impact 'medium' title "[#{control_abbrev.upcase}] Ensure that Security Key Enforcement is enabled for all admin accounts" desc 'Setup Security Key Enforcement for Google Cloud Platform admin accounts.' desc 'rationale', 'Google Cloud Platform users with Organization Administrator roles have the highest level of privilege in the organization. These accounts should be protected with the strongest form of two-factor authentication: Security Key Enforcement. Ensure that admins use Security Keys to log in instead of weaker second factors like SMS or one-time passwords (OTP). Security Keys are actual physical keys used to access Google Organization Administrator Accounts. They send an encrypted signature rather than a code, ensuring that logins cannot be phished.' tag cis_scored: false tag cis_level: 2 tag cis_gcp: control_id.to_s tag cis_version: cis_version.to_s tag project: gcp_project_id.to_s tag nist: ['IA-2'] ref 'CIS Benchmark', url: cis_url.to_s ref 'GCP Docs', url: 'https://cloud.google.com/security-key/' ref 'GCP Docs', url: 'https://gsuite.google.com/learn-more/key_for_working_smarter_faster_and_more_securely.html' describe 'This control is not scored' do skip 'This control is not scored' end end
ruby
Apache-2.0
40f83ec9c6ff8c7ab9c7b3814a3cc6c4eb37983e
2026-01-04T17:46:18.625233Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/app/helpers/contact_us/contacts_helper.rb
app/helpers/contact_us/contacts_helper.rb
module ContactUs::ContactsHelper end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/app/controllers/contact_us/contacts_controller.rb
app/controllers/contact_us/contacts_controller.rb
class ContactUs::ContactsController < ApplicationController def create @contact = ContactUs::Contact.new(params[:contact_us_contact]) if @contact.save redirect_to(ContactUs.success_redirect || '/', :notice => t('contact_us.notices.success')) else flash[:error] = t('contact_us.notices.error') render_new_page end end def new @contact = ContactUs::Contact.new render_new_page end protected def render_new_page case ContactUs.form_gem when 'formtastic' then render 'new_formtastic' when 'simple_form' then render 'new_simple_form' else render 'new' end end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/app/models/contact_us/contact.rb
app/models/contact_us/contact.rb
class ContactUs::Contact include ActiveModel::Conversion include ActiveModel::Validations attr_accessor :email, :message, :name, :subject validates :email, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, :presence => true validates :message, :presence => true validates :name, :presence => {:if => Proc.new{ContactUs.require_name}} validates :subject, :presence => {:if => Proc.new{ContactUs.require_subject}} def initialize(attributes = {}) attributes.each do |key, value| self.send("#{key}=", value) end end def save if self.valid? ContactUs::ContactMailer.contact_email(self).deliver_now return true end return false end def persisted? false end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/app/mailers/contact_us/contact_mailer.rb
app/mailers/contact_us/contact_mailer.rb
class ContactUs::ContactMailer < ContactUs.parent_mailer.constantize def contact_email(contact) @contact = contact mail :from => (ContactUs.mailer_from || @contact.email), :reply_to => @contact.email, :subject => (ContactUs.require_subject ? @contact.subject : t('contact_us.contact_mailer.contact_email.subject', :email => @contact.email)), :to => ContactUs.mailer_to end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/spec_helper.rb
spec/spec_helper.rb
require File.dirname(__FILE__) + '/../lib/contact_us/tasks/install' # Configure Rails Envinronment ENV["RAILS_ENV"] = "test" require File.expand_path("../dummy/config/environment.rb", __FILE__) require "rails/test_help" require "rspec/rails" require 'rails-controller-testing' require 'shoulda-matchers' unless defined?(Rubinius).present? or RUBY_VERSION == '1.8.7' require 'simplecov' SimpleCov.start do add_filter '/config/' add_group 'Controllers', 'app/controllers' add_group 'Helpers', 'app/helpers' add_group 'Mailers', 'app/mailers' add_group 'Models', 'app/models' add_group 'Libraries', 'lib' add_group 'Specs', 'spec' end end ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.default_url_options[:host] = "test.com" Rails.backtrace_cleaner.remove_silencers! # Configure capybara for integration testing require "capybara/rails" Capybara.default_driver = :rack_test Capybara.default_selector = :css # Run any available migration ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__) # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } RSpec.configure do |config| config.include RSpec::Matchers config.infer_spec_type_from_file_location! config.raise_errors_for_deprecations! [:controller, :view, :request].each do |type| config.include ::Rails::Controller::Testing::TestProcess, type: type config.include ::Rails::Controller::Testing::TemplateAssertions, type: type config.include ::Rails::Controller::Testing::Integration, type: type end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/support/active_model_lint.rb
spec/support/active_model_lint.rb
# adapted from rspec-rails: # http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb shared_examples_for 'ActiveModel' do include ActiveModel::Lint::Tests # to_s is to support ruby-1.9 ActiveModel::Lint::Tests.public_instance_methods.map(&:to_s).grep(/^test/).each do |m| example m.gsub('_', ' ') do send m end end def model subject end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/controllers/contact_us/contact_controller_spec.rb
spec/controllers/contact_us/contact_controller_spec.rb
require 'spec_helper' describe ContactUs::ContactsController do describe 'create' do before do ContactUs.mailer_to = 'test@example.com' end it 'should redirect with success message if valid contact' do ContactUs.success_redirect = nil post :create, :contact_us_contact => { :email => 'test@test.com', :message => 'test' } expect(assigns(:contact).valid?).to eql(true) expect(flash[:notice]).to eql('Contact email was successfully sent.') expect(response).to redirect_to('/') end it 'should redirect to custom URL with success message if valid contact' do ContactUs.success_redirect = '/success' post :create, :contact_us_contact => { :email => 'test@test.com', :message => 'test' } expect(assigns(:contact).valid?).to eql(true) expect(flash[:notice]).to eql('Contact email was successfully sent.') expect(response).to redirect_to('/success') ContactUs.success_redirect = '/' end it 'should render new with error message if invalid contact' do post :create, :contact_us_contact => { :email => 'test@test.com', :message => '' } expect(assigns(:contact).valid?).to eql(false) expect(flash[:error]).to eql('You must enter both fields.') expect(response).to render_template('new') end end describe 'new' do it 'should assign contact for form and render page successfully' do get :new expect(assigns(:contact)).to be_an_instance_of(ContactUs::Contact) expect(response).to be_success end end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/models/contact_us/contact_spec.rb
spec/models/contact_us/contact_spec.rb
require 'spec_helper' describe ContactUs::Contact do it_should_behave_like 'ActiveModel' describe "Validations" do it {is_expected.to validate_presence_of(:email)} it {is_expected.to validate_presence_of(:message)} it {is_expected.not_to validate_presence_of(:name)} it {is_expected.not_to validate_presence_of(:subject)} context 'with name and subject settings' do after do ContactUs.require_name = false ContactUs.require_subject = false end before do ContactUs.require_name = true ContactUs.require_subject =true end it {is_expected.to validate_presence_of(:name)} it {is_expected.to validate_presence_of(:subject)} end end describe 'Methods' do describe '#read_attribute_for_validation' do it 'should return attributes set during initialization' do contact = ContactUs::Contact.new(:email => "Valid@Email.com", :message => "Test") expect(contact.read_attribute_for_validation(:email)).to eql("Valid@Email.com") expect(contact.read_attribute_for_validation(:message)).to eql("Test") end end describe '#save' do it 'should return false if records invalid' do contact = ContactUs::Contact.new(:email => "Valid@Email.com", :message => "") expect(contact.save).to eql(false) end it 'should send email and return true if records valid' do mail = Mail.new(:from=>"Valid@Email.com", :to => "test@test.com") allow(mail).to receive(:deliver_now).and_return(true) contact = ContactUs::Contact.new(:email => "Valid@Email.com", :message => "Test") expect(ContactUs::ContactMailer).to receive(:contact_email).with(contact).and_return(mail) expect(contact.save).to eql(true) end end describe '#to_key' do it { expect(subject).to respond_to(:to_key) } end end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/features/contact_us_lint_spec.rb
spec/features/contact_us_lint_spec.rb
require 'spec_helper' describe 'Contact Us page', :type => :feature do after do ActionMailer::Base.deliveries = [] ContactUs.mailer_from = nil ContactUs.mailer_to = nil ContactUs.require_name = false ContactUs.require_subject = false end before do ActionMailer::Base.deliveries = [] ContactUs.mailer_to = 'test@test.com' end it 'displays default contact form properly' do visit contact_us_path within "form#new_contact_us_contact" do expect(page).to have_selector "input#contact_us_contact_email" expect(page).to have_selector "textarea#contact_us_contact_message" expect(page).not_to have_selector "input#contact_us_contact_name" expect(page).not_to have_selector "input#contact_us_contact_subject" expect(page).to have_selector "input.submit" end end context "Submitting the form" do before do visit contact_us_path end context "when valid" do before do fill_in 'Email', :with => 'test@example.com' fill_in 'Message', :with => 'howdy' click_button 'Submit' end it "I should be redirected to the homepage" do expect(current_path).to eq("/") end it "An email should have been sent" do expect(ActionMailer::Base.deliveries.size).to eq(1) end it "The email should have the correct attributes" do mail = ActionMailer::Base.deliveries.last expect(mail.to).to eq(['test@test.com']) expect(mail.from).to eq(['test@example.com']) expect(mail.body).to match 'howdy' end end context "when invalid" do context "Email and message are invalid" do before do fill_in 'Email', :with => 'a' fill_in 'Message', :with => '' click_button 'Submit' end it "I should see two error messages" do within '#contact_us_contact_email_input' do expect(page).to have_content "is invalid" end within '#contact_us_contact_message_input' do expect(page).to have_content "can't be blank" end end it "An email should not have been sent" do expect(ActionMailer::Base.deliveries.size).to eq(0) end end end end context 'with name and subject configuration' do before do ContactUs.require_name = true ContactUs.require_subject = true visit contact_us_path end it "displays an input for name and subject" do expect(page).to have_selector "input#contact_us_contact_name" expect(page).to have_selector "input#contact_us_contact_subject" end context "Submitting the form" do context "when valid" do before do fill_in 'Email', :with => 'test@example.com' fill_in 'Message', :with => 'howdy' fill_in 'contact_us_contact[name]', :with => 'Jeff' fill_in 'contact_us_contact[subject]', :with => 'Testing contact form.' click_button 'Submit' end it "I should be redirected to the homepage" do expect(current_path).to eq("/") end it "An email should have been sent" do expect(ActionMailer::Base.deliveries.size).to eq(1) end it "The email should have the correct attributes" do mail = ActionMailer::Base.deliveries.last expect(mail.body).to match 'howdy' expect(mail.body).to match 'Jeff' expect(mail.from).to eq(['test@example.com']) expect(mail.subject).to match 'Testing contact form.' expect(mail.to).to eq(['test@test.com']) end end context "when name and subject are blank" do before do click_button 'Submit' end it "I should see error messages" do within '#contact_us_contact_name_input' do expect(page).to have_content "can't be blank" end within '#contact_us_contact_subject_input' do expect(page).to have_content "can't be blank" end end it "An email should not have been sent" do expect(ActionMailer::Base.deliveries.size).to eq(0) end end end end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/app/helpers/application_helper.rb
spec/dummy/app/helpers/application_helper.rb
module ApplicationHelper end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/app/controllers/application_controller.rb
spec/dummy/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base protect_from_forgery end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/application.rb
spec/dummy/config/application.rb
require File.expand_path('../boot', __FILE__) require 'rails/all' require 'formtastic' # If you have a Gemfile, require the gems listed there, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) module Dummy class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de # JavaScript files you want as :defaults (application.js is always included). # config.action_view.javascript_expansions[:defaults] = %w(jquery rails) # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/environment.rb
spec/dummy/config/environment.rb
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Dummy::Application.initialize!
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/routes.rb
spec/dummy/config/routes.rb
Dummy::Application.routes.draw do # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match 'products/:id' => 'catalog#view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products # Sample resource route with options: # resources :products do # member do # get 'short' # post 'toggle' # end # # collection do # get 'sold' # end # end # Sample resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Sample resource route with more complex sub-resources # resources :products do # resources :comments # resources :sales do # get 'recent', :on => :collection # end # end # Sample resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end # You can have the root of your site routed with "root" # just remember to delete public/index.html. root :to => "contact_us/contacts#new" # See how all your routes lay out with "rake routes" # This is a legacy wild controller route that's not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. # match ':controller(/:action(/:id(.:format)))' end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/boot.rb
spec/dummy/config/boot.rb
require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/initializers/session_store.rb
spec/dummy/config/initializers/session_store.rb
# Be sure to restart your server when you modify this file. Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rails generate session_migration") # Dummy::Application.config.session_store :active_record_store
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/initializers/inflections.rb
spec/dummy/config/initializers/inflections.rb
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/initializers/backtrace_silencers.rb
spec/dummy/config/initializers/backtrace_silencers.rb
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers!
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/initializers/mime_types.rb
spec/dummy/config/initializers/mime_types.rb
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/initializers/secret_token.rb
spec/dummy/config/initializers/secret_token.rb
# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Dummy::Application.config.secret_token = 'c4ec078296b891578571fa0441c5954fa62dd7825eb269a779d9d4233aa29209870035e5176696b1b233e9722d3b8cb7ed75a9f9690626a9a075e3f6b8c6c56f'
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/environments/test.rb
spec/dummy/config/environments/test.rb
Dummy::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Use SQL instead of Active Record's schema dumper when creating the test database. # This is necessary if your schema can't be completely dumped by the schema dumper, # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/environments/development.rb
spec/dummy/config/environments/development.rb
Dummy::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.cache_classes = false # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true config.action_view.debug_rjs = true config.action_controller.perform_caching = false # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false # Print deprecation notices to the Rails logger config.active_support.deprecation = :log # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/dummy/config/environments/production.rb
spec/dummy/config/environments/production.rb
Dummy::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Specifies the header that your server uses for sending files config.action_dispatch.x_sendfile_header = "X-Sendfile" # For nginx: # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # If you have no front-end server that supports something like X-Sendfile, # just comment this out and Rails will serve the files # See everything in the log (default is :info) # config.log_level = :debug # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Use a different cache store in production # config.cache_store = :mem_cache_store # Disable Rails's static asset server # In production, Apache or nginx will already do this config.serve_static_assets = false # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false # Enable threaded mode # config.threadsafe! # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true # Send deprecation notices to registered listeners config.active_support.deprecation = :notify end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/lib/install_spec.rb
spec/lib/install_spec.rb
require 'spec_helper' describe "Rake tasks" do after(:each) do @destination_root = File.expand_path("../../dummy", __FILE__) FileUtils.rm_rf(@destination_root + "/config/initializers/contact_us.rb") FileUtils.rm_rf(@destination_root + "/config/locales/contact_us.en.yml") FileUtils.rm_rf(@destination_root + "/app/views/contact_us") FileUtils.rm_rf(@destination_root + "/app/views/contact_us/contact_mailer") FileUtils.rm_rf(@destination_root + "/app/views/contact_us/contacts") end before(:each) do @destination_root = File.expand_path("../../dummy", __FILE__) expect(File.exists?(@destination_root + "/config/initializers/contact_us.rb")).to eql(false) expect(File.exists?(@destination_root + "/config/locales/contact_us.en.yml")).to eql(false) expect(File.directory?(@destination_root + "/app/views/contact_us")).to eql(false) expect(File.directory?(@destination_root + "/app/views/contact_us/contact_mailer")).to eql(false) expect(File.directory?(@destination_root + "/app/views/contact_us/contacts")).to eql(false) end describe "contact_us:install" do before do ContactUs::Tasks::Install.run end it "creates initializer file" do expect(File.exists?(File.join(@destination_root + "/config/initializers/contact_us.rb"))).to eql(true) end end describe 'contact_us:copy_locales' do before do ContactUs::Tasks::Install.copy_locales_files end it "creates locales files" do expect(File.exists?(File.join(@destination_root + "/config/locales/contact_us.en.yml"))).to eql(true) end end describe "contact_us:install" do before do ContactUs::Tasks::Install.copy_view_files end it "creates view files" do expect(File.directory?(@destination_root + "/app/views/contact_us")).to eql(true) expect(File.directory?(@destination_root + "/app/views/contact_us/contact_mailer")).to eql(true) expect(File.directory?(@destination_root + "/app/views/contact_us/contacts")).to eql(true) end end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/lib/contact_us_spec.rb
spec/lib/contact_us_spec.rb
require 'spec_helper' describe ContactUs do after do ContactUs.mailer_from = nil ContactUs.mailer_to = nil ContactUs.require_name = false ContactUs.require_subject = false ContactUs.success_redirect = nil end it "should be valid" do expect(ContactUs).to be_a(Module) end describe 'setup block' do it 'should yield self' do ContactUs.setup do |config| expect(ContactUs).to eql(config) end end end describe 'mailer_from' do it 'should be configurable' do ContactUs.mailer_from = "contact@please-change-me.com" expect(ContactUs.mailer_from).to eql("contact@please-change-me.com") end end describe 'mailer_to' do it 'should be configurable' do ContactUs.mailer_to = "contact@please-change-me.com" expect(ContactUs.mailer_to).to eql("contact@please-change-me.com") end end describe 'require_name' do it 'should be configurable' do ContactUs.require_name = true expect(ContactUs.require_name).to eql(true) end end describe 'require_subject' do it 'should be configurable' do ContactUs.require_subject = true expect(ContactUs.require_subject).to eql(true) end end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/spec/mailers/contact_us/contact_mailer_spec.rb
spec/mailers/contact_us/contact_mailer_spec.rb
require 'spec_helper' describe ContactUs::ContactMailer do describe "#contact_email" do before do ContactUs.mailer_to = "contact@please-change-me.com" @contact = ContactUs::Contact.new(:email => 'test@email.com', :message => 'Thanks!') end it "should render successfully" do expect { ContactUs::ContactMailer.contact_email(@contact) }.not_to raise_error end it "should use the ContactUs.mailer_from setting when it is set" do ContactUs.mailer_from = "contact@please-change-me.com" @mailer = ContactUs::ContactMailer.contact_email(@contact) expect(@mailer.from).to eql([ContactUs.mailer_from]) ContactUs.mailer_from = nil end describe "rendered without error" do before do @mailer = ContactUs::ContactMailer.contact_email(@contact) end it "should have the initializers to address" do expect(@mailer.to).to eql([ContactUs.mailer_to]) end it "should use the users email in the from field when ContactUs.mailer_from is not set" do expect(@mailer.from).to eql([@contact.email]) end it "should use the users email in the reply_to field" do expect(@mailer.reply_to).to eql([@contact.email]) end it "should have users email in the subject line" do expect(@mailer.subject).to eql("Contact Us message from #{@contact.email}") end it "should have the message in the body" do expect(@mailer.body).to match("<p>Thanks!</p>") end it "should deliver successfully" do expect { ContactUs::ContactMailer.contact_email(@contact).deliver_now }.not_to raise_error end describe "and delivered" do it "should be added to the delivery queue" do expect { ContactUs::ContactMailer.contact_email(@contact).deliver_now }.to change(ActionMailer::Base.deliveries,:size).by(1) end end end end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/lib/contact_us.rb
lib/contact_us.rb
module ContactUs require 'contact_us/engine' # Address ContactUs email notifications are sent from. mattr_accessor :mailer_from # Address to send ContactUs email notifications to. mattr_accessor :mailer_to # Enable or Disable name field. mattr_accessor :require_name # Enable or Disable subject field. mattr_accessor :require_subject # Formtastic or SimpleForm mattr_accessor :form_gem # URL after a successful submission mattr_accessor :success_redirect # Configure parent mailer mattr_accessor :parent_mailer @@parent_mailer = "ActionMailer::Base" # allows for a locale to appear in the path # (e.g. /fr/contact-us OR /en/contact-us) mattr_accessor :localize_routes # Default way to setup ContactUs. Run rake contact_us:install to create # a fresh initializer with all configuration values. def self.setup yield self end end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false
JDutil/contact_us
https://github.com/JDutil/contact_us/blob/8f39e962881f17362cdf66a88da3edede22b77b8/lib/templates/contact_us.rb
lib/templates/contact_us.rb
# Use this hook to configure contact mailer. ContactUs.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which email notifications should be sent from. If emails must be sent from a verified email address you may set it here. # Example: # config.mailer_from = "contact@please-change-me.com" config.mailer_from = nil # Configure the e-mail address which should receive the contact form email notifications. config.mailer_to = "contact@please-change-me.com" # ==> Form Configuration # Configure the form to ask for the users name. config.require_name = false # Configure the form to ask for a subject. config.require_subject = false # Configure the form gem to use. # Example: # config.form_gem = 'formtastic' config.form_gem = nil # Configure the redirect URL after a successful submission config.success_redirect = '/' # Configure the parent action mailer # Example: # config.parent_mailer = "ActionMailer::Base" end
ruby
MIT
8f39e962881f17362cdf66a88da3edede22b77b8
2026-01-04T17:46:23.553669Z
false