Skip to content

Commit 9f1464d

Browse files
Ak-skyvburckhardt
andauthored
feat: added pre-wired rule targetting HPCS in fscloud module (#310)
Co-authored-by: Vincent Burckhardt <[email protected]>
1 parent aca87f3 commit 9f1464d

File tree

7 files changed

+62
-97
lines changed

7 files changed

+62
-97
lines changed

examples/fscloud/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
This example demonstrates how to use the [fscloud profile](../../profiles/fscloud/) module to lay out a complete "secure by default" coarse-grained CBR topology in a given account.
44

5-
This examples is designed to show case some of the key customization options for the module. In addition to the pre-wired CBR rules documented at [fscloud profile](../../profiles/fscloud/), this examples show how to customize the module to:
6-
1. Open up network traffic flow from ICD mongodb, ICD Postgresql to the Key Protect private endpoints.
7-
2. Open up network traffic flow from Schematics to Key Protect public endpoints.
8-
3. Open up network traffic flow from a block of IPs to the Schematics public endpoint.
9-
4. Open up network traffic flow from the VPC created in this example to ICD postgresql private endpoints.
5+
This examples is designed to show case some of the key customization options for the module. In addition to the pre-wired CBR rules documented at [fscloud profile](../../profiles/fscloud/), this example shows how to customize the module to:
6+
1. Open up network traffic flow from Schematics to Key Protect and HPCS public endpoints. Note that for illustration purpose, this example configures the use of both Key Protect and HPCS through the `kms_service_targeted_by_prewired_rules` variable. In a real-world scenario, only one Key Management Service would be used
7+
2. Open up network traffic flow from a block of IPs to the Schematics public endpoint.
8+
3. Open up network traffic flow from the VPC created in this example to ICD postgresql private endpoints.
109

1110
Context: this examples covers a "pseudo" real-world scenario where:
12-
1. ICD Mongodb and Postgresql instances are encrypted using keys storage in Key Protect.
13-
2. Schematics is used to execute terraform that create Key Protect keys and key ring over its public endpoint.
14-
3. Operators use machines with a set list of public IPs to interact with Schematics.
15-
4. Applications are running the VPC and need access to PostgreSQL via the private endpoint - eg: a VPE.
16-
5. Skips creation of zones for these two service references ["user-management", "iam-groups"].
11+
1. Schematics is used to execute terraform that create Key Protect, and HPCS keys and key ring over its public endpoint.
12+
2. Operators use machines with a set list of public IPs to interact with Schematics.
13+
3. Applications are running the VPC and need access to PostgreSQL via the private endpoint - eg: a VPE.
14+
4. Skips creation of zones for these two service references ["user-management", "iam-groups"].
1715

1816
## Note
1917
- The services 'compliance', 'directlink', 'iam-groups', 'containers-kubernetes', 'user-management' do not support restriction per location for zone creation.

examples/fscloud/main.tf

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,19 @@ resource "ibm_is_subnet" "testacc_subnet" {
5959
##############################################################################
6060

6161
module "cbr_account_level" {
62-
source = "../../modules/fscloud"
63-
prefix = var.prefix
64-
zone_vpc_crn_list = [ibm_is_vpc.example_vpc.crn]
65-
allow_cos_to_kms = var.allow_cos_to_kms
66-
allow_block_storage_to_kms = var.allow_block_storage_to_kms
67-
allow_roks_to_kms = var.allow_roks_to_kms
68-
allow_icd_to_kms = var.allow_icd_to_kms
69-
allow_vpcs_to_container_registry = var.allow_vpcs_to_container_registry
70-
allow_vpcs_to_cos = var.allow_vpcs_to_cos
71-
allow_at_to_cos = var.allow_at_to_cos
72-
allow_iks_to_is = var.allow_iks_to_is
73-
allow_is_to_cos = var.allow_is_to_cos
62+
source = "../../modules/fscloud"
63+
prefix = var.prefix
64+
zone_vpc_crn_list = [ibm_is_vpc.example_vpc.crn]
65+
# Demonstrates how to target either key-protect, hpcs, or both. Both in this fictional example.
66+
kms_service_targeted_by_prewired_rules = ["key-protect", "hs-crypto"]
7467

7568
# Demonstrates how zone creation will be skipped for these two service references ["user-management", "iam-groups"]
7669
skip_specific_services_for_zone_creation = ["user-management", "iam-groups"]
7770

7871
## Enable enforcement for key protect as an example
7972
## The other services not referenced here, are either report, or disabled (when not support report)
8073
target_service_details = {
74+
# Using 'kms' for Key Protect value as target service name supported by CBR for Key Protect is 'kms'.
8175
"kms" = {
8276
"enforcement_mode" = "enabled"
8377
"instance_id" = module.key_protect_module.key_protect_guid
@@ -86,23 +80,21 @@ module "cbr_account_level" {
8680

8781
# Demonstrates how additional context to the rules created by this module can be added.
8882
# This example open up:
89-
# 1. Flows from icd mongodb, postgresql to kms on private endpoint
90-
# 2. Flow from schematics on public kms endpoint
91-
# 3. Add a block of ips to schematics public endpoint
92-
# 4. Flow from vpc(s) specified in input zone_vpc_crn_list to postgresql private endpoint
93-
custom_rule_contexts_by_service = {
94-
"kms" = [{
95-
endpointType = "private"
96-
service_ref_names = ["databases-for-mongodb", "databases-for-postgresql"]
97-
},
83+
# 1. Flow from schematics to KMS on public HPCS endpoint
84+
# 2. Add a block of ips to schematics public endpoint
85+
# 3. Flow from vpc(s) specified in input zone_vpc_crn_list to PostgreSQL private endpoint
86+
# 4. Add a block of ips to Key Protect public endpoint
87+
88+
custom_rule_contexts_by_service = merge({
89+
"kms" = [
9890
{
9991
endpointType = "public"
10092
service_ref_names = ["schematics"]
10193
},
10294
{
10395
endpointType = "public"
10496
zone_ids = [module.cbr_zone_operator_ips.zone_id] }
105-
],
97+
] }, {
10698
"schematics" = [{
10799
endpointType = "public"
108100
zone_ids = [module.cbr_zone_operator_ips.zone_id]
@@ -112,7 +104,13 @@ module "cbr_account_level" {
112104
## Give access to the zone containing the VPC passed in zone_vpc_crn_list input
113105
add_managed_vpc_zone = true
114106
}]
115-
}
107+
}, {
108+
# Using 'kms' for Key Protect value as target service name supported by CBR for Key Protect is 'kms'.
109+
"kms" = [
110+
{
111+
endpointType = "public"
112+
zone_ids = [module.cbr_zone_operator_ips.zone_id] }
113+
] })
116114
}
117115

118116
## Example of zone using ip addresses, and reference in one of the zone created by the cbr_account_level above.

examples/fscloud/variables.tf

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,57 +27,3 @@ variable "resource_tags" {
2727
description = "Optional list of tags to be added to created resources"
2828
default = []
2929
}
30-
31-
variable "allow_cos_to_kms" {
32-
type = bool
33-
description = "Set rule for COS to KMS, default is true"
34-
default = true
35-
}
36-
37-
variable "allow_block_storage_to_kms" {
38-
type = bool
39-
description = "Set rule for block storage to KMS, default is true"
40-
default = true
41-
}
42-
43-
variable "allow_roks_to_kms" {
44-
type = bool
45-
description = "Set rule for ROKS to KMS, default is true"
46-
default = true
47-
}
48-
49-
variable "allow_icd_to_kms" {
50-
type = bool
51-
description = "Set rule for ICD to KMS, deafult is true"
52-
default = true
53-
}
54-
55-
variable "allow_vpcs_to_container_registry" {
56-
type = bool
57-
description = "Set rule for VPCs to container registry, default is true"
58-
default = true
59-
}
60-
61-
variable "allow_vpcs_to_cos" {
62-
type = bool
63-
description = "Set rule for VPCs to COS, default is true"
64-
default = true
65-
}
66-
67-
variable "allow_at_to_cos" {
68-
type = bool
69-
description = "Set rule for Activity Tracker to COS, default is true"
70-
default = true
71-
}
72-
73-
variable "allow_iks_to_is" {
74-
type = bool
75-
description = "Set rule for IKS to IS (VPC Infrastructure Services), default is true"
76-
default = true
77-
}
78-
79-
variable "allow_is_to_cos" {
80-
type = bool
81-
description = "Set rule for IS (VPC Infrastructure Services) to COS, default is true"
82-
default = true
83-
}

modules/fscloud/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ This module creates default coarse-grained CBR rules in a given account followin
44
- COS -> KMS
55
- Block storage -> KMS
66
- ROKS -> KMS
7+
- All ICD services -> KMS
78
- Activity Tracker route -> COS
89
- VPCs where clusters are deployed -> COS
910
- IS (VPC Infrastructure Services) -> COS
1011
- VPCs -> container registry
11-
- All ICD -> KMS
12+
- All ICD -> HPCS
1213
- IKS -> IS (VPC Infrastructure Services)
1314

15+
**Note on KMS**: the module supports setting up rules for Key Protect, and Hyper Protect Crypto Services. By default the modules set rules for Hyper Protect Crypto Services, but this can be modified to use Key Protect, Hyper Protect, or both Key Protect and Hyper Protect Crypto Services using the input variable `kms_service_targeted_by_prewired_rules`.
16+
1417
This module is designed to allow the consumer to add additional custom rules to open up additional flows necessarity for their usage. See the `custom_rule_contexts_by_service` input variable, and an [usage example](../../examples/fscloud/) demonstrating how to open up more flows.
1518

1619
The module also pre-create CBR zone for each service in the account as a best practice. CBR rules associated with these CBR zone can be set by using the `custom_rule_contexts_by_service` variable.
@@ -95,6 +98,7 @@ module "cbr_fscloud" {
9598
| <a name="input_custom_rule_contexts_by_service"></a> [custom\_rule\_contexts\_by\_service](#input\_custom\_rule\_contexts\_by\_service) | Any additional context to add to the CBR rules created by this module. The context are added to the CBR rule targetting the service passed as a key. The module looks up the zone id when service\_ref\_names or add\_managed\_vpc\_zone are passed in. | <pre>map(list(object(<br> {<br> endpointType = string # "private, public or direct"<br><br> # Service-name (module lookup for existing network zone) and/or CBR zone id<br> service_ref_names = optional(list(string), [])<br> add_managed_vpc_zone = optional(bool, false)<br> zone_ids = optional(list(string), [])<br> })))</pre> | `{}` | no |
9699
| <a name="input_existing_cbr_zone_vpcs"></a> [existing\_cbr\_zone\_vpcs](#input\_existing\_cbr\_zone\_vpcs) | Provide a existing zone id for VPC | <pre>object(<br> {<br> zone_id = string<br> })</pre> | `null` | no |
97100
| <a name="input_existing_serviceref_zone"></a> [existing\_serviceref\_zone](#input\_existing\_serviceref\_zone) | Provide a valid service reference and existing zone id | <pre>map(object(<br> {<br> zone_id = string<br> }))</pre> | `{}` | no |
101+
| <a name="input_kms_service_targeted_by_prewired_rules"></a> [kms\_service\_targeted\_by\_prewired\_rules](#input\_kms\_service\_targeted\_by\_prewired\_rules) | IBM Cloud offers two distinct Key Management Services (KMS): Key Protect and Hyper Protect Crypto Services (HPCS). This variable determines the specific KMS service to which the pre-configured rules will be applied. Use the value 'key-protect' to specify the Key Protect service, and 'hs-crypto' for the Hyper Protect Crypto Services (HPCS). | `list(string)` | <pre>[<br> "hs-crypto"<br>]</pre> | no |
98102
| <a name="input_location"></a> [location](#input\_location) | The region in which the network zone is scoped | `string` | `null` | no |
99103
| <a name="input_prefix"></a> [prefix](#input\_prefix) | Prefix to append to all vpc\_zone\_list, service\_ref\_zone\_list and cbr\_rule\_description created by this submodule | `string` | n/a | yes |
100104
| <a name="input_skip_specific_services_for_zone_creation"></a> [skip\_specific\_services\_for\_zone\_creation](#input\_skip\_specific\_services\_for\_zone\_creation) | Provide a list of service references for which zone creation is not required | `list(string)` | `[]` | no |

modules/fscloud/main.tf

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ locals {
6363
"kms" : {
6464
"enforcement_mode" : "report"
6565
},
66+
"hs-crypto" : {
67+
"enforcement_mode" : "report"
68+
},
6669
"containers-kubernetes" : {
6770
"enforcement_mode" : "disabled"
6871
},
@@ -183,6 +186,10 @@ module "cbr_zone_vpcs" {
183186
##############################################################################
184187

185188
locals {
189+
kms_values = [
190+
for kms_val in var.kms_service_targeted_by_prewired_rules :
191+
kms_val == "key-protect" ? "kms" : kms_val # It maps 'key-protect' input to 'kms' because target service name supported by CBR for Key Protect is 'kms'.
192+
]
186193
## define FsCloud pre-wired CBR rule context - contains the known default flow that must be open for fscloud ref architecture
187194
cos_cbr_zone_id = local.cbr_zones["cloud-object-storage"].zone_id
188195
# tflint-ignore: terraform_naming_convention
@@ -210,9 +217,9 @@ locals {
210217
# tflint-ignore: terraform_naming_convention
211218
is_cbr_zone_id = local.cbr_zones["is"].zone_id
212219

213-
prewired_rule_contexts_by_service = {
214-
# COS -> KMS, Block storage -> KMS, ROKS -> KMS, ICD -> KMS
215-
"kms" : [{
220+
prewired_rule_contexts_by_service = merge({
221+
# COS -> HPCS, Block storage -> HPCS, ROKS -> HPCS, ICD -> HPCS
222+
for key in local.kms_values : key => [{
216223
endpointType : "private",
217224
networkZoneIds : flatten([
218225
var.allow_cos_to_kms ? [local.cos_cbr_zone_id] : [],
@@ -227,7 +234,7 @@ locals {
227234
local.databases-for-postgresql_cbr_zone_id,
228235
local.databases-for-redis_cbr_zone_id] : []
229236
])
230-
}],
237+
}] }, {
231238
# Fs VPCs -> COS, AT -> COS, IS (VPC Infrastructure Services) -> COS
232239
"cloud-object-storage" : [{
233240
endpointType : "direct",
@@ -236,22 +243,22 @@ locals {
236243
var.allow_at_to_cos ? [local.logdnaat_cbr_zone_id] : [],
237244
var.allow_is_to_cos ? [local.is_cbr_zone_id] : []
238245
])
239-
}],
246+
}] }, {
240247
# VPCs -> container registry
241248
"container-registry" : [{
242249
endpointType : "private",
243250
networkZoneIds : flatten([
244251
var.allow_vpcs_to_container_registry ? [local.cbr_zone_vpcs.zone_id] : []
245252
])
246-
}],
253+
}] }, {
247254
# IKS -> IS (VPC Infrastructure Services)
248255
"is" : [{
249256
endpointType : "private",
250257
networkZoneIds : flatten([
251258
var.allow_iks_to_is ? [local.containers-kubernetes_cbr_zone_id] : []
252259
])
253260
}],
254-
}
261+
})
255262

256263
prewired_rule_contexts_by_service_check = { for key, value in local.prewired_rule_contexts_by_service :
257264
key => [

modules/fscloud/variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ variable "target_service_details" {
149149
"databases-for-mysql", "databases-for-postgresql", "databases-for-redis",
150150
"directlink", "dns-svcs", "messagehub", "kms", "containers-kubernetes",
151151
"messages-for-rabbitmq", "secrets-manager", "transit", "is",
152-
"schematics", "apprapp", "event-notifications", "compliance"], target_service_name)
152+
"schematics", "apprapp", "event-notifications", "compliance", "hs-crypto"], target_service_name)
153153
])
154154
error_message = "Provide a valid target service name that is supported by context-based restrictions"
155155
}
@@ -229,3 +229,15 @@ variable "location" {
229229
description = "The region in which the network zone is scoped"
230230
default = null
231231
}
232+
233+
variable "kms_service_targeted_by_prewired_rules" {
234+
type = list(string)
235+
description = "IBM Cloud offers two distinct Key Management Services (KMS): Key Protect and Hyper Protect Crypto Services (HPCS). This variable determines the specific KMS service to which the pre-configured rules will be applied. Use the value 'key-protect' to specify the Key Protect service, and 'hs-crypto' for the Hyper Protect Crypto Services (HPCS)."
236+
default = ["hs-crypto"]
237+
validation {
238+
condition = alltrue([
239+
for key_protect_val in var.kms_service_targeted_by_prewired_rules : can(regex("^(key-protect|hs-crypto)$", key_protect_val))
240+
])
241+
error_message = "Valid values for kms are 'key-protect' for Key Protect and 'hs-crypto' for HPCS"
242+
}
243+
}

0 commit comments

Comments
 (0)