Skip to content

Commit 1e4cc9e

Browse files
marcelorobjamandakarina
authored andcommitted
fix: adding tls to custom metrics
1 parent 92d1102 commit 1e4cc9e

8 files changed

Lines changed: 83 additions & 34 deletions

File tree

5-appinfra/modules/cicd-pipeline/project-iam-bindings.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ module "cb-gke-project-iam-bindings" {
156156
for_each = local.gke_projects
157157
project_id = each.value
158158

159-
project_roles = ["roles/container.admin", "roles/container.developer", "roles/gkehub.viewer", "roles/gkehub.gatewayEditor", "roles/cloudbuild.workerPoolUser", "roles/containeranalysis.notes.attacher"]
159+
project_roles = ["roles/privateca.admin", "roles/container.admin", "roles/container.developer", "roles/gkehub.viewer", "roles/gkehub.gatewayEditor", "roles/cloudbuild.workerPoolUser", "roles/containeranalysis.notes.attacher"]
160160
prefix = "serviceAccount"
161161
service_account_address = google_service_account.cloud_build.email
162162
}

5-appinfra/modules/htc-infra/agent/modules/config_apply/k8s/adapter_new_resource_model.yaml.templ

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ kind: APIService
144144
metadata:
145145
name: v1beta1.custom.metrics.k8s.io
146146
spec:
147-
insecureSkipTLSVerify: true
147+
insecureSkipTLSVerify: false
148+
caBundle: ${ca_bundle}
148149
group: custom.metrics.k8s.io
149150
groupPriorityMinimum: 100
150151
versionPriority: 100
@@ -158,7 +159,8 @@ kind: APIService
158159
metadata:
159160
name: v1beta2.custom.metrics.k8s.io
160161
spec:
161-
insecureSkipTLSVerify: true
162+
insecureSkipTLSVerify: false
163+
caBundle: ${ca_bundle}
162164
group: custom.metrics.k8s.io
163165
groupPriorityMinimum: 100
164166
versionPriority: 200
@@ -172,7 +174,8 @@ kind: APIService
172174
metadata:
173175
name: v1beta1.external.metrics.k8s.io
174176
spec:
175-
insecureSkipTLSVerify: true
177+
insecureSkipTLSVerify: false
178+
caBundle: ${ca_bundle}
176179
group: external.metrics.k8s.io
177180
groupPriorityMinimum: 100
178181
versionPriority: 100

5-appinfra/modules/htc-infra/agent/modules/config_apply/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ resource "null_resource" "cluster_init" {
126126
"adapter_new_resource_model_yaml" = templatefile(
127127
"${path.module}/k8s/adapter_new_resource_model.yaml.templ", {
128128
namespace = var.namespace
129+
ca_bundle = local.ca_bundle_base64
129130
}),
130131
"volume_claim_yaml" = templatefile(
131132
"${path.module}/k8s/volume_claim.yaml.templ", {
@@ -137,7 +138,6 @@ resource "null_resource" "cluster_init" {
137138
triggers = {
138139
template = each.value
139140
cluster_change = local.cluster_config
140-
test = true
141141
}
142142

143143
provisioner "local-exec" {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
/**
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
locals {
19+
ca_bundle_base64 = base64encode(google_privateca_certificate_authority.custom_metrics_ca.pem_ca_certificates[0])
20+
}
21+
22+
resource "google_privateca_ca_pool" "custom_metrics_ca_pool" {
23+
project = var.cluster_project_id
24+
location = var.region
25+
name = "custom-metrics-ca-pool"
26+
tier = "DEVOPS"
27+
28+
publishing_options {
29+
publish_ca_cert = true
30+
publish_crl = false
31+
}
32+
}
33+
34+
resource "google_privateca_certificate_authority" "custom_metrics_ca" {
35+
project = var.cluster_project_id
36+
location = var.region
37+
pool = google_privateca_ca_pool.custom_metrics_ca_pool.name
38+
certificate_authority_id = "custom-metrics-stackdriver-adapter-ca"
39+
lifetime = "31536000s" # 1 year
40+
deletion_protection = false
41+
42+
config {
43+
subject_config {
44+
subject {
45+
organization = "HTC Infra"
46+
common_name = "custom-metrics-ca"
47+
}
48+
}
49+
x509_config {
50+
ca_options {
51+
is_ca = true
52+
}
53+
key_usage {
54+
base_key_usage {
55+
cert_sign = true
56+
crl_sign = true
57+
}
58+
extended_key_usage {
59+
server_auth = false
60+
client_auth = false
61+
}
62+
}
63+
}
64+
}
65+
key_spec {
66+
algorithm = "RSA_PKCS1_4096_SHA256"
67+
}
68+
}

5-appinfra/modules/htc-infra/agent/modules/config_apply/variables.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,50 +138,30 @@ variable "parallelstore_access_points" {
138138
type = string
139139
default = null
140140
description = "Access points for the parallel store. Must be provided if parallelstore_enabled is true."
141-
validation {
142-
condition = var.parallelstore_enabled ? var.parallelstore_access_points != null : true
143-
error_message = "parallelstore_access_points must be set when parallelstore_enabled is true."
144-
}
145141
}
146142

147143
variable "parallelstore_vpc_name" {
148144
type = string
149145
default = null
150146
description = "Name of the VPC associated with the parallel store. Required when parallelstore_enabled is true."
151-
validation {
152-
condition = var.parallelstore_enabled ? var.parallelstore_vpc_name != null : true
153-
error_message = "parallelstore_vpc_name must be set when parallelstore_enabled is true."
154-
}
155147
}
156148

157149
variable "parallelstore_location" {
158150
type = string
159151
default = null
160152
description = "Location of the parallel store. Mandatory if parallelstore_enabled is true."
161-
validation {
162-
condition = var.parallelstore_enabled ? var.parallelstore_location != null : true
163-
error_message = "parallelstore_location must be set when parallelstore_enabled is true."
164-
}
165153
}
166154

167155
variable "parallelstore_instance_name" {
168156
type = string
169157
default = null
170158
description = "Name of the parallel store instance. Must be specified when parallelstore_enabled is true."
171-
validation {
172-
condition = var.parallelstore_enabled ? var.parallelstore_instance_name != null : true
173-
error_message = "parallelstore_instance_name must be set when parallelstore_enabled is true."
174-
}
175159
}
176160

177161
variable "parallelstore_capacity_gib" {
178162
type = number
179163
default = null
180164
description = "Capacity of the parallel store in GiB. Required if parallelstore_enabled is true."
181-
validation {
182-
condition = var.parallelstore_enabled ? var.parallelstore_capacity_gib != null : true
183-
error_message = "parallelstore_capacity_gib must be set when parallelstore_enabled is true."
184-
}
185165
}
186166

187167
variable "namespace" {

5-appinfra/modules/htc-infra/agent/modules/gke/outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ output "test_scripts_list" {
3232
])
3333
}
3434

35-
output "first_test_script" {
36-
description = "First test script"
37-
value = length(var.gke_cluster_names) > 0 ? module.config_apply[0].test_scripts : ""
38-
}
39-
4035
# Cluster
4136
output "cluster_urls" {
4237
description = "Cluster urls"

5-appinfra/modules/htc-infra/apis.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module "enabled_google_apis" {
2323
"bigquery.googleapis.com",
2424
"parallelstore.googleapis.com",
2525
"container.googleapis.com",
26-
"logging.googleapis.com"
26+
"logging.googleapis.com",
27+
"privateca.googleapis.com"
2728
]
2829
}
2930

@@ -34,7 +35,8 @@ resource "google_project_iam_member" "team_roles_infra_project" {
3435
"roles/pubsub.publisher",
3536
"roles/pubsub.viewer",
3637
"roles/pubsub.subscriber",
37-
"roles/monitoring.viewer"
38+
"roles/monitoring.viewer",
39+
"roles/privateca.admin"
3840
])
3941

4042
project = var.infra_project
@@ -49,7 +51,8 @@ resource "google_project_iam_member" "team_roles_cluster_project" {
4951
"roles/pubsub.publisher",
5052
"roles/pubsub.viewer",
5153
"roles/pubsub.subscriber",
52-
"roles/monitoring.viewer"
54+
"roles/monitoring.viewer",
55+
"roles/privateca.admin"
5356
])
5457

5558
project = var.cluster_project_id

examples/htc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ The steps below assume that you are checked out on the same level as `terraform-
121121
1. Retrieve HTC repositories created on 4-appfactory.
122122

123123
```bash
124-
cd eab-applicationfactory/envs/production/
124+
cd eab-applicationfactory/envs/shared/
125125
terraform init
126126
127127
export htc_project=$(terraform output -json app-group | jq -r '.["htc.htc"]["app_admin_project_id"]')

0 commit comments

Comments
 (0)