Skip to content

Commit c4f70d5

Browse files
slmjyhyder
andauthored
create_policies variable to turn off any potential policy creation tempt (#325) (#442)
* create_policies variable to turn off any potential policy creation attempt (#325) * create_policies > review feedback (#325) * create_policies > review feedback (#325) * Renamed kms_key_id to cluster_kms_key_id Co-authored-by: Ali Mukadam <lmukadam@gmail.com>
1 parent 5790493 commit c4f70d5

File tree

12 files changed

+76
-53
lines changed

12 files changed

+76
-53
lines changed

docs/configuration.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Alternatively, you can also specify these using Terraform environment variables
7777
export TF_api_fingerprint = "1a:bc:23:45:6d:78:e9:f0:gh:ij:kl:m1:23:no:4p:5q"
7878
----
7979

80-
You would have obtained your values when doing the {uri-prereqs}[Prerequisites].
80+
You would have obtained your values when doing the {uri-prereqs}[Prerequisites].
8181

8282
{uri-terraform-options}#identity-and-access[Reference]
8383

@@ -129,7 +129,7 @@ The list of regions can be found {uri-oci-region}[here].
129129

130130
== Configure OCI Networking parameters
131131

132-
The networking parameters concern the VCN and the subnets network configuration as well as whether to enable some specific features such as the NAT Gateway.
132+
The networking parameters concern the VCN and the subnets network configuration as well as whether to enable some specific features such as the NAT Gateway.
133133

134134
You can leave most of the default options. However, you may want to change the following 2 parameters:
135135

@@ -272,6 +272,7 @@ create_operator = true
272272
enable_operator_instance_principal = true
273273
enable_operator_pv_encryption_in_transit = false
274274
operator_volume_kms_id = <operator_volume_kms_id>
275+
create_policies = true
275276
----
276277

277278
OKE also supports enforcing the use of signed images. You can enforce the use of signed image using the following parameters:

docs/instructions.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ If you wish to use {uri-oci-kms}[OCI KMS] to encrypt Kubernetes secrets, the fol
7474
** {uri-oci-manage-policies}[manage policies in root tenancy]
7575
* link:#adding-the-bastion-host[bastion must be enabled]
7676
* link:#enabling-instance_principal-on-the-operator-host[operator instance_principal must be enabled]
77-
7877
* use_cluster_encryption must be set to _true_
7978
* cluster_kms_key_id must be provided
79+
* create_policies should be set to _true_ if policies for cluster access to KMS are not already in place
8080

8181
If you wish to use {uri-oci-kms}[OCI KMS] to encrypt OKE nodepool boot/block volume, the following is required:
8282

docs/terraformoptions.adoc

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
3131

3232
== OCI Provider parameters
3333

34-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
34+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
3535
|===
3636
|Parameter
3737
|Description
@@ -88,7 +88,7 @@ region = "ap-sydney-1"
8888

8989
== General OCI
9090

91-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
91+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
9292
|===
9393
|Parameter
9494
|Description
@@ -109,7 +109,7 @@ region = "ap-sydney-1"
109109

110110
== SSH Keys
111111

112-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
112+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
113113
|===
114114
|Parameter
115115
|Description
@@ -146,7 +146,7 @@ EOT
146146

147147
== OCI Networking
148148

149-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
149+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
150150
|===
151151
|Parameter
152152
|Description
@@ -171,10 +171,10 @@ EOT
171171
|internet_gateway_route_rules
172172
|(Updatable) List of routing rules to add to Internet Gateway Route Table.
173173
|
174-
[
174+
[
175175
{
176176
destination = "192.168.0.0/16"
177-
destination_type = "CIDR_BLOCK"
177+
destination_type = "CIDR_BLOCK"
178178
network_entity_id = "drg"
179179
description = "Terraformed"
180180
},
@@ -184,7 +184,7 @@ EOT
184184
|local_peering_gateways
185185
|Map of Local Peering Gateways to attach to the VCN.
186186
|
187-
to_spoke2 = {
187+
to_spoke2 = {
188188
route_table_id = ""
189189
peer_id = ""
190190
}
@@ -198,10 +198,10 @@ EOT
198198
|nat_gateway_route_rules
199199
|(Updatable) List of routing rules to add to Internet Gateway Route Table.
200200
|
201-
[
201+
[
202202
{
203203
destination = "192.168.0.0/16"
204-
destination_type = "CIDR_BLOCK"
204+
destination_type = "CIDR_BLOCK"
205205
network_entity_id = "drg"
206206
description = "Terraformed"
207207
},
@@ -254,7 +254,7 @@ EOT
254254

255255
== Bastion Host
256256

257-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
257+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
258258
|===
259259
|Parameter
260260
|Description
@@ -334,7 +334,7 @@ EOT
334334

335335
== OCI Bastion Service
336336

337-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
337+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
338338
|===
339339
|Parameter
340340
|Description
@@ -364,7 +364,7 @@ EOT
364364

365365
== Operator Host
366366

367-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
367+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
368368
|===
369369
|Parameter
370370
|Description
@@ -451,7 +451,7 @@ EOT
451451

452452
== Availability Domain
453453

454-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
454+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
455455
|===
456456
|Parameter
457457
|Description
@@ -475,7 +475,7 @@ EOT
475475

476476
== Tagging
477477

478-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
478+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
479479
|===
480480
|Parameter
481481
|Description
@@ -528,7 +528,7 @@ EOT
528528

529529
== OKE
530530

531-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
531+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
532532
|===
533533
|Parameter
534534
|Description
@@ -604,7 +604,7 @@ EOT
604604

605605
== KMS integration
606606

607-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
607+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
608608
|===
609609
|Parameter
610610
|Description
@@ -618,8 +618,11 @@ EOT
618618

619619
|cluster_kms_key_id
620620
|The id of the OCI KMS key to be used as the master encryption key for encrypting Kubernetes' etcd . *Required* if _use_cluster_encryption_ is set to *true*
621-
|`ocid1.key.oc1....`
622-
|
621+
622+
|create_policies
623+
|Whether to create dynamic group for cluster with policies to access {uri-oci-kms}[OCI KMS] when using encryption.
624+
|true/false
625+
|true
623626

624627
|use_node_pool_volume_encryption
625628
|Whether to use {uri-oci-kms}[OCI KMS] to encrypt Kubernetes Nodepool's boot/block volume.
@@ -642,15 +645,15 @@ EOT
642645
|false
643646

644647
|`image_signing_keys`
645-
|A list of KMS key ids used by the worker nodes to verify signed images. The keys must use RSA algorithm. *Required* if _use_signed_images_ is set to *true*
648+
|A list of KMS key ids used by the worker nodes to verify signed images. The keys must use RSA algorithm. *Required* if _use_signed_images_ is set to *true*
646649
|
647650
`["ocid1.key.oc1....", "ocid1.key.oc1...."]`
648651
|[]
649652
|===
650653

651654
== Node pools
652655

653-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
656+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
654657
|===
655658
|Parameter
656659
|Description
@@ -671,8 +674,8 @@ Refer to {uri-topology}[topology] for more thorough examples.
671674
node_pools = {
672675
np1 = { shape = "VM.Standard.E4.Flex", ocpus = 1, memory = 16, node_pool_size = 1, boot_volume_size = 150, label = { app = "frontend", pool = "np1" } }
673676
np2 = {shape="VM.Standard.E2.2",node_pool_size=2,boot_volume_size=150,label={app="application",name="test"}}
674-
np3 = {shape="VM.Standard.E2.2",node_pool_size=1}
675-
}
677+
np3 = {shape="VM.Standard.E2.2",node_pool_size=1}
678+
}
676679
|
677680
node_pools = {
678681
np1 = {shape="VM.Standard.E3.Flex",ocpus=2,node_pool_size=2,boot_volume_size=150}
@@ -714,7 +717,7 @@ node_pools = {
714717

715718
== File Storage
716719

717-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
720+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
718721
|===
719722
|Parameter
720723
|Description
@@ -745,7 +748,7 @@ node_pools = {
745748

746749
== Upgrade cluster
747750

748-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
751+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
749752
|===
750753
|Parameter
751754
|Description
@@ -776,15 +779,15 @@ node_pools = {
776779

777780
== OKE Load Balancers
778781

779-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
782+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
780783
|===
781784
|Parameter
782785
|Description
783786
|Values
784787
|Default
785788

786789
|load_balancers
787-
|The type of load balancer subnets to create.
790+
|The type of load balancer subnets to create.
788791

789792
Even if you set the load balancer subnets to be internal, you still need to set the correct {uri-oci-loadbalancer-annotations}[annotations] when creating internal load balancers. Just setting this value to internal is *_not_* sufficient.
790793

@@ -826,7 +829,7 @@ Refer to {uri-topology}[topology] for more thorough examples.
826829

827830
== OCIR
828831

829-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
832+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
830833
|===
831834
|Parameter
832835
|Description
@@ -862,7 +865,7 @@ Refer to {uri-topology}[topology] for more thorough examples.
862865

863866
== Calico
864867

865-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
868+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
866869
|===
867870
|Parameter
868871
|Description
@@ -883,7 +886,7 @@ Refer to {uri-topology}[topology] for more thorough examples.
883886

884887
== Kubernetes Metrics Server
885888

886-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
889+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
887890
|===
888891
|Parameter
889892
|Description
@@ -909,7 +912,7 @@ Refer to {uri-topology}[topology] for more thorough examples.
909912

910913
== Gatekeeper
911914

912-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
915+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
913916
|===
914917
|Parameter
915918
|Description
@@ -930,7 +933,7 @@ Refer to {uri-topology}[topology] for more thorough examples.
930933

931934
== Service Account
932935

933-
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
936+
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
934937
|===
935938
|Parameter
936939
|Description

main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module "bastion" {
6464
upgrade_bastion = var.upgrade_bastion
6565

6666
# bastion notification
67-
enable_bastion_notification = var.enable_bastion_notification
67+
enable_bastion_notification = var.enable_bastion_notification && var.create_policies
6868
bastion_notification_endpoint = var.bastion_notification_endpoint
6969
bastion_notification_protocol = var.bastion_notification_protocol
7070
bastion_notification_topic = var.bastion_notification_topic
@@ -102,7 +102,7 @@ module "operator" {
102102

103103
# operator host parameters
104104
operator_image_id = var.operator_image_id
105-
enable_operator_instance_principal = var.enable_operator_instance_principal
105+
enable_operator_instance_principal = var.enable_operator_instance_principal && var.create_policies
106106
enable_pv_encryption_in_transit = var.enable_operator_pv_encryption_in_transit
107107
operator_os_version = var.operator_os_version
108108
operator_shape = var.operator_shape
@@ -227,6 +227,7 @@ module "oke" {
227227
vcn_id = module.vcn.vcn_id
228228
use_cluster_encryption = var.use_cluster_encryption
229229
cluster_kms_key_id = var.cluster_kms_key_id
230+
create_policies = var.create_policies
230231
use_signed_images = var.use_signed_images
231232
image_signing_keys = var.image_signing_keys
232233
admission_controller_options = var.admission_controller_options
@@ -329,6 +330,7 @@ module "extensions" {
329330
use_cluster_encryption = var.use_cluster_encryption
330331
cluster_kms_key_id = var.cluster_kms_key_id
331332
cluster_kms_dynamic_group_id = module.oke.cluster_kms_dynamic_group_id
333+
create_policies = var.create_policies
332334

333335
# ocir parameters
334336
email_address = var.email_address

modules/extensions/iam.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@ terraform {
1313
required_version = ">= 1.0.0"
1414
}
1515

16+
locals {
17+
create_operator_instance_principal_dynamic_group = (var.use_cluster_encryption == true && var.create_policies == true && var.create_bastion_host == true && var.enable_operator_instance_principal == true)
18+
}
19+
1620
resource "oci_identity_policy" "operator_instance_principal_dynamic_group" {
1721
provider = oci.home
1822
compartment_id = var.tenancy_id
1923
description = "policy to allow operator host to manage dynamic group"
2024
name = var.label_prefix == "none" ? "operator-instance-principal-dynamic-group-${substr(uuid(), 0, 8)}" : "${var.label_prefix}-operator-instance-principal-dynamic-group-${substr(uuid(), 0, 8)}"
2125
statements = ["Allow dynamic-group ${var.operator_dynamic_group} to use dynamic-groups in tenancy"]
22-
count = (var.use_cluster_encryption == true && var.create_bastion_host == true && var.enable_operator_instance_principal == true) ? 1 : 0
26+
count = (local.create_operator_instance_principal_dynamic_group == true) ? 1 : 0
2327
}
2428

2529
# 30s delay to allow policies to take effect globally
2630
resource "time_sleep" "wait_30_seconds" {
2731
depends_on = [oci_identity_policy.operator_instance_principal_dynamic_group]
2832

2933
create_duration = "30s"
34+
count = (local.create_operator_instance_principal_dynamic_group == true) ? 1 : 0
3035
}
3136

3237
resource "null_resource" "update_dynamic_group" {
@@ -58,5 +63,5 @@ resource "null_resource" "update_dynamic_group" {
5863
]
5964
}
6065

61-
count = (var.use_cluster_encryption == true && var.create_bastion_host == true && var.bastion_state == "RUNNING" && var.enable_operator_instance_principal == true) ? 1 : 0
66+
count = (local.create_operator_instance_principal_dynamic_group && var.bastion_state == "RUNNING" ) ? 1 : 0
6267
}

modules/extensions/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ variable "use_cluster_encryption" {
6060

6161
variable "cluster_kms_key_id" {}
6262

63+
6364
variable "cluster_kms_dynamic_group_id" {}
65+
66+
variable "create_policies" {
67+
type = bool
68+
}
69+
6470
# ocir
6571
variable "email_address" {}
6672

0 commit comments

Comments
 (0)