Skip to content

bug fix: Don't drop secrets from index that don't come from ci-secret-generator config#5311

Open
psalajova wants to merge 1 commit into
openshift:mainfrom
psalajova:fix-ci-secret-generator-preserve-manual-index-entries
Open

bug fix: Don't drop secrets from index that don't come from ci-secret-generator config#5311
psalajova wants to merge 1 commit into
openshift:mainfrom
psalajova:fix-ci-secret-generator-preserve-manual-index-entries

Conversation

@psalajova

@psalajova psalajova commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

ci-secret-generator runs every 12h and rebuilds the collection index from _config.yaml. Secrets created manually (e.g. secret-manager create cherrypick-signing-key/id_ed25519 using the CLI tool) were dropped from the index each run — GSM kept the secret but the index didn't list it, so secret-manager list missed it and create/update could fail.

Root cause: The generator read the previous index but only used it to rescue failed command executions — it never merged in entries not derived from config.

Fix: After building index entries from config, merge in previous index entries whose names don't appear in the config-managed set. Index is now sorted for determinism.

Example: Some GSM secrets (including cherrypick-signing-key__id_ed25519) were missing from the index while present in GSM. After this fix they persist across generator runs.

Trade-off: Secrets removed from config will linger in the index (indistinguishable from manual secrets). No GSM-side deletion occurs — cleanup is manual.


Fix ci-secret-generator dropping manually created GSM secrets during its periodic (12-hour) index rebuilds.

In the cmd/ci-secret-generator component, newly generated index entries from _config.yaml are now merged with the previous index contents for any entries that are not config-managed (including entries for disabled clusters). The resulting index is then sorted deterministically so secret-manager can reliably discover the full set of GSM secrets, not just those coming from config. If a secret is removed from _config.yaml, it is kept in the index and requires manual cleanup; the generator does not delete anything in GSM.

Unit tests were updated to verify preservation of manually created entries across rebuilds and to assert the expected deterministic ordering of index fields/items.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@openshift-ci openshift-ci Bot requested review from Prucek and jmguzik July 13, 2026 16:24
@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 13, 2026
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Changes

GSM index preservation

Layer / File(s) Summary
Merge and sort index entries
cmd/ci-secret-generator/main.go
Config-managed normalized keys are identified, generated entries are merged with existing unmanaged entries, and the result is sorted before return.
Validate preservation and ordering
cmd/ci-secret-generator/main_test.go
Tests cover disabled-cluster, manually created, and otherwise unmanaged entry preservation alongside deterministic ordering.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: openshift-merge-bot[bot]

🚥 Pre-merge checks | ✅ 17
✅ Passed checks (17 passed)
Check name Status Explanation
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.
Go Error Handling ✅ Passed PASS: The new helpers only merge/sort index entries; no ignored errors, panics, or nil dereferences were added in the changed code.
Test Coverage For New Features ✅ Passed buildSecretsToUpdate has table-driven regression cases for preserved manual/disabled index entries, which exercise the new helper logic.
Stable And Deterministic Test Names ✅ Passed All modified test titles are static literals; no fmt.Sprintf, concatenation, or volatile data appears in names.
Test Structure And Quality ✅ Passed Changed tests are table-driven unit tests, not Ginkgo; no cluster resources or waits, and assertions are reasonably descriptive.
Microshift Test Compatibility ✅ Passed Only cmd/ci-secret-generator unit tests changed; no Ginkgo e2e tests, MicroShift guards, or unsupported OpenShift APIs/resources were added.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo/e2e tests were added; the touched tests are plain unit tests and don't make any multi-node/SNO assumptions.
Topology-Aware Scheduling Compatibility ✅ Passed Only ci-secret-generator logic/tests changed; no manifests/controllers/scheduling constraints were added.
Ote Binary Stdout Contract ✅ Passed The PR only adds helper logic/tests; main() still uses logrus (stderr) and no fmt.Print/logging-to-stdout paths appear in process-level hooks.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo/e2e tests were added; changed tests are table-driven unit tests with no IPv4/external connectivity assumptions.
No-Weak-Crypto ✅ Passed Touched code only merges/sorts GSM index entries; scans of cmd/ci-secret-generator found no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB or secret comparisons.
Container-Privileges ✅ Passed PR only changes Go code/tests; no container/K8s manifests or privileged settings were introduced.
No-Sensitive-Data-In-Logs ✅ Passed No new log statements or sensitive-value logging were introduced; the PR only changes index merging/sorting and adds tests.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: preserving non-config-managed secrets in the index.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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

🧹 Nitpick comments (1)
cmd/ci-secret-generator/main.go (1)

287-289: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated GSM key-normalization logic.

The same NormalizeName(...) + CollectionSecretDelimiter + NormalizeName(...) construction appears in both configManagedIndexEntries and the main loop. Extracting a shared helper avoids future drift between the "managed" set and the "generated" set (which would silently break the merge logic).

♻️ Proposed helper extraction
+func gsmIndexKey(itemName, fieldName string) string {
+	return fmt.Sprintf("%s%s%s", gsmvalidation.NormalizeName(itemName), gsmvalidation.CollectionSecretDelimiter, gsmvalidation.NormalizeName(fieldName))
+}
+
 func configManagedIndexEntries(config secretgenerator.Config) sets.Set[string] {
 	managed := sets.New[string]()
 	for _, item := range config {
 		for _, field := range item.Fields {
-			normalizedGroup := gsmvalidation.NormalizeName(item.ItemName)
-			normalizedField := gsmvalidation.NormalizeName(field.Name)
-			managed.Insert(fmt.Sprintf("%s%s%s", normalizedGroup, gsmvalidation.CollectionSecretDelimiter, normalizedField))
+			managed.Insert(gsmIndexKey(item.ItemName, field.Name))
 		}
 	}
 	return managed
 }

and reuse gsmIndexKey(item.ItemName, field.Name) in place of Lines 336-338.

Also applies to: 336-338

🤖 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 `@cmd/ci-secret-generator/main.go` around lines 287 - 289, Extract the
duplicated normalized GSM key construction into a shared gsmIndexKey helper that
normalizes the group and field names and joins them with
CollectionSecretDelimiter. Update both configManagedIndexEntries and the main
loop to call gsmIndexKey(item.ItemName, field.Name), replacing their inline
construction while preserving the existing managed/generated set behavior.
🤖 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 `@cmd/ci-secret-generator/main.go`:
- Around line 283-293: Update configManagedIndexEntries to accept
disabledClusters and exclude fields belonging to disabled clusters, matching the
skip behavior in buildSecretsToUpdate. Propagate the new argument from its
callers so mergeIndexEntries preserves existing index entries for disabled
clusters, and add a test combining existingIndexValues with a disabled cluster.

---

Nitpick comments:
In `@cmd/ci-secret-generator/main.go`:
- Around line 287-289: Extract the duplicated normalized GSM key construction
into a shared gsmIndexKey helper that normalizes the group and field names and
joins them with CollectionSecretDelimiter. Update both configManagedIndexEntries
and the main loop to call gsmIndexKey(item.ItemName, field.Name), replacing
their inline construction while preserving the existing managed/generated set
behavior.
🪄 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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 2a48fe7f-9117-4d1c-9dd0-56ff81c02157

📥 Commits

Reviewing files that changed from the base of the PR and between 9caad80 and 705c194.

📒 Files selected for processing (2)
  • cmd/ci-secret-generator/main.go
  • cmd/ci-secret-generator/main_test.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/release (manual)
  • openshift/ci-docs (manual)
  • openshift/release-controller (manual)
  • openshift/ci-chat-bot (manual)

Comment thread cmd/ci-secret-generator/main.go Outdated
@psalajova psalajova force-pushed the fix-ci-secret-generator-preserve-manual-index-entries branch from 705c194 to aca8969 Compare July 13, 2026 16:43
@Prucek

Prucek commented Jul 14, 2026

Copy link
Copy Markdown
Member

/override ci/prow/images

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

openshift-ci Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Prucek, psalajova

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 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@Prucek: Overrode contexts on behalf of Prucek: ci/prow/images

Details

In response to this:

/override ci/prow/images

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.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e

@psalajova

Copy link
Copy Markdown
Contributor Author

the e2e test ran for 3h without even starting....
/test e2e

@psalajova

Copy link
Copy Markdown
Contributor Author

/test e2e

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD b90489e and 2 for PR HEAD aca8969 in total

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD bd4a564 and 1 for PR HEAD aca8969 in total

@openshift-ci

openshift-ci Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@psalajova: 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/images aca8969 link true /test images

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.

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. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants