Skip to content

Fix Redfish protocol and TLS certificate verification handling#739

Open
stefanhipfel wants to merge 3 commits intomainfrom
fix/issue-395-tls-certificate-validation
Open

Fix Redfish protocol and TLS certificate verification handling#739
stefanhipfel wants to merge 3 commits intomainfrom
fix/issue-395-tls-certificate-validation

Conversation

@stefanhipfel
Copy link
Copy Markdown
Contributor

@stefanhipfel stefanhipfel commented Mar 17, 2026

Fixes #395

This commit addresses a security vulnerability where TLS certificate verification was hardcoded to be disabled (Insecure: true) in the Redfish BMC client, regardless of configuration.

Summary by CodeRabbit

  • New Features

    • Added CLI flags to explicitly set connection protocol (HTTP/HTTPS) and to skip TLS certificate validation.
  • Deprecated

    • Legacy insecure flag deprecated in favor of the new protocol and skip-cert flags.
  • Improvements

    • More explicit protocol selection and clearer behavior for certificate validation, plus informational warning when HTTPS is used with verification disabled.

Fixes #395

This commit addresses a security vulnerability where TLS certificate
verification was hardcoded to be disabled (Insecure: true) in the
Redfish BMC client, regardless of configuration.

Changes:

1. BMC Package (bmc/redfish.go):
   - Added InsecureTLS bool field to Options struct
   - Updated newRedfishBaseBMCClient to use configurable TLS setting
     instead of hardcoded true

2. Command-Line Flags (cmd/main.go):
   - Added --protocol flag for explicit HTTP/HTTPS selection
   - Added --skip-cert-validation flag for TLS verification control
   - Deprecated --insecure flag with backward compatibility
   - Added clear warning messages for insecure configurations

3. Reconcilers (internal/controller/*):
   - Replaced Insecure bool field with DefaultProtocol and
     SkipCertValidation fields in all reconcilers:
     * EndpointReconciler
     * BMCReconciler
     * ServerReconciler
     * BIOSSettingsReconciler
     * BIOSVersionReconciler
     * BMCSettingsReconciler
     * BMCVersionReconciler
     * BMCUserReconciler

4. Utilities (internal/bmcutils/bmcutils.go):
   - Updated GetProtocolScheme to accept defaultScheme parameter
   - Updated GetBMCClientForServer with protocol and TLS parameters
   - Updated GetBMCClientFromBMC with protocol and TLS parameters
   - Updated CreateBMCClient to configure InsecureTLS option

5. Tests:
   - Updated suite_test.go with new field names
   - Updated server_controller_test.go with new field names
   - All tests passing

Migration Guide:
- Old: --insecure=false (HTTPS but no cert validation)
- New: --protocol=https --skip-cert-validation=false (secure HTTPS)

Backward Compatibility:
- Existing --insecure flag continues to work with deprecation warnings
- No breaking changes to existing deployments

Security Improvements:
- TLS certificate verification is now configurable
- Users can enable secure HTTPS connections with proper cert validation
- Clear warnings when running in insecure mode
@github-actions github-actions bot added size/L bug Something isn't working labels Mar 17, 2026
@stefanhipfel stefanhipfel marked this pull request as ready for review March 30, 2026 08:04
@stefanhipfel stefanhipfel requested a review from a team as a code owner March 30, 2026 08:04
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: de8993d6-9561-46a2-8def-5c8ec35c4561

📥 Commits

Reviewing files that changed from the base of the PR and between 0b19bfd and dd83b8d.

📒 Files selected for processing (12)
  • bmc/redfish.go
  • cmd/main.go
  • internal/bmcutils/bmcutils.go
  • internal/controller/biossettings_controller.go
  • internal/controller/biosversion_controller.go
  • internal/controller/bmc_controller.go
  • internal/controller/bmcsettings_controller.go
  • internal/controller/bmcuser_controller.go
  • internal/controller/bmcversion_controller.go
  • internal/controller/server_controller.go
  • internal/controller/server_controller_test.go
  • internal/controller/suite_test.go
✅ Files skipped from review due to trivial changes (2)
  • internal/controller/server_controller_test.go
  • internal/controller/biosversion_controller.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • bmc/redfish.go
  • internal/controller/suite_test.go
  • internal/controller/bmcsettings_controller.go
  • internal/controller/biossettings_controller.go
  • internal/controller/bmcuser_controller.go
  • internal/bmcutils/bmcutils.go

Walkthrough

This PR replaces the legacy single Insecure boolean with explicit protocol and TLS verification controls: adds CLI flags --protocol and --skip-cert-validation, threads DefaultProtocol and SkipCertValidation through controllers and bmc utils, and wires Options.InsecureTLS into the Redfish client configuration.

Changes

Cohort / File(s) Summary
BMC client & Redfish
bmc/redfish.go, internal/bmcutils/bmcutils.go
Add Options.InsecureTLS and propagate skipCertValidation into BMC client creation; GetProtocolScheme signature changed to accept a defaultScheme.
CLI / entrypoint
cmd/main.go
Add --protocol and --skip-cert-validation flags, deprecate --insecure, compute effectiveProtocol/effectiveSkipCert, and pass DefaultProtocol/SkipCertValidation into all reconciler initializers.
Controller reconcilers
internal/controller/...
endpoint_controller.go, bmc_controller.go, server_controller.go, biossettings_controller.go, biosversion_controller.go, bmcsettings_controller.go, bmcuser_controller.go, bmcversion_controller.go
Replace Insecure bool with DefaultProtocol and SkipCertValidation fields; update BMC client construction calls to use the new parameters and set bmc.Options.InsecureTLS.
Tests / suite
internal/controller/server_controller_test.go, internal/controller/suite_test.go
Update test setup to use DefaultProtocol: metalv1alpha1.HTTPProtocolScheme and SkipCertValidation: true (mock Redfish server lacks TLS).

Sequence Diagram(s)

mermaid
sequenceDiagram
participant CLI as CLI (main)
participant Reconcilers as Controllers (various reconcilers)
participant BMCUtils as internal/bmcutils
participant BMCClient as BMC client (redfish/other)
CLI->>Reconcilers: pass DefaultProtocol & SkipCertValidation
Reconcilers->>BMCUtils: request BMC client (defaultProtocol, skipCertValidation, options)
BMCUtils->>BMCClient: create client with InsecureTLS = skipCertValidation
BMCClient->>BMCClient: perform connection / logout as needed
BMCClient-->>BMCUtils: client ready / error
BMCUtils-->>Reconcilers: return client / error
Reconcilers-->>CLI: reconciliation outcomes / logs

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

api-change, size/XL

Suggested reviewers

  • afritzler
  • xkonni
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The pull request description is minimal but identifies the linked issue and explains the security vulnerability, though it lacks details about proposed changes as specified in the template. Expand the description to follow the template structure with 'Proposed Changes' section detailing how protocol selection and TLS validation were refactored.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing Redfish protocol and TLS certificate verification handling, which aligns with the security vulnerability being addressed.
Linked Issues check ✅ Passed The PR successfully addresses issue #395 by making TLS certificate validation configurable, renaming CLI flags (--protocol, --skip-cert-validation), and removing hardcoded insecure settings across all BMC client implementations.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing TLS certificate verification handling and protocol selection as specified in issue #395, with no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-395-tls-certificate-validation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/controller/suite_test.go (1)

164-168: Add at least one HTTPS + verification-enabled suite path.

All shared controller fixtures here still use the legacy-equivalent combination of http plus SkipCertValidation: true, so CI never exercises the branch that actually verifies certificates. That leaves the security fix unpinned and won't catch regressions where protocol selection and cert validation get coupled again.

Also applies to: 177-178, 190-191, 228-234, 244-250, 265-271, 280-286, 313-316

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/controller/suite_test.go` around lines 164 - 168, Tests currently
only exercise HTTP with SkipCertValidation:true; add at least one suite that
sets DefaultProtocol to the HTTPS scheme and SkipCertValidation to false so the
certificate-verification branch is exercised. Locate the suite struct(s) that
set Client, Scheme, MACPrefixes, DefaultProtocol (currently
metalv1alpha1.HTTPProtocolScheme) and SkipCertValidation and add or modify a
parallel test case where DefaultProtocol is the HTTPS constant (e.g.,
metalv1alpha1.HTTPSProtocolScheme) and SkipCertValidation is false; apply the
same change to the other listed fixtures (the blocks around the referenced
locations) so CI covers both HTTP+skip and HTTPS+verify paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/controller/bmcuser_controller.go`:
- Around line 355-360: bmcConnectionTest currently discards the BMC client
returned by bmcutils.CreateBMCClient, leaking Redfish sessions; modify
bmcConnectionTest to call Logout() on the returned client after a successful
credential check (or defer a safe logout) so sessions are closed, ensuring you
check the client is non-nil before calling Logout; this prevents leaks when
updateEffectiveSecret invokes bmcConnectionTest multiple times.

---

Nitpick comments:
In `@internal/controller/suite_test.go`:
- Around line 164-168: Tests currently only exercise HTTP with
SkipCertValidation:true; add at least one suite that sets DefaultProtocol to the
HTTPS scheme and SkipCertValidation to false so the certificate-verification
branch is exercised. Locate the suite struct(s) that set Client, Scheme,
MACPrefixes, DefaultProtocol (currently metalv1alpha1.HTTPProtocolScheme) and
SkipCertValidation and add or modify a parallel test case where DefaultProtocol
is the HTTPS constant (e.g., metalv1alpha1.HTTPSProtocolScheme) and
SkipCertValidation is false; apply the same change to the other listed fixtures
(the blocks around the referenced locations) so CI covers both HTTP+skip and
HTTPS+verify paths.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ab78603-e34b-4035-8757-29c209d50e1f

📥 Commits

Reviewing files that changed from the base of the PR and between 095085d and 0b19bfd.

📒 Files selected for processing (13)
  • bmc/redfish.go
  • cmd/main.go
  • internal/bmcutils/bmcutils.go
  • internal/controller/biossettings_controller.go
  • internal/controller/biosversion_controller.go
  • internal/controller/bmc_controller.go
  • internal/controller/bmcsettings_controller.go
  • internal/controller/bmcuser_controller.go
  • internal/controller/bmcversion_controller.go
  • internal/controller/endpoint_controller.go
  • internal/controller/server_controller.go
  • internal/controller/server_controller_test.go
  • internal/controller/suite_test.go

Merged latest main branch (commit 7ef9f11) which included:
- Simplified BMCSettings reconciler with renamed constants
- Improved error handling and cleanup logic
- GitHub Actions dependency updates

Fixed CodeRabbit identified issues:
- Fixed session leak in bmcConnectionTest() by properly calling
  defer bmcClient.Logout() after creating BMC client
- Added documentation about test coverage limitation for HTTPS +
  certificate verification (mock server only supports HTTP)

All tests passing (102 controller specs, composite coverage: 57.6%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Fix Redfish protocol and TLS verification handling

3 participants