---
title: "Kubernetes image pulls with External Secrets and Kyverno"
description: "Replace static imagePullSecrets on EKS, AKS, or GKE. Use OIDC, External Secrets, and Kyverno to pull from five registries through one Cloudsmith cache."
canonical_url: "https://cloudsmith.com/blog/kubernetes-image-pulls-with-external-secrets-and-kyverno"
last_updated: "2028-11-16T13:00:00.000Z"
---
# Kubernetes image pulls with External Secrets and Kyverno

Most clusters pull private images with a static `imagePullSecret`. The token rarely expires, nobody rotates it, and if it leaks it works until someone revokes it.

In [Goodbye imagePullSecrets, Hello Kubernetes Credential Providers](https://cloudsmith.com/blog/goodbye-image-pull-secrets-hello-kubernetes-credential-providers), we showed how the kubelet can exchange a pod's ServiceAccount token for a Cloudsmith token. That approach depends on a beta kubelet feature, and it needs a plugin and kubelet configuration on every node.

This post details another approach that uses [External Secrets Operator](https://external-secrets.io/) and [Kyverno](https://kyverno.io/) and can run on Amazon EKS, Azure AKS, or Google GKE.

## **Benefits of the new approach**

- **No long-lived credentials.** The cluster signs in to Cloudsmith with OpenID Connect (OIDC). External Secrets replaces the credential every 50 minutes.
- **No manifest changes.** Developers keep writing `image: ghcr.io/acme/api:1.4`. Kyverno points it at Cloudsmith at admission.
- **One cache for every registry.** One Cloudsmith repository proxies Docker Hub, GHCR, GCR, Amazon ECR Public, and Microsoft Container Registry (MCR).

## **How it works**

```json
{
  "_key": "2735b9b4f641",
  "_type": "image",
  "alt": "Kubernetes diagram",
  "asset": {
    "_createdAt": "2026-11-19T15:26:11Z",
    "_id": "image-7b4451c9000afae300c84a61c2af54b9fbef59f0-3536x1420-png",
    "_rev": "S703pLG3KfJGL68CVU9voV",
    "_type": "sanity.imageAsset",
    "_updatedAt": "2026-11-19T15:26:11Z",
    "assetId": "7b4451c9000afae300c84a61c2af54b9fbef59f0",
    "extension": "png",
    "metadata": {
      "_type": "sanity.imageMetadata",
      "blurHash": "D7S6Mmxv={eZ-+_MjJsEf}ae",
      "dimensions": {
        "_type": "sanity.imageDimensions",
        "aspectRatio": 2.4901408450704223,
        "height": 1420,
        "width": 3536
      },
      "hasAlpha": true,
      "isOpaque": true,
      "lqip": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAAPoAAAD6AG1e1JrAAABZUlEQVQokU2S2bLiMAxE+f9fHIrLciGEkHiPHW9nyg5MzUNX21JZasl9KBVSrqRYduRKKdDijXOGGFu+klLt99z5C/6hvTm0oLMJOQfUsuFdYQ1gfMVt4H1B6w2lAsZEVpc7nEudvauEFWLYix5iLMyvlfuPZvr1GJmZVeEyJV6qIG3ksRiub8l9VozC8ZSWu9A8hUXKyKorwUFKreBWmAbH7Y9mum6YpfISieMQeCwRYSL3RXMaF06D4DJqzqPiNApuk2JeAlZUvP0o3EJmGiz3VvCyF3zLxHn0PEXE2IyQkecQuP2sXI8rl6Pl97rynjbUnFBT6SrzrjAhRsPzpHh3hQWhc1c367avilMVORZe58RwjDyOgemaMHPFidrZm/ZZcEgpY5VHvhx6Tnhb8aFiQmUNlS3Q97Ma+mitoRUFJyvB7rnG0X9GLqUSUyHG3O3RunS7fG3zsc5ulw++5/8s87XNX6gUa3vi1vVkAAAAAElFTkSuQmCC",
      "palette": {
        "_type": "sanity.imagePalette",
        "darkMuted": {
          "_type": "sanity.imagePaletteSwatch",
          "background": "#343c5c",
          "foreground": "#fff",
          "population": 0.01,
          "title": "#fff"
        },
        "darkVibrant": {
          "_type": "sanity.imagePaletteSwatch",
          "background": "#94b426",
          "foreground": "#000",
          "population": 0.01,
          "title": "#fff"
        },
        "dominant": {
          "_type": "sanity.imagePaletteSwatch",
          "background": "#b7a9c8",
          "foreground": "#000",
          "population": 0.2,
          "title": "#fff"
        },
        "lightMuted": {
          "_type": "sanity.imagePaletteSwatch",
          "background": "#b7a9c8",
          "foreground": "#000",
          "population": 0.2,
          "title": "#fff"
        },
        "lightVibrant": {
          "_type": "sanity.imagePaletteSwatch",
          "background": "#9aede4",
          "foreground": "#000",
          "population": 0.02,
          "title": "#000"
        },
        "muted": {
          "_type": "sanity.imagePaletteSwatch",
          "background": "#5a78ac",
          "foreground": "#fff",
          "population": 0.12,
          "title": "#fff"
        },
        "vibrant": {
          "_type": "sanity.imagePaletteSwatch",
          "background": "#d5d438",
          "foreground": "#000",
          "population": 0.05,
          "title": "#fff"
        }
      },
      "thumbHash": "vQcGC4CWlZl3iPdop3mPL5k="
    },
    "mimeType": "image/png",
    "originalFilename": "Diagram_Kubernetes Image pulls.png",
    "path": "images/rafvlnhi/production/7b4451c9000afae300c84a61c2af54b9fbef59f0-3536x1420.png",
    "sha1hash": "7b4451c9000afae300c84a61c2af54b9fbef59f0",
    "size": 299917,
    "uploadId": "8a108699c15beb776aa40734e942aa8d1ff2f70e",
    "url": "https://cdn.sanity.io/images/rafvlnhi/production/7b4451c9000afae300c84a61c2af54b9fbef59f0-3536x1420.png"
  },
  "link": {
    "_type": "link",
    "href": null,
    "openInNewTab": false
  },
  "markDefs": null
}
```

1. **OIDC token exchange.** External Secrets sends a ServiceAccount JWT, signed by your cluster, to Cloudsmith. Cloudsmith returns a short-lived Cloudsmith JWT.
2. **Pull secret distribution.** External Secrets writes the Cloudsmith JWT into a pull secret. Kyverno copies it into every namespace.
3. **Image rewrite.** Kyverno points each Pod image at Cloudsmith and adds the pull secret.
4. **Pull through the cache.** The kubelet pulls from Cloudsmith, which serves the image from its cache or fetches it from the upstream.

## **Prerequisites**

- An Amazon EKS, Azure AKS, or Google GKE cluster, plus `kubectl` and Helm 3.
- Terraform 1.5 or later.
- A Cloudsmith workspace and an API key that can manage repositories, services, and OIDC providers.

The examples use the workspace `acme-corp` and the repository `kubernetes`. Replace them with your own values. Every file in this post is also in [this gist](https://gist.github.com/cloudsmith-iduffy/35ff66554819858df731874a94727445) for copy and paste.

## **Step 1: Find the OIDC issuer URL of your cluster**

Cloudsmith checks each ServiceAccount JWT against the public keys that your cluster publishes at its OIDC issuer URL. See [Service account issuer discovery](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#service-account-issuer-discovery). Copy the URL exactly, including any trailing slash.

### **Amazon EKS**

Every cluster has an issuer URL. You do not need an IAM OIDC provider. See [Create an IAM OIDC provider for your cluster](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html).

```json
{
  "_key": "bbcab10c2a41",
  "_type": "code",
  "code": "aws eks describe-cluster --name CLUSTER_NAME \\\n  --query \"cluster.identity.oidc.issuer\" --output text",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Azure AKS**

The issuer is on by default for AKS Automatic and for AKS Standard clusters created on Kubernetes 1.34 or later. For other clusters, enable it first. This restarts the API server and cannot be undone. See [Use the OpenID Connect (OIDC) issuer in AKS](https://learn.microsoft.com/en-us/azure/aks/use-oidc-issuer).

```json
{
  "_key": "c872b7b6278a",
  "_type": "code",
  "code": "az aks update --resource-group RESOURCE_GROUP --name CLUSTER_NAME --enable-oidc-issuer\naz aks show --resource-group RESOURCE_GROUP --name CLUSTER_NAME \\\n  --query \"oidcIssuerProfile.issuerUrl\" -o tsv",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Google GKE**

Every cluster has an issuer at `https://container.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/clusters/CLUSTER_NAME`. See the [GKE OpenID configuration reference](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1/projects.locations.clusters.well-known/getOpenid-configuration). This command also works on EKS and AKS:

```json
{
  "_key": "c929c9083241",
  "_type": "code",
  "code": "kubectl get --raw /.well-known/openid-configuration | jq -r .issuer",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

## **Step 2: Configure Cloudsmith with Terraform**

Put the blocks below, in order, into `main.tf`. You can reference the complete, collated file [here](https://gist.github.com/cloudsmith-iduffy/35ff66554819858df731874a94727445#file-main-tf). The [Cloudsmith Terraform provider](https://registry.terraform.io/providers/cloudsmith-io/cloudsmith/latest) reads your API key from the environment.

```json
{
  "_key": "d822e35c2350",
  "_type": "code",
  "code": "export CLOUDSMITH_API_KEY=\"your-api-key\"",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Provider and inputs**

Your workspace slug and the issuer URL of your cluster.

```json
{
  "_key": "9492acbcd659",
  "_type": "code",
  "code": "terraform {\n  required_providers {\n    cloudsmith = {\n      source = \"cloudsmith-io/cloudsmith\"\n    }\n  }\n}\n\nprovider \"cloudsmith\" {}\n\nvariable \"workspace\" {\n  type = string\n}\n\nvariable \"cluster_issuer_url\" {\n  type = string\n}",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Your identity**

Look up the user or service that owns your API key, so that you keep Admin access to the repository.

```json
{
  "_key": "899f2124eb4e",
  "_type": "code",
  "code": "data \"cloudsmith_user_self\" \"current\" {}",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Repository**

One repository caches every upstream. `default_privilege = "None"` removes implicit access for workspace members.

```json
{
  "_key": "718e72a74a96",
  "_type": "code",
  "code": "resource \"cloudsmith_repository\" \"kubernetes\" {\n  name              = \"kubernetes\"\n  slug              = \"kubernetes\"\n  namespace         = var.workspace\n  default_privilege = \"None\"\n}",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Upstreams**

Cloudsmith tries the upstreams in priority order. Docker Hub is first, so short names such as `nginx:1.27` resolve there.

```json
{
  "_key": "cf4a1fa4c3f5",
  "_type": "code",
  "code": "locals {\n  docker_upstreams = {\n    dockerhub = { url = \"https://index.docker.io\", priority = 1 }\n    ghcr      = { url = \"https://ghcr.io\", priority = 2 }\n    gcr       = { url = \"https://gcr.io\", priority = 3 }\n    ecr       = { url = \"https://public.ecr.aws\", priority = 4 }\n    mcr       = { url = \"https://mcr.microsoft.com\", priority = 5 }\n  }\n}\n\nresource \"cloudsmith_repository_upstream\" \"docker\" {\n  for_each = local.docker_upstreams\n\n  name          = each.key\n  namespace     = var.workspace\n  repository    = cloudsmith_repository.kubernetes.slug_perm\n  upstream_type = \"docker\"\n  upstream_url  = each.value.url\n  mode          = \"Cache and Proxy\"\n  priority      = each.value.priority\n}",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Service**

The machine identity that the cluster signs in as.

```json
{
  "_key": "46bf3bce1949",
  "_type": "code",
  "code": "resource \"cloudsmith_service\" \"image_pull\" {\n  name         = \"Kubernetes image pull\"\n  organization = var.workspace\n  role         = \"Member\"\n}",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Privileges**

The service is read-only. You keep Admin, so Terraform can still manage the repository.

```json
{
  "_key": "1d0e3242bd0c",
  "_type": "code",
  "code": "resource \"cloudsmith_repository_privileges\" \"kubernetes\" {\n  organization = var.workspace\n  repository   = cloudsmith_repository.kubernetes.slug\n\n  service {\n    privilege = \"Admin\"\n    slug      = data.cloudsmith_user_self.current.slug\n  }\n  service {\n    privilege = \"Read\"\n    slug      = cloudsmith_service.image_pull.slug\n  }\n}",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **OIDC provider**

Trust JWTs for the `cloudsmith-token` ServiceAccount in the `external-secrets` namespace, with the `cloudsmith` audience, from your cluster. A matching JWT signs in as the service.

```json
{
  "_key": "45183d59a16f",
  "_type": "code",
  "code": "resource \"cloudsmith_oidc\" \"cluster\" {\n  namespace        = var.workspace\n  name             = \"kubernetes-cluster\"\n  enabled          = true\n  provider_url     = var.cluster_issuer_url\n  service_accounts = [cloudsmith_service.image_pull.slug]\n\n  claims = {\n    aud = \"cloudsmith\"\n    iss = var.cluster_issuer_url\n    sub = \"system:serviceaccount:external-secrets:cloudsmith-token\"\n  }\n}",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Output**

The service slug, for step 4 (see below).

```json
{
  "_key": "9850961bc6bf",
  "_type": "code",
  "code": "output \"image_pull_service_slug\" {\n  value = cloudsmith_service.image_pull.slug\n}",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Variables**

Your values, in `terraform.tfvars`.

```json
{
  "_key": "8ba378bb1057",
  "_type": "code",
  "code": "workspace          = \"acme-corp\"\ncluster_issuer_url = \"https://oidc.eks.eu-west-1.amazonaws.com/id/EXAMPLE\"",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Apply**

After you collate the above sections into `main.tf`, record the service slug that the last command prints.

```json
{
  "_key": "751f33dabc46",
  "_type": "code",
  "code": "terraform init\nterraform apply\nterraform output -raw image_pull_service_slug",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

## **Step 3: Install External Secrets Operator and Kyverno**

See the [External Secrets](https://external-secrets.io/latest/introduction/getting-started/) and [Kyverno](https://kyverno.io/docs/installation/) installation guides for other options.

### **Helm repositories**

```json
{
  "_key": "3a60b29ec38c",
  "_type": "code",
  "code": "helm repo add external-secrets https://charts.external-secrets.io\nhelm repo add kyverno https://kyverno.github.io/kyverno/\nhelm repo update",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **External Secrets Operator**

```json
{
  "_key": "7cac51e3f2f4",
  "_type": "code",
  "code": "helm install external-secrets external-secrets/external-secrets \\\n  --namespace external-secrets --create-namespace \\\n  --version 2.6.0 --set installCRDs=true --wait",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Kyverno**

```json
{
  "_key": "97cb2b5a9992",
  "_type": "code",
  "code": "helm install kyverno kyverno/kyverno \\\n  --namespace kyverno --create-namespace \\\n  --version 3.5.2 --wait",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

## **Step 4: Mint a short-lived pull secret with OIDC**

Put the three blocks below, in order, into `pull-secret.yaml`. You can reference the complete file [here](https://gist.github.com/cloudsmith-iduffy/35ff66554819858df731874a94727445#file-pull-secret-yaml).

### **ServiceAccount**

The identity that the cluster presents to Cloudsmith.

```json
{
  "_key": "8a79a44ac45d",
  "_type": "code",
  "code": "apiVersion: v1\nkind: ServiceAccount\nmetadata:\n  name: cloudsmith-token\n  namespace: external-secrets",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Generator**

The External Secrets [Cloudsmith generator](https://external-secrets.io/latest/api/generator/cloudsmith/) exchanges a ServiceAccount JWT for a short-lived Cloudsmith JWT. Set `serviceSlug` to the slug from step 2.

```json
{
  "_key": "4f9067d968f0",
  "_type": "code",
  "code": "---\napiVersion: generators.external-secrets.io/v1alpha1\nkind: CloudsmithAccessToken\nmetadata:\n  name: cloudsmith-token\n  namespace: external-secrets\nspec:\n  orgSlug: acme-corp\n  serviceSlug: SERVICE_SLUG\n  serviceAccountRef:\n    name: cloudsmith-token\n    namespace: external-secrets\n    audiences:\n      - cloudsmith",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **ExternalSecret**

Writes the Cloudsmith JWT into a pull secret and refreshes it every 50 minutes, well inside the JWT expiry time.

```json
{
  "_key": "08c3afc0c8b7",
  "_type": "code",
  "code": "---\napiVersion: external-secrets.io/v1\nkind: ExternalSecret\nmetadata:\n  name: cloudsmith-pull-secret\n  namespace: external-secrets\nspec:\n  refreshInterval: 50m\n  target:\n    name: cloudsmith-pull-secret\n    creationPolicy: Owner\n    template:\n      type: kubernetes.io/dockerconfigjson\n      data:\n        .dockerconfigjson: |\n          {\"auths\": {\"docker.cloudsmith.io\": {\"auth\": \"{{ .auth }}\"}}}\n  dataFrom:\n    - sourceRef:\n        generatorRef:\n          apiVersion: generators.external-secrets.io/v1alpha1\n          kind: CloudsmithAccessToken\n          name: cloudsmith-token",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Apply**

```json
{
  "_key": "982b15365e67",
  "_type": "code",
  "code": "kubectl apply -f pull-secret.yaml\nkubectl -n external-secrets get secret cloudsmith-pull-secret",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

## **Step 5: **Automatically copy the pull secret into every namespace with Kynerno

Put the two blocks below, in order, into `distribute.yaml`. You can reference the complete file [here](https://gist.github.com/cloudsmith-iduffy/35ff66554819858df731874a94727445#file-distribute-yaml).

### **ClusterRole**

Let Kyverno manage Secrets.

```json
{
  "_key": "8df723e87722",
  "_type": "code",
  "code": "apiVersion: rbac.authorization.k8s.io/v1\nkind: ClusterRole\nmetadata:\n  name: kyverno-clone-pull-secret\n  labels:\n    rbac.kyverno.io/aggregate-to-admission-controller: \"true\"\n    rbac.kyverno.io/aggregate-to-background-controller: \"true\"\nrules:\n  - apiGroups: [\"\"]\n    resources: [\"secrets\"]\n    verbs: [\"get\", \"list\", \"watch\", \"create\", \"update\", \"delete\"]",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Generate policy**

Copies the Secret into every namespace, including new ones, and keeps the copies in sync.

```json
{
  "_key": "451b4d407814",
  "_type": "code",
  "code": "---\napiVersion: kyverno.io/v1\nkind: ClusterPolicy\nmetadata:\n  name: cloudsmith-distribute-pull-secret\nspec:\n  generateExisting: true\n  rules:\n    - name: clone-pull-secret\n      match:\n        any:\n          - resources:\n              kinds: [\"Namespace\"]\n      exclude:\n        any:\n          - resources:\n              names: [\"kube-system\", \"kube-public\", \"kube-node-lease\", \"external-secrets\", \"kyverno\"]\n      generate:\n        apiVersion: v1\n        kind: Secret\n        name: cloudsmith-pull-secret\n        namespace: \"{{ request.object.metadata.name }}\"\n        synchronize: true\n        clone:\n          namespace: external-secrets\n          name: cloudsmith-pull-secret",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Apply**

```json
{
  "_key": "7517f8389c2f",
  "_type": "code",
  "code": "kubectl apply -f distribute.yaml",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

## **Step 6: Rewrite every image at admission**

Put the four blocks below, in order, into `rewrite.yaml`. You can reference the complete file [here](https://gist.github.com/cloudsmith-iduffy/35ff66554819858df731874a94727445#file-rewrite-yaml).

### **Policy header**

```json
{
  "_key": "85608c5ab00d",
  "_type": "code",
  "code": "apiVersion: kyverno.io/v1\nkind: ClusterPolicy\nmetadata:\n  name: cloudsmith-registry\n  annotations:\n    pod-policies.kyverno.io/autogen-controllers: none\nspec:\n  background: false\n  rules:",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Rewrite containers**

Replaces the registry host with the Cloudsmith repository path. `ghcr.io/acme/api:1.4` becomes `docker.cloudsmith.io/acme-corp/kubernetes/acme/api:1.4`. Images already on Cloudsmith are left alone.

```json
{
  "_key": "3688c92cea9c",
  "_type": "code",
  "code": "    - name: rewrite-containers\n      match:\n        any:\n          - resources:\n              kinds: [\"Pod\"]\n      exclude:\n        any:\n          - resources:\n              namespaces: [\"kube-system\", \"kube-public\", \"kube-node-lease\", \"external-secrets\", \"kyverno\"]\n      mutate:\n        foreach:\n          - list: \"request.object.spec.containers\"\n            preconditions:\n              all:\n                - key: \"{{ contains(element.image, 'docker.cloudsmith.io') }}\"\n                  operator: Equals\n                  value: false\n            patchStrategicMerge:\n              spec:\n                containers:\n                  - name: \"{{ element.name }}\"\n                    image: \"{{ regex_replace_all('^(localhost/|(?:[a-z0-9-]+\\\\.)+[a-z0-9-]+(?::[0-9]+)?/)?(.*)$', element.image, 'docker.cloudsmith.io/acme-corp/kubernetes/$2') }}\"",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Rewrite init containers**

The same rewrite for init containers, when the Pod has any.

```json
{
  "_key": "618d03786b75",
  "_type": "code",
  "code": "    - name: rewrite-init-containers\n      match:\n        any:\n          - resources:\n              kinds: [\"Pod\"]\n      exclude:\n        any:\n          - resources:\n              namespaces: [\"kube-system\", \"kube-public\", \"kube-node-lease\", \"external-secrets\", \"kyverno\"]\n      preconditions:\n        all:\n          - key: \"{{ request.object.spec.initContainers[] || `[]` | length(@) }}\"\n            operator: GreaterThanOrEquals\n            value: 1\n      mutate:\n        foreach:\n          - list: \"request.object.spec.initContainers\"\n            preconditions:\n              all:\n                - key: \"{{ contains(element.image, 'docker.cloudsmith.io') }}\"\n                  operator: Equals\n                  value: false\n            patchStrategicMerge:\n              spec:\n                initContainers:\n                  - name: \"{{ element.name }}\"\n                    image: \"{{ regex_replace_all('^(localhost/|(?:[a-z0-9-]+\\\\.)+[a-z0-9-]+(?::[0-9]+)?/)?(.*)$', element.image, 'docker.cloudsmith.io/acme-corp/kubernetes/$2') }}\"",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Add the pull secret**

```json
{
  "_key": "c889b5361176",
  "_type": "code",
  "code": "    - name: add-pull-secret\n      match:\n        any:\n          - resources:\n              kinds: [\"Pod\"]\n      exclude:\n        any:\n          - resources:\n              namespaces: [\"kube-system\", \"kube-public\", \"kube-node-lease\", \"external-secrets\", \"kyverno\"]\n      mutate:\n        patchStrategicMerge:\n          spec:\n            imagePullSecrets:\n              - name: cloudsmith-pull-secret",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Apply**

```json
{
  "_key": "a04b02f23dbd",
  "_type": "code",
  "code": "kubectl apply -f rewrite.yaml",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

## **Step 7: Verify the setup**

### **Deploy a test workload**

Pulls from four registries and does not mention Cloudsmith. Save it as `multi-registry-app.yaml`.

```json
{
  "_key": "5bd168f6b03f",
  "_type": "code",
  "code": "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: multi-registry-app\n  namespace: apps\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: multi-registry-app\n  template:\n    metadata:\n      labels:\n        app: multi-registry-app\n    spec:\n      containers:\n        - name: ghcr\n          image: ghcr.io/stefanprodan/podinfo:6.7.0\n        - name: gcr\n          image: gcr.io/google-containers/pause:3.2\n        - name: ecr\n          image: public.ecr.aws/docker/library/nginx:1.27\n        - name: mcr\n          image: mcr.microsoft.com/dotnet/runtime:8.0\n          command: [\"sleep\", \"infinity\"]",
  "filename": null,
  "language": null,
  "markDefs": null
}
```



```json
{
  "_key": "78fbba2b9823",
  "_type": "code",
  "code": "kubectl create namespace apps\nkubectl apply -f multi-registry-app.yaml\nkubectl -n apps rollout status deploy/multi-registry-app",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

### **Check the images**

Every image now comes from Cloudsmith, and the running Pod proves that the short-lived Cloudsmith JWT works.

```json
{
  "_key": "6b8fb2bb8178",
  "_type": "code",
  "code": "kubectl -n apps get pod -l app=multi-registry-app \\\n  -o jsonpath='{range .items[0].spec.containers[*]}{.name}{\"\\t\"}{.image}{\"\\n\"}{end}'",
  "filename": null,
  "language": null,
  "markDefs": null
}
```



```json
{
  "_key": "389434aa9a8f",
  "_type": "code",
  "code": "ghcr    docker.cloudsmith.io/acme-corp/kubernetes/stefanprodan/podinfo:6.7.0\ngcr     docker.cloudsmith.io/acme-corp/kubernetes/google-containers/pause:3.2\necr     docker.cloudsmith.io/acme-corp/kubernetes/docker/library/nginx:1.27\nmcr     docker.cloudsmith.io/acme-corp/kubernetes/dotnet/runtime:8.0",
  "filename": null,
  "language": null,
  "markDefs": null
}
```

## **Things to know**

- **The pull secret is short-lived, but it is still a Secret.** Use Kubernetes RBAC to limit who can read Secrets.
- **Image names can collide.** `ghcr.io/acme/api` and `docker.io/acme/api` both become `acme/api`, and Cloudsmith serves the first upstream match. Use a separate repository for each upstream if that is a risk.
- **Kyverno is in the Pod creation path.** Kyverno fails closed by default, so run several replicas in production.
- **System namespaces are excluded,** so cluster add-ons do not depend on Cloudsmith or Kyverno.

New to Cloudsmith? [Book a demo](https://cloudsmith.com/book-a-demo) to see how Cloudsmith can protect and speed up every image pull in your clusters.
