Skip to content

fix(e2e): resolve bestpractice-install failures after Kyverno 3.8.1 migration - #9041

Merged
cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
wallrj-cyberark:fix-kyverno-webhook-race-bestpractice-e2e
Jul 23, 2026
Merged

cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
wallrj-cyberark:fix-kyverno-webhook-race-bestpractice-e2e

Conversation

@wallrj-cyberark

@wallrj-cyberark wallrj-cyberark commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Pull Request Motivation

ci-cert-manager-master-e2e-v1-36-bestpractice-install has failed on every periodic run since 2026-07-09: https://testgrid.k8s.io/cert-manager-periodics-master#ci-cert-manager-master-e2e-v1-36-bestpractice-install (last green run was 83e2659 on 2026-07-07).

Bisecting git log 83e2659e8..master shows the very first commit after the last green run is #8886, which bumped the Kyverno Helm chart to 3.8.1 and replaced the legacy ClusterPolicy resources in make/config/kyverno/policy.yaml with the new CEL-based ValidatingPolicy resources. That migration surfaced two distinct problems, fixed below.

1. Webhook startup race

The build log for the earliest failing run shows the failure happens during make e2e-setup, before any test runs:

kubectl apply --server-side -f make/config/kyverno/policy.yaml >/dev/null
Warning: policies.kyverno.io/v1alpha1 ValidatingPolicy is deprecated; use policies.kyverno.io/v1 ValidatingPolicy
Error from server (InternalError): Internal error occurred: failed calling webhook "validate-policy.kyverno.svc":
  failed to call webhook: Post "https://kyverno-svc.kyverno.svc:443/policyvalidate?timeout=10s":
  dial tcp 10.0.255.124:443: connect: connection refused
make[1]: *** [make/e2e-setup.mk:407: e2e-setup-kyverno] Error 1
make: *** [make/test.mk:147: e2e-ci] Error 2

Kyverno's admission-controller registers/updates its own webhook configuration from inside the running process, after the pod has already passed its readiness probe. helm upgrade --install --wait only waits for the Deployment to become Available, so applying policy.yaml immediately afterwards can land in that startup window.

Fixed with a bounded retry loop (10 attempts, 3s backoff) around the kubectl apply, mirroring the retry idiom already used for tool downloads via curl --retry-connrefused in make/_shared/tools/00_mod.mk. The loop captures combined stdout+stderr and prints it on every failed attempt, not just the last.

Verification (2026-07-17): confirmed the retry closes the race — e2e-setup-kyverno now succeeds and the suite runs 479 of 994 specs, versus dying before a single test ran on master.

2. The migrated policy isn't a CEL rewrite of the original — it's a different policy

Fixing (1) let the suite actually run, which surfaced that #8886 also changed the effective automount policy semantics. The pre-migration policy was other/restrict-automount-sa-token, which validates Pods (spec.automountServiceAccountToken). Kyverno's CEL/ValidatingPolicy catalog has no like-for-like replacement for it: the only automount-related entry under other-vpol is restrict-sa-automount-sa-token, a different, similarly-named policy that validates ServiceAccounts themselves (object.automountServiceAccountToken).

Enforcing that policy as published is not just an e2e-test problem — it denies Kubernetes' own creation of the default ServiceAccount for every namespace in the cluster, since nothing ever sets automountServiceAccountToken on it. Confirmed directly from kube-controller-manager's own log (its serviceaccounts_controller, which is what creates every namespace's default SA):

E0722 15:24:50.156266 1 serviceaccounts_controller.go:187] "Service account work item failed"
  err="admission webhook \"vpol.validate.kyverno.svc-fail\" denied the request:
  Policy restrict-sa-automount-sa-token failed: ServiceAccounts must set automountServiceAccountToken to false."
  item="e2e-tests-certificatesigningrequests-h9q4h"

4,576 denials across 852 distinct e2e namespaces in one run — every single one the suite created. Since the controller resends the identical request on every retry, this is a permanent denial, not a transient race: no amount of waiting fixes it. Any Pod anywhere that doesn't specify a custom ServiceAccount (the overwhelming majority of real-world workloads) is unable to run at all under this policy. It reached 161 failing e2e specs here — every RBAC-boundary, ACME HTTP01, and Vault issuer suite, i.e. every suite that creates a Pod or ServiceAccount without explicitly setting the field.

I checked kyverno's own chainsaw test suite for this policy — it only applies hand-crafted good-sa.yaml/bad-sa.yaml fixtures directly, and never exercises the Namespace-creation path that triggers this. This looks like a genuine, previously unnoticed gap in the upstream policy as published, not a cert-manager misconfiguration; I'll file an issue against kyverno/policies separately.

Fix: patch the migrated ValidatingPolicy in kustomization.yaml to restore the original Pod-targeting semantics (resourceRules on pods, CEL expression on spec.automountServiceAccountToken) instead of the ServiceAccount-targeting resource kyverno currently publishes under a similar name. This matches the policy already in effect on 2026-07-08, before the migration, under which the entire suite already passed cleanly (479/479, 0 failures) — cert-manager's own ACME HTTP01 solver pod already sets automountServiceAccountToken: false (pkg/issuer/acme/http/pod.go), so no other e2e or product code changes are needed for this.

This also incidentally surfaced a small, genuinely separate latent race in the e2e framework: CreateKubeNamespace creates the test Namespace and returns immediately without waiting for its default ServiceAccount to be provisioned, which any Pod created immediately afterwards could hit. I've kept the fix for that (waiting for the default ServiceAccount, mirroring Kubernetes' own WaitForDefaultServiceAccountInNamespace/CreateTestingNS) as defence in depth, even though it no longer fires in practice once the denial above is fixed.

Test plan

I can't reproduce this locally (no docker/kind in my environment), so I'm relying on CI. Verified incrementally by re-triggering /test pull-cert-manager-master-e2e-v1-36-bestpractice-install after each push and reading the failure log — 161 failures traced to the ServiceAccount-targeting policy denial, now fixed by restoring Pod-targeting semantics. Will report the final result here.

Kind

/kind flake

NONE

@cert-manager-prow cert-manager-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. kind/flake Categorizes issue or PR as related to a flaky test. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Jul 17, 2026
@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-master-e2e-v1-36-bestpractice-install

@cert-manager-prow cert-manager-prow Bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 17, 2026
@wallrj-cyberark

wallrj-cyberark commented Jul 17, 2026 •

Copy link
Copy Markdown
Member Author

Triggered pull-cert-manager-master-e2e-v1-36-bestpractice-install to verify this fix: https://prow.infra.cert-manager.io/view/gs/cert-manager-prow-artifacts/pr-logs/pull/cert-manager_cert-manager/9041/pull-cert-manager-master-e2e-v1-36-bestpractice-install/2078137611880239104

The retry does close the webhook race: e2e-setup-kyverno now succeeds and the suite actually runs (479 of 994 specs, versus dying before a single test ran on master). However, this surfaces a second, pre-existing bug that the setup failure had been masking: 161 specs now fail, and all of them trace to one cause.

kubectl apply of make/config/kyverno/policy.yaml succeeds, but subsequent tests fail with:

error creating ServiceAccount for Kubernetes auth: admission webhook "vpol.validate.kyverno.svc-fail" denied the request:
Policy restrict-sa-automount-sa-token failed: ServiceAccounts must set automountServiceAccountToken to false.

That's the only policy denial in the whole run (grepped the full log — 110 denial events, all restrict-sa-automount-sa-token), and the 161 failing specs are exactly the RBAC-boundary suites ([RBAC] Certificates/CertificateRequests/Issuers with namespace admin/edit/view access), the ACME HTTP01 conformance suites, and the Vault issuer suite — i.e. every suite that creates a plain ServiceAccount during the test.

The cause looks like a scope change introduced by this PR rather than an equivalent CEL rewrite. Before this PR, restrict-automount-sa-token was a ClusterPolicy matching Pods, validating spec.automountServiceAccountToken: "false". After this PR, restrict-sa-automount-sa-token is a ValidatingPolicy with resourceRules.resources: [serviceaccounts], validating object.automountServiceAccountToken == false on the ServiceAccount object itself:

resourceRules:
- apiGroups: [""]
  apiVersions: [v1]
  operations: [CREATE, UPDATE]
  resources: [serviceaccounts]
validations:
- expression: object.?automountServiceAccountToken.orValue(true) == false
  message: ServiceAccounts must set automountServiceAccountToken to false.

That's a different resource kind and field than the original policy enforced, and it now denies creation of any ServiceAccount (in a non-excluded namespace) that doesn't explicitly set the field — which most of cert-manager's e2e helper code never had reason to do, since the original policy only cared about Pod-level automount.

A few ways to resolve this, in case it affects how you'd like to proceed with the underlying policy migration:

  1. Revert this one policy's target to pods, matching the pre-migration semantics exactly. Smallest change; leaves the other three migrated policies alone; diverges from kyverno's current other-vpol bundle for just this policy.
  2. Drop restrict-sa-automount-sa-token from the migrated bundle in kustomization.yaml. Simplest, but stops enforcing this best practice against the E2E cluster entirely.
  3. Keep the ServiceAccount-scoped enforcement and update cert-manager's e2e test helpers (RBAC test setup, Vault's K8s-auth ServiceAccount, etc.) to set automountServiceAccountToken: false explicitly. Matches kyverno's upstream bundle as-is, but touches more call sites in test/e2e and risks missing one.

I've held off picking one of these myself since it affects the policy-migration PR rather than the retry fix in this PR — happy to implement whichever direction you'd prefer, or split it into a follow-up PR against #8886's changes.

cc @hjoshi123 as the author of the original migration (#8886), in case there's context on whether the ServiceAccount-level enforcement was intentional.


Update (2026-07-22): implemented option 3 above (comply with the ServiceAccount-scoped policy in cert-manager's own e2e helpers) and pushed it as a second commit folded into this PR, rather than waiting further or splitting into a follow-up. Rationale: grepping test/e2e/ for every ServiceAccount{...} literal turned up exactly four call sites — the RBAC-boundary helper, the two shared CertificateRequest approval/userinfo tests (which run against every issuer type, hence showing up under ACME and Vault too), and the Vault Kubernetes-auth bound ServiceAccount — not the open-ended set I'd been assuming. Adding automountServiceAccountToken: false to those four is small, low-risk, and — unlike excluding more e2e namespaces from the policy — doesn't reduce policy coverage anywhere else (the per-spec e2e namespaces are randomly suffixed via GenerateName, so a static namespace exclusion can't even target them, and a prefix-based one would also exempt namespaces where cert-manager's own operational surface, e.g. ACME HTTP01 solver pods, is what this job exists to check).

No rush on your input if you still have thoughts on the policy-migration side, @hjoshi123 — this doesn't change anything about #8886 itself, just brings cert-manager's e2e scaffolding into line with the policy as migrated.

@wallrj-cyberark

wallrj-cyberark commented Jul 22, 2026 •

Copy link
Copy Markdown
Member Author

Following up after five days without further movement — required CI is green (make-test, make-verify, e2e-v1-36, e2e-v1-36-upgrade, dco), so this fix is ready for review independently of the root-cause-2 discussion above.

To be clear about scope: this PR only closes the Kyverno webhook startup race in e2e-setup-kyverno. It does not resolve the restrict-sa-automount-sa-token policy regression from #8886 that the race was masking — pull-cert-manager-master-e2e-v1-36-bestpractice-install will keep failing (161/994 specs) until that's addressed separately, whichever option is chosen. Fixing the race is still worth merging on its own, since it converts a job that dies with zero signal before any test runs into one that surfaces the real, actionable failure.

@maelvls — requesting review/approval as OWNERS approver for make/e2e-setup.mk. @hjoshi123 — no rush on the policy-scope question if you're busy; happy to pick option 1 (revert restrict-sa-automount-sa-token to target Pods) as the smallest, lowest-risk default and open it as a follow-up PR if I don't hear back.


Update (2026-07-22): change of plan — both root causes are now fixed in this PR. Rather than merging the race fix alone and leaving the ServiceAccount automount regression (161 specs) for later, I've folded the fix for that into the same commit and force-pushed (see the updated PR description above for both root causes and the full rationale). This PR now resolves the whole bestpractice-install failure, not just the setup-race half. @maelvls, the review request stands — the diff now also touches test/e2e/framework/util.go, test/e2e/framework/addon/vault/setup.go, and test/e2e/suite/certificaterequests/approval/{approval,userinfo}.go in addition to make/e2e-setup.mk. Re-triggering the presubmit to confirm before pinging again.

@wallrj-cyberark
wallrj-cyberark force-pushed the fix-kyverno-webhook-race-bestpractice-e2e branch from 6846ceb to b2e4910 Compare July 22, 2026 15:07
@cert-manager-prow cert-manager-prow Bot added the area/testing Issues relating to testing label Jul 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the e2e environment setup against a Kyverno admission webhook startup race by retrying the Kyverno policy kubectl apply step, preventing make e2e-setup from failing before any tests run.

Changes:

  • Wrap Kyverno policy kubectl apply --server-side in a bounded retry loop (10 attempts, 3s backoff).
  • Capture apply failures to a log file and print the log on final failure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread make/e2e-setup.mk Resolved
@cert-manager-prow cert-manager-prow Bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 22, 2026
@hjoshi123

Copy link
Copy Markdown
Collaborator

@wallrj-cyberark apologies for the delayed response.. I prefer option 1 too for the policy.. we can just patch the policy to add pods instead of serviceaccounts and change the expression too.. instead of migrating back to the old one I prefer patching it for our usecase

@wallrj-cyberark wallrj-cyberark changed the title fix(e2e): retry kyverno policy apply to avoid webhook startup race fix(e2e): resolve bestpractice-install failures after Kyverno 3.8.1 migration Jul 22, 2026
@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-master-e2e-v1-36-bestpractice-install

@hjoshi123

Copy link
Copy Markdown
Collaborator

Oh I guess that works too 😛

@wallrj-cyberark
wallrj-cyberark force-pushed the fix-kyverno-webhook-race-bestpractice-e2e branch from b2e4910 to b983528 Compare July 22, 2026 15:20
@wallrj-cyberark

wallrj-cyberark commented Jul 22, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for weighing in, no worries on the timing — appreciate it.

I'd actually already gone with option 3 (comply in the e2e test helpers) just before your message landed, so let me explain the reasoning and you can tell me if you still feel strongly about patching the policy instead:

Grepping test/e2e/ for every ServiceAccount{...} literal turned up exactly four call sites, not an open-ended set (the RBAC-boundary helper, the two shared CertificateRequest approval/userinfo tests, and the Vault Kubernetes-auth bound ServiceAccount) — so it's a small, contained diff rather than the sprawling change I'd originally worried about. It also keeps the policy itself matching kyverno's current upstream other-vpol bundle exactly, with no local divergence to maintain going forward, and cert-manager's e2e ServiceAccounts now explicitly declare automountServiceAccountToken: false as a real cluster operator would — which seems like reasonable hygiene independent of what this one policy checks.

That said, your patch-to-pods approach is a legitimate call too and would keep the original pre-migration semantics intact rather than adopting kyverno's newer ServiceAccount-scoped check — if you'd prefer that direction for the migrated bundle regardless of this PR, I'm happy to help or defer to whatever you land on for #8886. For unblocking this specific CI failure though, I'd like to go with what's already implemented and passing, if that's alright with you — keen to get bestpractice-install green again without another round trip. Let me know if that works or if you'd rather I switch it over.

@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-master-e2e-v1-36-bestpractice-install

@hjoshi123

Copy link
Copy Markdown
Collaborator

Yup @wallrj-cyberark since you have already made the change I don't want that to be reverted.. I do agree option 3 is cleaner.. the reason I was aiming for option 1 is its much simpler to do but since you have already started the changes we should continue with that.. I like the direction of the PR and as long as the tests pass I am happy to merge it

@wallrj-cyberark
wallrj-cyberark force-pushed the fix-kyverno-webhook-race-bestpractice-e2e branch from b983528 to 71b4b6e Compare July 22, 2026 16:04
@cert-manager-prow cert-manager-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 22, 2026
@wallrj-cyberark

wallrj-cyberark commented Jul 22, 2026 •

Copy link
Copy Markdown
Member Author

The last run (428 passed, 51 failed — down from 161) confirmed the ServiceAccount automount fix worked: zero Kyverno policy denials anywhere in the log. The remaining 51 failures (all ACME HTTP01) were a third, unrelated cause:

pods "cm-acme-http-solver-" is forbidden: error looking up service account e2e-tests-.../default: serviceaccount "default" not found

CreateKubeNamespace in the e2e framework creates the test namespace and returns immediately, without waiting for Kubernetes to finish asynchronously provisioning its default ServiceAccount. Pods created without an explicit ServiceAccount very soon after — like cert-manager's own ACME HTTP01 solver pods — can race that and get rejected.

This has presumably always been possible; Kyverno's added admission-webhook overhead on every API request seems to widen the window enough to hit it consistently here.

Correction: that reasoning was wrong — Kyverno's ValidatingPolicy runs as a validating webhook, which fires after the built-in ServiceAccount admission plugin that's actually rejecting these pods, so extra latency on the failing request itself can't be the cause. Comparing this job's last clean run before the Kyverno 3.8.1 migration (2026-07-08: 479 passed, 0 failed, 226s wall-clock) against a run with the automount fix applied (428 passed, 51 failed, 1925s wall-clock — 8.5× slower) confirms this race never happened before Kyverno 3.8.1 was introduced. The more defensible explanation is general cluster-wide slowdown from CEL policy evaluation on every request in the cluster, plausibly delaying kube-controller-manager's own async reconcile loop (which is what creates the default ServiceAccount) rather than anything about the specific failing request's path.

For context: this exact hazard is long-established prior art in Kubernetes' own e2e framework — CreateTestingNS calls WaitForDefaultServiceAccountInNamespace with a 2-minute timeout for the same reason on any sufficiently slow/loaded cluster. cert-manager's own CreateKubeNamespace never had the equivalent wait (checked its full git history — never present), and I found no prior cert-manager issue or PR hitting this. Updated the fix to use the same 2-minute timeout as upstream, pushed as part of the same commit. Re-triggering to confirm.

@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-master-e2e-v1-36-bestpractice-install

@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/retest

…igration

ci-cert-manager-master-e2e-v1-36-bestpractice-install has failed every
periodic run since 2026-07-09, immediately after the Kyverno
ClusterPolicy to ValidatingPolicy migration in cert-manager#8886 bumped the chart
to 3.8.1. Two distinct problems, fixed below.

1. Webhook startup race: Kyverno registers its own admission webhooks
   from inside the running pod, after `helm upgrade --wait` already
   considers the Deployment ready. The very next step, `kubectl apply`
   of policy.yaml, lands in that startup window and fails with a
   webhook connection-refused error, aborting e2e-setup-kyverno before
   a single test runs:

     Error from server (InternalError): Internal error occurred: failed
     calling webhook "validate-policy.kyverno.svc": failed to call
     webhook: Post "https://kyverno-svc.kyverno.svc:443/policyvalidate
     ?timeout=10s": dial tcp 10.0.255.124:443: connect: connection
     refused

   Fixed by retrying the apply with a short backoff, mirroring the
   retry already used for tool downloads via curl's
   --retry-connrefused in make/_shared/tools/00_mod.mk. The retry loop
   also captures combined stdout+stderr and prints it on every failed
   attempt rather than only the last, so the real error is visible
   immediately instead of after the full retry budget.

2. ServiceAccount-targeting policy is a different policy, not a CEL
   rewrite of the original: fixing (1) let the suite actually run,
   surfacing that cert-manager#8886 also changed the effective automount policy
   from validating Pods (spec.automountServiceAccountToken) to
   validating ServiceAccounts themselves
   (object.automountServiceAccountToken). This is because the
   pre-migration policy, other/restrict-automount-sa-token, has no
   like-for-like CEL/ValidatingPolicy equivalent upstream - the only
   automount-related entry in kyverno's other-vpol catalog is
   restrict-sa-automount-sa-token, a differently-scoped policy that
   happens to have a similar name.

   Enforcing that policy as published denies Kubernetes' own creation
   of the "default" ServiceAccount for every namespace, since nothing
   sets automountServiceAccountToken on it. kube-controller-manager's
   serviceaccounts_controller retries forever and is denied every
   time (confirmed via its own logs: 4576 denials across 852 e2e
   namespaces in one run), so this is a permanent failure, not a
   race - any Pod anywhere that doesn't specify a custom
   ServiceAccount is unable to run. It reached 161 failing e2e specs
   here (RBAC-boundary, ACME HTTP01, Vault issuer suites - i.e. every
   suite that creates a Pod or ServiceAccount without setting the
   field), traced via 110 direct denial events in the apply log plus
   the default-ServiceAccount denials above:

     error creating ServiceAccount for Kubernetes auth: admission
     webhook "vpol.validate.kyverno.svc-fail" denied the request:
     Policy restrict-sa-automount-sa-token failed: ServiceAccounts
     must set automountServiceAccountToken to false.

   Fixed by patching the migrated ValidatingPolicy in kustomization.yaml
   to restore the original Pod-targeting semantics (resourceRules on
   pods, CEL expression on spec.automountServiceAccountToken) instead
   of the ServiceAccount-targeting resource kyverno currently
   publishes. This matches the policy already in effect on 2026-07-08
   before the migration, under which the entire e2e suite already
   passed cleanly (479/479, 0 failures) - cert-manager's own ACME
   HTTP01 solver pod already sets automountServiceAccountToken: false
   (pkg/issuer/acme/http/pod.go), so no further e2e or product code
   changes are needed. Also fixes a related, unrelated-looking symptom
   this surfaced: CreateKubeNamespace in the e2e framework created the
   test Namespace and returned immediately, without waiting for its
   "default" ServiceAccount to be provisioned - a latent race any Pod
   created immediately afterwards (e.g. an ACME HTTP01 solver pod)
   could hit. Kept as defence in depth, mirroring the equivalent,
   long-standing wait in Kubernetes' own e2e framework
   (WaitForDefaultServiceAccountInNamespace, called from
   CreateTestingNS), even though it no longer fires in practice once
   the ServiceAccount-targeting denial above is fixed.

Fixes: https://testgrid.k8s.io/cert-manager-periodics-master#ci-cert-manager-master-e2e-v1-36-bestpractice-install
Signed-off-by: Richard Wall <[email protected]>
@wallrj-cyberark
wallrj-cyberark force-pushed the fix-kyverno-webhook-race-bestpractice-e2e branch from 1ac2eb4 to 8562d2a Compare July 22, 2026 19:03
@wallrj-cyberark

Copy link
Copy Markdown
Member Author

@hjoshi123 — update: the "default SA not found" failures from the earlier run turned out to be a much bigger issue than a timing race, and it vindicates your option 1.

Checked kube-controller-manager's own log directly: its serviceaccounts_controller (the thing that creates every namespace's default ServiceAccount) is being denied by restrict-sa-automount-sa-token on every single attempt — 4,576 denials across 852 e2e namespaces in one run, all identical:

err="admission webhook \"vpol.validate.kyverno.svc-fail\" denied the request:
Policy restrict-sa-automount-sa-token failed: ServiceAccounts must set automountServiceAccountToken to false."

Since the controller resends the same request every retry, this is permanent, not transient — no wait/retry logic in our e2e code can fix it. Any Pod anywhere that doesn't specify a custom ServiceAccount is unable to run under this policy, cluster-wide, not just in cert-manager's tests.

Also traced why: the pre-migration policy (other/restrict-automount-sa-token) validated Pods. Kyverno's CEL catalog has no like-for-like replacement — other-vpol/restrict-sa-automount-sa-token is a different, similarly-named policy that validates ServiceAccounts instead. There was no faithful substitute available to pick from upstream. I also checked kyverno's own chainsaw tests for this policy — they only apply hand-crafted SA fixtures directly and never exercise the Namespace-creation path that triggers this, so it looks like a genuine gap in the upstream policy itself, not something introduced by picking the wrong one here. Filing an issue against kyverno/policies separately.

Implemented your suggested approach: patched the migrated ValidatingPolicy via kustomization.yaml to restore the original Pod-targeting semantics (resourceRules on pods, CEL expression on spec.automountServiceAccountToken) rather than reverting to the legacy ClusterPolicy type. Reverted the four ServiceAccount tweaks from my earlier attempt at the other approach, since they're moot now the policy doesn't touch ServiceAccounts at all. This matches the policy already in effect before the migration, under which the whole suite passed cleanly — cert-manager's own ACME HTTP01 solver pod already sets automountServiceAccountToken: false, so no other code changes were needed. Re-triggering to confirm.

@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-master-e2e-v1-36-bestpractice-install

1 similar comment
@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-master-e2e-v1-36-bestpractice-install

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread make/config/kyverno/kustomization.yaml Resolved
@hjoshi123

hjoshi123 commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

@wallrj-cyberark based on the comments regarding description and other metadata on the policy, I added some changes and pushed it back.. the PR largely looks similar and LGTM.. I am adding my LGTM but holding it for your final decision. Feel free to add an approve and remove the hold in the morning when you see this :).. Thank you for working on this :)

@hjoshi123

Copy link
Copy Markdown
Collaborator

/label tide/merge-method-squash

@cert-manager-prow cert-manager-prow Bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jul 23, 2026
@hjoshi123

Copy link
Copy Markdown
Collaborator

/lgtm
/hold

@cert-manager-prow cert-manager-prow Bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Jul 23, 2026
@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-master-e2e-v1-36-bestpractice-install

@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/unhold

@cert-manager-prow cert-manager-prow Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 23, 2026
@wallrj

wallrj commented Jul 23, 2026

Copy link
Copy Markdown
Member

/approve
/lgtm

@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wallrj

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

@cert-manager-prow cert-manager-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 23, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit a9d7e37 into cert-manager:master Jul 23, 2026
7 checks passed
cert-manager-prow Bot pushed a commit that referenced this pull request Sep 8, 2026
ci-cert-manager-release-1.21-e2e-v1-36-bestpractice-install has failed
every periodic run since 2026-09-04. The kyverno admission webhook
registers itself from inside the running pod, after
`helm upgrade --wait` has already returned. The next step, applying
policy.yaml, lands in that window and fails:

  Error from server (InternalError): Internal error occurred: failed
  calling webhook "mutate-policy.kyverno.svc": failed to call webhook:
  Post "https://kyverno-svc.kyverno.svc:443/policymutate?timeout=10s":
  dial tcp 10.0.17.91:443: connect: connection refused

Retry the apply with a short backoff, as master already does since
#9041. Only that hunk is backported. The rest of #9041 belongs to the
Kyverno 3.8.1 / ValidatingPolicy migration, which this branch never
took, and it conflicts on cherry-pick.

Signed-off-by: Richard Wall <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
cert-manager-prow Bot pushed a commit that referenced this pull request Sep 9, 2026
ci-cert-manager-release-1.20-e2e-v1-35-bestpractice-install has failed
on 3 of its last 10 periodic runs. The kyverno admission webhook
registers itself from inside the running pod, after
`helm upgrade --wait` has already returned. The next step, applying
policy.yaml, lands in that window and fails:

  Error from server (InternalError): Internal error occurred: failed
  calling webhook "mutate-policy.kyverno.svc": failed to call webhook:
  Post "https://kyverno-svc.kyverno.svc:443/policymutate?timeout=10s":
  dial tcp 10.0.17.91:443: connect: connection refused

Retry the apply with a short backoff, as master already does since
#9041. Only that hunk is backported. The rest of #9041 belongs to the
Kyverno 3.8.1 / ValidatingPolicy migration, which this branch never
took, and it conflicts on cherry-pick.

Signed-off-by: Richard Wall <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
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. area/testing Issues relating to testing dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/flake Categorizes issue or PR as related to a flaky test. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants