fix: reconcile webhook token rotation for group and project Hook - #375
Merged
Conversation
GitLab never returns the webhook secret, so IsHookUpToDate cannot compare it and Update only ran when some other field drifted. Rotating only the referenced secret was therefore never propagated to GitLab. Detect rotation on the desired side: store a SHA-256 digest of the token last pushed in status.atProvider.tokenHash (never the raw token). Observe resolves the secret (only when every other field already matches) and compares its hash to the stored one; a mismatch drives Update, which re-pushes the token and rewrites the digest. The hash is written in Update (crossplane-runtime reverts status changes made during Create), so a freshly created hook with a token self-corrects via a single Update. Also for the project Hook: - enforce projectId immutability with a CEL XValidation rule, matching the group Hook. - remove the dead errHookNotFound/IsErrorHookNotFound string matcher (GitLab returns "404 Not Found"; not-found is handled by clients.IsResponseNotFound on the response status). Fixes #374 Signed-off-by: Markus Siebert <markus.siebert@deutschebahn.com>
Delete used cr.Status.AtProvider.ID for the hook id while Observe and Update derive it from the external-name. If the resource was deleted before a successful Observe ever populated atProvider.ID (created then deleted quickly, or status lost/restored while the external-name annotation survives), atProvider.ID is 0 and Delete would call DeleteHook(..., 0), failing to remove the real webhook and orphaning it. Parse the hook id from the external-name in Delete, matching Observe/Update. Applies to both the group and project Hook. Addresses review feedback on #372. Signed-off-by: Markus Siebert <markus.siebert@deutschebahn.com>
dariozachow
approved these changes
Jul 3, 2026
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of your changes
Fixes #374. Reconciles webhook token rotation for both the group
Hookand the projectHook, plus two related project-Hookconsistency fixes.Token rotation (group + project)
GitLab never returns the webhook secret, so
IsHookUpToDatecan't compare it andUpdateonly ran when some other field drifted. Rotating only the referenced secret was therefore never propagated.The change detects rotation on the desired side:
status.atProvider.tokenHashholds a SHA-256 digest of the token last pushed (never the raw token), via a sharedclients.TokenHashhelper.Observeresolves the secret — only when every other field already matches — and compares its hash to the stored one; a mismatch drivesUpdate.Updatere-pushes the token and rewrites the digest.Update(crossplane-runtime reverts status changes made duringCreate), so a freshly created hook with a token self-corrects via a singleUpdate.Project
Hookconsistency (mirroring the groupHook)projectIdimmutability with a CELXValidationrule.errHookNotFound/IsErrorHookNotFoundmatcher (GitLab returns"404 Not Found"; not-found is already handled byclients.IsResponseNotFoundon the response status).How has this code been tested
go build ./...,go vet ./...,go test ./...all pass; new unit tests cover the token-rotation path (TokenRotated) and hash persistence for both hooks (namespaced + generated cluster variants).Live e2e on a self-managed GitLab 18.11.5-ee group (provider out-of-cluster against a kwok control plane): created a group hook with a token, then rotated only the referenced secret. The reconciler detected the change and issued an
Update—status.atProvider.tokenHashmoved fromsha256(v1)tosha256(v2)— confirming the previously-broken path now works. All sandbox resources were cleaned up afterward.Delete by external-name (group + project)
Deleteusedstatus.atProvider.IDfor the hook id whileObserve/Updatederive it from the external-name. If the resource was deleted before a successfulObservepopulatedatProvider.ID, that id is0andDeletewould callDeleteHook(..., 0), orphaning the real webhook.Deletenow parses the hook id from the external-name, matchingObserve/Update.