Provide a Prometheus-consumable system:monitoring client certificate for scraping TCP metrics #1212
Jakob3xD
started this conversation in
Feature Requests
Replies: 1 comment 1 reply
I'm interested about your perspective, mostly because I'm for option no.1 and extend the I'm biased, I know, but I'll br happy to extend it and offer on the same Secret the related cert and private key. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Follow-up to the monitoring discussion in #1171. That issue was the
apiserver-kubelet-clientClusterRoleBinding bug (fixed by #1172, now closed); this is the separate "proper monitoring identity" idea that came up in its comments.Goal: let Prometheus scrape a TCP's control-plane metrics with a dedicated least-privilege client cert, instead of reusing
apiserver-kubelet-client.Prometheus can't consume the
KubeconfigGeneratoroutput as-is. AServiceMonitor/PodMonitortlsConfigtakes the client cert and key as PEM via two references (cert= SecretOrConfigMap,keySecret= SecretKeySelector) and runspem.Decodeon each. The generator writes a single Secret keyvalueholding the whole kubeconfig YAML (withclient-certificate-data/client-key-database64-nested inside), sopem.Decodeon it finds no PEM block →tls: failed to find any PEM data in certificate input.What it needs is PEM under the referenced key(s). That can be the conventional split
tls.crt/tls.key, or even a single key holding a combined cert+key PEM referenced by bothcertandkeySecret(Go'sX509KeyPairscans each input for the matching block, so that works too). The one thing it won't do is unwrap the kubeconfig — so cert and key sharing one Secret is fine; the kubeconfig packaging is the problem.Two relevant points:
system:monitoringis a built-in ClusterRole with a built-in ClusterRoleBinding to thesystem:monitoringgroup (GET on/metrics,/livez,/readyz, …). A client cert withO=system:monitoringis authorized in every tenant out of the box — no RBAC to ship. That's also why it sidesteps the binding theapiserver-kubelet-clientidentity needs in fix(kubeadm): call AllowAPIServerToAccessKubeletAPI in BootstrapToken added in k8s v1.36.1 #1172.KubeconfigGeneratorwithuser=monitoring-agent,groups=[system:monitoring]mints exactlysubject=O=system:monitoring, CN=monitoring-agent, signed by the tenant CA. The identity is correct — only the packaging is wrong for Prometheus.So the only real gap is the cert format. Options for kamaji to emit something Prometheus-ready:
KubeconfigGeneratorto also write the cert/key as PEM (e.g.tls.crt/tls.key) next tovalue. Cheapest — the PEM bytes already exist in the controller, and the consumers that loop the secret keys (e.g.extractCertificateFromKubeconfig) tolerate unknown keys. Downside: mixes a kubeconfig and raw PEM in one Secret.system:monitoringclient cert that kamaji generates per TCP, using the same secret/rotation machinery as its existing cert secrets (split.crt/.key, x509-labeled and TCP-owned so the certificate-lifecycle controller rotates it automatically), with the cert minted underO=system:monitoringthe way theKubeconfigGeneratoralready does. To be explicit: this is a new, purpose-built least-privilege cert — not a reuse ofapiserver-kubelet-client, which is the overprivileged identity we want to move away from.I'd lean toward option 2 for a clean built-in story, but I'm happy with 1 if you'd rather keep it inside the generator. Which direction do you prefer?
One operational note either way: the
KubeconfigGeneratoris an opt-in separate deployment today (kubeconfigGenerator.enabled=false), so the generator-based path means operators run an extra component.All reactions