Skip to content

test/kms: add reusable Vault KMS helpers and KMSTestProvider abstraction#2225

Open
gangwgr wants to merge 1 commit into
openshift:masterfrom
gangwgr:update-kms-provider
Open

test/kms: add reusable Vault KMS helpers and KMSTestProvider abstraction#2225
gangwgr wants to merge 1 commit into
openshift:masterfrom
gangwgr:update-kms-provider

Conversation

@gangwgr
Copy link
Copy Markdown
Contributor

@gangwgr gangwgr commented May 14, 2026

Move the Vault KMS encryption config and AppRole secret setup from cluster-kube-apiserver-operator into library-go so any operator can reuse them.

Add KMSTestProvider type that pairs an encryption config with its setup function, enabling the same test cases to run against multiple KMS provider without duplicating test logic.

Summary by CodeRabbit

  • Tests
    • Enhanced Vault KMS encryption tests with Enterprise namespace support and AppRole authentication credentials setup
    • Updated encryption provider configuration structure with wrapper type supporting optional per-provider setup hooks
    • Reorganized supported static encryption providers list for encryption test scenario handling

@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 May 14, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 14, 2026

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
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR introduces a setup-hook mechanism for encryption test providers. It adds an EncryptionProvider wrapper type that pairs encryption configs with optional setup functions, updates three test scenarios and their corresponding test functions to use it, and implements the first concrete setup helper for Vault AppRole authentication.

Changes

Encryption Provider Setup Hook Infrastructure

Layer / File(s) Summary
EncryptionProvider wrapper type and scenario contracts
test/library/encryption/scenarios.go
Introduces EncryptionProvider struct embedding configv1.APIServerEncryption with optional Setup func(t testing.TB) hook. Updates OnOffScenario, ProvidersMigrationScenario, RotationScenario, and ShuffleEncryptionProviders to use the new wrapper type.
Test execution with setup hooks
test/library/encryption/scenarios.go
Updates TestEncryptionTurnOnAndOff, TestEncryptionProvidersMigration, and TestEncryptionRotation to optionally run provider setup hooks before deriving the embedded encryption config and running test steps.
Static encryption provider list
test/library/encryption/helpers.go
Updates SupportedStaticEncryptionProviders to wrap AES-GCM and AES-CBC entries in EncryptionProvider structs.
Vault AppRole setup implementation
test/library/encryption/kms/vault.go
Adds DefaultVaultEnterpriseNS = "admin" and EnsureDefaultVaultAppRoleSecret(t testing.TB) helper that reads role-id and secret-id from the vault-credentials Kubernetes secret and creates an AppRole secret in openshift-config. Wires the helper into the default Vault encryption provider and updates the Vault KMS config to use the enterprise namespace.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • openshift/library-go#2220: Refactors the encryption test harness provider config plumbing that this PR extends with setup-hook infrastructure.

Suggested labels

approved, lgtm

Suggested reviewers

  • dgrisonnet
  • p0lyn0mial
🚥 Pre-merge checks | ✅ 10 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Structure And Quality ⚠️ Warning Missing timeouts on cluster operations (context.Background() in vault.go), missing assertion messages in scenarios.go lines 279-280, and no cleanup for AppRole secret created by setup function. Add context.WithTimeout to vault.go L82, add messages to require.NoError calls at scenarios.go L279-280, implement cleanup for AppRole secret resource.
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: introducing Vault KMS helpers and the EncryptionProvider abstraction that enables provider-agnostic test execution.
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 No Ginkgo tests added. Test step names use stable values: enum constants and struct fields. No dynamic information.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests added. PR only modifies library helper files in test/library/encryption/ with utility functions and types.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR modifies test library/helper files only. No new Ginkgo e2e tests (It, Describe, Context, When) are added. The custom check applies only to new e2e tests, not library abstractions.
Topology-Aware Scheduling Compatibility ✅ Passed This PR modifies only test library code (test/library/encryption/) with no deployment manifests, operator code, controllers, or scheduling constraints.
Ote Binary Stdout Contract ✅ Passed No process-level stdout writes detected. All files are library packages with no main(), init(), TestMain(), or Ginkgo suite functions. Logging uses testing.TB.Logf() which is permitted.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests added. PR modifies library helpers only, using cluster-internal DNS and no IPv4/external connectivity issues.

✏️ 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
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 14, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gangwgr
Once this PR has been reviewed and has the lgtm label, please assign dgrisonnet for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@gangwgr gangwgr force-pushed the update-kms-provider branch from 514f7c1 to 0af0751 Compare May 14, 2026 17:27
Copy link
Copy Markdown

@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: 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/kms/vault.go`:
- Around line 80-83: Before creating the target secret, validate that creds.Data
contains non-empty "role-id" and "secret-id" values: check creds.Data["role-id"]
and creds.Data["secret-id"] exist and have length > 0 (or non-empty string/byte
slice), and if either is missing/empty, fail early (return an error or call
t.Fatalf in the test) instead of proceeding to build the Data map used in the
secret write; update the code around the Data: map[string][]byte{...}
construction in vault.go to perform this validation on creds and only populate
roleID/secretID when valid.
- Around line 85-88: When creating the secret via
cs.Kube.CoreV1().Secrets(DefaultAppRoleTargetNamespace).Create(...,
appRoleSecret, ...), don't blindly call Update on any error; instead check if
the error is an AlreadyExists error
(k8s.io/apimachinery/pkg/api/errors.IsAlreadyExists(err)); if so, fetch the
existing secret with
cs.Kube.CoreV1().Secrets(DefaultAppRoleTargetNamespace).Get(ctx,
appRoleSecret.Name, metav1.GetOptions{}), copy its ResourceVersion into
appRoleSecret.ObjectMeta.ResourceVersion, then call Update; for other create
errors return/fail as before. Ensure you use the same ctx and metav1 types and
handle Get/Update errors with require.NoError where appropriate.
🪄 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: d5651548-77ce-4c42-b3f5-f47dbe458712

📥 Commits

Reviewing files that changed from the base of the PR and between 2291b96 and 0af0751.

📒 Files selected for processing (2)
  • test/library/encryption/kms/provider.go
  • test/library/encryption/kms/vault.go

Comment thread test/library/encryption/kms/vault.go Outdated
Comment thread test/library/encryption/kms/vault.go Outdated
@gangwgr gangwgr force-pushed the update-kms-provider branch 2 times, most recently from 4834028 to aef73c8 Compare May 15, 2026 16:24
@gangwgr gangwgr marked this pull request as ready for review May 18, 2026 05:35
@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 May 18, 2026
@openshift-ci openshift-ci Bot requested review from dgrisonnet and p0lyn0mial May 18, 2026 05:36
const (
DefaultVaultNamespace = "vault-kms"
DefaultVaultCredentialsSecret = "vault-credentials"
DefaultVaultAppRoleSecretName = "vault-approle-secret"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
DefaultVaultAppRoleSecretName = "vault-approle-secret"
DefaultAppRoleSecretName = "vault-approle-secret"

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.

Better to have this DefaultVaultAppRoleSecretName, because all are specific to vault

Comment thread test/library/encryption/kms/vault.go Outdated

roleID, ok := creds.Data["role-id"]
require.Truef(t, ok && len(roleID) > 0, "missing or empty key %q in %s/%s", "role-id", DefaultVaultNamespace, DefaultVaultCredentialsSecret)
secretID, ok := creds.Data["secret-id"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should be careful to not leak

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.

Validatio uses require.Contains which only prints key names, never secret values

Comment thread test/library/encryption/kms/vault.go Outdated
if apierrors.IsAlreadyExists(err) {
existing, getErr := cs.Kube.CoreV1().Secrets(DefaultAppRoleTargetNamespace).Get(ctx, DefaultVaultAppRoleSecretName, metav1.GetOptions{})
require.NoError(t, getErr, "failed to get existing AppRole secret for update")
appRoleSecret.ResourceVersion = existing.ResourceVersion
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need ResourceVersion?

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 needed removed

Comment thread test/library/encryption/kms/vault.go Outdated
existing, getErr := cs.Kube.CoreV1().Secrets(DefaultAppRoleTargetNamespace).Get(ctx, DefaultVaultAppRoleSecretName, metav1.GetOptions{})
require.NoError(t, getErr, "failed to get existing AppRole secret for update")
appRoleSecret.ResourceVersion = existing.ResourceVersion
_, err = cs.Kube.CoreV1().Secrets(DefaultAppRoleTargetNamespace).Update(ctx, appRoleSecret, metav1.UpdateOptions{})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we update?

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.

updated, if secret already exists, just log and return

@gangwgr gangwgr force-pushed the update-kms-provider branch from aef73c8 to afa6db9 Compare May 18, 2026 08:55
Copy link
Copy Markdown

@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.

♻️ Duplicate comments (1)
test/library/encryption/kms/vault.go (1)

78-90: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Validate AppRole credential values are non-empty before creating the target secret.

require.Contains only verifies key presence; empty role-id/secret-id values still get written and defer failure to later test stages.

Proposed fix
 	require.Contains(t, creds.Data, "role-id", "vault-credentials secret is missing the role-id key")
 	require.Contains(t, creds.Data, "secret-id", "vault-credentials secret is missing the secret-id key")
+	roleID := creds.Data["role-id"]
+	secretID := creds.Data["secret-id"]
+	require.NotEmpty(t, roleID, "vault-credentials secret has empty role-id")
+	require.NotEmpty(t, secretID, "vault-credentials secret has empty secret-id")
@@
 		Data: map[string][]byte{
-			"roleID":   creds.Data["role-id"],
-			"secretID": creds.Data["secret-id"],
+			"roleID":   roleID,
+			"secretID": secretID,
 		},
 	}
🤖 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/kms/vault.go` around lines 78 - 90, The test
currently only checks for presence of "role-id" and "secret-id" keys via
require.Contains but may still allow empty values; before constructing
appRoleSecret (the Secret created with Name DefaultVaultAppRoleSecretName in
namespace DefaultAppRoleTargetNamespace using creds.Data), assert that
creds.Data["role-id"] and creds.Data["secret-id"] are non-empty (e.g.
require.NotEmpty or require.True on len > 0) and/or trim whitespace, and fail
the test early if either value is empty so the subsequent creation of
appRoleSecret with keys "roleID"/"secretID" cannot proceed with blank
credentials.
🤖 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.

Duplicate comments:
In `@test/library/encryption/kms/vault.go`:
- Around line 78-90: The test currently only checks for presence of "role-id"
and "secret-id" keys via require.Contains but may still allow empty values;
before constructing appRoleSecret (the Secret created with Name
DefaultVaultAppRoleSecretName in namespace DefaultAppRoleTargetNamespace using
creds.Data), assert that creds.Data["role-id"] and creds.Data["secret-id"] are
non-empty (e.g. require.NotEmpty or require.True on len > 0) and/or trim
whitespace, and fail the test early if either value is empty so the subsequent
creation of appRoleSecret with keys "roleID"/"secretID" cannot proceed with
blank credentials.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: f66e9580-a1e7-49f1-82d8-c656413eb3eb

📥 Commits

Reviewing files that changed from the base of the PR and between aef73c8 and afa6db9.

📒 Files selected for processing (2)
  • test/library/encryption/kms/provider.go
  • test/library/encryption/kms/vault.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/library/encryption/kms/provider.go

Comment thread test/library/encryption/kms/provider.go Outdated
// KMSTestProvider pairs a KMS encryption config with its prerequisite setup.
// This allows the same test cases to run against any KMS provider (Vault, AWS, etc.)
// by simply iterating over a slice of providers.
type KMSTestProvider struct {
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 will this provider be used ? why do we need it ?

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.

Right now KAS-O tests we only have Vault KMS. But whenwe have a second provider (e.g. AWS KMS) and want to add add that, we want to run same cases

Run the same TestKMSEncryptionOnOff test against each provider
Run TestEncryptionProvidersMigration across all providers
Each provider needs its own setup (Vault needs AppRole secret, AWS would need IAM credentials, etc.)
KMSTestProvider groups the config + setup together so the operator test just does:


var allProviders = []kms.KMSTestProvider{
    kms.DefaultVaultTestProvider,
    // future: kms.DefaultAWSTestProvider,
}

func testKMSEncryptionOnOff(t testing.TB) {
    kms.SetupAll(t, allProviders)
    for _, p := range allProviders {
        library.TestEncryptionTurnOnAndOff(t, library.OnOffScenario{
            EncryptionProvider: p.EncryptionConfig,
            ...
        })
    }

}

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.

then let's extend all providers, not only KMS.

for example

EncryptionProvider configv1.APIServerEncryption

this field could be extended by a struct that holds configv1.APIServerEncryption and a custom setup function. WDYT

Comment thread test/library/encryption/kms/vault.go Outdated
// EnsureVaultAppRoleSecret reads credentials from the vault-credentials secret
// (created by a CI step) and creates the AppRole secret in openshift-config.
// If the secret already exists it is left untouched.
func EnsureVaultAppRoleSecret(t testing.TB) {
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.

will this function create an AppRole Secret for the default configuration ?

if yes, then maybe we should rename to EnsureDefaultVaultAppRoleSecret

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, updated

Authentication: configv1.VaultAuthentication{
Type: configv1.VaultAuthenticationTypeAppRole,
AppRole: configv1.VaultAppRoleAuthentication{
Secret: configv1.VaultSecretReference{Name: DefaultVaultAppRoleSecretName},
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.

could we just simply use DefaultVaultCredentialsSecret ? why do we need a new secret ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We enforce the users to create a Secret under openshift-config namespace. Vault is deployed to dedicated vault-kms namespace. So we need this action

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 for same as @ardaguclu said

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.

ah, ok, thx.

@gangwgr gangwgr force-pushed the update-kms-provider branch from afa6db9 to fa3f16b Compare May 18, 2026 09:19
Comment thread test/library/encryption/kms/vault.go Outdated
creds, err := cs.Kube.CoreV1().Secrets(DefaultVaultNamespace).Get(ctx, DefaultVaultCredentialsSecret, metav1.GetOptions{})
require.NoError(t, err, "failed to read %s/%s secret (was the vault-install CI step run?)", DefaultVaultNamespace, DefaultVaultCredentialsSecret)

require.Contains(t, creds.Data, "role-id", "vault-credentials secret is missing the role-id key")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume that require.Contains is smart enough to check that creds.Data map contains role-id key.

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

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.

do we have to compare the content ? or is it ok to assume the default will not change ?

Copy link
Copy Markdown

@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.

♻️ Duplicate comments (1)
test/library/encryption/kms/vault.go (1)

79-91: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Validate AppRole credential values are non-empty before creating the target secret.

Line 79 and Line 80 only verify key presence. Empty role-id / secret-id still pass and produce an invalid openshift-config secret, shifting failure downstream.

Suggested fix
-	require.Contains(t, creds.Data, "role-id", "vault-credentials secret is missing the role-id key")
-	require.Contains(t, creds.Data, "secret-id", "vault-credentials secret is missing the secret-id key")
+	roleID, ok := creds.Data["role-id"]
+	require.Truef(t, ok && len(roleID) > 0, "vault-credentials secret has missing/empty %q", "role-id")
+	secretID, ok := creds.Data["secret-id"]
+	require.Truef(t, ok && len(secretID) > 0, "vault-credentials secret has missing/empty %q", "secret-id")
@@
 		Data: map[string][]byte{
-			"roleID":   creds.Data["role-id"],
-			"secretID": creds.Data["secret-id"],
+			"roleID":   roleID,
+			"secretID": secretID,
 		},
 	}
🤖 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/kms/vault.go` around lines 79 - 91, The test
currently only asserts the presence of "role-id" and "secret-id" keys in
creds.Data but does not validate their values; update the test to assert that
creds.Data["role-id"] and creds.Data["secret-id"] are non-empty (e.g. using
require.NotEmpty or equivalent) before constructing appRoleSecret, so that the
appRoleSecret.Data entries ("roleID"/"secretID") are guaranteed to contain valid
bytes; reference creds.Data, DefaultVaultAppRoleSecretName,
DefaultAppRoleTargetNamespace and appRoleSecret when adding these additional
checks.
🤖 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.

Duplicate comments:
In `@test/library/encryption/kms/vault.go`:
- Around line 79-91: The test currently only asserts the presence of "role-id"
and "secret-id" keys in creds.Data but does not validate their values; update
the test to assert that creds.Data["role-id"] and creds.Data["secret-id"] are
non-empty (e.g. using require.NotEmpty or equivalent) before constructing
appRoleSecret, so that the appRoleSecret.Data entries ("roleID"/"secretID") are
guaranteed to contain valid bytes; reference creds.Data,
DefaultVaultAppRoleSecretName, DefaultAppRoleTargetNamespace and appRoleSecret
when adding these additional checks.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: b2807e54-e4fc-4c0b-b944-e4d6b6930e5e

📥 Commits

Reviewing files that changed from the base of the PR and between afa6db9 and fa3f16b.

📒 Files selected for processing (2)
  • test/library/encryption/kms/provider.go
  • test/library/encryption/kms/vault.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/library/encryption/kms/provider.go

@gangwgr gangwgr force-pushed the update-kms-provider branch 2 times, most recently from dcb9f25 to 3833b5b Compare May 18, 2026 11:08
Comment thread test/library/encryption/scenarios.go Outdated

func TestEncryptionTurnOnAndOff(t testing.TB, scenario OnOffScenario) {
if scenario.EncryptionProvider.Setup != nil {
scenario.EncryptionProvider.Setup(t)
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.

IIRC all tests use SetAndWaitForEncryptionType. So I think this should be the only place that calls the setup fn.

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.

updated

DefaultVaultNamespace = "vault-kms"
DefaultVaultCredentialsSecret = "vault-credentials"
DefaultVaultAppRoleSecretName = "vault-approle-secret"
DefaultVaultKMSPluginImage = "quay.io/openshifttest/mock-kms-plugin@sha256:03bb07a2c08b509653c4c70217a06a4b389c10b4d87922f50ee5eac82db5e140"
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.

is this a Vault img ? or it will be in the future ?

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.

it is vault fake image which we are current using, in future we will update with real vault plugin image

Comment thread test/library/encryption/kms/vault.go Outdated
// If the secret already exists it is left untouched.
func EnsureDefaultVaultAppRoleSecret(t testing.TB) {
t.Helper()
ctx := context.Background()
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.

use t.Context()

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.

updated

@gangwgr gangwgr force-pushed the update-kms-provider branch 2 times, most recently from 795bd67 to 5b7f45c Compare May 18, 2026 12:27
Comment thread test/library/encryption/helpers.go Outdated
func SetAndWaitForEncryptionType(t testing.TB, ep EncryptionProvider, defaultTargetGRs []schema.GroupResource, namespace, labelSelector string) ClientSet {
t.Helper()

if ep.Setup != 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.

I think this should moved down around the line 77, no ?

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.

updated

Comment thread test/library/encryption/kms/vault.go Outdated
creds, err := cs.Kube.CoreV1().Secrets(DefaultVaultNamespace).Get(ctx, DefaultVaultCredentialsSecret, metav1.GetOptions{})
require.NoError(t, err, "failed to read %s/%s secret (was the vault-install CI step run?)", DefaultVaultNamespace, DefaultVaultCredentialsSecret)

require.Contains(t, creds.Data, "role-id", "vault-credentials secret is missing the role-id key")
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.

do we have to compare the content ? or is it ok to assume the default will not change ?

Move the Vault KMS encryption config and AppRole secret setup from
cluster-kube-apiserver-operator into library-go so any operator can
reuse them.

Add KMSTestProvider type that pairs an encryption config with its
setup function, enabling the same test cases to run against multiple
KMS providers (Vault, AWS, etc.) without duplicating test logic.
@gangwgr gangwgr force-pushed the update-kms-provider branch from 5b7f45c to 4aaba6e Compare May 18, 2026 14:08
@gangwgr
Copy link
Copy Markdown
Contributor Author

gangwgr commented May 18, 2026

#2225 (comment)
Better to compare

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 18, 2026

@gangwgr: 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.

func SetAndWaitForEncryptionType(t testing.TB, ep EncryptionProvider, defaultTargetGRs []schema.GroupResource, namespace, labelSelector string) ClientSet {
t.Helper()

provider := ep.APIServerEncryption
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.

let's remove this var.

type UpdateUnsupportedConfigFunc func(raw []byte) error

func SetAndWaitForEncryptionType(t testing.TB, provider configv1.APIServerEncryption, defaultTargetGRs []schema.GroupResource, namespace, labelSelector string) ClientSet {
func SetAndWaitForEncryptionType(t testing.TB, ep EncryptionProvider, defaultTargetGRs []schema.GroupResource, namespace, labelSelector string) ClientSet {
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.

rename ep to provider.

"secretID": creds.Data["secret-id"],
}

existing, err := cs.Kube.CoreV1().Secrets(DefaultAppRoleTargetNamespace).Get(ctx, DefaultVaultAppRoleSecretName, metav1.GetOptions{})
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.

could this be replaced by resourceapply.ApplySecret ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants