Skip to content

Commit f504f8f

Browse files
Merge pull request #120 from openstack-lightspeed/feat/OSPR-30557_tls-metrics-endpoint
Fix: Secure TLS for Prometheus metrics endpoint
2 parents a8a71f8 + 4e0116a commit f504f8f

5 files changed

Lines changed: 33 additions & 7 deletions

File tree

bundle/manifests/openstack-lightspeed-operator-metrics_v1_service.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
apiVersion: v1
22
kind: Service
33
metadata:
4+
annotations:
5+
service.beta.openshift.io/serving-cert-secret-name: operator-metrics-tls
46
creationTimestamp: null
57
labels:
68
app.kubernetes.io/managed-by: kustomize

bundle/manifests/openstack-lightspeed-operator.clusterserviceversion.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,18 @@ spec:
331331
capabilities:
332332
drop:
333333
- ALL
334+
volumeMounts:
335+
- mountPath: /tmp/k8s-metrics-server/serving-certs
336+
name: cert
337+
readOnly: true
334338
securityContext:
335339
runAsNonRoot: true
336340
serviceAccountName: openstack-lightspeed-operator-controller-manager
337341
terminationGracePeriodSeconds: 10
342+
volumes:
343+
- name: cert
344+
secret:
345+
secretName: operator-metrics-tls
338346
permissions:
339347
- rules:
340348
- apiGroups:

cmd/main.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func main() {
7171
var probeAddr string
7272
var secureMetrics bool
7373
var enableHTTP2 bool
74+
var certDir string
75+
var certName string
76+
var keyName string
7477
var tlsOpts []func(*tls.Config)
7578
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
7679
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
@@ -82,6 +85,12 @@ func main() {
8285
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
8386
flag.BoolVar(&enableHTTP2, "enable-http2", false,
8487
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
88+
flag.StringVar(&certDir, "cert-dir", "/tmp/k8s-metrics-server/serving-certs",
89+
"The directory where the TLS certificates are stored.")
90+
flag.StringVar(&certName, "cert-name", "tls.crt",
91+
"The name of the TLS certificate file.")
92+
flag.StringVar(&keyName, "key-name", "tls.key",
93+
"The name of the TLS key file.")
8594
opts := zap.Options{
8695
Development: true,
8796
}
@@ -116,13 +125,10 @@ func main() {
116125
metricsServerOptions := metricsserver.Options{
117126
BindAddress: metricsAddr,
118127
SecureServing: secureMetrics,
119-
// TODO(user): TLSOpts is used to allow configuring the TLS config used for the server. If certificates are
120-
// not provided, self-signed certificates will be generated by default. This option is not recommended for
121-
// production environments as self-signed certificates do not offer the same level of trust and security
122-
// as certificates issued by a trusted Certificate Authority (CA). The primary risk is potentially allowing
123-
// unauthorized access to sensitive metrics data. Consider replacing with CertDir, CertName, and KeyName
124-
// to provide certificates, ensuring the server communicates using trusted and secure certificates.
125-
TLSOpts: tlsOpts,
128+
TLSOpts: tlsOpts,
129+
CertDir: certDir,
130+
CertName: certName,
131+
KeyName: keyName,
126132
}
127133

128134
if secureMetrics {

config/default/metrics_service.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ metadata:
55
control-plane: controller-manager
66
app.kubernetes.io/name: openstack-lightspeed-operator
77
app.kubernetes.io/managed-by: kustomize
8+
annotations:
9+
service.beta.openshift.io/serving-cert-secret-name: operator-metrics-tls
810
name: metrics
911
namespace: system
1012
spec:

config/manager/manager.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,13 @@ spec:
113113
requests:
114114
cpu: 10m
115115
memory: 64Mi
116+
volumeMounts:
117+
- name: cert
118+
mountPath: /tmp/k8s-metrics-server/serving-certs
119+
readOnly: true
116120
serviceAccountName: controller-manager
121+
volumes:
122+
- name: cert
123+
secret:
124+
secretName: operator-metrics-tls
117125
terminationGracePeriodSeconds: 10

0 commit comments

Comments
 (0)