Skip to content

feat(metricprovider): support self-signed certs for prometheus provider - #4964

Open
abhyudayareddy wants to merge 2 commits into
argoproj:masterfrom
abhyudayareddy:feat/prometheus-self-signed-cert-support
Open

feat(metricprovider): support self-signed certs for prometheus provider#4964
abhyudayareddy wants to merge 2 commits into
argoproj:masterfrom
abhyudayareddy:feat/prometheus-self-signed-cert-support

Conversation

@abhyudayareddy

Copy link
Copy Markdown

Problem

The prometheus metric provider only supports skipping TLS verification entirely via insecure: true. There is no way to connect to a prometheus server that presents a certificate signed by a private/self-signed CA while keeping certificate verification enabled. Users who run their own CA (common for in-cluster prometheus, e.g. via OpenShift monitoring or self-managed clusters) are forced to disable TLS verification altogether to work around this, which is undesirable.

Relates to #2298.

Root cause

NewPrometheusAPI in metricproviders/prometheus/prometheus.go only ever chose between two fixed http.Transports: secureTransport (default Go root CA trust store, full verification) and insecureTransport (InsecureSkipVerify: true). There was no option to trust an additional/custom CA while still validating the server certificate against it.

Fix

  • Added a new optional caCert field to PrometheusMetric (pkg/apis/rollouts/v1alpha1/analysis_types.go), holding a PEM-encoded CA certificate bundle.
  • Added newHTTPTransportWithCACert in metricproviders/prometheus/prometheus.go, which parses the PEM bundle into an x509.CertPool and builds a transport with TLSClientConfig.RootCAs set to that pool (verification remains enabled, unlike insecure: true).
  • NewPrometheusAPI now uses this transport when caCert is set (and insecure is not also set — insecure still takes precedence, matching previous behavior of skipping verification when set).
  • Regenerated all code-generated artifacts affected by the new API field: generated.pb.go/generated.proto (protobuf), openapi_generated.go, and the CRD manifests (manifests/crds/*.yaml, manifests/install.yaml, docs/features/kustomize/rollout_cr_schema.json) via make gen-proto, make gen-openapi, make gen-crd, and make manifests.
  • Documented the new option in docs/analysis/prometheus.md, alongside the existing "Skip TLS verification" section.

Example

provider:
  prometheus:
    address: https://prometheus.example.com
    caCert: |
      -----BEGIN CERTIFICATE-----
      MIIDXTCCAkWgAwIBAgIJAJC1...
      -----END CERTIFICATE-----
    query: ...

The certificate can be sourced from a Kubernetes Secret via the existing valueFrom.secretKeyRef support for AnalysisTemplate arguments.

Testing

  • Added unit tests in metricproviders/prometheus/prometheus_test.go:
    • TestNewPrometheusAPIWithCACert / TestNewPrometheusAPIWithInvalidCACert — valid/invalid caCert handling in NewPrometheusAPI.
    • TestNewHTTPTransportWithCACert / TestNewHTTPTransportWithInvalidCACert — transport construction and PEM parsing.
    • TestRunSuccessfullyWithCACert — end-to-end test using httptest.NewTLSServer with a self-signed certificate; configures caCert to the server's own certificate and asserts the query succeeds (proving TLS verification actually passes against the CA).
    • TestRunErrorWithWrongCACert — same TLS server, but with an unrelated CA cert, asserting the connection is rejected (proving verification is not silently bypassed).
  • go build ./... — passes.
  • go vet ./metricproviders/... ./pkg/apis/... — passes.
  • go test ./... — all 84 packages pass, no failures.
  • golangci-lint run ./metricproviders/prometheus/... ./pkg/apis/rollouts/v1alpha1/... — 0 issues.
  • Verified git diff --exit-code after codegen only touches the expected files (no unrelated churn beyond the standard fully-rewritten gzipped proto file descriptor blob that any type change causes).

Checklist

  • This is a feature addition scoped to a single provider; no proposal needed per CONTRIBUTING.md guidance for changes of this size.
  • PR title is conventional and references the related issue.
  • Commits are signed off (DCO).
  • Unit tests added/passing; full test suite passes locally.

@abhyudayareddy
abhyudayareddy requested review from a team as code owners August 9, 2026 04:45
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.19%. Comparing base (8abfe51) to head (03a1829).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4964      +/-   ##
==========================================
- Coverage   85.20%   85.19%   -0.01%     
==========================================
  Files         166      166              
  Lines       19453    19467      +14     
==========================================
+ Hits        16575    16585      +10     
- Misses       2027     2029       +2     
- Partials      851      853       +2     
Flag Coverage Δ
e2e 53.09% <0.00%> (-0.12%) ⬇️
unit-tests 81.66% <100.00%> (+0.01%) ⬆️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Published E2E Test Results

  4 files    4 suites   4h 11m 43s ⏱️
149 tests 135 ✅  7 💤  7 ❌
606 runs  568 ✅ 28 💤 10 ❌

For more details on these failures, see this check.

Results for commit 03a1829.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Published Unit Test Results

2 635 tests   2 635 ✅  3m 30s ⏱️
  131 suites      0 💤
    1 files        0 ❌

Results for commit 03a1829.

♻️ This comment has been updated with latest results.

@abhyudayareddy

Copy link
Copy Markdown
Author

cc @argoproj/argo-rollouts-approvers — this is ready for review whenever you have a chance; CI is green. Thanks!

@abhyudayareddy

Copy link
Copy Markdown
Author

Checking back in on this one — all checks are still green (CodeQL, unit tests, e2e across 1.32-1.35, SonarCloud). Let me know if there's anything I can do to help move it forward. Thanks!

@abhyudayareddy

Copy link
Copy Markdown
Author

Another gentle nudge on this one — it's been ~3 weeks with no review. All 27 checks are still green (CodeQL, unit, e2e across k8s 1.32–1.35, SonarCloud), no conflicts with master. It's a small, self-contained change (self-signed cert support for the Prometheus metric provider, opt-in via config). Happy to rebase or adjust anything. Thanks!

Abhyuday added 2 commits September 1, 2026 16:36
Adds an optional caCert field to the prometheus metric provider spec,
allowing a PEM-encoded CA certificate bundle to be supplied so that
TLS verification succeeds against a prometheus server using a
private/self-signed certificate.

Previously the only way to talk to such a server was to set
insecure: true, which disables certificate verification entirely.
caCert instead adds the given CA to the trusted pool used for
verification, so TLS validation stays enabled.

Relates to argoproj#2298

Signed-off-by: Abhyuday <abhyudayreddy@gmail.com>
The prior commit added PrometheusMetric.CACert to the Go types and
regenerated most codegen artifacts, but missed the swagger spec and
the UI's generated TypeScript models, which the CI 'Verify Codegen'
job caught. Applying the exact diff that job's codegen run produced.

Signed-off-by: Abhyuday <abhyudayreddy@gmail.com>
@kostis-codefresh
kostis-codefresh force-pushed the feat/prometheus-self-signed-cert-support branch from d663422 to 03a1829 Compare September 1, 2026 13:36
@sonarqubecloud

sonarqubecloud Bot commented Sep 1, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant