ROX-33336: [Operator] Propagate cluster-wide TLS settings - #18864
Conversation
|
Skipping CI for Draft Pull Request. |
|
Images are ready for the commit at b411ea4. To use with deploy scripts, first |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18864 +/- ##
========================================
Coverage 49.59% 49.60%
========================================
Files 2756 2760 +4
Lines 208036 208144 +108
========================================
+ Hits 103183 103246 +63
- Misses 97192 97232 +40
- Partials 7661 7666 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
65477e3 to
1947c4e
Compare
5f90175 to
67aa3a3
Compare
0f9fa38 to
be483be
Compare
be483be to
8a708ee
Compare
b3d11f9 to
6c56818
Compare
6c56818 to
25bf072
Compare
25bf072 to
b75703a
Compare
b75703a to
43f247e
Compare
0023d83 to
7f73d85
Compare
porridge
left a comment
There was a problem hiding this comment.
LGTM overall, just a bunch of nitpicks.
ce6b24d to
63200ee
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThe pull request introduces OpenShift cluster-wide TLS profile support to the Operator. The Operator now reads the cluster TLS profile from Changes
Sequence DiagramsequenceDiagram
participant Operator as Operator<br/>(main.go)
participant BootClient as Bootstrap<br/>Controller Client
participant OSAPIServer as OpenShift<br/>APIServer API
participant TLSProfile as TLS Profile<br/>Provider
participant Reconcilers as Central &<br/>SecuredCluster<br/>Reconcilers
participant Enricher as TLS Profile<br/>Enricher
participant HelmValues as Helm<br/>Values
Operator->>BootClient: Create bootstrap client
Operator->>OSAPIServer: Fetch cluster TLS profile
OSAPIServer-->>TLSProfile: Return APIServer resource
TLSProfile->>TLSProfile: Convert profile spec<br/>(minVersion, ciphers)
TLSProfile-->>Operator: ClusterTLSProfile
Operator->>Operator: Setup TLS profile<br/>watcher (callbacks)
Operator->>Reconcilers: Pass tlsProfile to<br/>RegisterNewReconciler
Reconcilers->>Enricher: Create with tlsProfile
Reconcilers->>HelmValues: Enrich Helm values<br/>with TLS env vars
HelmValues-->>Reconcilers: Merged values<br/>(user overrides<br/>preserved)
Operator->>Operator: Start manager with<br/>cancelable context
Operator->>OSAPIServer: Monitor TLS changes
OSAPIServer-->>Operator: TLS config changed
Operator->>Operator: Trigger cancel(),<br/>operator restarts
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/tlsprofile/profile.go (1)
88-88: Consider keepingTLSv1.0as a backward-compatible alias.Line 88 now accepts
TLSv1only. This can break existing manualROX_TLS_MIN_VERSION=TLSv1.0configurations by silently falling back to default.Suggested compatibility patch
var supportedVersions = map[string]uint16{ "TLSv1": tls.VersionTLS10, + "TLSv1.0": tls.VersionTLS10, "TLSv1.1": tls.VersionTLS11, "TLSv1.2": tls.VersionTLS12, "TLSv1.3": tls.VersionTLS13, }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/tlsprofile/profile.go` at line 88, Add a backward-compatible alias for TLSv1.0 by mapping the string "TLSv1.0" to tls.VersionTLS10 in the same TLS version lookup used in pkg/tlsprofile/profile.go (i.e., alongside the existing "TLSv1": tls.VersionTLS10 entry); ensure the parser or lookup that reads ROX_TLS_MIN_VERSION accepts the new "TLSv1.0" key so existing env values continue to be recognized without changing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@operator/internal/tlsprofile/provider.go`:
- Around line 55-58: The code currently treats
discovery.IsGroupDiscoveryFailedError(err) the same as IsNotFound/IsNoMatchError
and returns (nil, nil), which silently skips cluster-profile enforcement; change
the logic in the block that calls c.Get(ctx, NamespacedName{Name:
apiserverClusterName}, apiServer) so that IsNotFound and meta.IsNoMatchError
still return (nil, nil) but discovery.IsGroupDiscoveryFailedError(err) is
handled differently: log a warning (including err) and return the error (not
nil) so the caller can retry and clusterTLS in watch.go is not left nil; update
handling around c.Get, apiServer, and any caller expectations in watch.go to
ensure the restart watcher is armed when appropriate.
---
Nitpick comments:
In `@pkg/tlsprofile/profile.go`:
- Line 88: Add a backward-compatible alias for TLSv1.0 by mapping the string
"TLSv1.0" to tls.VersionTLS10 in the same TLS version lookup used in
pkg/tlsprofile/profile.go (i.e., alongside the existing "TLSv1":
tls.VersionTLS10 entry); ensure the parser or lookup that reads
ROX_TLS_MIN_VERSION accepts the new "TLSv1.0" key so existing env values
continue to be recognized without changing behavior.
🪄 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: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: f485a3a2-a5e1-4eb4-9172-e48c17c4fea9
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (15)
CHANGELOG.mdgo.modimage/templates/helm/stackrox-central/templates/01-central-12-central-db.yamloperator/cmd/main.gooperator/internal/central/reconciler/reconciler.gooperator/internal/securedcluster/reconciler/reconciler.gooperator/internal/tlsprofile/convert.gooperator/internal/tlsprofile/convert_test.gooperator/internal/tlsprofile/enricher.gooperator/internal/tlsprofile/enricher_test.gooperator/internal/tlsprofile/provider.gooperator/internal/tlsprofile/provider_test.gooperator/internal/tlsprofile/watch.gopkg/tlsprofile/profile.gopkg/tlsprofile/profile_test.go
Co-authored-by: Marcin Owsiany <marcin@owsiany.pl>
63200ee to
b411ea4
Compare
Description
When an OpenShift cluster has a cluster-wide TLS security profile configured via
apiserver.config.openshift.io/cluster, the Operator now:ROX_TLS_MIN_VERSION,ROX_TLS_CIPHER_SUITES, andROX_OPENSSL_TLS_CIPHER_SUITESenvironment variables (when thespec.tlsAdherencepolicy requires it, or whenFORCE_OPENSHIFT_TLS_PROFILE=true). The individual deployments can use the env var that is suitable for them (e.g. Go apps would useROX_TLS_CIPHER_SUITES, C++/Rust/Postgres components would useROX_OPENSSL_TLS_CIPHER_SUITES)The propagation uses
customize.envVarsin the Helm values, which would also allows users to set per-component overrides. TheFORCE_OPENSHIFT_TLS_PROFILEOperator env var allows enforcement on clusters wherespec.tlsAdherenceis not yet available.On non-OpenShift clusters, the feature is a no-op.
This PR follows the recommendations from this document, but adapted to the fact that we need to also support non-Openshift k8s. Note that in our implementation, we fetch the TLS settings only in the Operator. This avoids having multiple implementations in various languages for all our components and makes sure that the handling of these settings is consistent, by parsing them in a single place.
Related links:
User-facing documentation
Testing and quality
Automated testing
How I validated my change
Tested on an OpenShift 4.21 cluster with
CentralandSecuredClusterCRs deployed. Verified env vars on all 8 workloads: central, central-db, sensor, admission-control, scanner-v4-indexer, scanner-v4-matcher, scanner-v4-db, collector.Default (Intermediate) profile with
FORCE_OPENSHIFT_TLS_PROFILE=true:FORCE_OPENSHIFT_TLS_PROFILE=trueon the operator CSVtlsSecurityProfileset on the cluster (defaults to Intermediate)ROX_TLS_MIN_VERSION=TLSv1.2, 6 ECDHE ciphers in both IANA and OpenSSL formatsModern profile:
apiserver.config.openshift.io/clustertotype: Moderncluster TLS profile changed, restarting Operator to apply new settings, oldMinTLSVersion=VersionTLS12, newMinTLSVersion=VersionTLS13ROX_TLS_MIN_VERSION=TLSv1.3, empty cipher lists (TLS 1.3 ciphers handled separately by Go/OpenSSL)Tried also tls-scanner, all pods look OK:
However the DB pods (central-db, scanner-db, scanner-v4-db) were not tested properly (they show up as
NO_TLS).Full results here.
Custom profile:
minTLSVersion: VersionTLS12ROX_TLS_MIN_VERSION=TLSv1.2, exactly the 3 specified ciphers in both IANA (TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) and OpenSSL formatOld profile:
Note that for the OpenShift 4.11 tests I had to use
FORCE_OPENSHIFT_TLS_PROFILE=true, as thetlsAdherencefield will only be available in OpenShift 4.22.Test on OCP 4.22 (dev preview) with native
tlsAdherencesupportDeployed on OCP 4.22.0-ec.4 with
DevPreviewNoUpgradefeature gate to enable theTLSAdherencefeature.StrictAllComponents + Modern profile: