Skip to content

Commit 166fc9f

Browse files
authored
Merge pull request #78 from hyder/kms
oci kms integration with existing key
2 parents 05035e5 + f58231b commit 166fc9f

21 files changed

+382
-9
lines changed

docs/configuration.adoc

Lines changed: 16 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
@@ -57,6 +58,7 @@
5758
. link:#configure-helm-parameters[Configure helm parameters]
5859
. link:#configure-calico-parameters[Configure Calico parameters]
5960
. link:#configure-kubernetes-metrics-server-parameters[Configure Kubernetes Metrics Server parameters]
61+
. link:#configure-kms-integration-parameters[Configure KMS Integration parameters]
6062

6163
=== Assumptions
6264

@@ -143,7 +145,7 @@ If you need to change the default VCN's CIDR, note the following:
143145

144146
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.
145147

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

148150
{uri-terraform-options}#bastion-host[Reference]
149151

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

215217
{uri-terraform-options}#kubernetes-metrics-server[Reference]
218+
219+
=== Configure KMS Integration parameters
220+
221+
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.
222+
223+
----
224+
create_bastion = true
225+
enable_instance_principal = true
226+
use_encryption = true
227+
existing_key_id = <existing_key_ocid>
228+
----
229+
230+
{uri-terraform-options}#kms-integration[Reference]

docs/instructions.adoc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
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
28+
:uri-oci-manage-dynamic-groups: https://docs.cloud.oracle.com/iaas/Content/Identity/Tasks/managingdynamicgroups.htm
29+
:uri-oci-manage-policies: https://docs.cloud.oracle.com/iaas/Content/Identity/Tasks/managingpolicies.htm
2630
:uri-oci-ocir: https://docs.cloud.oracle.com/iaas/Content/Registry/Concepts/registryoverview.htm
2731
:uri-oke: https://docs.cloud.oracle.com/iaas/Content/ContEng/Concepts/contengoverview.htm
2832
:uri-oracle: https://www.oracle.com
@@ -40,9 +44,13 @@
4044
:uri-k8s-dashboard: http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
4145

4246
. link:#assumptions[Assumptions]
47+
. link:#kms-integration[KMS Integration]
4348
. link:#creating-the-oke-cluster[Creating the OKE Cluster]
4449
. link:#adding-the-bastion-host[Adding the bastion host]
4550
. link:#using-the-bastion-host[Using the bastion host]
51+
.. link:#enabling-instance_principal-on-the-bastion-host[Enabling instance_principal on the bastion host]
52+
.. link:#disabling-instance_principal-on-the-bastion-host[Disabling instance_principal on the bastion host]
53+
.. link:#recommendations-for-using-instance_principal[Recommendations for using instance_principal]
4654
. link:#interacting-with-the-oke-cluster-locally[Interacting with the OKE Cluster locally]
4755
. link:#creating-an-auth-token-for-ocir[Creating an auth token for OCIR]
4856
. link:#installing-helm[Installing helm]
@@ -60,6 +68,18 @@ This section assumes you have completed the following:
6068
. all the {uri-prereqs}[pre-requisites]
6169
. all the required {uri-configuration}[configuration]
6270

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

6585
Initialize a working directory containing Terraform configuration files:
@@ -116,6 +136,51 @@ A utility script is also generated that contains the command to ssh to the basti
116136
scripts/tesseract.sh
117137
----
118138

139+
==== Enabling instance_principal on the bastion host
140+
{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.
141+
142+
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.
143+
144+
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].
145+
146+
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.
147+
148+
You can also turn on and off the feature at any time without impact on the bastion or the cluster.
149+
150+
To enable, set enable_instance_principal to true:
151+
152+
----
153+
enable_instance_principal = "true"
154+
----
155+
156+
and verify:
157+
158+
----
159+
oci network vcn list --compartment-id <compartment-ocid>
160+
----
161+
162+
==== Disabling instance_principal on the bastion host
163+
164+
. Set enable_instance_principal to false in terraform.tfvars
165+
166+
+
167+
----
168+
enable_instance_principal = false
169+
----
170+
171+
. Run terraform apply again:
172+
173+
+
174+
----
175+
terraform apply
176+
----
177+
178+
==== Recommendations for using instance_principal
179+
180+
. Do not enable instance_principal if you are not using link:#kms-integration[KMS Integration]
181+
. Enable instance_principal *_if and only if_* you are using link:#kms-integration[KMS Integration]
182+
. Disable instance_principal once the cluster is created
183+
119184
=== Interacting with the OKE Cluster locally
120185

121186
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+
|

locals.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ locals {
101101
cluster_options_kubernetes_network_config_services_cidr = var.services_cidr
102102
cluster_subnets = module.network.subnet_ids
103103
vcn_id = module.base.vcn_id
104+
use_encryption = var.use_encryption
105+
kms_key_id = var.existing_key_id
106+
104107
}
105108

106109
node_pools = {
@@ -136,4 +139,9 @@ locals {
136139
calico_version = var.calico_version
137140
install_calico = var.install_calico
138141
}
142+
143+
oke_kms = {
144+
use_encryption = var.use_encryption
145+
key_id = var.existing_key_id
146+
}
139147
}

main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ module "base" {
2424
oci_base_bastion = local.oci_base_bastion
2525
}
2626

27+
module "policies" {
28+
source = "./modules/policies"
29+
30+
# identity
31+
oci_identity = local.oci_base_identity
32+
33+
ssh_keys = local.oci_base_ssh_keys
34+
35+
label_prefix = var.label_prefix
36+
37+
bastion = local.oke_bastion
38+
39+
dynamic_group = module.base.group_name
40+
41+
oke_kms = local.oke_kms
42+
43+
cluster_id = module.oke.cluster_id
44+
45+
}
46+
2747
module "auth" {
2848
source = "./modules/auth"
2949

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/kms/variables.tf

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

0 commit comments

Comments
 (0)