Skip to content

Commit 5abca90

Browse files
authored
feat: added CBR support (#529)
1 parent 23a24c9 commit 5abca90

File tree

11 files changed

+166
-30
lines changed

11 files changed

+166
-30
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ Optionally, you need the following permissions to attach Access Management tags
256256
| <a name="module_attach_sg_to_lb"></a> [attach\_sg\_to\_lb](#module\_attach\_sg\_to\_lb) | terraform-ibm-modules/security-group/ibm | 2.6.2 |
257257
| <a name="module_attach_sg_to_master_vpe"></a> [attach\_sg\_to\_master\_vpe](#module\_attach\_sg\_to\_master\_vpe) | terraform-ibm-modules/security-group/ibm | 2.6.2 |
258258
| <a name="module_attach_sg_to_registry_vpe"></a> [attach\_sg\_to\_registry\_vpe](#module\_attach\_sg\_to\_registry\_vpe) | terraform-ibm-modules/security-group/ibm | 2.6.2 |
259+
| <a name="module_cbr_rule"></a> [cbr\_rule](#module\_cbr\_rule) | terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module | 1.24.0 |
259260
| <a name="module_cos_instance"></a> [cos\_instance](#module\_cos\_instance) | terraform-ibm-modules/cos/ibm | 8.13.2 |
260261
261262
### Resources
@@ -296,6 +297,7 @@ Optionally, you need the following permissions to attach Access Management tags
296297
| <a name="input_addons"></a> [addons](#input\_addons) | Map of OCP cluster add-on versions to install (NOTE: The 'vpc-block-csi-driver' add-on is installed by default for VPC clusters and 'ibm-storage-operator' is installed by default in OCP 4.15 and later, however you can explicitly specify it here if you wish to choose a later version than the default one). For full list of all supported add-ons and versions, see https://cloud.ibm.com/docs/containers?topic=containers-supported-cluster-addon-versions | <pre>object({<br/> debug-tool = optional(string)<br/> image-key-synchronizer = optional(string)<br/> openshift-data-foundation = optional(string)<br/> vpc-file-csi-driver = optional(string)<br/> static-route = optional(string)<br/> cluster-autoscaler = optional(string)<br/> vpc-block-csi-driver = optional(string)<br/> ibm-storage-operator = optional(string)<br/> })</pre> | `{}` | no |
297298
| <a name="input_allow_default_worker_pool_replacement"></a> [allow\_default\_worker\_pool\_replacement](#input\_allow\_default\_worker\_pool\_replacement) | (Advanced users) Set to true to allow the module to recreate a default worker pool. Only use in the case where you are getting an error indicating that the default worker pool cannot be replaced on apply. Once the default worker pool is handled as a stand-alone ibm\_container\_vpc\_worker\_pool, if you wish to make any change to the default worker pool which requires the re-creation of the default pool set this variable to true. | `bool` | `false` | no |
298299
| <a name="input_attach_ibm_managed_security_group"></a> [attach\_ibm\_managed\_security\_group](#input\_attach\_ibm\_managed\_security\_group) | Specify whether to attach the IBM-defined default security group (whose name is kube-<clusterid>) to all worker nodes. Only applicable if custom\_security\_group\_ids is set. | `bool` | `true` | no |
300+
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | The list of context-based restriction rules to create. | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> tags = optional(list(object({<br/> name = string<br/> value = string<br/> })), [])<br/> operations = optional(list(object({<br/> api_types = list(object({<br/> api_type_id = string<br/> }))<br/> })))<br/> }))</pre> | `[]` | no |
299301
| <a name="input_cluster_config_endpoint_type"></a> [cluster\_config\_endpoint\_type](#input\_cluster\_config\_endpoint\_type) | Specify which type of endpoint to use for for cluster config access: 'default', 'private', 'vpe', 'link'. 'default' value will use the default endpoint of the cluster. | `string` | `"default"` | no |
300302
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The name that will be assigned to the provisioned cluster | `string` | n/a | yes |
301303
| <a name="input_cluster_ready_when"></a> [cluster\_ready\_when](#input\_cluster\_ready\_when) | The cluster is ready when one of the following: MasterNodeReady (not recommended), OneWorkerNodeReady, Normal, IngressReady | `string` | `"IngressReady"` | no |

cra-config.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
version: "v1"
22
CRA_TARGETS:
3-
- CRA_TARGET: "examples/fscloud"
3+
- CRA_TARGET: "examples/advanced"
44
CRA_IGNORE_RULES_FILE: "cra-tf-validate-ignore-rules.json"
55
PROFILE_ID: "fe96bd4d-9b37-40f2-b39f-a62760e326a3" # SCC profile ID (currently set to 'IBM Cloud Framework for Financial Services' '1.7.0' profile).
66
CRA_ENVIRONMENT_VARIABLES: # An optional map of environment variables for CRA, where the key is the variable name and value is the value. Useful for providing TF_VARs.
7-
TF_VAR_hpcs_instance_guid: "e6dce284-e80f-46e1-a3c1-830f7adff7a9"
8-
TF_VAR_hpcs_key_crn_cluster: "crn:v1:bluemix:public:hs-crypto:us-south:a/abac0df06b644a9cabc6e44f55b3880e:e6dce284-e80f-46e1-a3c1-830f7adff7a9:key:1368d2eb-3ed0-4a8b-b09c-2155895f01ea"
9-
TF_VAR_hpcs_key_crn_worker_pool: "crn:v1:bluemix:public:hs-crypto:us-south:a/abac0df06b644a9cabc6e44f55b3880e:e6dce284-e80f-46e1-a3c1-830f7adff7a9:key:1368d2eb-3ed0-4a8b-b09c-2155895f01ea"
107
TF_VAR_region: "us-south"
11-
TF_VAR_prefix: "base-ocp-std"
8+
TF_VAR_prefix: "base-ocp-adv"

cra-tf-validate-ignore-rules.json

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
11
{
22
"scc_rules": [
33
{
4-
"scc_rule_id": "rule-8cbd597c-7471-42bd-9c88-36b2696456e9",
5-
"description": "Check whether Cloud Object Storage network access is restricted to a specific IP range",
6-
"ignore_reason": "This module supports restricting network access using Context Based Restrictions (CBRs), however SCC does not yet support scanning for CBR rules, hence the rule currently fails. SCC CBR support is being tracked in AHA SCC-961",
7-
"is_valid": true
8-
},
9-
{
10-
"scc_rule_id": "rule-4d86c074-097e-4ff3-a763-ccff128388e2",
11-
"description": "Check whether multifactor authentication (MFA) is enabled at the account level",
12-
"ignore_reason": "This is an account based rule, so unrelated to this module itself",
13-
"is_valid": true
14-
},
15-
{
16-
"scc_rule_id": "rule-0704e840-e443-4781-b9be-ec57469d09c1",
17-
"description": "Check whether permissions for API key creation are limited and configured in IAM settings for the account owner",
18-
"ignore_reason": "This is an account based rule, so unrelated to this module itself",
19-
"is_valid": true
20-
},
21-
{
22-
"scc_rule_id": "rule-0244c010-fde6-4db3-95aa-8952bd292ac3",
23-
"description": "Check whether permissions for service ID creation are limited and configured in IAM settings for the account owner",
24-
"ignore_reason": "This is an account based rule, so unrelated to this module itself",
25-
"is_valid": true
4+
"scc_rule_id": "rule-64c0bea0-8760-4a6b-a56c-ee375a48961e",
5+
"description": "Check whether Virtual Private Cloud (VPC) has no public gateways attached",
6+
"ignore_reason": "This rule is not relevant to the module itself, just the VPC resource that is used in the example that is scanned",
7+
"is_valid": false
268
}
279
]
2810
}

examples/fscloud/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ The following resources are provisioned by this example:
1010
- An IBM Cloud Monitoring (Sysdig) instance.
1111
- An IBM Cloud Activity Tracker instance, if existing ones is not passed in.
1212
- A context-based restriction (CBR) rule to only allow COS Instance to be accessible from within the VPC.
13+
- A Context-based restriction (CBR) network zone containing the VPC.
14+
- A Context-based restriction network zone containing the schematics service.
15+
- CBR rules that allow only the VPC and schematics to access the OCP cluster over the private endpoint.
1316
- An OCP cluster in a VPC with the default worker pool deployed across 3 availability zones with cluster and boot volume encrypted with the given Hyper Protect Crypto Service root key.
1417

1518
:exclamation: **Important:** OCP provisions a COS bucket, but you cannot use your own encryption keys. This will fail the requirement for Cloud Object Storage to be enabled with customer-managed encryption and Keep Your Own Key (KYOK). In OCP 4.14, COS will become optional to provision a cluster.

examples/fscloud/main.tf

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,33 @@ data "ibm_iam_account_settings" "iam_account_settings" {
110110
# Create CBR Zone and Rules
111111
########################################################################################################################
112112

113-
module "cbr_zone" {
113+
module "cbr_vpc_zone" {
114114
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
115115
version = "1.28.0"
116116
name = "${var.prefix}-VPC-network-zone"
117-
zone_description = "CBR Network zone containing VPC"
117+
zone_description = "CBR Network zone representing VPC"
118118
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
119119
addresses = [{
120120
type = "vpc", # to bind a specific vpc to the zone
121121
value = module.vpc.vpc_crn,
122122
}]
123123
}
124124

125+
module "cbr_zone_schematics" {
126+
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
127+
version = "1.27.0"
128+
name = "${var.prefix}-schematics-zone"
129+
zone_description = "CBR Network zone containing Schematics"
130+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
131+
addresses = [{
132+
type = "serviceRef",
133+
ref = {
134+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
135+
service_name = "schematics"
136+
}
137+
}]
138+
}
139+
125140
module "cbr_rules" {
126141
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module"
127142
version = "1.28.0"
@@ -159,7 +174,7 @@ module "cbr_rules" {
159174
},
160175
{
161176
name = "networkZoneId"
162-
value = module.cbr_zone.zone_id
177+
value = module.cbr_vpc_zone.zone_id
163178
}]
164179
}]
165180
}
@@ -240,4 +255,41 @@ module "ocp_fscloud" {
240255
crk_id = local.cluster_hpcs_cluster_key_id
241256
private_endpoint = true
242257
}
258+
cbr_rules = [
259+
{
260+
description = "${var.prefix}-OCP-base access only from vpc"
261+
enforcement_mode = "enabled"
262+
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
263+
rule_contexts = [{
264+
attributes = [
265+
{
266+
"name" : "endpointType",
267+
"value" : "private"
268+
},
269+
{
270+
name = "networkZoneId"
271+
value = module.cbr_vpc_zone.zone_id
272+
}]
273+
}, {
274+
attributes = [
275+
{
276+
"name" : "endpointType",
277+
"value" : "private"
278+
},
279+
{
280+
name = "networkZoneId"
281+
value = module.cbr_zone_schematics.zone_id
282+
}]
283+
}]
284+
operations = [{
285+
api_types = [
286+
{
287+
"api_type_id" : "crn:v1:bluemix:public:containers-kubernetes::::api-type:management"
288+
}
289+
]
290+
}]
291+
}
292+
293+
]
294+
243295
}

examples/fscloud/provider.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
provider "ibm" {
66
ibmcloud_api_key = var.ibmcloud_api_key
77
region = var.region
8+
visibility = "private"
89
}

main.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,44 @@ module "attach_sg_to_registry_vpe" {
657657
use_existing_security_group_id = true
658658
target_ids = [local.registry_vpe_id]
659659
}
660+
661+
##############################################################################
662+
# Context Based Restrictions
663+
##############################################################################
664+
locals {
665+
default_operations = [{
666+
api_types = [
667+
{
668+
"api_type_id" : "crn:v1:bluemix:public:context-based-restrictions::::api-type:"
669+
}
670+
]
671+
}]
672+
}
673+
module "cbr_rule" {
674+
count = length(var.cbr_rules) > 0 ? length(var.cbr_rules) : 0
675+
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module"
676+
version = "1.24.0"
677+
rule_description = var.cbr_rules[count.index].description
678+
enforcement_mode = var.cbr_rules[count.index].enforcement_mode
679+
rule_contexts = var.cbr_rules[count.index].rule_contexts
680+
resources = [{
681+
attributes = [
682+
{
683+
name = "accountId"
684+
value = var.cbr_rules[count.index].account_id
685+
operator = "stringEquals"
686+
},
687+
{
688+
name = "serviceInstance"
689+
value = var.ignore_worker_pool_size_changes ? ibm_container_vpc_cluster.autoscaling_cluster[0].id : ibm_container_vpc_cluster.cluster[0].id
690+
operator = "stringEquals"
691+
},
692+
{
693+
name = "serviceName"
694+
value = "containers-kubernetes"
695+
operator = "stringEquals"
696+
}
697+
],
698+
}]
699+
operations = var.cbr_rules[count.index].operations == null ? local.default_operations : var.cbr_rules[count.index].operations
700+
}

modules/fscloud/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ No resources.
118118
| <a name="input_addons"></a> [addons](#input\_addons) | Map of OCP cluster add-on versions to install (NOTE: The 'vpc-block-csi-driver' add-on is installed by default for VPC clusters and 'ibm-storage-operator' is installed by default in OCP 4.15 and later, however you can explicitly specify it here if you wish to choose a later version than the default one). For full list of all supported add-ons and versions, see https://cloud.ibm.com/docs/containers?topic=containers-supported-cluster-addon-versions | <pre>object({<br/> debug-tool = optional(string)<br/> image-key-synchronizer = optional(string)<br/> openshift-data-foundation = optional(string)<br/> vpc-file-csi-driver = optional(string)<br/> static-route = optional(string)<br/> cluster-autoscaler = optional(string)<br/> vpc-block-csi-driver = optional(string)<br/> ibm-storage-operator = optional(string)<br/> })</pre> | `{}` | no |
119119
| <a name="input_allow_default_worker_pool_replacement"></a> [allow\_default\_worker\_pool\_replacement](#input\_allow\_default\_worker\_pool\_replacement) | (Advanced users) Set to true to allow the module to recreate a default worker pool. Only use in the case where you are getting an error indicating that the default worker pool cannot be replaced on apply. Once the default worker pool is handled as a stand-alone ibm\_container\_vpc\_worker\_pool, if you wish to make any change to the default worker pool which requires the re-creation of the default pool set this variable to true. | `bool` | `false` | no |
120120
| <a name="input_attach_ibm_managed_security_group"></a> [attach\_ibm\_managed\_security\_group](#input\_attach\_ibm\_managed\_security\_group) | Specify whether to attach the IBM-defined default security group (whose name is kube-<clusterid>) to all worker nodes. Only applicable if custom\_security\_group\_ids is set. | `bool` | `true` | no |
121+
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | The list of context-based restriction rules to create. | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> tags = optional(list(object({<br/> name = string<br/> value = string<br/> })), [])<br/> operations = optional(list(object({<br/> api_types = list(object({<br/> api_type_id = string<br/> }))<br/> })))<br/> }))</pre> | `[]` | no |
121122
| <a name="input_cluster_config_endpoint_type"></a> [cluster\_config\_endpoint\_type](#input\_cluster\_config\_endpoint\_type) | Specify which type of endpoint to use for for cluster config access: 'private', 'vpe', 'link'. | `string` | `"private"` | no |
122123
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The name that will be assigned to the provisioned cluster | `string` | n/a | yes |
123124
| <a name="input_cluster_ready_when"></a> [cluster\_ready\_when](#input\_cluster\_ready\_when) | The cluster is ready when one of the following: MasterNodeReady (not recommended), OneWorkerNodeReady, Normal, IngressReady | `string` | `"IngressReady"` | no |

modules/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ module "fscloud" {
3434
additional_lb_security_group_ids = var.additional_lb_security_group_ids
3535
number_of_lbs = var.number_of_lbs
3636
additional_vpe_security_group_ids = var.additional_vpe_security_group_ids
37+
cbr_rules = var.cbr_rules
3738
}

modules/fscloud/variables.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,31 @@ variable "additional_vpe_security_group_ids" {
237237
}
238238

239239
##############################################################################
240+
241+
##############################################################
242+
# Context-based restriction (CBR)
243+
##############################################################
244+
245+
variable "cbr_rules" {
246+
type = list(object({
247+
description = string
248+
account_id = string
249+
rule_contexts = list(object({
250+
attributes = optional(list(object({
251+
name = string
252+
value = string
253+
}))) }))
254+
enforcement_mode = string
255+
tags = optional(list(object({
256+
name = string
257+
value = string
258+
})), [])
259+
operations = optional(list(object({
260+
api_types = list(object({
261+
api_type_id = string
262+
}))
263+
})))
264+
}))
265+
description = "The list of context-based restriction rules to create."
266+
default = []
267+
}

0 commit comments

Comments
 (0)