Skip to content

CCXDEV-16594: add custom proxy field to insights config - #1329

Open
opokornyy wants to merge 3 commits into
openshift:masterfrom
opokornyy:CCXDEV-16594-custom-proxy-config
Open

CCXDEV-16594: add custom proxy field to insights config#1329
opokornyy wants to merge 3 commits into
openshift:masterfrom
opokornyy:CCXDEV-16594-custom-proxy-config

Conversation

@opokornyy

@opokornyy opokornyy commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Allow configuring a custom CA certificate for trusting the archive upload endpoint, scoped to the Insights Operator. This avoids requiring changes to the cluster-wide proxy trusted CA bundle.

Categories

  • Bugfix
  • Data Enhancement
  • Feature
  • Backporting
  • Others (CI, Infrastructure, Documentation)

Sample Archive

  • None

Documentation

  • None

Unit Tests

  • pkg/insights/insightsclient/requests_test.go
  • pkg/ocm/clustertransfer/cluster_transfer_test.go
  • pkg/insights/insightsclient/insightsclient_test.go
  • pkg/config/configobserver/config_aggregator_test.go
  • pkg/config/config_test.go

Privacy

Yes. There are no sensitive data in the newly collected information.

Changelog

  • None

Breaking Changes

No

References

https://redhat.atlassian.net/browse/CCXDEV-16594

Summary by CodeRabbit

  • New Features

    • Added support for configuring a custom CA certificate for Insights data reporting.
    • Custom CA certificates are now applied to secure Insights connections alongside cluster proxy certificates.
    • Configuration overrides now correctly preserve and apply CA certificate settings.
  • Bug Fixes

    • Fixed missing CA certificate propagation during configuration conversion and merging.
    • Improved handling and validation of invalid certificate data.

Allow configuring a custom CA certificate for
trusting the archive upload endpoint, scoped to
the Insights Operator. This avoids requiring
changes to the cluster-wide proxy trusted CA bundle.

Signed-off-by: Ondrej Pokorny <opokorny@redhat.com>
Introduce Config interface to thread Insights
configuration into the HTTP client. Rename Client
to InsightsClient and getTrustedCABundle to
getRootCAs. The custom CACert from the
insights-config ConfigMap is now appended to the
trusted CA pool alongside the proxy CA bundle.

Only the following endpoints should use the
custom proxy configuration: uploadEndpoint,
downloadEndpoint, downloadEndpointTechPreview and
processingStatusEndpoint

Signed-off-by: Ondrej Pokorny <opokorny@redhat.com>
Signed-off-by: Ondrej Pokorny <opokorny@redhat.com>
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 28, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@opokornyy: This pull request references CCXDEV-16594 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Allow configuring a custom CA certificate for trusting the archive upload endpoint, scoped to the Insights Operator. This avoids requiring changes to the cluster-wide proxy trusted CA bundle.

Categories

  • Bugfix
  • Data Enhancement
  • Feature
  • Backporting
  • Others (CI, Infrastructure, Documentation)

Sample Archive

  • None

Documentation

  • None

Unit Tests

  • pkg/insights/insightsclient/requests_test.go
  • pkg/ocm/clustertransfer/cluster_transfer_test.go
  • pkg/insights/insightsclient/insightsclient_test.go
  • pkg/config/configobserver/config_aggregator_test.go
  • pkg/config/config_test.go

Privacy

Yes. There are no sensitive data in the newly collected information.

Changelog

  • None

Breaking Changes

No

References

https://redhat.atlassian.net/browse/CCXDEV-16594

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The change adds serialized and runtime CA certificate support, merges CA data into effective configuration, applies it to Insights client TLS transports, and replaces the former client type with InsightsClient across callers. Uploader failure summaries are also made explicit.

Changes

Insights CA configuration and client refactor

Layer / File(s) Summary
CA certificate configuration flow
pkg/config/types.go, pkg/config/config.go, pkg/config/configobserver/..., pkg/config/config_test.go
Serialized configuration now carries CACert as a string, runtime configuration stores it as bytes, conversion populates it, and merging compares and overrides it.
Insights client TLS support
pkg/insights/insightsclient/insightsclient.go, pkg/insights/insightsclient/requests.go, pkg/insights/insightsclient/*_test.go
InsightsClient accepts configuration and builds TLS root pools from configured and mounted CA bundles; request methods use the updated client and transport signatures.
Client wiring migration
pkg/controller/..., pkg/gather/gather.go, pkg/insights/insightsreport/..., pkg/insights/insightsuploader/..., pkg/ocm/...
Client construction, gatherer APIs, reporting, uploading, SCA, and cluster-transfer test setup use InsightsClient and NewInsightsClient.
Uploader status updates
pkg/insights/insightsuploader/insightsuploader.go
Authorization and upload failure summaries now set explicit operation, reason, and message fields while preserving retry behavior.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ConfigAggregator
  participant GatherJob
  participant InsightsClient
  participant TLSTransport
  participant InsightsAPI
  ConfigAggregator->>GatherJob: provide effective configuration
  GatherJob->>InsightsClient: construct with configAggregator
  InsightsClient->>TLSTransport: configure request transport with CACert
  TLSTransport->>InsightsAPI: send HTTPS request
Loading
🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (14 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change by calling out a custom CA/proxy-related config addition for Insights.
Description check ✅ Passed The description follows the required template and fills the main sections, including tests, privacy, breaking changes, and references.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed No Ginkgo titles or generated names were added; all changed tests use static string literals in table-driven t.Run names.
Test Structure And Quality ✅ Passed Changed tests are plain table-driven unit tests, not Ginkgo; they use defer/delete cleanup, and no Eventually/Consistently or cluster waits were added.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e specs were added; the changed tests are standard unit tests and don’t require MicroShift compatibility gating.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the touched tests are standard unit tests with fake clients and no multi-node/SNO assumptions.
Topology-Aware Scheduling Compatibility ✅ Passed The PR only updates config/TLS client wiring and tests; no manifests, affinities, nodeSelectors, replicas, or other scheduling constraints were added.
Ote Binary Stdout Contract ✅ Passed PR changes only library/test code; no modified main/init/TestMain/suite setup or top-level stdout writes were found.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the modified tests are Go unit tests using httptest.NewServer and contain no hardcoded IPv4s or public internet dependencies.
No-Weak-Crypto ✅ Passed The PR only adds CA-certificate handling; changed files use x509/PEM and ECDSA in tests, with no MD5/SHA1/DES/RC4/ECB or secret/token comparisons.
Container-Privileges ✅ Passed PR touches only Go sources/tests; no K8s manifests were changed and no privileged/hostPID/hostNetwork/hostIPC/SYS_ADMIN settings appear in touched files.
No-Sensitive-Data-In-Logs ✅ Passed PASS: The PR adds no logs of secrets; new messages are generic CA/proxy errors, and token-bearing values are not logged in the changed code.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@openshift-ci
openshift-ci Bot requested a review from ncaak July 28, 2026 08:16
@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 28, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
pkg/config/configobserver/config_aggregator.go (1)

155-157: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for removing a previously configured CA.

This branch intentionally replaces a non-empty existing certificate with an empty/nil incoming value. Add a regression case that starts with an existing CA and applies a configuration without CACert, then asserts the CA is cleared.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/config/configobserver/config_aggregator.go` around lines 155 - 157, Add a
regression test for the configuration aggregation flow around the CACert update
branch: initialize the existing/default configuration with a non-empty
DataReporting.CACert, apply an incoming configuration where CACert is omitted or
nil, and assert that the resulting CA value is cleared.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/config/types.go`:
- Line 39: Update getRootCAs to initialize the pool from x509.SystemCertPool()
rather than x509.NewCertPool(), then append CACert and any trusted CA bundle to
that pool. Preserve appropriate fallback handling if the system pool cannot be
loaded while ensuring custom certificates are still included.

In `@pkg/insights/insightsclient/insightsclient.go`:
- Around line 124-145: Update the certificate pool initialization in the shown
TLS configuration flow to start from x509.SystemCertPool() rather than
x509.NewCertPool(), preserving system roots while still appending configured and
trusted CA certificates. Handle any SystemCertPool error appropriately before
processing CACert and the trusted CA bundle, keeping the existing invalid-PEM
and missing-bundle behavior unchanged.

---

Nitpick comments:
In `@pkg/config/configobserver/config_aggregator.go`:
- Around line 155-157: Add a regression test for the configuration aggregation
flow around the CACert update branch: initialize the existing/default
configuration with a non-empty DataReporting.CACert, apply an incoming
configuration where CACert is omitted or nil, and assert that the resulting CA
value is cleared.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 321bed84-0298-4536-b519-1ad9b3f6cb37

📥 Commits

Reviewing files that changed from the base of the PR and between c475f8a and a8c984f.

📒 Files selected for processing (16)
  • pkg/config/config.go
  • pkg/config/config_test.go
  • pkg/config/configobserver/config_aggregator.go
  • pkg/config/configobserver/config_aggregator_test.go
  • pkg/config/types.go
  • pkg/controller/gather_commands.go
  • pkg/controller/operator.go
  • pkg/gather/gather.go
  • pkg/insights/insightsclient/insightsclient.go
  • pkg/insights/insightsclient/insightsclient_test.go
  • pkg/insights/insightsclient/requests.go
  • pkg/insights/insightsclient/requests_test.go
  • pkg/insights/insightsreport/insightsreport.go
  • pkg/insights/insightsuploader/insightsuploader.go
  • pkg/ocm/clustertransfer/cluster_transfer_test.go
  • pkg/ocm/sca/sca.go

Comment thread pkg/config/types.go
ProcessingStatusEndpoint string `json:"processingStatusEndpoint,omitempty"`
Obfuscation Obfuscation `json:"obfuscation,omitempty"`
DisableRuntimeExtractor string `json:"disableRuntimeExtractor,omitempty"`
CACert string `json:"CACert,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n 'NewCertPool|SystemCertPool|RootCAs|trusted-ca-bundle' pkg/insights/insightsclient

Repository: openshift/insights-operator

Length of output: 1140


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '110,190p' pkg/insights/insightsclient/insightsclient.go
printf '\n--- tests ---\n'
sed -n '150,260p' pkg/insights/insightsclient/insightsclient_test.go

Repository: openshift/insights-operator

Length of output: 4480


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,120p' pkg/insights/insightsclient/insightsclient.go

Repository: openshift/insights-operator

Length of output: 2796


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n 'func GetTLSConfigFromAPIServer|SystemCertPool|RootCAs' pkg/insights/insightsclient
sed -n '1,220p' pkg/insights/insightsclient/*.go | sed -n '/func GetTLSConfigFromAPIServer/,/}/p'

Repository: openshift/insights-operator

Length of output: 1117


🏁 Script executed:

#!/bin/bash
set -euo pipefail

cat -n pkg/insights/insightsclient/apiserver_config.go

Repository: openshift/insights-operator

Length of output: 3791


Preserve system trust roots when building the CA pool. getRootCAs starts from x509.NewCertPool(), so setting tlsConfig.RootCAs drops the default roots whenever CACert or the trusted CA bundle is present. Start from x509.SystemCertPool() and append the custom bundles instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/config/types.go` at line 39, Update getRootCAs to initialize the pool
from x509.SystemCertPool() rather than x509.NewCertPool(), then append CACert
and any trusted CA bundle to that pool. Preserve appropriate fallback handling
if the system pool cannot be loaded while ensuring custom certificates are still
included.

Comment on lines +124 to +145
certs := x509.NewCertPool()
hasAnyCert := false

if config != nil && len(config.Config().DataReporting.CACert) > 0 {
if ok := certs.AppendCertsFromPEM(config.Config().DataReporting.CACert); !ok {
return nil, errors.New("error loading configured CACert: invalid PEM data")
}
hasAnyCert = true
}

caBundleBytes, err := os.ReadFile("/var/run/configmaps/trusted-ca-bundle/ca-bundle.crt")
if err != nil {
if os.IsNotExist(err) {
return nil, nil
if !os.IsNotExist(err) {
return nil, err
}
return nil, err
klog.Infof("ca-bundle does not exist")
}
if len(caBytes) == 0 {
return nil, nil
if len(caBundleBytes) > 0 {
if ok := certs.AppendCertsFromPEM(caBundleBytes); !ok {
return nil, errors.New("error loading trusted CA bundle: invalid PEM data")
}
hasAnyCert = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

According to the official Go crypto/tls documentation, does assigning a non-nil tls.Config.RootCAs replace the platform system certificate pool?

💡 Result:

Yes, according to the official Go documentation, assigning a non-nil *x509.CertPool to tls.Config.RootCAs replaces the platform's system certificate pool for that TLS configuration [1][2]. The documentation explicitly states: "If RootCAs is nil, TLS uses the host's root CA set." [1][3][2]. Conversely, when you assign a specific *x509.CertPool to the RootCAs field, Go uses that pool instead of the default system roots to verify server certificates [1][2]. If you wish to augment the system pool rather than replace it, you must first load the system's certificate pool using x509.SystemCertPool and then add your additional certificates to that pool before assigning it to tls.Config.RootCAs.

Citations:


Preserve the system root CA pool here. x509.NewCertPool() starts empty, so assigning it to tls.Config.RootCAs drops the host trust store for endpoints that rely on public/system CAs. Start from x509.SystemCertPool() and append the configured/trusted PEMs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/insights/insightsclient/insightsclient.go` around lines 124 - 145, Update
the certificate pool initialization in the shown TLS configuration flow to start
from x509.SystemCertPool() rather than x509.NewCertPool(), preserving system
roots while still appending configured and trusted CA certificates. Handle any
SystemCertPool error appropriately before processing CACert and the trusted CA
bundle, keeping the existing invalid-PEM and missing-bundle behavior unchanged.

@opokornyy

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@opokornyy

Copy link
Copy Markdown
Contributor Author

/retest

@opokornyy

Copy link
Copy Markdown
Contributor Author

/cc @JiriPapousek

@openshift-ci

openshift-ci Bot commented Jul 30, 2026

Copy link
Copy Markdown

@opokornyy: GitHub didn't allow me to request PR reviews from the following users: JiriPapousek.

Note that only openshift members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @JiriPapousek

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@opokornyy

Copy link
Copy Markdown
Contributor Author

/retest

@openshift-ci

openshift-ci Bot commented Aug 4, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JiriPapousek, opokornyy

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

The pull request process is described 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

@opokornyy

Copy link
Copy Markdown
Contributor Author

/retest

3 similar comments
@opokornyy

Copy link
Copy Markdown
Contributor Author

/retest

@opokornyy

Copy link
Copy Markdown
Contributor Author

/retest

@opokornyy

Copy link
Copy Markdown
Contributor Author

/retest

@openshift-ci

openshift-ci Bot commented Aug 5, 2026

Copy link
Copy Markdown

@opokornyy: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/insights-runtime-extractor-tests a8c984f link true /test insights-runtime-extractor-tests

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants