Skip to content

fix(api): preserve authentication union across v1alpha1 spoke round trip (AUTH-14) - #168

Merged
konih merged 1 commit into
mainfrom
worktree-fix-qmc-auth-conversion-roundtrip
Jul 29, 2026
Merged

konih merged 1 commit into
mainfrom
worktree-fix-qmc-auth-conversion-roundtrip

Conversation

@konih

@konih konih commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Root-causes and fixes the E2E regression on main (E2E workflow failing on recovers union-auth QueueManagerConnection readiness after auth-secret rotation), which the last several commits (f450f23, 30d480d, f16d881, 1102948, fd0da61) tried to fix as a timing/race issue without success.

Actual root cause: QueueManagerConnection.ConvertTo (v1alpha1 spoke → v1beta1 hub) unconditionally sets spec.authentication = nil. The reconciler always works through the v1alpha1 type, and the very first reconcile of any new object adds a finalizer via a full v1alpha1 Update — a metadata-only change that still round-trips the whole object down (ConvertFrom) then back up (ConvertTo) through the spoke. For a union-auth QMC (no v1alpha1 representation exists for the union), this permanently wiped spec.authentication in etcd moments after creation — not a race, so no amount of timeout widening could help.

Fix: stash the hub's authentication union as JSON on an annotation during down-conversion, restore it during up-conversion if present, and strip the annotation so it never leaks into storage. Safe against concurrent v1beta1 writers because the spoke/hub share one storage object + resourceVersion (a stale spoke write conflicts rather than clobbering).

Verification: added a unit-level round-trip test (api/v1alpha1) and an end-to-end envtest test against a real API server + conversion webhook (test/conversionwebhook) — confirmed the new envtest case fails on the prior code and passes with the fix, since the in-process conversion functions alone can't prove apiextensions-apiserver's restoreObjectMeta actually carries a webhook-set annotation through a real round trip.

Also included (minor doc/diagnostic gaps found along the way):

  • e2e diagnostic dump now queries the v1beta1 hub explicitly instead of the ambiguous unqualified queuemanagerconnection, which silently resolved to the lossy v1alpha1 view and made the prior diagnostic inconclusive.
  • Corrected stale comments in conversion_auth.go / cacheconfig/secret.go that claimed dropping the union on down-conversion loses "nothing at rest" (true for reads, false once a spoke write round-trips it).
  • Added the missing docs/ARCHITECTURE.md note on Secret/QMC-hub cache bypass (DisableFor), closing a deferred doc gap referenced in internal/cacheconfig/secret.go.

Test plan

  • go test ./api/v1alpha1/... -run QueueManagerConnection — unit round-trip tests pass
  • go test ./test/conversionwebhook/... (real envtest API server + conversion webhook) — new regression test passes with the fix, fails without it (verified both ways)
  • go test -race ./internal/... ./api/... ./test/... (with KUBEBUILDER_ASSETS via setup-envtest) — full suite green
  • task lint, task verify, task scrub — all clean
  • Full E2E GitHub Actions workflow (kind + IBM MQ) — not runnable locally in this environment; should be confirmed green on this PR's CI run

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
api/v1alpha1/conversion_auth.go 73.33% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@konih
konih marked this pull request as ready for review July 29, 2026 20:06
@konih

konih commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

REVIEW — MKurator/PR#168 (worktree-fix-qmc-auth-conversion-roundtrip) @ af498d2 — REQUEST CHANGES — 2026-07-29

Verdict: REQUEST CHANGES

Orient: Fixes the AUTH-14 post-merge E2E regression by root-causing it to QueueManagerConnection.ConvertTo unconditionally nil-ing spec.authentication whenever a v1alpha1-typed write (e.g. the reconciler's finalizer-add Update, which never touches .spec) round-trips through the conversion webhook. Fix stashes the hub's auth union as JSON on a well-known annotation during down-conversion and restores/strips it on up-conversion.

Gate Result Notes
go build ./... ✅ clean
task verify ✅ generated artifacts fresh, no diff after regen
task lint (+arch-lint) ✅ 0 issues, arch-lint OK
task test:run (race) ✅ all packages pass, incl. new test/conversionwebhook real-envtest regression case
coverage floor ✅ internal/ 92.7% (≥90%), api/ 76.4% (≥75%)
task scrub / task scrub:tree ✅ clean
task changelog ✅ commit follows Conventional Commits, renders correctly (CHANGELOG.md is generated, not hand-edited — N/A to touch)
codecov/patch ⚠️ advisory 73% patch on conversion_auth.go; matches the untested malformed-JSON branches below
ID Sev Area Finding Evidence Blocks?
F1 P1 TDD/Correctness The json.Unmarshal error branch in ConvertTo (malformed/tampered authentication-union-snapshot annotation) is completely untested — 0% coverage, matches codecov's flagged lines. Reachable: any v1alpha1-typed writer (kubectl edit, GitOps re-apply, SSA) that echoes back a corrupted value for this well-known annotation makes that write attempt fail with an opaque "restore authentication union snapshot: ..." error instead of a clear, validated message. (Self-heals on the next reconcile's fresh Get since ConvertTo never commits on error, but the failure mode itself is undocumented and unverified — "zero-coverage new production code" per review floor.) api/v1alpha1/conversion_auth.go:177-184; no case in conversion_auth_union_test.go or test/conversionwebhook/suite_test.go exercises it Yes
F2 P1 Docs/Governance ADR-0027 explicitly evaluated and rejected "Preserve via conversion annotations on the v1alpha1 spoke — fragile" as an alternative to the union's storage-sequencing decision, and GOVERNANCE.md requires an ADR write/update + maintainer LGTM for changes to "reconciliation... security posture" architecture. This PR implements exactly the previously-rejected annotation mechanism (as a transient scratch value rather than permanent storage, which changes the risk profile but not the underlying fragility class) without touching ADR-0027 or recording why the earlier rejection no longer applies. Future readers of ADR-0027 will be misled about what's actually in production. docs/adr/0027-mqweb-authentication-modes.md:97 ("Preserve via conversion annotations... fragile; rejected"); GOVERNANCE.md:36; PR touches no ADR file Yes
F3 P2 Architecture (non-blocking) The deeper fix — migrating QueueManagerConnectionReconciler off the v1alpha1 spoke onto the v1beta1 hub type directly — would eliminate this whole class of spoke-round-trip data loss at the source rather than patching the symptom per hub-only field. Worth a follow-up ticket/ADR note even if this PR's stopgap ships first. internal/controller/queuemanagerconnection_controller.go:49 (conn := &messagingv1alpha1.QueueManagerConnection{}) No

Adversarial check performed: Verified copyObjectMeta uses DeepCopyInto (no annotation-map aliasing between src/dst). Verified optimistic-concurrency safety claim holds (reconciler's Update reuses the same object from its own Get, carrying resourceVersion). Verified the malformed-annotation scenario cannot durably corrupt stored state (ConvertTo fails atomically pre-commit; ConvertFrom always regenerates or deletes the key from fresh state) — narrowed F1 from an initially-suspected "permanently stuck Terminating object" to the lesser-but-still-real "untested opaque failure on one write attempt," which is what's reported above. No credential material (only secretRef names) transits the annotation, consistent with the secretRef-only contract in docs/development/guidelines.md §"TLS and credentials" — kubectl describe/audit-log exposure of this annotation reveals nothing beyond what's already visible on the v1beta1 hub's own spec.

Functional correctness: Root cause is correctly diagnosed and the regression test (test/conversionwebhook/suite_test.go, real envtest API server + conversion webhook) is a genuine behaviour test — it fails on the prior code and passes with the fix, exactly reproducing the finalizer-only-Update round trip. The unit-level test is likewise a real regression test, not tautological.

Coverage delta: api/ package floor still met overall (76.4%), but the new error-handling branch in the touched file is at 0% — see F1.

Summary / next steps: Solid root-cause diagnosis and a real regression test after four misdiagnosed timeout-widening PRs. Before merge: (1) add a test for the malformed-annotation ConvertTo error path, and consider whether it should fail-closed (current) or fail-open/log-and-drop given it can only affect an already-privileged writer; (2) update ADR-0027 to record that the previously-rejected annotation mechanism is now in use, scoped to transient round-trip carry-through, and why that's an acceptable narrowing of the original "fragile" concern — this is a governance-doc requirement per GOVERNANCE.md, not optional polish.

…rip (AUTH-14)

The AUTH-14 post-merge e2e regression was not a race or a timing issue (the
5m->8m timeout widenings never helped): QueueManagerConnection.ConvertTo
unconditionally nils spec.authentication when up-converting the v1alpha1
spoke to the v1beta1 hub. The reconciler always works through the v1alpha1
type, and its very first reconcile of any new object adds a finalizer via a
full v1alpha1 Update - a metadata-only change that still round-trips the
whole object down (ConvertFrom) then back up (ConvertTo) through the spoke.
For a union-auth QMC that has no v1alpha1 representation at all, that round
trip permanently wiped spec.authentication in etcd moments after creation,
so mqrest's cacheFingerprint failed with "resource name may not be empty"
on every reconcile for the rest of the test's 8-minute window.

Fix: stash the hub's authentication union as JSON on an annotation during
down-conversion (ConvertFrom) and restore it during up-conversion (ConvertTo)
if present, stripping the annotation so it never leaks into storage. A true
v1alpha1-origin write has no snapshot and is unaffected. This is safe against
concurrent v1beta1 writers because the spoke and hub share one storage object
and resourceVersion, so a stale spoke write is rejected as a conflict rather
than silently clobbering a newer union.

Verified both at the unit level (api/v1alpha1) and end-to-end against a real
envtest API server + conversion webhook (test/conversionwebhook), confirming
the new test fails on the prior code and passes with the fix - the in-process
conversion functions alone can't prove apiextensions-apiserver's
restoreObjectMeta actually carries a webhook-set annotation through.

Also: point the e2e diagnostic dump at the v1beta1 hub explicitly instead of
the unqualified "queuemanagerconnection" (which silently resolves to the
lossy v1alpha1 view and made the prior diagnostic inconclusive), and correct
now-stale comments that claimed dropping the union on down-conversion loses
"nothing at rest."
@konih
konih force-pushed the worktree-fix-qmc-auth-conversion-roundtrip branch from af498d2 to 6842f10 Compare July 29, 2026 20:41
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant