Skip to content

Commit

Permalink
Add an option to enable Prometheus with real certificates
Browse files Browse the repository at this point in the history
While the install scripts do not enable Prometheus integration by default, solutions running upstream may want to use and enable it with Prometheus. This addition offers a way for upstream users to understand how to properly configure Prometheus using real certificates.

At the very least, it serves as documentation and provides an option for those installing from source who want to implement secure Prometheus integration.
  • Loading branch information
camilamacedo86 committed Nov 25, 2024
1 parent 659787f commit 81a5241
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
15 changes: 12 additions & 3 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ func main() {
operatorControllerVersion bool
systemNamespace string
caCertDir string
certFile string
keyFile string
globalPullSecret string
)
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8443", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&caCertDir, "ca-certs-dir", "", "The directory of TLS certificate to use for verifying HTTPS connections to the Catalogd and docker-registry web servers.")
flag.StringVar(&certFile, "tls-cert", "", "The certificate file used for serving catalog contents over HTTPS. Requires tls-key.")
flag.StringVar(&keyFile, "tls-key", "", "The key file used for serving catalog contents over HTTPS. Requires tls-cert.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -122,6 +126,11 @@ func main() {
os.Exit(0)
}

if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
setupLog.Error(nil, "unable to configure TLS certificates: tls-cert and tls-key flags must be used together")
os.Exit(1)
}

ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))

setupLog.Info("starting up the controller", "version info", version.String())
Expand Down Expand Up @@ -190,9 +199,9 @@ func main() {
// Ensure that metrics is protected with certs managed by cert-manager
// If not informed, the metrics service provided by controller-runtime will generate
// and use its own self-assigned certs which is not recommended for production envs.
CertDir: "/var/certs/",
CertName: "olm-ca.crt",
KeyName: "ca.crt",
CertDir: caCertDir,
CertName: certFile,
KeyName: keyFile,
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down
27 changes: 15 additions & 12 deletions config/base/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Prometheus Monitor Service (Metrics)
# Patch for Prometheus ServiceMonitor to enable secure TLS configuration
# using certificates managed by cert-manager
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
control-plane: operator-controller-controller-manager
name: controller-manager-metrics-monitor
namespace: system
spec:
endpoints:
- path: /metrics
port: https
scheme: https
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
tlsConfig:
insecureSkipVerify: true
selector:
matchLabels:
control-plane: operator-controller-controller-manager
- tlsConfig:
insecureSkipVerify: false
ca:
secret:
name: olmv1-ca
key: ca.crt
cert:
secret:
name: olmv1-ca
key: olm-ca.crt
keySecret:
name: olmv1-ca
key: ca.crt
6 changes: 6 additions & 0 deletions config/components/tls/patches/manager_deployment_cert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
- op: add
path: /spec/template/spec/containers/0/args/-
value: "--ca-certs-dir=/var/certs"
- op: add
path: /spec/template/spec/containers/0/args/-
value: "--tls-cert=olm-ca.crt"
- op: add
path: /spec/template/spec/containers/0/args/-
value: "--tls-key=ca.crt"

0 comments on commit 81a5241

Please sign in to comment.