Skip to content

Commit 4e5efd3

Browse files
committed
added outputs for instance_principal dynamic group, enabled update_dynamic_group.sh, bug fix in update_dynamic_group.sh, updated documentation
Signed-off-by: Ali Mukadam <[email protected]>
1 parent 54f1477 commit 4e5efd3

File tree

12 files changed

+154
-20
lines changed

12 files changed

+154
-20
lines changed

docs/configuration.adoc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
:uri-oci: https://cloud.oracle.com/cloud-infrastructure
3030
:uri-oci-documentation: https://docs.cloud.oracle.com/iaas/Content/home.htm
3131
:uri-oci-instance-principal: https://docs.cloud.oracle.com/iaas/Content/Identity/Tasks/callingservicesfrominstances.htm
32+
:uri-oci-kms: https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Concepts/keyoverview.htm
3233
:uri-oci-loadbalancer-annotations: https://github.com/oracle/oci-cloud-controller-manager/blob/master/docs/load-balancer-annotations.md
3334
:uri-oci-region: https://docs.cloud.oracle.com/iaas/Content/General/Concepts/regions.htm
3435
:uri-oci-ocir: https://docs.cloud.oracle.com/iaas/Content/Registry/Concepts/registryoverview.htm
@@ -143,7 +144,7 @@ If you need to change the default VCN's CIDR, note the following:
143144

144145
The bastion host parameters concern whether you want to enable the bastion. 1 parameter to keep in mind here is the enable_instance_principal. Be aware that if this is enabled, it gives API access to the bastion host without authentication.
145146

146-
Read more about {uri-oci-instance-principal}[instance_principal].
147+
Read {uri-instructions}#enabling-instance_principal-on-the-bastion-host[more] about {uri-oci-instance-principal}[instance_principal].
147148

148149
{uri-terraform-options}#bastion-host[Reference]
149150

@@ -213,3 +214,16 @@ The calico parameters control the installation of {uri-calico}[Calico] for {uri-
213214
The Kubernetes Metrics Server parameter controls the installation of {uri-metrics-server}[Kubernetes Metrics Server]. *Required* for {uri-kubernetes-hpa}[Horizontal Pod Autoscaling].
214215

215216
{uri-terraform-options}#kubernetes-metrics-server[Reference]
217+
218+
=== Configure KMS Integration parameters
219+
220+
The KMS integration parameters control whether {uri-oci-kms}[OCI Key Management Service] will be used for encrypting Kubernetes secrets. Additionally, the bastion host must be enabled as well as instance_principal on the bastion.
221+
222+
----
223+
create_bastion = true
224+
enable_instance_principal = true
225+
use_encryption = true
226+
existing_key_id = <existing_key_ocid>
227+
----
228+
229+
{uri-terraform-options}#kms-integration[Reference]

docs/instructions.adoc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
:uri-networks-subnets-cidr: https://erikberg.com/notes/networks.html
2424
:uri-oci: https://cloud.oracle.com/cloud-infrastructure
2525
:uri-oci-documentation: https://docs.cloud.oracle.com/iaas/Content/home.htm
26+
:uri-oci-instance-principal: https://docs.cloud.oracle.com/iaas/Content/Identity/Tasks/callingservicesfrominstances.htm
27+
:uri-oci-kms: https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Concepts/keyoverview.htm
2628
:uri-oci-ocir: https://docs.cloud.oracle.com/iaas/Content/Registry/Concepts/registryoverview.htm
2729
:uri-oke: https://docs.cloud.oracle.com/iaas/Content/ContEng/Concepts/contengoverview.htm
2830
:uri-oracle: https://www.oracle.com
@@ -40,9 +42,13 @@
4042
:uri-k8s-dashboard: http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
4143

4244
. link:#assumptions[Assumptions]
45+
. link:#kms-integration[KMS Integration]
4346
. link:#creating-the-oke-cluster[Creating the OKE Cluster]
4447
. link:#adding-the-bastion-host[Adding the bastion host]
4548
. link:#using-the-bastion-host[Using the bastion host]
49+
.. link:#enabling-instance_principal-on-the-bastion-host[Enabling instance_principal on the bastion host]
50+
.. link:#disabling-instance_principal-on-the-bastion-host[Disabling instance_principal on the bastion host]
51+
.. link:#recommendations-for-using-instance_principal[Recommendations for using instance_principal]
4652
. link:#interacting-with-the-oke-cluster-locally[Interacting with the OKE Cluster locally]
4753
. link:#creating-an-auth-token-for-ocir[Creating an auth token for OCIR]
4854
. link:#installing-helm[Installing helm]
@@ -60,6 +66,18 @@ This section assumes you have completed the following:
6066
. all the {uri-prereqs}[pre-requisites]
6167
. all the required {uri-configuration}[configuration]
6268

69+
=== KMS Integration
70+
71+
If you wish to use {uri-oci-kms}[OCI KMS] to encrypt Kubernetes secrets, the following is required:
72+
73+
* the Terraform user must have the following rights
74+
** manage dynamic groups
75+
** manage policies in root tenancy
76+
* link:#adding-the-bastion-host[bastion must be enabled]
77+
* link:#enabling-instance_principal-on-the-bastion-host[bastion instance_principal must be enabled]
78+
* use_encryption must be set to _true_
79+
* existing_key_id must be provided
80+
6381
=== Creating the OKE Cluster
6482

6583
Initialize a working directory containing Terraform configuration files:
@@ -116,6 +134,51 @@ A utility script is also generated that contains the command to ssh to the basti
116134
scripts/tesseract.sh
117135
----
118136

137+
==== Enabling instance_principal on the bastion host
138+
{uri-oci-instance-principal}[instance_principal] is an IAM service feature that enables instances to be authorized actors (or principals) to perform actions on service resources. Each compute instance has its own identity, and it authenticates using the certificates that are added to it. These certificates are automatically created, assigned to instances and rotated, preventing the need for you to distribute credentials to your hosts and rotate them.
139+
140+
Any user who has access to the instance (who can SSH to the instance), automatically inherits the privileges granted to the instance. Before you enable this feature, ensure that you know who can access it, and that they should be authorized with the permissions you are granting to the instance.
141+
142+
By default, this feature is *_disabled_*. However, it is *_required_* at the time of cluster creation *_if_* you wish to enable link:#kms-integration[KMS Integration].
143+
144+
When you enable this feature, by default, the bastion has privileges to all resources in the compartment. If you are enabling it for link:#kms-integration[KMS Integration], the bastion host will also have rights to create policies in the root tenancy.
145+
146+
You can also turn on and off the feature at any time without impact on the bastion or the cluster.
147+
148+
To enable, set enable_instance_principal to true:
149+
150+
----
151+
enable_instance_principal = "true"
152+
----
153+
154+
and verify:
155+
156+
----
157+
oci network vcn list --compartment-id <compartment-ocid>
158+
----
159+
160+
==== Disabling instance_principal on the bastion host
161+
162+
. Set enable_instance_principal to false in terraform.tfvars
163+
164+
+
165+
----
166+
enable_instance_principal = false
167+
----
168+
169+
. Run terraform apply again:
170+
171+
+
172+
----
173+
terraform apply
174+
----
175+
176+
==== Recommendations for using instance_principal
177+
178+
. Do not enable instance_principal if you are not using link:#kms-integration[KMS Integration]
179+
. Enable instance_principal *_if and only if_* you are using link:#kms-integration[KMS Integration]
180+
. Disable instance_principal once the cluster is created
181+
119182
=== Interacting with the OKE Cluster locally
120183

121184
kubectl installed in bastion host by default and the kubeconfig file is set in the default location (~/.kube/config) so you don't need to set the KUBECONFIG environment variable every time you log in to the bastion. An alias "*k*" will be created for kubectl on the bastion host.

docs/prerequisites.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
:uri-oci-documentation: https://docs.cloud.oracle.com/iaas/Content/home.htm
2020
:uri-oci-keys: https://docs.cloud.oracle.com/iaas/Content/API/Concepts/apisigningkey.htm#two
2121
:uri-oci-keys-upload: https://docs.cloud.oracle.com/iaas/Content/API/Concepts/apisigningkey.htm#two
22+
:uri-oci-kms: https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Concepts/keyoverview.htm
23+
:uri-oci-managing-keys: https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Tasks/managingkeys.htm
24+
:uri-oci-managing-vaults: https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Tasks/managingvaults.htm
2225
:uri-oci-oke-policy: https://docs.cloud.oracle.com/iaas/Content/ContEng/Concepts/contengpolicyconfig.htm#PolicyPrerequisitesService
2326

2427
:uri-terraform: https://www.terraform.io
@@ -28,13 +31,21 @@ This section will guide you through the pre-requisites before you can use this p
2831

2932
You can proceed to {uri-instructions}[creating the cluster] if you have already done these.
3033

34+
. link:#identity-and-access-management-rights[Identity and Access Management Rights]
3135
. link:#install-terraform[Install Terraform]
3236
. link:#generate-api-keys[Generate API Keys]
3337
. link:#upload-your-api-keys[Upload API Keys]
3438
. link:#create-an-oci-compartment[Create an OCI Compartment]
3539
. link:#obtain-the-necessary-ocids[Obtain the necessary OCIDs]
3640
. link:#configure-oci-policy-for-oke[Configure OCI Policy for OKE]
3741

42+
== Identity and Access Management Rights
43+
44+
The Terraform user must have the rights to:
45+
46+
. manage dynamic groups
47+
. manage policies in root tenancy
48+
3849
== Install Terraform
3950

4051
Start by installing Terraform and configuring your path.
@@ -108,6 +119,8 @@ To obtain the compartment OCID:
108119
2. Click on your Compartment
109120
3. Locate OCID on the page and click on 'Copy'
110121

122+
If you wish to encrypt Kubernetes secrets with a key from {uri-oci-kms}[OCI KMS], you also need to create {uri-oci-managing-vaults}[a vault] and {uri-oci-managing-keys}[a key] and obtain the key id.
123+
111124
== Configure OCI Policy for OKE
112125

113126
Follow the documentation for {uri-oci-oke-policy}[to create the necessary OKE policy].

docs/terraformoptions.adoc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
:uri-kubernetes-hpa: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
1818
:uri-metrics-server: https://github.com/kubernetes-incubator/metrics-server
1919
:uri-oci-images: https://docs.cloud.oracle.com/iaas/images/
20+
:uri-oci-kms: https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Concepts/keyoverview.htm
2021
:uri-oci-loadbalancer-annotations: https://github.com/oracle/oci-cloud-controller-manager/blob/master/docs/load-balancer-annotations.md
2122
:uri-oci-region: https://docs.cloud.oracle.com/iaas/Content/General/Concepts/regions.htm
2223
:uri-terraform-cidrsubnet: https://www.terraform.io/docs/configuration/functions/cidrsubnet.html
@@ -495,3 +496,23 @@ Refer to {uri-topology}[topology] for more thorough examples.
495496
|Whether to install {uri-metrics-server}[Kubernetes Metrics Server]. *Required* for {uri-kubernetes-hpa}[Horizontal Pod Autoscaling].
496497
|true/false
497498
|false
499+
|===
500+
501+
== KMS integration
502+
503+
[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"]
504+
|===
505+
|Parameter
506+
|Description
507+
|Values
508+
|Default
509+
510+
|use_encryption
511+
|Whether to use {uri-oci-kms}[OCI KMS] to encrypt secrets.
512+
|true/false
513+
|false
514+
515+
|existing_key_id
516+
|ocid of existing KMS key
517+
|
518+
|

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module "policies" {
3636

3737
bastion = local.oke_bastion
3838

39+
dynamic_group = module.base.group_name
40+
3941
oke_kms = local.oke_kms
4042

4143
cluster_id = module.oke.cluster_id

modules/base/bastion/iam.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ data "oci_identity_compartments" "compartments_name" {
2222
}
2323
}
2424

25-
resource "oci_identity_dynamic_group" "instance_principal" {
25+
resource "oci_identity_dynamic_group" "bastion_instance_principal" {
2626
provider = "oci.home"
2727
compartment_id = var.oci_base_identity.tenancy_ocid
2828
description = "dynamic group to allow instances to call services for 1 bastion"
2929
matching_rule = "ALL {instance.id = '${join(",", data.oci_core_instance.bastion.*.id)}'}"
30-
name = "${var.oci_bastion_general.label_prefix}-instance_principal"
30+
name = "${var.oci_bastion_general.label_prefix}-bastion_instance_principal"
3131
count = var.oci_bastion.enable_instance_principal == true ? 1 : 0
3232
}
3333

34-
resource "oci_identity_policy" "instance_principal" {
34+
resource "oci_identity_policy" "bastion_instance_principal" {
3535
provider = "oci.home"
3636
compartment_id = var.oci_base_identity.compartment_ocid
37-
description = "dynamic group to allow instances to call services"
38-
name = "${var.oci_bastion_general.label_prefix}-instance_principal"
39-
statements = ["Allow dynamic-group ${oci_identity_dynamic_group.instance_principal[0].name} to manage all-resources in compartment ${data.oci_identity_compartments.compartments_name.compartments.0.name}"]
37+
description = "policy to allow bastion host to call services"
38+
name = "${var.oci_bastion_general.label_prefix}-bastion_instance_principal"
39+
statements = ["Allow dynamic-group ${oci_identity_dynamic_group.bastion_instance_principal[0].name} to manage all-resources in compartment ${data.oci_identity_compartments.compartments_name.compartments.0.name}"]
4040
count = var.oci_bastion.enable_instance_principal == true ? 1 : 0
41-
}
41+
}

modules/base/bastion/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
output "bastion_public_ip" {
55
value = join(",", data.oci_core_vnic.bastion_vnic.*.public_ip_address)
66
}
7+
8+
output "bastion_instance_principal_group_name" {
9+
value = oci_identity_dynamic_group.bastion_instance_principal[0].name
10+
}

modules/base/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ output "bastion_public_ip" {
1111
value = module.bastion.bastion_public_ip
1212
}
1313

14+
output "group_name" {
15+
value = module.bastion.bastion_instance_principal_group_name
16+
}
17+
1418
output "ig_route_id" {
1519
value = module.vcn.ig_route_id
1620
}

modules/policies/groups.tf

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ resource "oci_identity_dynamic_group" "oke-kms-cluster" {
66
compartment_id = var.oci_identity.tenancy_ocid
77
description = "dynamic group to allow cluster to use kms"
88
matching_rule = local.dynamic_group_rule_all_clusters
9-
# matching_rule = local.dynamic_group_rule_this_cluster
109
name = "${var.label_prefix}-oke-kms-cluster"
1110
count = var.oke_kms.use_encryption == true ? 1 : 0
1211

@@ -25,7 +24,7 @@ data "template_file" "update_dynamic_group_script" {
2524

2625
depends_on = ["oci_identity_dynamic_group.oke-kms-cluster"]
2726

28-
count = var.oke_kms.use_encryption == true && var.bastion.create_bastion ==true && var.bastion.enable_instance_principal == true ? 1 : 0
27+
count = var.oke_kms.use_encryption == true && var.bastion.create_bastion == true && var.bastion.enable_instance_principal == true ? 1 : 0
2928
}
3029

3130
resource null_resource "update_dynamic_group" {
@@ -41,20 +40,20 @@ resource null_resource "update_dynamic_group" {
4140
user = var.bastion.image_operating_system == "Canonical Ubuntu" ? "ubuntu" : "opc"
4241
}
4342

44-
depends_on = ["oci_identity_dynamic_group.oke-kms-cluster"]
43+
depends_on = ["oci_identity_dynamic_group.oke-kms-cluster", "oci_identity_policy.bastion_instance_principal_dynamic_group"]
4544

4645
provisioner "file" {
4746
content = data.template_file.update_dynamic_group_script[0].rendered
4847
destination = "~/update_dynamic_group.sh"
4948
}
5049

51-
# provisioner "remote-exec" {
52-
# inline = [
53-
# "chmod +x $HOME/update_dynamic_group.sh",
54-
# "$HOME/update_dynamic_group.sh",
55-
# # "rm -f $HOME/update_dynamic_group.sh"
56-
# ]
57-
# }
50+
provisioner "remote-exec" {
51+
inline = [
52+
"chmod +x $HOME/update_dynamic_group.sh",
53+
"$HOME/update_dynamic_group.sh",
54+
"rm -f $HOME/update_dynamic_group.sh"
55+
]
56+
}
5857

59-
count = var.oke_kms.use_encryption == true && var.bastion.create_bastion ==true && var.bastion.enable_instance_principal == true ? 1 : 0
58+
count = var.oke_kms.use_encryption == true && var.bastion.create_bastion == true && var.bastion.enable_instance_principal == true ? 1 : 0
6059
}

modules/policies/policies.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl
33

4+
resource "oci_identity_policy" "bastion_instance_principal_dynamic_group" {
5+
provider = "oci.home"
6+
compartment_id = var.oci_identity.tenancy_ocid
7+
description = "policy to allow bastion host to manage dynamic group"
8+
name = "${var.label_prefix}-bastion-instance-principal-dynamic-group"
9+
statements = ["Allow dynamic-group ${var.dynamic_group} to use dynamic-groups in tenancy"]
10+
count = var.oke_kms.use_encryption == true ? 1 : 0
11+
}
12+
413
resource "oci_identity_policy" "oke-kms" {
514
provider = "oci.home"
615
compartment_id = var.oci_identity.compartment_ocid

0 commit comments

Comments
 (0)