← worklog

2026-11-20

Production hotfix: Kyverno upgrade silently broke ECR image routing

KubernetesKyvernoGitOpsFluxCDIncident Response

Context

All EKS clusters route image pulls through an ECR pull-through cache via Kyverno mutation policies that rewrite Pod image references on admission. The policies use foreach to iterate containers and init containers and apply regex-based registry substitution. This had been working without issue for months.

What broke

After upgrading Kyverno to 3.9.0, the mutation policies stopped rewriting images. Pods were created successfully — Kyverno admitted them without errors — but the images came from upstream registries rather than ECR. For clusters in a restricted network zone, this meant pod startup failures.

The root cause: Kyverno 3.x removed support for patchStrategicMerge inside foreach mutation rules. The old policies used this form:

foreach:
  - list: request.object.spec.containers
    patchStrategicMerge:
      spec:
        containers:
          - name: "{{ element.name }}"
            image: "{{ ... }}"

In Kyverno 3.x, foreach only accepts patchesJson6902. Because patchStrategicMerge was silently ignored rather than rejected, the admission webhook returned a success response with the original (unmodified) image references. No policy violation, no error — just the wrong behaviour.

Fix

Rewrote both policies (ecr-pull-through-cache and the EMEA Harbor variant) to use patchesJson6902 with an explicit replace operation and index-based path:

foreach:
  - list: request.object.spec.containers
    patchesJson6902: |-
      - op: replace
        path: /spec/containers/{{elementIndex}}/image
        value: >-
          {{ regex_replace_all(...) }}

Applied as a hotfix directly on a branch from the last production tag (v1.1.0), tagged v1.1.1, and pushed — integration and production clusters picked it up immediately via the semver tag. The fix was then merged back to main.

Why this was silent

Kyverno's foreach block accepts multiple patch strategies, and the admission webhook returns success as long as the policy spec is structurally valid — it doesn't validate that the patch strategy is supported for the given context. patchStrategicMerge is valid in direct mutate rules, so Kyverno accepted the YAML without complaint and simply skipped the unrecognised strategy in foreach.

The gap: policy tests covered the regex logic but ran against a matching Kyverno version. The upgrade test gap was no Kyverno version matrix in CI. Added a note to the upgrade runbook to verify mutation policies after any Kyverno minor version bump.