Skip to content

Commit cd42805

Browse files
authored
fix: adjust log filters for SHA/CIS compliance (#261)
1 parent 3dfda65 commit cd42805

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

1-org/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Enabling Data Access logs might result in your project being charged for the add
1515
For details on costs you might incur, go to [Pricing](https://cloud.google.com/stackdriver/pricing).
1616
You can choose not to enable the Data Access logs by setting variable `data_access_logs_enabled` to false.
1717

18+
**Note:** This module creates sink to export all logs to Google Storage. It's also create sinks to export a subset of security related logs
19+
to Bigquery and Pub/Sub. This will result in additional charges for those copies of logs.
20+
You can change the filters & sinks by modifying the configuration in `envs/shared/log_sinks.tf`.
21+
1822
**Note:** Currently, this module does not enable bucket policy retention for organization logs, please, enable it if needed.
1923

2024
### Setup to run via Cloud Build

1-org/envs/shared/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| interconnect\_project\_alert\_pubsub\_topic | The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}` for the interconnect project. | string | `"null"` | no |
1919
| interconnect\_project\_alert\_spent\_percents | A list of percentages of the budget to alert on when threshold is exceeded for the interconnect project. | list(number) | `<list>` | no |
2020
| interconnect\_project\_budget\_amount | The amount to use as the budget for the interconnect project. | number | `"1000"` | no |
21+
| log\_export\_storage\_force\_destroy | (Optional) If set to true, delete all contents when destroying the resource; otherwise, destroying the resource will fail if contents are present. | bool | `"false"` | no |
2122
| log\_export\_storage\_location | The location of the storage bucket used to export logs. | string | `"US"` | no |
2223
| log\_export\_storage\_retention\_policy | Configuration of the bucket's data retention policy for how long objects in the bucket should be retained. | object | `"null"` | no |
2324
| org\_audit\_logs\_project\_alert\_pubsub\_topic | The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}` for the org audit logs project. | string | `"null"` | no |

1-org/envs/shared/log_sinks.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
locals {
1818
parent_resource_id = var.parent_folder != "" ? var.parent_folder : var.org_id
1919
parent_resource_type = var.parent_folder != "" ? "folder" : "organization"
20-
all_logs_filter = <<EOF
20+
main_logs_filter = <<EOF
2121
logName: /logs/cloudaudit.googleapis.com%2Factivity OR
2222
logName: /logs/cloudaudit.googleapis.com%2Fsystem_event OR
2323
logName: /logs/cloudaudit.googleapis.com%2Fdata_access OR
2424
logName: /logs/compute.googleapis.com%2Fvpc_flows OR
2525
logName: /logs/compute.googleapis.com%2Ffirewall OR
2626
logName: /logs/cloudaudit.googleapis.com%2Faccess_transparency
2727
EOF
28+
all_logs_filter = ""
2829
}
2930

3031
resource "random_string" "suffix" {
@@ -41,7 +42,7 @@ module "log_export_to_biqquery" {
4142
source = "terraform-google-modules/log-export/google"
4243
version = "~> 5.0"
4344
destination_uri = module.bigquery_destination.destination_uri
44-
filter = local.all_logs_filter
45+
filter = local.main_logs_filter
4546
log_sink_name = "sk-c-logging-bq"
4647
parent_resource_id = local.parent_resource_id
4748
parent_resource_type = local.parent_resource_type
@@ -84,6 +85,7 @@ module "storage_destination" {
8485
uniform_bucket_level_access = true
8586
location = var.log_export_storage_location
8687
retention_policy = var.log_export_storage_retention_policy
88+
force_destroy = var.log_export_storage_force_destroy
8789
}
8890

8991
/******************************************
@@ -94,7 +96,7 @@ module "log_export_to_pubsub" {
9496
source = "terraform-google-modules/log-export/google"
9597
version = "~> 5.0"
9698
destination_uri = module.pubsub_destination.destination_uri
97-
filter = local.all_logs_filter
99+
filter = local.main_logs_filter
98100
log_sink_name = "sk-c-logging-pub"
99101
parent_resource_id = local.parent_resource_id
100102
parent_resource_type = local.parent_resource_type

1-org/envs/shared/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ variable "log_export_storage_location" {
9696
default = "US"
9797
}
9898

99+
variable "log_export_storage_force_destroy" {
100+
description = "(Optional) If set to true, delete all contents when destroying the resource; otherwise, destroying the resource will fail if contents are present."
101+
type = bool
102+
default = false
103+
}
104+
99105
variable "audit_logs_table_delete_contents_on_destroy" {
100106
description = "(Optional) If set to true, delete all the tables in the dataset when destroying the resource; otherwise, destroying the resource will fail if tables are present."
101107
type = bool

test/fixtures/org/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ module "test" {
3232
domains_to_allow = [var.domain_to_allow]
3333
create_access_context_manager_access_policy = false
3434
audit_logs_table_delete_contents_on_destroy = true
35+
log_export_storage_force_destroy = true
3536
}

test/integration/org/controls/gcp_logging.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
parent_resource_id = attribute('parent_resource_id')
1818
logs_export_storage_bucket_name = attribute('logs_export_storage_bucket_name')
1919
logs_export_pubsub_topic = attribute('logs_export_pubsub_topic')
20-
21-
all_logs_filter = [
20+
main_logs_filter = [
2221
'logName: /logs/cloudaudit.googleapis.com%2Factivity',
2322
'logName: /logs/cloudaudit.googleapis.com%2Fsystem_event',
2423
'logName: /logs/cloudaudit.googleapis.com%2Fdata_access',
@@ -62,7 +61,7 @@
6261
name: 'sk-c-logging-bq'
6362
) do
6463
it { should exist }
65-
all_logs_filter.each do |filter|
64+
main_logs_filter.each do |filter|
6665
its('filter') do
6766
should include filter
6867
end
@@ -76,10 +75,8 @@
7675
name: 'sk-c-logging-bkt'
7776
) do
7877
it { should exist }
79-
all_logs_filter.each do |filter|
80-
its('filter') do
81-
should include filter
82-
end
78+
its('filter') do
79+
should be_nil
8380
end
8481
its('include_children') { should cmp 'true' }
8582
its('destination') { should cmp "storage.googleapis.com/#{logs_export_storage_bucket_name}" }
@@ -90,7 +87,7 @@
9087
name: 'sk-c-logging-pub'
9188
) do
9289
it { should exist }
93-
all_logs_filter.each do |filter|
90+
main_logs_filter.each do |filter|
9491
its('filter') do
9592
should include filter
9693
end

0 commit comments

Comments
 (0)