Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › CI/CD

Stop Untrusted Images Before They Reach Kubernetes: Cosign and OPA in CI/CD

By Freedom251 Team · · 5 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Cosign to sign an image and verify who signed it; use OPA Gatekeeper to decide whether Kubernetes should admit it. A signature alone is not enough: verification must trust the intended signer and issuer, and deployment policy must enforce the rules you actually need. Carry the image digest through the pipeline so each step refers to the same immutable artifact.

What each control proves—and what it does not

Image trust is a chain of separate checks, not a single “signed” status. Keep these three questions distinct:

As an Amazon Associate I earn from qualifying purchases.

  • Signature: Is there cryptographic evidence that an identity signed this image?
  • Authorized signer: Is that identity, from that issuer, allowed to sign images for this project or release?
  • Deployment policy: Does the image meet the rules for this Kubernetes workload, and should the cluster allow it?

Cosign provides image signing and verification. OPA Gatekeeper evaluates Kubernetes resources against policy at admission and can report existing violations through audit. Digest pinning adds a different control: it makes the image reference point to specific content, but does not prove that content came from an authorized builder.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to build the CI/CD trust path

  1. Build and publish the image. Push it to an OCI-compatible registry. Capture its digest and pass that digest to later jobs; do not rely on a mutable tag as the artifact’s identity.
  2. Sign the published image with Cosign. Sigstore documents a GitHub Actions example that uses OIDC, grants id-token: write, installs Cosign with its official installer, publishes an image, signs it, and demonstrates verification. Treat that as a starting pattern, not a complete production trust policy: constrain the accepted identity to the intended workflow and organization rather than copying a wildcard example.
  3. Verify with explicit identity and issuer expectations. Require the signer identity and OIDC issuer your organization intends to trust. Cosign’s verification documentation says the signature payload includes the image digest and that Cosign checks the digest by default. Avoid disabling claim checking unless you have documented why and have another way to validate those claims.
  4. Test deployment policy before rollout. Use Gatekeeper’s gator CLI to check Kubernetes objects against policy in CI. Gatekeeper documentation also describes packaging policy files as OCI artifacts, which can help teams distribute a versioned policy bundle consistently.
  5. Enforce the policy at Kubernetes admission. Gatekeeper uses OPA’s Constraint Framework. A ConstraintTemplate defines a policy type; a Constraint applies that policy to resources. Start in a non-blocking mode, inspect results, resolve intended exceptions, then move to denial when the policy is ready.

Choose the signing model with the verifier in mind

Keyless signing with Sigstore

Sigstore’s keyless flow uses an OIDC identity. Fulcio issues a short-lived certificate that binds an ephemeral key to that identity, and the signing event is recorded in Rekor’s transparency log. This avoids distributing a long-lived signing key, but it does not make verification automatic: the verifier still needs tight identity and issuer restrictions.

Self-managed signing keys

Cosign also supports signing with self-managed keys. That option puts key custody and distribution under your operational control. The choice changes how signing credentials are managed; it does not remove the need to verify that the signer is authorized or to enforce a deployment policy.

Use signatures, attestations, and digests for different questions

  • Signatures provide evidence that a signer signed an artifact. Verification should check the expected identity and issuer as well as the image digest.
  • Attestations can carry additional claims for a policy to inspect. Cosign supports attaching them with cosign attest and verifying them with cosign verify-attestation.
  • Digest requirements make a workload refer to specific image content. Gatekeeper Library documents an Image Digests constraint for requiring digests in image references. Check that example against the Gatekeeper version you operate before applying it; a digest is not proof of trusted origin.

Test first, then choose an enforcement mode

Gatekeeper supports admission behavior that can deny, warn, or dry-run requests; its audit mode reports violations in existing resources. These modes provide a rollout path: observe what would be affected, correct policy and workloads, and only then block noncompliant deployments.

  1. Run policy checks in CI against representative Kubernetes objects with gator.
  2. Deploy the policy in a non-blocking mode and review admission feedback and audit findings.
  3. Validate exceptions deliberately. An exception should be narrow enough that it does not silently exempt unrelated workloads.
  4. Move to denial when the policy and exception process are understood. Decide how the team will respond if the policy controller is unavailable, and whether that failure should block deployments or permit them.

Test both the valid path and expected failures: an image signed by the intended workflow, an image with an unexpected signer or issuer, an image reference without a digest when policy requires one, and a workload that should qualify for a documented exception. Policy testing cannot replace verification of the image signature, and a successful signature check cannot replace admission policy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Operating Gatekeeper or using a managed integration

Gatekeeper lists managed integrations as well as its own project, but the available documentation does not establish a comparable total cost, latency, or staffing advantage. Evaluate the operational boundary in your environment rather than assuming that one pattern is inherently faster, cheaper, or more secure.

Decision area Operating Gatekeeper in your cluster Using a managed Kubernetes policy integration
Controller operations Your team must establish who upgrades the controller and responds to failures. Confirm which responsibilities the provider assumes and which remain with your team; the documentation does not state a universal split.
Verification location Decide whether checks run in CI, at admission, or in both places. Confirm where verification occurs; the documentation does not establish a shared behavior across integrations.
Identity and issuer policy Define and maintain the accepted signer identities and issuers. Confirm how identities and issuers are configured and maintained for the specific integration.
Policy testing and distribution Run CI checks and decide how policy artifacts are versioned and distributed. Confirm whether the integration supports your CI testing and policy distribution workflow.
Rollout and exceptions Plan non-blocking evaluation, denial, exception handling, and controller-failure behavior. Verify the available enforcement modes, exception process, availability expectations, and fail-open or fail-closed behavior.

A practical trust checklist

  • Build once, publish the image, and carry its digest through signing, verification, and deployment.
  • Constrain verification to the intended signer identity and OIDC issuer; do not treat any valid signature as trusted by default.
  • Keep claim checking enabled unless an alternative validation method is documented.
  • Use CI policy tests and Kubernetes admission enforcement as complementary controls.
  • Use audit or another non-blocking mode to understand impact before denying workloads.
  • Document exceptions and the response to policy-controller failures before relying on enforcement for production deployments.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

CI/CDcontainer securityCosignimage signingKubernetesOPA Gatekeeper

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.