Skip to content

fix(operator): keep an existing target and the connection token intact when keys are missing - #287

Merged
BryanFRD merged 2 commits into
mainfrom
fix/operator-keep-target-on-missing-keys
Oct 7, 2026
Merged

BryanFRD merged 2 commits into
mainfrom
fix/operator-keep-target-on-missing-keys

Conversation

@BryanFRD

@BryanFRD BryanFRD commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Makes it safe for a FerrVaultSecret to sync a connection's own token Secret, so operator tokens can be rotated from FerrVault (create the new token into the vault, the operator writes it into the token Secret, then revoke the old one).

What changed:

  • When the reveal reports missing keys and the target Secret already exists, the target is left untouched (Ready=False MissingKeys). Before, the target was rewritten with only the keys found (Data=nil, StringData=found), so a missing key deleted the value from a working Secret.
  • No empty target is created when nothing was found (the ferrlens-headless-token case: an empty Secret appeared and consumers restarted on it).
  • Missing keys are retried within a minute instead of waiting a full refresh interval, so a value added after the FerrVaultSecret is picked up quickly (part of FerrLabs/Infra#793).
  • When the target is the Secret named by the connection's tokenSecretRef, the FerrVaultSecret no longer sets itself as controller owner (and drops an existing reference). Deleting the FerrVaultSecret, or a Flux prune, would otherwise garbage-collect the token and lock the connection out.
  • In that case, if the synced data has no key matching tokenSecretRef.key, the target is left alone with Ready=False TokenKeyMissing.

New targets with a partial reveal are still created with the keys found, as before.

Tests in ferrvaultsecret_guard_test.go cover each case; breaking the missing-key guard or the ownership skip makes them fail. go test -race ./... passes locally. golangci-lint was not available locally, CI runs it.

Comment thread internal/controller/ferrvaultsecret_guard_test.go Fixed

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

The guards look correct. A partial reveal no longer rewrites an existing target. An empty reveal doesn't create an empty Secret. A target that holds the connection token is only written when the token key is present, and it no longer carries an owner reference, so deleting the CR won't garbage-collect it. Missing keys now requeue within a minute. The tests cover each of these paths.

Nit: targetContentHash in ferrvaultsecret_sync.go (around line 198) still works out the target name by hand. Replace those four lines with name := targetName(cr) so every caller uses the same lookup. That code isn't in the diff, so I couldn't attach a suggestion to it.

Comment thread internal/controller/ferrvaultsecret_guard.go
@BryanFRD

BryanFRD commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Applied the targetName nit in targetContentHash, and renamed the owner UID test constant that gitleaks read as a key (it is a fixed fake UID). Kept the small owner-ref helper: RemoveOwnerReference errors when the reference is absent, so the helper stays simpler than a HasOwnerReference guard plus RemoveOwnerReference.

Comment thread internal/controller/ferrvaultsecret_guard_test.go

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

48811cd fixes the targetContentHash nit: it now uses targetName(cr). The fixture rename doesn't change behaviour. No new findings.

@BryanFRD
BryanFRD merged commit 340cf09 into main Oct 7, 2026
19 checks passed
@BryanFRD
BryanFRD deleted the fix/operator-keep-target-on-missing-keys branch October 7, 2026 11:10
ferrflow Bot added a commit that referenced this pull request Oct 7, 2026
## [5.3.3] - 2026-10-07

### Bug Fixes

- fix(operator): keep an existing target and the connection token intact when keys are missing (#287)
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.

2 participants