Skip to content

Commit 8108e45

Browse files
authored
fix: added fix to ensure only service-group-id should be specified when the pseudo service IAM is used (#487)
1 parent efff26e commit 8108e45

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

examples/fscloud/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This examples is designed to show case some of the key customization options for
88
3. Open up network traffic flow from a block of IPs to the Schematics public endpoint.
99
4. Open up network traffic flow from the VPC created in this example to ICD postgresql private endpoints.
1010
5. Customize the rule description for `kms` and the zone name for `codeengine`.
11+
6. Restrict network traffic flow for pseudo `IAM` service.
1112

1213
Context: this examples covers a "pseudo" real-world scenario where:
1314
1. ICD Mongodb and Postgresql instances are encrypted using keys storage in Key Protect.
@@ -17,4 +18,4 @@ Context: this examples covers a "pseudo" real-world scenario where:
1718
5. Skips creation of zones for these two service references ["user-management", "iam-groups"].
1819

1920
## Note
20-
- The services 'compliance', 'directlink', 'iam-groups', 'containers-kubernetes', 'user-management' do not support restriction per location for zone creation.
21+
The services 'directlink', 'globalcatalog-collection', 'iam-groups' and 'user-management' do not support restrictions per location.

examples/fscloud/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ module "cbr_account_level" {
8787
}
8888
"mqcloud" : {
8989
"enforcement_mode" = "disabled"
90-
"region" = "eu-fr2" # BNPP region
90+
"region" = "eu-fr2" # BNPP region (region or serviceInstance is/are required for service 'mqcloud`)
91+
"global_deny" = false
92+
}
93+
"IAM" : {
94+
"enforcement_mode" = "report"
9195
"global_deny" = false
9296
}
9397
}

modules/fscloud/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Important: In order to avoid unexpected breakage in the account against which th
2727
**Note on Event Notifications**: Event Notifications introduced SMTP API that does not support `report` enforcement mode. By default `report` mode is set which excludes SMTP API. If enforcement mode is set to `enabled`, CBR will be applied to the SMTP API as well.
2828

2929
## Note
30-
The services 'directlink', 'globalcatalog-collection', 'iam-groups' and 'user-management' does not support restriction per location.
30+
The services 'directlink', 'globalcatalog-collection', 'iam-groups' and 'user-management' do not support restriction per location.
3131

3232
### Usage
3333

modules/fscloud/main.tf

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ data "ibm_iam_account_settings" "iam_account_settings" {
55
}
66

77
locals {
8+
9+
service_group_ids = ["IAM"] # List of pseudo services for which service_group_id is required
10+
811
target_service_details_default = {
912
"iam-groups" : {
1013
"enforcement_mode" : "report"
@@ -98,7 +101,6 @@ locals {
98101
},
99102
"IAM" : {
100103
"enforcement_mode" : "report"
101-
"service_group_id" : "IAM"
102104
},
103105
"context-based-restrictions" : {
104106
"enforcement_mode" : "report"
@@ -325,10 +327,6 @@ locals {
325327
] }]
326328
}
327329

328-
deny_rules_by_service = { for target_service_name in keys(local.global_deny_target_service_details) :
329-
target_service_name => []
330-
}
331-
332330
# Some services have restrictions on the api types that can apply CBR - we codify this below
333331
# Restrict and allow the api types as per the target service
334332
icd_api_types = ["crn:v1:bluemix:public:context-based-restrictions::::api-type:data-plane"]
@@ -355,18 +353,23 @@ locals {
355353
}
356354

357355
locals {
356+
358357
target_service_details_attributes = { for key, value in local.target_service_details :
359358
key => [
360359
{
361360
name = "accountId",
362361
operator = "stringEquals",
363362
value = data.ibm_iam_account_settings.iam_account_settings.account_id
364363
},
365-
try(value.service_group_id, null) != null ? {
364+
contains(local.service_group_ids, key) ? {
366365
name = "service_group_id",
367366
operator = "stringEquals",
368-
value = value.service_group_id
369-
} : {},
367+
value = key
368+
} : {
369+
name = "serviceName",
370+
operator = "stringEquals",
371+
value = lookup(local.fake_service_names, key, key)
372+
},
370373
try(value.target_rg, null) != null ? {
371374
name = "resourceGroupId",
372375
operator = "stringEquals",
@@ -381,11 +384,6 @@ locals {
381384
name = "region",
382385
operator = "stringEquals",
383386
value = value.region
384-
} : {},
385-
try(value.service_group_id, null) == null ? {
386-
name = "serviceName",
387-
operator = "stringEquals",
388-
value = lookup(local.fake_service_names, key, key)
389387
} : {}
390388
] }
391389
}
@@ -433,8 +431,7 @@ module "global_deny_cbr_rule" {
433431
source = "../../modules/cbr-rule-module"
434432
rule_description = try(each.value.description, null) != null ? each.value.description : "${var.prefix}-${each.key}-global-deny-rule"
435433
enforcement_mode = each.value.enforcement_mode
436-
rule_contexts = lookup(local.deny_rules_by_service, each.key, [])
437-
434+
rule_contexts = []
438435

439436
resources = [{
440437
tags = try(each.value.tags, null) != null ? [for tag in each.value.tags : {
@@ -447,10 +444,15 @@ module "global_deny_cbr_rule" {
447444
operator = "stringEquals",
448445
value = data.ibm_iam_account_settings.iam_account_settings.account_id
449446
},
450-
{
447+
contains(local.service_group_ids, each.key) ? {
448+
name = "service_group_id",
449+
operator = "stringEquals",
450+
value = each.key
451+
} : {
451452
name = "serviceName",
452453
operator = "stringEquals",
453454
value = lookup(local.fake_service_names, each.key, each.key)
454-
}]
455+
}
456+
]
455457
}]
456458
}

0 commit comments

Comments
 (0)