Skip to content

fix(tls): correct TLS adherence implementation - #646

Closed
RomanBednar wants to merge 5 commits into
openshift:mainfrom
RomanBednar:fix/tls-adherence-gate
Closed

fix(tls): correct TLS adherence implementation#646
RomanBednar wants to merge 5 commits into
openshift:mainfrom
RomanBednar:fix/tls-adherence-gate

Conversation

@RomanBednar

@RomanBednar RomanBednar commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the TLS adherence implementation from PR #643 (STOR-3054) by addressing four issues identified during cross-reference review against the OpenShift centralized-tls-config enhancement and the cluster-machine-approver reference implementation.

Changes

  • ShouldHonorClusterTLSProfile gate: Replace the non-empty profile check (tlsProfile.Ciphers != nil || tlsProfile.MinTLSVersion != "") with libcrypto.ShouldHonorClusterTLSProfile(adherence). As a new-to-TLS component, LSO should only honor the cluster TLS profile under StrictAllComponents mode, not LegacyAdheringComponentsOnly.

  • Graceful shutdown: Replace os.Exit(0) in the TLS watcher callbacks with context.CancelFunc, following the pattern documented in controller-runtime-common and used by cluster-machine-approver. This ensures leader election leases are released, defer cleanup runs, and in-flight reconciles finish.

  • Dead code removal: Remove ValidateMetricsAccess (never called from main.go) and three trivial pass-through wrapper functions (GetTLSConfigFromProfile, GetAdherencePolicyForLogging, FetchAPIServerTLSProfile). Main.go now calls controller-runtime-common directly, matching the cluster-machine-approver pattern.

References

Verification

  • go build ./cmd/local-storage-operator/... ./pkg/tls/... passes
  • go vet ./cmd/local-storage-operator/... ./pkg/tls/... passes
  • golangci-lint run --new-from-rev=origin/main reports 0 issues
  • Removed functions confirmed unreferenced via grep

Summary by CodeRabbit

  • New Features

    • Metrics serving now honors the cluster’s configured TLS profile and adherence policy.
    • TLS profile and adherence changes are detected automatically and applied through a graceful operator restart.
    • Startup and shutdown handling now use coordinated cancellation for more reliable lifecycle management.
  • Documentation

    • Added an implementation plan covering TLS adherence improvements, validation, and verification steps.

rhrmo and others added 5 commits July 30, 2026 13:47
- Gate TLS profile application on ShouldHonorClusterTLSProfile instead
  of a non-empty profile check, so new-to-TLS components only honor the
  cluster profile under StrictAllComponents mode
- Replace os.Exit(0) with context cancellation for graceful shutdown,
  allowing leader election lease release and defer cleanup
- Remove dead ValidateMetricsAccess and trivial wrapper functions,
  calling controller-runtime-common directly
Replace manual TLSProfileSpec construction with crcommon.GetTLSProfileSpec(nil)
which returns the same Intermediate default profile.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Walkthrough

The operator now derives metrics TLS settings from cluster adherence and profile data, watches for TLS changes, and uses shared context cancellation for lifecycle control. A new dependency and engineering plan document support the implementation.

Changes

TLS startup and lifecycle

Layer / File(s) Summary
Metrics TLS initialization
cmd/local-storage-operator/main.go, go.mod
Startup fetches TLS adherence and profile data, selects TLS configuration, and configures secure metrics serving.
TLS profile watcher lifecycle
pkg/tls/watcher.go, cmd/local-storage-operator/main.go, pkg/tls/tlsprofile.go
A security profile watcher cancels the shared operator context when TLS settings change, and manager startup uses that context.
TLS adherence implementation plan
docs/plans/...
Documents adherence gating, graceful cancellation, wrapper removal, verification requirements, and completion criteria.

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

Sequence Diagram(s)

sequenceDiagram
  participant LocalStorageOperator
  participant APIServer
  participant Manager
  participant SecurityProfileWatcher
  LocalStorageOperator->>APIServer: Fetch TLS adherence policy and TLS profile
  LocalStorageOperator->>Manager: Configure secure metrics serving
  LocalStorageOperator->>SecurityProfileWatcher: Register initial TLS state and cancellation callback
  SecurityProfileWatcher->>LocalStorageOperator: Notify TLS profile or adherence change
  LocalStorageOperator->>Manager: Cancel shared startup context
Loading

Possibly related PRs

Suggested labels: jira/valid-reference

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: fixing the TLS adherence implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 PASS: The PR diff only changes cmd/local-storage-operator/main.go, and no Ginkgo test titles were added or modified.
Test Structure And Quality ✅ Passed No Ginkgo test files or test logic were changed; the diff only touches implementation, docs, and vendor files.
Microshift Test Compatibility ✅ Passed No Ginkgo test files or It/Describe/Context/When additions were introduced in this PR, so MicroShift compatibility is not implicated.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo/e2e test files or suite blocks were added; the PR only touches main, TLS helpers, docs, and go.mod.
Topology-Aware Scheduling Compatibility ✅ Passed No pod specs or scheduling logic were added; changed files only adjust TLS startup/watcher code, and searches found no nodeSelector/affinity/spread/PDB/replica topology assumptions.
Ote Binary Stdout Contract ✅ Passed PASS: process-level code uses klog only; klog defaults to stderr, and no fmt.Print/println or os.Stdout writes were added.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests were added in the PR range; only operator/TLS code and docs changed, with no IPv4 or external-network assumptions found.
No-Weak-Crypto ✅ Passed Touched files only use crypto/tls and controller-runtime-common TLS helpers; no weak ciphers/hashes or unsafe secret comparisons found.
Container-Privileges ✅ Passed PR only changes Go code/docs/vendor files; no changed K8s/container manifests or privilege-related settings were introduced.
No-Sensitive-Data-In-Logs ✅ Passed New logs only print TLS adherence/profile details and unsupported cipher suites; no passwords, tokens, PII, hostnames, or customer data are logged.
✨ 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 review from mpatlasov and tsmetana July 30, 2026 17:19
@openshift-ci

openshift-ci Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RomanBednar

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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 30, 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)
docs/plans/2026-07-30-001-fix-lso-tls-adherence-plan.md (1)

146-153: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add behavior-specific verification gates.

The aggregate commands do not explicitly verify the two functional changes. Include tests or checks confirming that StrictAllComponents applies the cluster profile, other adherence modes use the default profile, and watcher callbacks cancel the shared context gracefully.

🤖 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 `@docs/plans/2026-07-30-001-fix-lso-tls-adherence-plan.md` around lines 146 -
153, Extend the Verification Contract with behavior-specific gates covering the
StrictAllComponents cluster-profile selection, default-profile selection for
other adherence modes, and graceful shared-context cancellation from watcher
callbacks. Define tests or checks that explicitly validate each behavior
alongside the existing aggregate build, test, vet, and dead-code gates.
🤖 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 `@docs/plans/2026-07-30-001-fix-lso-tls-adherence-plan.md`:
- Line 49: Update the fenced code block in the plan document by adding the go
language identifier to its opening fence, while leaving the snippet content and
closing fence unchanged.

In `@go.mod`:
- Line 99: Update the controller-runtime-common dependency entry in go.mod to
use an available tagged stable release instead of the pseudo-version. If no
suitable tagged release exists, add the dependency to the repository’s explicit
approved exception mechanism while preserving the required version.

---

Nitpick comments:
In `@docs/plans/2026-07-30-001-fix-lso-tls-adherence-plan.md`:
- Around line 146-153: Extend the Verification Contract with behavior-specific
gates covering the StrictAllComponents cluster-profile selection,
default-profile selection for other adherence modes, and graceful shared-context
cancellation from watcher callbacks. Define tests or checks that explicitly
validate each behavior alongside the existing aggregate build, test, vet, and
dead-code gates.
🪄 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: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3eed9eb7-581b-45cd-9e93-621dee3e6878

📥 Commits

Reviewing files that changed from the base of the PR and between 92569de and 0005f50.

⛔ Files ignored due to path filters (5)
  • go.sum is excluded by !**/*.sum
  • vendor/github.com/openshift/controller-runtime-common/LICENSE is excluded by !**/vendor/**, !vendor/**
  • vendor/github.com/openshift/controller-runtime-common/pkg/tls/controller.go is excluded by !**/vendor/**, !vendor/**
  • vendor/github.com/openshift/controller-runtime-common/pkg/tls/tls.go is excluded by !**/vendor/**, !vendor/**
  • vendor/modules.txt is excluded by !**/vendor/**, !vendor/**
📒 Files selected for processing (5)
  • cmd/local-storage-operator/main.go
  • docs/plans/2026-07-30-001-fix-lso-tls-adherence-plan.md
  • go.mod
  • pkg/tls/tlsprofile.go
  • pkg/tls/watcher.go


The `SecurityProfileWatcher`'s own source code documents the `cancel()` pattern as the intended usage — from [`controller-runtime-common/pkg/tls/controller.go:63-77`](https://github.com/openshift/controller-runtime-common/blob/fea68df23430b5c1e86599ac37d1de7e7fe55eb6/pkg/tls/controller.go#L63-L77):

```

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Specify the fenced block language.

Add go after the opening fence so Markdown linters and readers can identify the snippet correctly.

Proposed fix
-```
+```go
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```
🧰 Tools
🪛 markdownlint-cli2 (0.23.1)

[warning] 49-49: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 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 `@docs/plans/2026-07-30-001-fix-lso-tls-adherence-plan.md` at line 49, Update
the fenced code block in the plan document by adding the go language identifier
to its opening fence, while leaving the snippet content and closing fence
unchanged.

Source: Linters/SAST tools

Comment thread go.mod
github.com/aws/aws-sdk-go-v2/credentials v1.19.29
github.com/aws/aws-sdk-go-v2/service/ec2 v1.316.1
github.com/onsi/ginkgo/v2 v2.32.0
github.com/openshift/controller-runtime-common v0.0.0-20260722095319-fea68df23430

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:

#!/usr/bin/env bash
set -euo pipefail

module='github.com/openshift/controller-runtime-common'
version='v0.0.0-20260722095319-fea68df23430'

rg -n "^${module} ${version}( /go\.mod)? h1:" go.sum

curl -fsSL "https://proxy.golang.org/${module}/@v/list" |
  grep -Ev -- '-' || true

curl -fsSL https://api.osv.dev/v1/query \
  -H 'content-type: application/json' \
  -d "{\"package\":{\"ecosystem\":\"Go\",\"name\":\"${module}\"},\"version\":\"${version}\"}" |
  jq .

curl -fsSL "https://api.github.com/repos/openshift/controller-runtime-common/license" |
  jq -r '.license.spdx_id'

Repository: openshift/local-storage-operator

Length of output: 358


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf 'go.mod context:\n'
sed -n '90,105p' go.mod

echo
echo 'Available versions from proxy.golang.org (stable tags only):'
curl -fsSL "https://proxy.golang.org/github.com/openshift/controller-runtime-common/@v/list" \
  | sed '/-/d' \
  | tail -n 20 || true

echo
echo 'All listed versions count:'
curl -fsSL "https://proxy.golang.org/github.com/openshift/controller-runtime-common/@v/list" \
  | wc -l

Repository: openshift/local-storage-operator

Length of output: 874


Use a tagged release or add an explicit exception for this dependency.

github.com/openshift/controller-runtime-common v0.0.0-20260722095319-fea68df23430 is a pseudo-version, so it falls under the no pre-release versions policy for production dependencies.

🤖 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 `@go.mod` at line 99, Update the controller-runtime-common dependency entry in
go.mod to use an available tagged stable release instead of the pseudo-version.
If no suitable tagged release exists, add the dependency to the repository’s
explicit approved exception mechanism while preserving the required version.

Source: Path instructions

@openshift-ci

openshift-ci Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

@RomanBednar: 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/verify 0005f50 link true /test verify

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this file does not belong to the repository.

@RomanBednar

Copy link
Copy Markdown
Contributor Author

Closing in favor of: github.com//pull/643

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants