Skip to content

Replay WRT allowed-kinds validation at reconcile time - #708

Draft
eniko-dif wants to merge 2 commits into
temporalio:mainfrom
eniko-dif:eniko.dif/lift-wrt-freeze-path-b-no-webhooks-693232c4
Draft

eniko-dif wants to merge 2 commits into
temporalio:mainfrom
eniko-dif:eniko.dif/lift-wrt-freeze-path-b-no-webhooks-693232c4

Conversation

@eniko-dif

@eniko-dif eniko-dif commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Why

When the validating admission webhook is not served (e.g. deployments that embed the controller via the public controller.New and don't run webhooks), WorkerResourceTemplate specs are server-side-applied with controller identity and no validation of their own. The allowed-kinds allow-list was admission-time only. This closes that gap by enforcing the allow-list at reconcile time.

What

  • Replay the admission webhook's allowed-kinds validation (validateWorkerResourceTemplateSpec) in the WRT apply path: RenderWorkerResourceTemplate runs ValidateWorkerResourceTemplateSpecForApply before rendering, so an out-of-allow-list spec is rejected before any object is applied, surfaced the same way other render/apply errors surface (RenderError → ApplyError).
  • Fail-closed semantics preserved: an empty allow-list (ALLOWED_KINDS unset) rejects every kind, matching the webhook's deny-all default.
  • ConfigFromEnv() now populates AllowedKinds from ALLOWED_KINDS, so programs embedding the controller via controller.New without WithAllowedKinds inherit the environment default; WithAllowedKinds remains the explicit override.
  • The webhook itself is unchanged and stays authoritative for direct-tenant deployments.
  • Known, documented gap: HPAMatchLabelsStripTemporalPrefix is not replayed (validation runs as if false); harmless because auto-injection overwrites those keys at render time — noted in the ValidateWorkerResourceTemplateSpecForApply doc comment.

Tests

  • TestRenderWorkerResourceTemplate_RejectsKindOutsideAllowList, TestGetWorkerResourceApplies_AllowedKindsRejection, and the new TestConfigFromEnvAllowedKinds (table-driven, t.Setenv) cover the replay, the planner rejection path, and the env default. Verified they fail when the replay check or the ConfigFromEnv default is removed.
  • SSA apply-failure coverage kept: integration helpers set ALLOWED_KINDS so the wrt-apply-failure case still reaches a real SSA failure.

Deployments without the admission webhook let out-of-allow-list
WorkerResourceTemplate specs onto the cluster, where the controller
would happily apply them. Replay the webhook's pure spec validation
(the same allowed-kinds + structural checks ValidateCreate runs) in the
WRT render path, so a rejected spec fails before any object is applied
and surfaces as an applyError exactly like a render failure.

- Export ValidateWorkerResourceTemplateSpecForApply and a shared
  AllowedKindsFromEnv helper in api/v1alpha1; the webhook and the
  reconciler now parse ALLOWED_KINDS through one code path.
- RenderWorkerResourceTemplate takes the allow list and validates the
  spec first; an empty list denies all kinds, mirroring the webhook's
  fail-closed semantics.
- Plumb the list through planner.Config, getWorkerResourceApplies,
  WorkerDeploymentReconciler, and cmd/main.go.
- envtest sets ALLOWED_KINDS in setupTestEnvironment and covers the
  rejection with a new wrt-rejected-kind case.
…w-list enforcement

The wrt-apply-failure envtest case regressed into testing the new
validation path: FakeResource was not in the test ALLOWED_KINDS set, so
the WRT was rejected at reconcile time and the real SSA apply-failure
branch in execplan.go lost its only test. Add FakeResource to the test
allow list and restore the original case comment; the validation path
stays covered by wrt-rejected-kind (Deployment).

Also: gofmt reconciler_events_test.go; move testAllowedKinds above
createTestWRT's doc comment and reuse createTestWRT in the
AllowedKindsRejection planner test; and note in
docs/worker-resource-templates.md and the Helm manager.yaml comment
that the controller enforces the allowed-kinds list at reconcile time,
not only the webhook.
@eniko-dif
eniko-dif force-pushed the eniko.dif/lift-wrt-freeze-path-b-no-webhooks-693232c4 branch from 494e62b to d340465 Compare November 27, 2026 10:16
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