Skip to content

CNTRLPLANE-3237: KMS preflight checker part3#2313

Merged
openshift-merge-bot[bot] merged 2 commits into
openshift:masterfrom
p0lyn0mial:kms-preflight-checks-part3
Jun 18, 2026
Merged

CNTRLPLANE-3237: KMS preflight checker part3#2313
openshift-merge-bot[bot] merged 2 commits into
openshift:masterfrom
p0lyn0mial:kms-preflight-checks-part3

Conversation

@p0lyn0mial

@p0lyn0mial p0lyn0mial commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor
    • Improved KMS provider configuration handling to consistently retrieve provider-specific source settings through a shared abstraction.
  • New Features
    • Added deterministic hashing for KMS preflight checks, combining the provider configuration with explicitly referenced Secret/ConfigMap data using stable ordering for consistent change detection.
  • Tests
    • Expanded automated coverage to verify deterministic hash outputs across configuration variations and to confirm clear errors when referenced resources or required keys are missing.

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 17, 2026
@openshift-ci

openshift-ci Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: cd1c66e2-955d-4e1b-aa95-6665073c454f

📥 Commits

Reviewing files that changed from the base of the PR and between ad336ec and 8fc8f41.

📒 Files selected for processing (2)
  • pkg/operator/encryption/controllers/kms_preflight_controller.go
  • pkg/operator/encryption/controllers/kms_preflight_controller_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/operator/encryption/controllers/kms_preflight_controller_test.go
  • pkg/operator/encryption/controllers/kms_preflight_controller.go

Walkthrough

Extends the kmsProviderConfig interface with a sourceConfig() interface{} method, implements it on vaultProviderConfig to expose the underlying Vault config, and introduces a kmsConfigHasher helper that deterministically computes a base64-URL-encoded FNV-32 hash from provider config JSON and referenced Secret/ConfigMap key contents.

Changes

KMS Config Hashing

Layer / File(s) Summary
sourceConfig interface contract and Vault implementation
pkg/operator/encryption/controllers/key_controller.go
kmsProviderConfig interface gains sourceConfig() interface{}; vaultProviderConfig implements it by returning v.vault.
kmsConfigHasher: deterministic hash over provider config and referenced resources
pkg/operator/encryption/controllers/kms_preflight_controller.go
Adds base64, json, hash/fnv, and sort imports; defines kmsConfigHasher with constructor and hash() method that JSON-serializes sourceConfig(), then reads and sorts referenced Secret and optional ConfigMap keys, combining all values into an FNV-32 hash returned as a base64-URL-encoded string.
Test coverage for deterministic hashing
pkg/operator/encryption/controllers/kms_preflight_controller_test.go
Adds strings import and TestKMSConfigHasher that validates deterministic hash outputs for Vault KMS config variations, verifies error handling for missing objects and keys, and confirms extra unused keys do not affect the hash.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • openshift/library-go#2170: Modifies the same kms_preflight_controller.go file, adding the initial kmsPreflightController scaffolding that this PR extends with the deterministic config hasher.
  • openshift/library-go#2295: Introduces the kmsProviderConfig and vaultProviderConfig abstraction that this PR extends with the sourceConfig() method.

Suggested labels

lgtm

Suggested reviewers

  • ardaguclu
  • dgrisonnet
🚥 Pre-merge checks | ✅ 13 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Title check ❓ Inconclusive The title references a JIRA ticket but lacks descriptive content about what the PR actually changes; it provides no meaningful information about the KMS preflight checker implementation beyond a vague ordinal reference. Revise the title to clearly describe the main change, such as 'Add deterministic KMS configuration hashing for preflight validation' or 'Implement KMS config hash validation in preflight checks'.
✅ Passed checks (13 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 PR introduces standard Go tests (not Ginkgo) with table-driven t.Run() tests. All test names are static, hardcoded strings with no dynamic values, timestamps, IDs, or pod/namespace names.
Test Structure And Quality ✅ Passed Tests use standard Go testing (not Ginkgo), follow table-driven patterns consistent with codebase, include meaningful error messages via strings.Contains, and each test case focuses on specific beh...
Microshift Test Compatibility ✅ Passed No Ginkgo e2e tests added; PR contains only standard Go unit tests. Check applies only to Ginkgo e2e tests, not unit tests.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests were added; only standard Go unit tests in library-go for KMS configuration hashing. Check not applicable to this PR.
Topology-Aware Scheduling Compatibility ✅ Passed This PR modifies only KMS controller utility code without introducing deployment manifests or any scheduling constraints (affinity, topology spread, nodeSelectors, PDBs). The check is not applicabl...
Ote Binary Stdout Contract ✅ Passed No OTE Binary Stdout Contract violations detected. Modified files are controller implementations with no stdout writes in process-level code. One klog call is in a controller sync method, not proce...
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests added in this PR. New test TestKMSConfigHasher is a standard Go unit test using testing package, not Ginkgo (It/Describe/Context/When patterns).
No-Weak-Crypto ✅ Passed No weak crypto algorithms detected. PR uses FNV-32 (non-cryptographic hash) for configuration state synchronization only, not for security purposes. No MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB foun...
Container-Privileges ✅ Passed PR contains only Go source code files (key_controller.go, kms_preflight_controller.go, and test files). No Kubernetes manifests or container specifications are present; therefore, container privile...
No-Sensitive-Data-In-Logs ✅ Passed No sensitive data (credentials, tokens, secrets values) exposed in logs; only resource names and metadata appear in error messages; secret/configmap values are hashed, not logged.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 17, 2026
@p0lyn0mial

Copy link
Copy Markdown
Contributor Author

/assign @tjungblu

Comment thread pkg/operator/encryption/controllers/kms_preflight_controller.go
Comment thread pkg/operator/encryption/controllers/kms_preflight_controller.go

@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: 1

🤖 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/operator/encryption/controllers/kms_preflight_controller.go`:
- Around line 72-80: The hash stream is vulnerable to collisions because
key/value boundaries are not encoded when writing to the hasher. Currently, the
code at the hasher.Write call in the loop iterating over sorted keys only writes
the raw value bytes, which means different key-value combinations can produce
identical hashes. To fix this, encode the key and value boundaries into the hash
stream by writing both the key and value in a way that makes their boundaries
unambiguous (for example, by writing the key length, key, value length, and
value in sequence). Apply this same fix to all places where values are written
to the hasher, specifically in the loop handling secret data keys and in the
similar section handling ConfigMap data (which the comment indicates also exists
around lines 99-107).
🪄 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: b80c1c01-e2c1-490e-8f96-d483bae4c79b

📥 Commits

Reviewing files that changed from the base of the PR and between 6b59c06 and 176f74b.

📒 Files selected for processing (2)
  • pkg/operator/encryption/controllers/key_controller.go
  • pkg/operator/encryption/controllers/kms_preflight_controller.go

Comment thread pkg/operator/encryption/controllers/kms_preflight_controller.go
return "", err
}

return base64.URLEncoding.EncodeToString(hasher.Sum(nil)), nil

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.

how long is that going to be? 32 bit of FNV as base64 is 6 characters?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, 6 chars + padding (check the unit tests)

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.

can we use this as a suffix in a deployment name?

DC20hA==

"==" wouldn't work. Maybe just hex the string instead?

Alternatively we can just generate a random name and have this as a label, that's also cool for me. Just adds another filtering step to the queries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, I think we should have a stable pod name. There will be a single instance of the preflight pod per namespace at any given time. It will make cleanup easier.

We could add the hash as an annotation to keep track of the version/generation/configuration that the preflight pod is checking.

Comment thread pkg/operator/encryption/controllers/kms_preflight_controller.go
Comment thread pkg/operator/encryption/controllers/kms_preflight_controller.go
Comment thread pkg/operator/encryption/controllers/kms_preflight_controller.go
@p0lyn0mial p0lyn0mial force-pushed the kms-preflight-checks-part3 branch from 176f74b to ad336ec Compare June 18, 2026 08:12
@p0lyn0mial p0lyn0mial marked this pull request as ready for review June 18, 2026 08:13
@openshift-ci openshift-ci Bot requested review from ardaguclu and dgrisonnet June 18, 2026 08:13
@p0lyn0mial p0lyn0mial changed the title WIP: KMS preflight checker part3 CNTRLPLANE-3237: KMS preflight checker part3 Jun 18, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 18, 2026
@openshift-ci-robot

openshift-ci-robot commented Jun 18, 2026

Copy link
Copy Markdown

@p0lyn0mial: This pull request references CNTRLPLANE-3237 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 story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary by CodeRabbit

  • Refactor
  • Enhanced KMS provider configuration abstraction and handling in encryption controllers.
  • Added infrastructure for deterministic validation of KMS configuration changes, improving reliability of preflight checks.

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.

@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 18, 2026
@p0lyn0mial p0lyn0mial force-pushed the kms-preflight-checks-part3 branch from ad336ec to 361eec0 Compare June 18, 2026 08:29
name: "same config and resources produce the same hash",
vaultConfig: baseVaultConfig,
resources: []runtime.Object{baseSecret, baseConfigMap},
expectedHash: "k6dSVA==",

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.

this is a maintenance nitpick for me, but imagine we're changing the structure in the future and the hashes change. Maybe we don't want to hardcode the hashes on every test instead of a "match/mismatch" flag.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in an AI era the cost of updating the hashes is very low. I did that many time while I was developing the tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

also i wanted to avoid precomputing the hash in the test because i wanted to avoid using the same production code path or build a new function for the tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

does it make sense ?

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.

not really, how does the AI generate the hashes when the struct changes? Let's say we add a new provider in KMSPluginConfig.

avoid precomputing the hash in the test

so how did you get the hashes in the first place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so how did you get the hashes in the first place?

directly from the hash method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not really, how does the AI generate the hashes when the struct changes?

this is a similar technique to

just now you can ask ai to replace the hardcoded values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the following comment as a hint for agents:

// Each scenario changes exactly one field from the baseline and verifies the hash changes.
// If the hash algorithm or encoding changes, update the expectedHash values by running
// the test and copying the actual values from the error output.

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.

just now you can ask ai to replace the hardcoded values.

yeah, but the agent does the following (try it out and check the commands):

  • runs the tests
  • input the failed actual values into the expected values

You might as well just save yourself the tokens and directly generate the expected values.

@p0lyn0mial p0lyn0mial force-pushed the kms-preflight-checks-part3 branch from 361eec0 to 8fc8f41 Compare June 18, 2026 10:03
@openshift-ci

openshift-ci Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

@p0lyn0mial: all tests passed!

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.

@ardaguclu

Copy link
Copy Markdown
Member

LGTM

@tjungblu

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jun 18, 2026
@openshift-ci

openshift-ci Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: p0lyn0mial, tjungblu

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-merge-bot openshift-merge-bot Bot merged commit e1dc851 into openshift:master Jun 18, 2026
6 checks passed
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. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants