Skip to content

Commit f8ba05c

Browse files
Add Patch to give optional option to enable ServiceMonitor to use cert-manager-managed serving-cert with TLS verification
Adds a patch to configure ServiceMonitor with `insecureSkipVerify: false` to ensure TLS verification using cert-manager certificates. Updates documentation and corrects misaligned comments.
1 parent c331b70 commit f8ba05c

File tree

31 files changed

+396
-66
lines changed

31 files changed

+396
-66
lines changed

docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ func main() {
127127
}
128128

129129
if secureMetrics {
130+
// TODO(user): If cert-manager is enabled in config/default/kustomization.yaml,
131+
// you can uncomment the following lines to use the certificate managed by cert-manager.
132+
// metricsServerOptions.CertDir = "/var/run/secrets/kubernetes.io/certs"
133+
// metricsServerOptions.CertName = "tls.crt"
134+
// metricsServerOptions.KeyName = "tls.key"
135+
130136
// FilterProvider is used to protect the metrics endpoint with authn/authz.
131137
// These configurations ensure that only authorized users and service accounts
132138
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
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 [WEBHOOK] patch under config/default/kustomization.yaml
7+
# to mount the "serving-cert" secret in the Manager Deployment.
8+
#patches:
9+
# - path: monitor_tls_patch.yaml
10+
# target:
11+
# kind: ServiceMonitor

docs/book/src/cronjob-tutorial/testdata/project/config/prometheus/monitor.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@ spec:
1616
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
1717
tlsConfig:
1818
# TODO(user): The option insecureSkipVerify: true is not recommended for production since it disables
19-
# certificate verification. This poses a significant security risk by making the system vulnerable to
20-
# man-in-the-middle attacks, where an attacker could intercept and manipulate the communication between
21-
# Prometheus and the monitored services. This could lead to unauthorized access to sensitive metrics data,
22-
# compromising the integrity and confidentiality of the information.
23-
# Please use the following options for secure configurations:
24-
# caFile: /etc/metrics-certs/ca.crt
25-
# certFile: /etc/metrics-certs/tls.crt
26-
# keyFile: /etc/metrics-certs/tls.key
19+
# certificate verification, exposing the system to potential man-in-the-middle attacks.
20+
# For production environments, it is recommended to use cert-manager for automatic TLS certificate management.
21+
# To apply this configuration, enable cert-manager and use the patch located at config/prometheus/servicemonitor_tls_patch.yaml,
22+
# which securely references the certificate from the 'serving-cert' secret.
2723
insecureSkipVerify: true
2824
selector:
2925
matchLabels:
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: serving-cert
15+
key: ca.crt
16+
cert:
17+
secret:
18+
name: serving-cert
19+
key: tls.crt
20+
keySecret:
21+
name: serving-cert
22+
key: tls.key

docs/book/src/getting-started/testdata/project/cmd/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ func main() {
107107
}
108108

109109
if secureMetrics {
110+
// TODO(user): If cert-manager is enabled in config/default/kustomization.yaml,
111+
// you can uncomment the following lines to use the certificate managed by cert-manager.
112+
// metricsServerOptions.CertDir = "/var/run/secrets/kubernetes.io/certs"
113+
// metricsServerOptions.CertName = "tls.crt"
114+
// metricsServerOptions.KeyName = "tls.key"
115+
110116
// FilterProvider is used to protect the metrics endpoint with authn/authz.
111117
// These configurations ensure that only authorized users and service accounts
112118
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
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 [WEBHOOK] patch under config/default/kustomization.yaml
7+
# to mount the "serving-cert" secret in the Manager Deployment.
8+
#patches:
9+
# - path: monitor_tls_patch.yaml
10+
# target:
11+
# kind: ServiceMonitor

docs/book/src/getting-started/testdata/project/config/prometheus/monitor.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@ spec:
1616
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
1717
tlsConfig:
1818
# TODO(user): The option insecureSkipVerify: true is not recommended for production since it disables
19-
# certificate verification. This poses a significant security risk by making the system vulnerable to
20-
# man-in-the-middle attacks, where an attacker could intercept and manipulate the communication between
21-
# Prometheus and the monitored services. This could lead to unauthorized access to sensitive metrics data,
22-
# compromising the integrity and confidentiality of the information.
23-
# Please use the following options for secure configurations:
24-
# caFile: /etc/metrics-certs/ca.crt
25-
# certFile: /etc/metrics-certs/tls.crt
26-
# keyFile: /etc/metrics-certs/tls.key
19+
# certificate verification, exposing the system to potential man-in-the-middle attacks.
20+
# For production environments, it is recommended to use cert-manager for automatic TLS certificate management.
21+
# To apply this configuration, enable cert-manager and use the patch located at config/prometheus/servicemonitor_tls_patch.yaml,
22+
# which securely references the certificate from the 'serving-cert' secret.
2723
insecureSkipVerify: true
2824
selector:
2925
matchLabels:
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: serving-cert
15+
key: ca.crt
16+
cert:
17+
secret:
18+
name: serving-cert
19+
key: tls.crt
20+
keySecret:
21+
name: serving-cert
22+
key: tls.key

docs/book/src/multiversion-tutorial/testdata/project/cmd/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ func main() {
126126
}
127127

128128
if secureMetrics {
129+
// TODO(user): If cert-manager is enabled in config/default/kustomization.yaml,
130+
// you can uncomment the following lines to use the certificate managed by cert-manager.
131+
// metricsServerOptions.CertDir = "/var/run/secrets/kubernetes.io/certs"
132+
// metricsServerOptions.CertName = "tls.crt"
133+
// metricsServerOptions.KeyName = "tls.key"
134+
129135
// FilterProvider is used to protect the metrics endpoint with authn/authz.
130136
// These configurations ensure that only authorized users and service accounts
131137
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
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 [WEBHOOK] patch under config/default/kustomization.yaml
7+
# to mount the "serving-cert" secret in the Manager Deployment.
8+
#patches:
9+
# - path: monitor_tls_patch.yaml
10+
# target:
11+
# kind: ServiceMonitor

0 commit comments

Comments
 (0)