Skip to content

Commit ea6d722

Browse files
Camila MCamila M
authored andcommitted
Integrate cert-manager for production-grade metrics TLS and Prometheus integration
This change replaces controller-runtime's self-signed certificates for metrics with cert-manager managed certificates, ensuring production-grade security and automation. Key updates: - Configured `metricsServerOptions` to use cert-manager-managed certificates (`/var/metrics/certs`). - Added `ClusterIssuer` (`olmv1-metrics-ca`) and `Certificate` resources for automated certificate management. - Updated `ServiceMonitor` to enable secure TLS scraping by Prometheus using certificates issued by `olmv1-metrics-ca`. - The deployment was pushed to mount metrics certificates as secrets. Benefits: - Enhanced security with automated certificate lifecycle management. - Production-ready TLS setup for Prometheus metrics scraping.
1 parent 48dc64a commit ea6d722

File tree

8 files changed

+94
-0
lines changed

8 files changed

+94
-0
lines changed

cmd/manager/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ func main() {
198198
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
199199
// https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/filters#WithAuthenticationAndAuthorization
200200
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
201+
202+
metricsServerOptions.CertDir = "/var/metrics/certs"
203+
metricsServerOptions.CertName = "tls.crt"
204+
metricsServerOptions.KeyName = "tls.key"
201205
}
202206

203207
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
resources:
22
- monitor.yaml
3+
4+
# [PROMETHEUS WITH CERTMANAGER] The following patch configures the ServiceMonitor in ../prometheus
5+
# to securely reference certificates created and managed by cert-manager.
6+
# Additionally, ensure that you uncomment the [METRICS WITH CERTMANAGER] patch under config/default/kustomization.yaml
7+
# to mount the "metrics-server-cert" secret in the Manager Deployment.
8+
patches:
9+
- path: monitor_tls_patch.yaml
10+
target:
11+
kind: ServiceMonitor

config/base/prometheus/monitor.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ spec:
1717
selector:
1818
matchLabels:
1919
control-plane: operator-controller-controller-manager
20+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Patch for Prometheus ServiceMonitor to enable secure TLS configuration
2+
# using certificates managed by cert-manager
3+
apiVersion: monitoring.coreos.com/v1
4+
kind: ServiceMonitor
5+
metadata:
6+
name: controller-manager-metrics-monitor
7+
namespace: system
8+
spec:
9+
endpoints:
10+
- tlsConfig:
11+
insecureSkipVerify: false
12+
ca:
13+
secret:
14+
name: olmv1-metrics-ca
15+
key: ca.crt
16+
cert:
17+
secret:
18+
name: olmv1-metrics-ca
19+
key: tls.crt
20+
keySecret:
21+
name: olmv1-metrics-ca
22+
key: tls.key

config/components/ca/issuers.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,28 @@ metadata:
3030
spec:
3131
ca:
3232
secretName: olmv1-ca
33+
---
34+
apiVersion: cert-manager.io/v1
35+
kind: Certificate
36+
metadata:
37+
name: olmv1-metrics-ca
38+
namespace: cert-manager
39+
spec:
40+
isCA: true
41+
commonName: olmv1-metrics-ca
42+
secretName: olmv1-metrics-ca
43+
privateKey:
44+
algorithm: ECDSA
45+
size: 256
46+
issuerRef:
47+
name: self-sign-issuer
48+
kind: Issuer
49+
group: cert-manager.io
50+
---
51+
apiVersion: cert-manager.io/v1
52+
kind: ClusterIssuer
53+
metadata:
54+
name: olmv1-metrics-ca
55+
spec:
56+
ca:
57+
secretName: olmv1-metrics-ca

config/components/tls/kustomization.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ kind: Component
33
namespace: olmv1-system
44
resources:
55
- resources/manager_cert.yaml
6+
- resources/manager_metrics_cert.yaml
67
patches:
78
- target:
89
kind: Deployment
910
name: controller-manager
1011
path: patches/manager_deployment_cert.yaml
12+
- target:
13+
kind: Deployment
14+
name: controller-manager
15+
path: patches/manager_metrics_deployment_cert.yaml
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- op: add
2+
path: /spec/template/spec/volumes/-
3+
value:
4+
name: olmv1-metrics-ca
5+
secret:
6+
secretName: olmv1-metrics-ca
7+
- op: add
8+
path: /spec/template/spec/containers/0/volumeMounts/-
9+
value:
10+
name: olmv1-metrics-ca
11+
mountPath: /var/metrics/certs
12+
readOnly: true
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: Certificate
3+
metadata:
4+
name: olmv1-metrics-ca
5+
spec:
6+
secretName: olmv1-metrics-ca
7+
dnsNames:
8+
- controller-manager-metrics-service.olmv1-system.svc
9+
- controller-manager-metrics-service.olmv1-system.svc.cluster.local
10+
privateKey:
11+
algorithm: ECDSA
12+
size: 256
13+
issuerRef:
14+
name: olmv1-metrics-ca
15+
kind: ClusterIssuer
16+
group: cert-manager.io

0 commit comments

Comments
 (0)