Skip to content

Commit

Permalink
fix(cdr) - support empty audit logs block (#54)
Browse files Browse the repository at this point in the history
* fix(cdr) - support empty audit logs block

* Makefile fix
  • Loading branch information
legobrick authored Dec 31, 2024
1 parent 6df29e1 commit 615bf04
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
lint:
tflint --recursive --module
tflint --recursive --call-module-type=all
6 changes: 4 additions & 2 deletions modules/integrations/pub-sub/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ resource "random_uuid" "routing_key" {}
#-----------------------------------------------------------------------------------------
locals {
# Data structure will be a map for each service, that can have multiple audit_log_config
audit_log_config = { for audit in var.audit_log_config :
audit_log_config = {
for audit in var.audit_log_config :
audit["service"] => {
log_config = audit["log_config"]
}
if length(audit["log_config"]) > 0 # Include only if log_config is not empty
}
}

Expand Down Expand Up @@ -266,4 +268,4 @@ resource "sysdig_secure_cloud_auth_account_component" "gcp_pubsub_datasource" {
}
}
})
}
}
36 changes: 36 additions & 0 deletions test/examples/modular_organization/pub-sub-admin-write-only1.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#---------------------------------------------------------------------------------------------
# Ensure installation flow for foundational onboarding has been completed before
# installing additional Sysdig features.
#---------------------------------------------------------------------------------------------

module "pub-sub" {
source = "../../../modules/integrations/pub-sub"
project_id = module.onboarding.project_id
is_organizational = module.onboarding.is_organizational
organization_domain = module.onboarding.organization_domain
sysdig_secure_account_id = module.onboarding.sysdig_secure_account_id
ingestion_sink_filter = ""
audit_log_config = [
{
service = "allServices"
log_config = []
}
]
exclude_logs_filter = []
}

resource "sysdig_secure_cloud_auth_account_feature" "threat_detection" {
account_id = module.onboarding.sysdig_secure_account_id
type = "FEATURE_SECURE_THREAT_DETECTION"
enabled = true
components = [ module.pub-sub.pubsub_datasource_component_id ]
depends_on = [ module.pub-sub ]
}

resource "sysdig_secure_cloud_auth_account_feature" "identity_entitlement" {
account_id = module.onboarding.sysdig_secure_account_id
type = "FEATURE_SECURE_IDENTITY_ENTITLEMENT"
enabled = true
components = [module.pub-sub.pubsub_datasource_component_id]
depends_on = [sysdig_secure_cloud_auth_account_feature.config_posture, module.pub-sub]
}
31 changes: 31 additions & 0 deletions test/examples/modular_organization/pub-sub-admin-write-only2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#---------------------------------------------------------------------------------------------
# Ensure installation flow for foundational onboarding has been completed before
# installing additional Sysdig features.
#---------------------------------------------------------------------------------------------

module "pub-sub" {
source = "../../../modules/integrations/pub-sub"
project_id = module.onboarding.project_id
is_organizational = module.onboarding.is_organizational
organization_domain = module.onboarding.organization_domain
sysdig_secure_account_id = module.onboarding.sysdig_secure_account_id
ingestion_sink_filter = ""
audit_log_config = []
exclude_logs_filter = []
}

resource "sysdig_secure_cloud_auth_account_feature" "threat_detection" {
account_id = module.onboarding.sysdig_secure_account_id
type = "FEATURE_SECURE_THREAT_DETECTION"
enabled = true
components = [ module.pub-sub.pubsub_datasource_component_id ]
depends_on = [ module.pub-sub ]
}

resource "sysdig_secure_cloud_auth_account_feature" "identity_entitlement" {
account_id = module.onboarding.sysdig_secure_account_id
type = "FEATURE_SECURE_IDENTITY_ENTITLEMENT"
enabled = true
components = [module.pub-sub.pubsub_datasource_component_id]
depends_on = [sysdig_secure_cloud_auth_account_feature.config_posture, module.pub-sub]
}
36 changes: 35 additions & 1 deletion test/examples/modular_organization/pub-sub.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,40 @@ module "pub-sub" {
is_organizational = module.onboarding.is_organizational
organization_domain = module.onboarding.organization_domain
sysdig_secure_account_id = module.onboarding.sysdig_secure_account_id
ingestion_sink_filter = "protoPayload.@type = \"type.googleapis.com/google.cloud.audit.AuditLog\" (protoPayload.methodName!~ \"\\.(get|list)$\" OR protoPayload.serviceName != (\"k8s.io\" and \"storage.googleapis.com\"))"
audit_log_config = [
{
service = "cloudsql.googleapis.com"
log_config = [{ log_type = "DATA_READ",
exempted_members = [
"serviceAccount:[email protected]",
]
},
{ log_type = "DATA_WRITE" }
]
},
{
service = "storage.googleapis.com"
log_config = [{ log_type = "DATA_WRITE"
}]
},
{
service = "container.googleapis.com"
log_config = [{ log_type = "DATA_READ" }]
}
]
exclude_logs_filter = [
{
name = "nsexcllusion2"
description = "Exclude logs from namespace-2 in k8s"
filter = "resource.type = k8s_container resource.labels.namespace_name=\"namespace-2\" "
},
{
name = "nsexcllusion1"
description = "Exclude logs from namespace-1 in k8s"
filter = "resource.type = k8s_container resource.labels.namespace_name=\"namespace-1\" "
}
]
}

resource "sysdig_secure_cloud_auth_account_feature" "threat_detection" {
Expand All @@ -25,4 +59,4 @@ resource "sysdig_secure_cloud_auth_account_feature" "identity_entitlement" {
enabled = true
components = [module.pub-sub.pubsub_datasource_component_id]
depends_on = [sysdig_secure_cloud_auth_account_feature.config_posture, module.pub-sub]
}
}
34 changes: 34 additions & 0 deletions test/examples/modular_single_project/pub-sub-admin-write-only1.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#---------------------------------------------------------------------------------------------
# Ensure installation flow for foundational onboarding has been completed before
# installing additional Sysdig features.
#---------------------------------------------------------------------------------------------

module "pub-sub" {
source = "../../../modules/integrations/pub-sub"
project_id = module.onboarding.project_id
sysdig_secure_account_id = module.onboarding.sysdig_secure_account_id
ingestion_sink_filter = ""
audit_log_config = [
{
service = "allServices"
log_config = []
}
]
exclude_logs_filter = []
}

resource "sysdig_secure_cloud_auth_account_feature" "threat_detection" {
account_id = module.onboarding.sysdig_secure_account_id
type = "FEATURE_SECURE_THREAT_DETECTION"
enabled = true
components = [ module.pub-sub.pubsub_datasource_component_id ]
depends_on = [ module.pub-sub ]
}

resource "sysdig_secure_cloud_auth_account_feature" "identity_entitlement" {
account_id = module.onboarding.sysdig_secure_account_id
type = "FEATURE_SECURE_IDENTITY_ENTITLEMENT"
enabled = true
components = [module.pub-sub.pubsub_datasource_component_id]
depends_on = [sysdig_secure_cloud_auth_account_feature.config_posture, module.pub-sub]
}
29 changes: 29 additions & 0 deletions test/examples/modular_single_project/pub-sub-admin-write-only2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#---------------------------------------------------------------------------------------------
# Ensure installation flow for foundational onboarding has been completed before
# installing additional Sysdig features.
#---------------------------------------------------------------------------------------------

module "pub-sub" {
source = "../../../modules/integrations/pub-sub"
project_id = module.onboarding.project_id
sysdig_secure_account_id = module.onboarding.sysdig_secure_account_id
ingestion_sink_filter = ""
audit_log_config = []
exclude_logs_filter = []
}

resource "sysdig_secure_cloud_auth_account_feature" "threat_detection" {
account_id = module.onboarding.sysdig_secure_account_id
type = "FEATURE_SECURE_THREAT_DETECTION"
enabled = true
components = [ module.pub-sub.pubsub_datasource_component_id ]
depends_on = [ module.pub-sub ]
}

resource "sysdig_secure_cloud_auth_account_feature" "identity_entitlement" {
account_id = module.onboarding.sysdig_secure_account_id
type = "FEATURE_SECURE_IDENTITY_ENTITLEMENT"
enabled = true
components = [module.pub-sub.pubsub_datasource_component_id]
depends_on = [sysdig_secure_cloud_auth_account_feature.config_posture, module.pub-sub]
}
36 changes: 35 additions & 1 deletion test/examples/modular_single_project/pub-sub.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@ module "pub-sub" {
source = "../../../modules/integrations/pub-sub"
project_id = module.onboarding.project_id
sysdig_secure_account_id = module.onboarding.sysdig_secure_account_id
ingestion_sink_filter = "protoPayload.@type = \"type.googleapis.com/google.cloud.audit.AuditLog\" (protoPayload.methodName!~ \"\\.(get|list)$\" OR protoPayload.serviceName != (\"k8s.io\" and \"storage.googleapis.com\"))"
audit_log_config = [
{
service = "cloudsql.googleapis.com"
log_config = [{ log_type = "DATA_READ",
exempted_members = [
"serviceAccount:[email protected]",
]
},
{ log_type = "DATA_WRITE" }
]
},
{
service = "storage.googleapis.com"
log_config = [{ log_type = "DATA_WRITE"
}]
},
{
service = "container.googleapis.com"
log_config = [{ log_type = "DATA_READ" }]
}
]
exclude_logs_filter = [
{
name = "nsexcllusion2"
description = "Exclude logs from namespace-2 in k8s"
filter = "resource.type = k8s_container resource.labels.namespace_name=\"namespace-2\" "
},
{
name = "nsexcllusion1"
description = "Exclude logs from namespace-1 in k8s"
filter = "resource.type = k8s_container resource.labels.namespace_name=\"namespace-1\" "
}
]
}

resource "sysdig_secure_cloud_auth_account_feature" "threat_detection" {
Expand All @@ -23,4 +57,4 @@ resource "sysdig_secure_cloud_auth_account_feature" "identity_entitlement" {
enabled = true
components = [module.pub-sub.pubsub_datasource_component_id]
depends_on = [sysdig_secure_cloud_auth_account_feature.config_posture, module.pub-sub]
}
}

0 comments on commit 615bf04

Please sign in to comment.