Skip to content

Commit 032c772

Browse files
authored
feat: Scope auth policy for flow logs to exact cos bucket<br><br>NOTE: When upgrading from a previous version, you will see a recreate of this auth policy, however new auth policy will be created before destroyed so there will be no disruption to everyday services (#941)
1 parent 33309f8 commit 032c772

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

main.tf

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,47 @@ resource "ibm_is_public_gateway" "gateway" {
326326
# Add VPC to Flow Logs
327327
##############################################################################
328328

329-
# Create authorization policy to allow VPC to access COS instance
329+
# Create authorization policy to allow VPC to access COS Bucket
330330
resource "ibm_iam_authorization_policy" "policy" {
331331
count = (var.enable_vpc_flow_logs) ? ((var.create_authorization_policy_vpc_to_cos) ? 1 : 0) : 0
332332

333-
source_service_name = "is"
334-
source_resource_type = "flow-log-collector"
335-
target_service_name = "cloud-object-storage"
336-
target_resource_instance_id = var.existing_cos_instance_guid
337-
roles = ["Writer"]
333+
source_service_name = "is"
334+
source_resource_type = "flow-log-collector"
335+
roles = ["Writer"]
336+
337+
resource_attributes {
338+
name = "accountId"
339+
operator = "stringEquals"
340+
value = data.ibm_iam_account_settings.iam_account_settings.account_id
341+
}
342+
343+
resource_attributes {
344+
name = "serviceName"
345+
operator = "stringEquals"
346+
value = "cloud-object-storage"
347+
}
348+
349+
resource_attributes {
350+
name = "serviceInstance"
351+
operator = "stringEquals"
352+
value = var.existing_cos_instance_guid
353+
}
354+
355+
resource_attributes {
356+
name = "resourceType"
357+
operator = "stringEquals"
358+
value = "bucket"
359+
}
360+
361+
resource_attributes {
362+
name = "resource"
363+
operator = "stringEquals"
364+
value = var.existing_storage_bucket_name
365+
}
366+
367+
lifecycle {
368+
create_before_destroy = true
369+
}
338370
}
339371

340372
# Create VPC flow logs collector

solutions/fully-configurable/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ locals {
3333
kms_service_name = var.kms_encryption_enabled_bucket ? (length(module.existing_kms_key_crn_parser) > 0 ? module.existing_kms_key_crn_parser[0].service_name : module.existing_kms_instance_crn_parser[0].service_name) : null
3434
cos_kms_key_crn = var.kms_encryption_enabled_bucket ? (length(module.existing_kms_key_crn_parser) > 0 ? var.existing_flow_logs_bucket_kms_key_crn : module.kms[0].keys[format("%s.%s", local.kms_key_ring_name, local.kms_key_name)].crn) : null
3535
create_cos_kms_iam_auth_policy = var.enable_vpc_flow_logs && var.kms_encryption_enabled_bucket && !var.skip_cos_kms_iam_auth_policy
36-
create_cross_account_cos_kms_auth_policy = (local.create_cos_kms_iam_auth_policy && var.ibmcloud_kms_api_key == null) ? false : (local.cos_account_id != local.kms_account_id)
36+
create_cross_account_cos_kms_auth_policy = (local.create_cos_kms_iam_auth_policy && var.ibmcloud_kms_api_key == null) ? false : (local.kms_account_id != null ? (local.cos_account_id != local.kms_account_id) : false)
3737

3838
# configuration for the flow logs bucket
3939
bucket_config = [{
@@ -43,7 +43,7 @@ locals {
4343
kms_encryption_enabled = var.kms_encryption_enabled_bucket
4444
kms_guid = local.kms_guid
4545
kms_key_crn = local.cos_kms_key_crn
46-
skip_iam_authorization_policy = local.create_cross_account_cos_kms_auth_policy || var.skip_cos_kms_iam_auth_policy
46+
skip_iam_authorization_policy = local.create_cross_account_cos_kms_auth_policy || !local.create_cos_kms_iam_auth_policy
4747
management_endpoint_type = var.management_endpoint_type_for_bucket
4848
storage_class = var.cos_bucket_class
4949
resource_instance_id = var.existing_cos_instance_crn

0 commit comments

Comments
 (0)