Skip to content

Commit

Permalink
support custom log filters (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
xingao267 committed Oct 14, 2020
1 parent 2a01379 commit 3db1b70
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
11 changes: 11 additions & 0 deletions docs/tfengine/schemas/audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

## Properties

### additional_filters

Additional filters for log collection and export. List entries will be
concatenated by "OR" operator. Refer to
<https://cloud.google.com/logging/docs/view/query-library> for query syntax.
Need to escape \ and " to preserve them in the final filter strings.
See example usages under "examples/tfengine/".
Logs with filter "logName:\"logs/cloudaudit.googleapis.com\"" is always enabled.

Type: array(string)

### auditors_group

This group will be granted viewer access to the audit log dataset and
Expand Down
5 changes: 5 additions & 0 deletions examples/tfengine/folder_foundation.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ template "audit" {
logs_storage_bucket = {
name = "7yr-folder-audit-logs"
}
additional_filters = [
# Need to escape \ and " to preserve them in the final filter strings.
"logName=\\\"logs/forseti\\\"",
"logName=\\\"logs/application\\\"",
]
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/tfengine/generated/folder_foundation/audit/main.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions templates/tfengine/components/audit/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ limitations under the License. */ -}}
{{- $parent_var = "var.folder"}}
{{- end}}

{{- $filter := `logName:\"logs/cloudaudit.googleapis.com\"`}}
{{- range get . "additional_filters"}}
{{- $filter = printf "%s OR %s" $filter .}}
{{- end}}
# IAM Audit log configs to enable collection of all possible audit logs.
resource "google_{{.parent_type}}_iam_audit_config" "config" {
{{$parent_field}} = {{$parent_var}}
Expand All @@ -40,7 +45,7 @@ resource "google_logging_{{.parent_type}}_sink" "bigquery_audit_logs_sink" {
name = "bigquery-audit-logs-sink"
{{$parent_field}} = {{$parent_var}}
include_children = true
filter = "logName:\"logs/cloudaudit.googleapis.com\""
filter = "{{$filter}}"
destination = "bigquery.googleapis.com/projects/${module.project.project_id}/datasets/${module.bigquery_destination.bigquery_dataset.dataset_id}"
}
Expand Down Expand Up @@ -75,7 +80,7 @@ resource "google_logging_{{.parent_type}}_sink" "storage_audit_logs_sink" {
name = "storage-audit-logs-sink"
{{$parent_field}} = {{$parent_var}}
include_children = true
filter = "logName:\"logs/cloudaudit.googleapis.com\""
filter = "{{$filter}}"
destination = "storage.googleapis.com/${module.storage_destination.bucket.name}"
}
Expand Down
14 changes: 14 additions & 0 deletions templates/tfengine/recipes/audit.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ schema = {
description = "Location of logs storage bucket."
type = "string"
}
additional_filters = {
description = <<EOF
Additional filters for log collection and export. List entries will be
concatenated by "OR" operator. Refer to
<https://cloud.google.com/logging/docs/view/query-library> for query syntax.
Need to escape \ and " to preserve them in the final filter strings.
See example usages under "examples/tfengine/".
Logs with filter "logName:\"logs/cloudaudit.googleapis.com\"" is always enabled.
EOF
type = "array"
items = {
type = "string"
}
}
}
}

Expand Down

0 comments on commit 3db1b70

Please sign in to comment.