Skip to content

feat(openshift): secure component metrics endpoints with mutual TLS - #3848

Open
jkhelil wants to merge 2 commits into
tektoncd:mainfrom
jkhelil:SRVKP-8172
Open

feat(openshift): secure component metrics endpoints with mutual TLS#3848
jkhelil wants to merge 2 commits into
tektoncd:mainfrom
jkhelil:SRVKP-8172

Conversation

@jkhelil

@jkhelil jkhelil commented Aug 3, 2026

Copy link
Copy Markdown
Member

Changes

Secure component metrics endpoints with mutual TLS (mTLS) on OpenShift, gated
behind an opt-in feature flag.

Each reconciler syncs the Prometheus client CA bundle from
kube-system/extension-apiserver-authentication into the component namespace
as a metrics-client-ca ConfigMap. OpenShift's serving-cert controller is
triggered via annotation on each metrics Service to provision a
per-component TLS Secret. Manifest transformers (AnnotateMetricsServingCert,
RenameServicePort, ApplyMetricsTLS) wire the Secret and ConfigMap as
volumes and inject METRICS_PROMETHEUS_TLS_* env vars so knative/pkg's
prometheus.Server enables mTLS with required client auth.
ServiceMonitor resources are updated with scheme: https,
tlsConfig.serverName, and the correct port name.

The feature is opt-in via spec.platforms.openshift.enableMetricsMTLS on
TektonConfig (default false). When disabled, all mTLS transformers are
skipped and metrics stay on plain HTTP — existing clusters are unaffected.

Known limitation: tekton-results-api

tekton-results-api's Prometheus metrics endpoint
(cmd/api/main.go in tektoncd/results) is a bare net/http server that
never reads METRICS_PROMETHEUS_TLS_* env vars, so it cannot serve mTLS.
It is therefore excluded from the mTLS upgrade: its Service and
ServiceMonitor stay on plain HTTP regardless of the flag.
tekton-results-watcher is unaffected by this and gets full mTLS like every
other component, since it is a standard Knative-based reconciler. Fixing
tekton-results-api itself would require an upstream change in
tektoncd/results, tracked separately.

Testing performed

  • Enabled the flag on a live OpenShift cluster and verified, for every
    mTLS-capable component (pipeline, triggers, chains, pruner,
    results-watcher): the metrics-client-ca ConfigMap synced, the metrics
    Service port renamed to https-*, the serving-cert Secret was
    provisioned, and the ServiceMonitor was updated to https + tlsConfig.
  • Verified mTLS enforcement with curl: requests with a valid Prometheus
    client cert succeed (200, real metrics returned); requests without a
    client cert fail the TLS handshake (explicit "certificate required" alert).
  • Verified tekton-results-api metrics remain reachable over plain HTTP
    with the flag enabled (no regression from the mTLS work).
  • Disabled the flag and verified a clean rollback to plain HTTP for all
    components, with matching Service/ServiceMonitor ports.
  • Repeated the on/off toggle to confirm idempotency.

Submitter Checklist

  • Run make test lint before submitting a PR
  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices

Release Notes

Add opt-in `spec.platforms.openshift.enableMetricsMTLS` field to
`TektonConfig` to secure component Prometheus metrics endpoints with
mutual TLS on OpenShift. Disabled by default; existing clusters are
unaffected. Not supported for `tekton-results-api`, whose metrics
endpoint stays on plain HTTP.

Made with Cursor

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Aug 3, 2026
@tekton-robot
tekton-robot requested a review from infernus01 August 3, 2026 09:05
@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from jkhelil after the PR has been reviewed.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot
tekton-robot requested a review from khrm August 3, 2026 09:05
@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 3, 2026
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 25.87%. Comparing base (d64b59c) to head (bf655b1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3848      +/-   ##
==========================================
+ Coverage   25.49%   25.87%   +0.37%     
==========================================
  Files         449      451       +2     
  Lines       23508    23908     +400     
==========================================
+ Hits         5994     6185     +191     
- Misses      16824    17011     +187     
- Partials      690      712      +22     
Flag Coverage Δ
unit-tests 25.87% <ø> (+0.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jkhelil and others added 2 commits August 3, 2026 15:14
Secure component metrics endpoints with mutual TLS on OpenShift.
Each reconciler syncs the Prometheus client CA bundle from
kube-system/extension-apiserver-authentication into the component
namespace as a metrics-client-ca ConfigMap.

OpenShift's serving-cert controller is triggered via annotation on
each metrics Service to provision a per-component TLS Secret.
Two new manifest transformers (InjectMetricsServingCert,
ApplyMetricsTLS) wire the Secret and ConfigMap as volumes and inject
METRICS_PROMETHEUS_TLS_* env vars so that the knative/pkg
prometheus.Server enables mTLS with require client auth.

ServiceMonitor resources are updated with scheme: https, scrapeClass
tls-client-certificate-auth, and tlsConfig.serverName. The existing
UpdateServiceMonitorTargetNamespace transformer is extended to also
patch the namespace segment inside serverName at runtime.

Relates-To: SRVKP-8172

Signed-off-by: Jawed khelil <jkhelil@redhat.com>
Assisted-by: Claude Sonnet 4.6 (via Cursor)
Co-authored-by: Cursor <cursoragent@cursor.com>
Add opt-in feature flag spec.platforms.openshift.enableMetricsMTLS
to TektonConfig. When false (default) all mTLS transformers are
skipped so existing clusters are unaffected.

Key changes:
- Add EnableMetricsMTLS *bool to OpenShift API struct + CRD schema
- EnsureMetricsClientCA (TektonConfig-only) returns a clear error
  when kube-system/extension-apiserver-authentication is absent,
  asking the user to disable mTLS or install CMO
- Add ResolveMetricsMTLS helper (flag check + CM existence in one
  call) used by all 6 component PreReconcile methods
- Gate all mTLS transformers behind metricsMTLSReady on each
  component extension struct
- Include MetricsCABundle content in GetPlatformData() hash so
  component CRs are automatically re-annotated when TektonConfig
  creates the CM, triggering immediate component re-reconciles
- Add unit tests for IsMetricsMTLSEnabled, AnnotateMetricsServingCert,
  RenameServicePort, UpdateServiceMonitorForMetricsMTLS

Fix tekton-results ServiceMonitor/Service port mismatch:
05-results-monitoring.yaml unconditionally hardcoded scheme: https
and https-* port names for both results ServiceMonitors, while the
underlying Services keep plain port names unless the flag is on.
This broke Prometheus scraping for tekton-results-api and
tekton-results-watcher by default, regardless of the flag. The
static manifest now stays plain HTTP, and tektonpipeline's
filterAndTransformMonitoring conditionally upgrades the
results-watcher ServiceMonitor to mTLS in lockstep with the
Service port rename, matching every other component.

tekton-results-api is excluded from the mTLS upgrade entirely: its
Prometheus metrics endpoint (cmd/api/main.go in tektoncd/results)
is a bare net/http server that never reads METRICS_PROMETHEUS_TLS_*
env vars, so it cannot serve mTLS. Its Service/ServiceMonitor stay
on plain HTTP regardless of this flag; this is a known upstream
limitation, not something this operator can fix.

Signed-off-by: Jawed khelil <jkhelil@redhat.com>
Assisted-by: Claude Sonnet 4.6 (via Cursor)
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants