Skip to content

Commit fab3300

Browse files
feat: Split containers-kubernetes rules in the secure-by-default submodule (#336)
Co-authored-by: Vincent Burckhardt <vincent.burckhardt@ie.ibm.com>
1 parent 89b346e commit fab3300

File tree

5 files changed

+48
-35
lines changed

5 files changed

+48
-35
lines changed

examples/fscloud/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ This example demonstrates how to use the [fscloud profile](../../profiles/fsclou
44

55
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:
66
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.
7+
2. Open up network traffic flow from a block of IPs to the Schematics public endpoint and the private container clusters endpoints.
88
3. Open up network traffic flow from the VPC created in this example to ICD postgresql private endpoints.
99

1010
Context: this examples covers a "pseudo" real-world scenario where:
1111
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.
12+
2. Operators use machines with a set list of public IPs to interact with Schematics, and through private endpoints to the container clusters.
1313
3. Applications are running the VPC and need access to PostgreSQL via the private endpoint - eg: a VPE.
1414
4. Skips creation of zones for these two service references ["user-management", "iam-groups"].
1515

examples/fscloud/main.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,13 @@ module "cbr_account_level" {
103103
endpointType = "private"
104104
## Give access to the zone containing the VPC passed in zone_vpc_crn_list input
105105
add_managed_vpc_zone = true
106+
}],
107+
"containers-kubernetes-cluster" = [{
108+
endpointType = "private"
109+
## Give operator access to run kubectl against private endpoints on any cluster in account
110+
zone_ids = [module.cbr_zone_operator_ips.zone_id]
106111
}]
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-
] })
112+
})
114113
}
115114

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

modules/fscloud/README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# Pre-wired CBR configuration for FS Cloud
22

33
This module creates default coarse-grained CBR rules in a given account following a "secure by default" approach - that is: deny all flows by default, except known documented communication in the [Financial Services Cloud Reference Architecture](https://cloud.ibm.com/docs/framework-financial-services?topic=framework-financial-services-vpc-architecture-about):
4-
- COS -> KMS
5-
- Block storage -> KMS
6-
- ROKS -> KMS
7-
- All ICD services -> KMS
8-
- Activity Tracker route -> COS
9-
- VPCs where clusters are deployed -> COS
10-
- IS (VPC Infrastructure Services) -> COS
11-
- VPCs -> container registry
12-
- All ICD -> HPCS
13-
- IKS -> IS (VPC Infrastructure Services)
4+
- Cloud Object Storage (COS) -> Key Management Service (KMS)
5+
- Block Storage -> Key Management Service (KMS)
6+
- IBM Cloud Kubernetes Service (IKS) -> Key Management Service (KMS)
7+
- All IBM Cloud Databases (ICD) services -> Key Management Service (KMS)
8+
- Activity Tracker route -> Cloud Object Storage (COS)
9+
- Virtual Private Clouds (VPCs) where clusters are deployed -> Cloud Object Storage (COS)
10+
- IBM Cloud VPC Infrastructure Services (IS) -> Cloud Object Storage (COS)
11+
- Virtual Private Cloud workload (eg: Kubernetes worker nodes) -> IBM Cloud Container Registry
12+
- IBM Cloud Databases (ICD) -> Hyper Protect Crypto Services (HPCS)
13+
- IBM Cloud Kubernetes Service (IKS) -> IS (VPC Infrastructure Services)
14+
1415

1516
**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`.
1617

18+
**Note on containers-kubernetes**: the module supports the pseudo-service names `containers-kubernetes-management` and `containers-kubernetes-cluster` to distinguish between the cluster and management APIs (see [details](https://cloud.ibm.com/docs/containers?topic=containers-cbr&interface=ui#protect-api-types-cbr) ). The module creates separates CBR rules for the two types of APIs by default to align with common real-world scenarios. `containers-kubernetes` can be used to create a CBR targetting both the cluster and management APIs.
19+
1720
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.
1821

1922
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.

modules/fscloud/main.tf

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ locals {
6666
"hs-crypto" : {
6767
"enforcement_mode" : "report"
6868
},
69-
"containers-kubernetes" : {
69+
"containers-kubernetes-management" : {
70+
"enforcement_mode" : "disabled"
71+
},
72+
"containers-kubernetes-cluster" : {
7073
"enforcement_mode" : "disabled"
7174
},
7275
"messages-for-rabbitmq" : {
@@ -257,7 +260,7 @@ locals {
257260
networkZoneIds : flatten([
258261
var.allow_iks_to_is ? [local.containers-kubernetes_cbr_zone_id] : []
259262
])
260-
}],
263+
}]
261264
})
262265

263266
prewired_rule_contexts_by_service_check = { for key, value in local.prewired_rule_contexts_by_service :
@@ -311,16 +314,23 @@ locals {
311314
# Restrict and allow the api types as per the target service
312315
icd_api_types = ["crn:v1:bluemix:public:context-based-restrictions::::api-type:data-plane"]
313316
operations_apitype_val = {
314-
databases-for-enterprisedb = local.icd_api_types,
315-
containers-kubernetes = ["crn:v1:bluemix:public:containers-kubernetes::::api-type:cluster", "crn:v1:bluemix:public:containers-kubernetes::::api-type:management"],
316-
databases-for-cassandra = local.icd_api_types,
317-
databases-for-elasticsearch = local.icd_api_types,
318-
databases-for-etcd = local.icd_api_types,
319-
databases-for-mongodb = local.icd_api_types,
320-
databases-for-postgresql = local.icd_api_types,
321-
databases-for-redis = local.icd_api_types,
322-
messages-for-rabbitmq = local.icd_api_types,
323-
databases-for-mysql = local.icd_api_types
317+
databases-for-enterprisedb = local.icd_api_types,
318+
containers-kubernetes = ["crn:v1:bluemix:public:containers-kubernetes::::api-type:cluster", "crn:v1:bluemix:public:containers-kubernetes::::api-type:management"],
319+
containers-kubernetes-cluster = ["crn:v1:bluemix:public:containers-kubernetes::::api-type:cluster"],
320+
containers-kubernetes-management = ["crn:v1:bluemix:public:containers-kubernetes::::api-type:management"]
321+
databases-for-cassandra = local.icd_api_types,
322+
databases-for-elasticsearch = local.icd_api_types,
323+
databases-for-etcd = local.icd_api_types,
324+
databases-for-mongodb = local.icd_api_types,
325+
databases-for-postgresql = local.icd_api_types,
326+
databases-for-redis = local.icd_api_types,
327+
messages-for-rabbitmq = local.icd_api_types,
328+
databases-for-mysql = local.icd_api_types
329+
}
330+
331+
fake_service_names = {
332+
"containers-kubernetes-cluster" = "containers-kubernetes",
333+
"containers-kubernetes-management" = "containers-kubernetes"
324334
}
325335
}
326336

@@ -362,7 +372,7 @@ module "cbr_rule" {
362372
{
363373
name = "serviceName",
364374
operator = "stringEquals",
365-
value = each.key
375+
value = lookup(local.fake_service_names, each.key, each.key)
366376
}] : try(each.value.instance_id, null) != null ? [
367377
{
368378
name = "accountId",
@@ -377,7 +387,7 @@ module "cbr_rule" {
377387
{
378388
name = "serviceName",
379389
operator = "stringEquals",
380-
value = each.key
390+
value = lookup(local.fake_service_names, each.key, each.key)
381391
}] : [
382392
{
383393
name = "accountId",
@@ -387,7 +397,7 @@ module "cbr_rule" {
387397
{
388398
name = "serviceName",
389399
operator = "stringEquals",
390-
value = each.key
400+
value = lookup(local.fake_service_names, each.key, each.key)
391401
}]
392402
}]
393403
}

modules/fscloud/variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ variable "custom_rule_contexts_by_service" {
107107
for key, val in var.custom_rule_contexts_by_service :
108108
[for rule in val : [
109109
for ref in rule.service_ref_names : contains(["cloud-object-storage", "codeengine", "containers-kubernetes",
110+
"containers-kubernetes-cluster", "containers-kubernetes-management",
110111
"databases-for-cassandra", "databases-for-elasticsearch", "databases-for-enterprisedb",
111112
"databases-for-etcd", "databases-for-mongodb",
112113
"databases-for-mysql", "databases-for-postgresql",
@@ -147,7 +148,7 @@ variable "target_service_details" {
147148
"databases-for-enterprisedb", "databases-for-elasticsearch",
148149
"databases-for-etcd", "databases-for-mongodb",
149150
"databases-for-mysql", "databases-for-postgresql", "databases-for-redis",
150-
"directlink", "dns-svcs", "messagehub", "kms", "containers-kubernetes",
151+
"directlink", "dns-svcs", "messagehub", "kms", "containers-kubernetes", "containers-kubernetes-cluster", "containers-kubernetes-management",
151152
"messages-for-rabbitmq", "secrets-manager", "transit", "is",
152153
"schematics", "apprapp", "event-notifications", "compliance", "hs-crypto"], target_service_name)
153154
])

0 commit comments

Comments
 (0)