NO-JIRA: add two more encryption rotation scenarios#2218
Conversation
|
@tjungblu: This pull request explicitly references no jira issue. DetailsIn response to this:
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. |
|
Skipping CI for Draft Pull Request. |
| // TODO(thomas): wire up a hook to define this from a provider configuration | ||
| // TODO(thomas): when we're on KMS provider we can grab the keyId from an annotation | ||
| // TODO(thomas): a new rotation controller can update the annotation for KMS | ||
|
|
||
| // TODO(thomas): alternative, when we detect a new KeyId, we can also remove the migrated-* annotations, | ||
| // that way the controller will definitely try to reconcile it again. |
There was a problem hiding this comment.
I'll remove that, sorry
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tjungblu The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
WalkthroughThis PR introduces encryption migration and rotation testing helpers for OpenShift's library-go. It consolidates operator condition polling into a shared callback type in helpers.go, adds encryption state polling and rotation tracking helpers, extends rotation test scenarios with operator-aware progress detection, and introduces two new test scenarios that exercise key rotation during encryption migration windows. ChangesEncryption migration and rotation testing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 10 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (10 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
7e6ba8f to
9f815c4
Compare
from library-go openshift/library-go#2218 Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
p0lyn0mial
left a comment
There was a problem hiding this comment.
I did a first quick pass. I’d like to clarify the scope. Are we creating new cases that will support all providers, or just KMS?
| t.Skipf("initial migration finished before an in-progress window was observed; set GetOperatorConditionsFunc or use a cluster where migration stays visible longer") | ||
| } | ||
|
|
||
| require.NoError(e, ForceKeyRotation(e, scenario.UnsupportedConfigFunc, fmt.Sprintf("test-rotation-during-first-migration-%s", rand.String(4)))) |
There was a problem hiding this comment.
ForceKeyRotation has no effect on KMS. What is out plan here ? Do we want to run the new scenarios for all encryption providers ?
There was a problem hiding this comment.
ForceKeyRotation will be implemented differently later on
| // ClearForcedKeyRotationReason clears encryption.reason under UnsupportedConfigOverrides (same merge path as | ||
| // ForceKeyRotation). Call when a test finishes so the next test in sequence does not inherit a non-empty | ||
| // reason and the key controller does not keep seeing an external rotation request. | ||
| func ClearForcedKeyRotationReason(t testing.TB, updateUnsupportedConfig UpdateUnsupportedConfigFunc) error { |
There was a problem hiding this comment.
instead of a new fn why no to change teh ForceKeyRotation to register a cleanup routine via t.Cleanup ?
There was a problem hiding this comment.
why would I couple those two functionalities together? what if I just want to force a key rotation and not cleanup?
|
|
||
| require.NoError(e, ForceKeyRotation(e, scenario.UnsupportedConfigFunc, fmt.Sprintf("test-rotation-during-first-migration-%s", rand.String(4)))) | ||
| // n=2: one write-key revision from turning encryption on, one from ForceKeyRotation. | ||
| WaitForNRotations(e, clientSet.Kube, scenario.EncryptionProvider, scenario.TargetGRs, ns, labelSelector, prevMeta, 2) |
There was a problem hiding this comment.
also for KMS, rotation will not create a new key.
There was a problem hiding this comment.
yep, so this would be implemented differently in KMS - I assume this would use this API that you and Ben cobbled together so far
20aff62 to
0cadc78
Compare
This adds two new encryption tests: * Forced rotation during first migration * Forced rotation during a rotation Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@test/library/encryption/helpers.go`:
- Around line 399-416: The operator-condition branch currently returns true for
any Migrating condition; change the loop that scans conds (inside the wait.Poll
using getOp) to also verify the expectedWriteKey is the target of that
migration: only treat a condition as success if c.Type ==
encryptionMigrationControllerProgressingType && c.Status ==
operatorv1.ConditionTrue && c.Reason == "Migrating" AND (expectedWriteKey == ""
OR the condition text contains expectedWriteKey). In practice, update the
condition check in the loop to inspect the condition's message/text (e.g.,
c.Message) for expectedWriteKey and only return true when it matches; keep the
existing fallback to secret metadata polling and the t.Logf call unchanged.
- Around line 339-355: WaitUntilEncryptionStable compares meta.Mode to the raw
expectedMode which can be the zero-value; normalize empty expectedMode to the
canonical defaultEncryptionMode before polling so callers passing "" don’t hang.
In WaitUntilEncryptionStable set wantMode := string(expectedMode) and if
wantMode == "" assign wantMode = defaultEncryptionMode (same mapping used by
WaitForEncryptionKeyBasedOn) so the meta.Mode comparison and
allTargetGRsMigrated checks use the normalized mode.
🪄 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: 62d417f5-06d3-4c1f-95cd-58e2149b95b8
📒 Files selected for processing (3)
test/library/encryption/helpers.gotest/library/encryption/perf_scenarios.gotest/library/encryption/scenarios.go
💤 Files with no reviewable changes (1)
- test/library/encryption/perf_scenarios.go
🚧 Files skipped from review as they are similar to previous changes (1)
- test/library/encryption/scenarios.go
| func WaitUntilEncryptionStable(t testing.TB, kube kubernetes.Interface, expectedMode configv1.EncryptionType, targetGRs []schema.GroupResource, namespace, labelSelector string) { | ||
| t.Helper() | ||
| wantMode := string(expectedMode) | ||
| err := wait.Poll(waitPollInterval, waitPollTimeout, func() (bool, error) { | ||
| meta, err := GetLastKeyMeta(t, kube, namespace, labelSelector) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| if meta.Mode != wantMode { | ||
| return false, nil | ||
| } | ||
| if !allTargetGRsMigrated(meta, targetGRs) { | ||
| return false, nil | ||
| } | ||
| return true, nil | ||
| }) | ||
| require.NoError(t, err) |
There was a problem hiding this comment.
Normalize empty expectedMode to identity before polling.
WaitForEncryptionKeyBasedOn already maps "" to defaultEncryptionMode, but this helper compares meta.Mode to "" directly. Any caller that passes the zero-value encryption type will sit here until timeout, and WaitForNRotations inherits that behavior.
Suggested fix
func WaitUntilEncryptionStable(t testing.TB, kube kubernetes.Interface, expectedMode configv1.EncryptionType, targetGRs []schema.GroupResource, namespace, labelSelector string) {
t.Helper()
wantMode := string(expectedMode)
+ if wantMode == "" {
+ wantMode = defaultEncryptionMode
+ }
err := wait.Poll(waitPollInterval, waitPollTimeout, func() (bool, error) {
meta, err := GetLastKeyMeta(t, kube, namespace, labelSelector)
if err != nil {
return false, err📝 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.
| func WaitUntilEncryptionStable(t testing.TB, kube kubernetes.Interface, expectedMode configv1.EncryptionType, targetGRs []schema.GroupResource, namespace, labelSelector string) { | |
| t.Helper() | |
| wantMode := string(expectedMode) | |
| err := wait.Poll(waitPollInterval, waitPollTimeout, func() (bool, error) { | |
| meta, err := GetLastKeyMeta(t, kube, namespace, labelSelector) | |
| if err != nil { | |
| return false, err | |
| } | |
| if meta.Mode != wantMode { | |
| return false, nil | |
| } | |
| if !allTargetGRsMigrated(meta, targetGRs) { | |
| return false, nil | |
| } | |
| return true, nil | |
| }) | |
| require.NoError(t, err) | |
| func WaitUntilEncryptionStable(t testing.TB, kube kubernetes.Interface, expectedMode configv1.EncryptionType, targetGRs []schema.GroupResource, namespace, labelSelector string) { | |
| t.Helper() | |
| wantMode := string(expectedMode) | |
| if wantMode == "" { | |
| wantMode = defaultEncryptionMode | |
| } | |
| err := wait.Poll(waitPollInterval, waitPollTimeout, func() (bool, error) { | |
| meta, err := GetLastKeyMeta(t, kube, namespace, labelSelector) | |
| if err != nil { | |
| return false, err | |
| } | |
| if meta.Mode != wantMode { | |
| return false, nil | |
| } | |
| if !allTargetGRsMigrated(meta, targetGRs) { | |
| return false, nil | |
| } | |
| return true, nil | |
| }) | |
| require.NoError(t, err) |
🤖 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 `@test/library/encryption/helpers.go` around lines 339 - 355,
WaitUntilEncryptionStable compares meta.Mode to the raw expectedMode which can
be the zero-value; normalize empty expectedMode to the canonical
defaultEncryptionMode before polling so callers passing "" don’t hang. In
WaitUntilEncryptionStable set wantMode := string(expectedMode) and if wantMode
== "" assign wantMode = defaultEncryptionMode (same mapping used by
WaitForEncryptionKeyBasedOn) so the meta.Mode comparison and
allTargetGRsMigrated checks use the normalized mode.
| if getOp != nil { | ||
| err := wait.Poll(2*time.Second, windowWait, func() (bool, error) { | ||
| conds, err := getOp(t) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| for _, c := range conds { | ||
| if c.Type == encryptionMigrationControllerProgressingType && c.Status == operatorv1.ConditionTrue && c.Reason == "Migrating" { | ||
| return true, nil | ||
| } | ||
| } | ||
| return false, nil | ||
| }) | ||
| if err == nil { | ||
| return true | ||
| } | ||
| t.Logf("encryption migration progressing condition not observed within %v, falling back to secret metadata polling: %v", windowWait, err) | ||
| } |
There was a problem hiding this comment.
Gate the operator-condition path on expectedWriteKey.
This branch returns true on any Migrating condition, even if expectedWriteKey has not become the active write key yet. Since the metadata path is the only branch that validates the key and it does not run until after the full operator poll window, a stale/previous migration can satisfy this early and the next rotation gets stacked at the wrong time.
Suggested fix
if getOp != nil {
err := wait.Poll(2*time.Second, windowWait, func() (bool, error) {
+ meta, err := GetLastKeyMeta(t, kube, namespace, labelSelector)
+ if err != nil {
+ return false, err
+ }
+ if meta.Name != expectedWriteKey {
+ return false, nil
+ }
+ if allTargetGRsMigrated(meta, targetGRs) {
+ return false, nil
+ }
+
conds, err := getOp(t)
if err != nil {
return false, err
}
for _, c := range conds {📝 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.
| if getOp != nil { | |
| err := wait.Poll(2*time.Second, windowWait, func() (bool, error) { | |
| conds, err := getOp(t) | |
| if err != nil { | |
| return false, err | |
| } | |
| for _, c := range conds { | |
| if c.Type == encryptionMigrationControllerProgressingType && c.Status == operatorv1.ConditionTrue && c.Reason == "Migrating" { | |
| return true, nil | |
| } | |
| } | |
| return false, nil | |
| }) | |
| if err == nil { | |
| return true | |
| } | |
| t.Logf("encryption migration progressing condition not observed within %v, falling back to secret metadata polling: %v", windowWait, err) | |
| } | |
| if getOp != nil { | |
| err := wait.Poll(2*time.Second, windowWait, func() (bool, error) { | |
| meta, err := GetLastKeyMeta(t, kube, namespace, labelSelector) | |
| if err != nil { | |
| return false, err | |
| } | |
| if meta.Name != expectedWriteKey { | |
| return false, nil | |
| } | |
| if allTargetGRsMigrated(meta, targetGRs) { | |
| return false, nil | |
| } | |
| conds, err := getOp(t) | |
| if err != nil { | |
| return false, err | |
| } | |
| for _, c := range conds { | |
| if c.Type == encryptionMigrationControllerProgressingType && c.Status == operatorv1.ConditionTrue && c.Reason == "Migrating" { | |
| return true, nil | |
| } | |
| } | |
| return false, nil | |
| }) | |
| if err == nil { | |
| return true | |
| } | |
| t.Logf("encryption migration progressing condition not observed within %v, falling back to secret metadata polling: %v", windowWait, err) | |
| } |
🤖 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 `@test/library/encryption/helpers.go` around lines 399 - 416, The
operator-condition branch currently returns true for any Migrating condition;
change the loop that scans conds (inside the wait.Poll using getOp) to also
verify the expectedWriteKey is the target of that migration: only treat a
condition as success if c.Type == encryptionMigrationControllerProgressingType
&& c.Status == operatorv1.ConditionTrue && c.Reason == "Migrating" AND
(expectedWriteKey == "" OR the condition text contains expectedWriteKey). In
practice, update the condition check in the loop to inspect the condition's
message/text (e.g., c.Message) for expectedWriteKey and only return true when it
matches; keep the existing fallback to secret metadata polling and the t.Logf
call unchanged.
from library-go openshift/library-go#2218 Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
from library-go openshift/library-go#2218 Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
from library-go openshift/library-go#2218 Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
This adds two new encryption tests:
Summary by CodeRabbit
Tests