Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

[GPII-3326]: Apply audit config in gcp-project module #246

Merged
merged 15 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions common/modules/gcp-project/audit.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
variable "nonce" {}

resource "null_resource" "add_audit_config" {
triggers = {
nonce = "${var.nonce}"
}

depends_on = [
"google_project_iam_policy.project",
]

provisioner "local-exec" {
command = <<EOF
set -e

auditConfigs=$(cat ${path.module}/resources/auditConfigs.json | jq -c -r -S .)
policy=$(gcloud projects get-iam-policy ${google_project.project.project_id} --format json)
policy_bindings=$(echo $policy | jq -c -r .bindings)
natarajaya marked this conversation as resolved.
Show resolved Hide resolved
policy_auditConfigs=$(echo $policy | jq -c -r -S .auditConfigs)
natarajaya marked this conversation as resolved.
Show resolved Hide resolved

if [ "$(echo $auditConfigs | md5sum)" != "$(echo $policy_auditConfigs | md5sum)" ]; then
natarajaya marked this conversation as resolved.
Show resolved Hide resolved
jq -n -r \
--argjson auditConfigs "$auditConfigs" \
--argjson bindings "$policy_bindings" \
'{"auditConfigs":$auditConfigs,"bindings":$bindings}' > ${path.module}/${google_project.project.project_id}.iam.policy.json

echo "Applying audit configs..."
gcloud -q projects set-iam-policy ${google_project.project.project_id} ${path.module}/${google_project.project.project_id}.iam.policy.json

rm ${path.module}/${google_project.project.project_id}.iam.policy.json
else
echo "Audit configs are up-to-date..."
fi
EOF
}
}
112 changes: 112 additions & 0 deletions common/modules/gcp-project/resources/auditConfigs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "cloudkms.googleapis.com"
},
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "compute.googleapis.com"
},
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "dns.googleapis.com"
},
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "storage.googleapis.com"
},
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "iam.googleapis.com"
},
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "container.googleapis.com"
},
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "serviceusage.googleapis.com"
},
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "logging.googleapis.com"
},
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "monitoring.googleapis.com"
},
{
"auditLogConfigs": [
{
"logType": "DATA_READ"
},
{
"logType": "DATA_WRITE"
}
],
"service": "cloudtrace.googleapis.com"
}
]
1 change: 1 addition & 0 deletions gcp/modules/gcp-secret-mgmt/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module "gcp-secret-mgmt" {
encryption_keys = "${var.encryption_keys}"
storage_location = "${var.storage_location}"
keyring_name = "${var.keyring_name}"
apply_audit_config = false
natarajaya marked this conversation as resolved.
Show resolved Hide resolved
}

# Re-export variable. See https://www.terraform.io/docs/providers/terraform/d/remote_state.html#root-outputs-only
Expand Down