-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that metrics is protected with TLS for Prometheus integration
This change replaces controllers-runtime's self-signed certificates for metrics with cert-manager-managed certificates, ensuring security. We should not use `insecureSkipVerify: true`. Also, it is not a good practice for production env relay on the certs self-signed generated by controller-runtime and/or the old kube-rbac-proxy according to sig-security. 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.
- Loading branch information
Camila M
authored and
Camila M
committed
Nov 17, 2024
1 parent
48dc64a
commit 32c69b4
Showing
8 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,10 @@ func main() { | |
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info: | ||
// https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/filters#WithAuthenticationAndAuthorization | ||
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization | ||
|
||
metricsServerOptions.CertDir = "/var/metrics/certs" | ||
metricsServerOptions.CertName = "tls.crt" | ||
metricsServerOptions.KeyName = "tls.key" | ||
} | ||
|
||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
resources: | ||
- monitor.yaml | ||
|
||
# [PROMETHEUS WITH CERTMANAGER] The following patch configures the ServiceMonitor in ../prometheus | ||
# to securely reference certificates created and managed by cert-manager. | ||
# Additionally, ensure that you uncomment the [METRICS WITH CERTMANAGER] patch under config/default/kustomization.yaml | ||
# to mount the "metrics-server-cert" secret in the Manager Deployment. | ||
patches: | ||
- path: monitor_tls_patch.yaml | ||
target: | ||
kind: ServiceMonitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ spec: | |
selector: | ||
matchLabels: | ||
control-plane: operator-controller-controller-manager | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Patch for Prometheus ServiceMonitor to enable secure TLS configuration | ||
# using certificates managed by cert-manager | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: controller-manager-metrics-monitor | ||
namespace: system | ||
spec: | ||
endpoints: | ||
- tlsConfig: | ||
insecureSkipVerify: false | ||
ca: | ||
secret: | ||
name: olmv1-metrics-ca | ||
key: ca.crt | ||
cert: | ||
secret: | ||
name: olmv1-metrics-ca | ||
key: tls.crt | ||
keySecret: | ||
name: olmv1-metrics-ca | ||
key: tls.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
config/components/tls/patches/manager_metrics_deployment_cert.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
- op: add | ||
path: /spec/template/spec/volumes/- | ||
value: | ||
name: olmv1-metrics-ca | ||
secret: | ||
secretName: olmv1-metrics-ca | ||
- op: add | ||
path: /spec/template/spec/containers/0/volumeMounts/- | ||
value: | ||
name: olmv1-metrics-ca | ||
mountPath: /var/metrics/certs | ||
readOnly: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
name: olmv1-metrics-ca | ||
spec: | ||
secretName: olmv1-metrics-ca | ||
dnsNames: | ||
- controller-manager-metrics-service.olmv1-system.svc | ||
- controller-manager-metrics-service.olmv1-system.svc.cluster.local | ||
privateKey: | ||
algorithm: ECDSA | ||
size: 256 | ||
issuerRef: | ||
name: olmv1-metrics-ca | ||
kind: ClusterIssuer | ||
group: cert-manager.io |