Safeguard
Developer Tools•

What tag naming scheme makes image retention rules easy to write?

Retention rules match tags, so design tags for them: a class prefix, a version, and a build id. A scheme that works with ECR, Harbor and Artifact Registry.

Safeguard Security Team
3 min read

Put the image class first in the tag, then the version, then a build identifier, for example release-1.4.2, pr-482-a1b2c3d and ci-20261019-77. A class prefix lets one rule target one kind of image, which is what every major registry retention feature is built to match.

Why the tag matters

Retention rules cannot read your intent. They read tags, ages, counts and, in some cases, pull times. A rule can only protect or expire what it can recognise. If release and throwaway images share a tag shape, you cannot write a rule that treats them differently.

All three registries reviewed here match on tag text. Amazon ECR supports tag prefix lists and tag pattern lists with wildcards, limited to four wildcards per string. Google Artifact Registry supports tag prefixes and version prefixes. Harbor supports tag filters with wildcards, including matching or excluding names.

The scheme

ClassExample tagRule
Releaserelease-1.4.2Keep the last N, never expire by age
Long term supportlts-1.2.9Keep until the line ends
Release candidaterc-1.5.0-3Expire after a short age
Pull requestpr-482-a1b2c3dExpire after a few days
CI buildci-20261019-77Expire after a few days

The prefix is the handle, the version identifies the release, and the suffix ties the image to a commit or build.

Rules that avoid common mistakes

  • Do not rely on latest. A mutable tag is not a version, and a rule cannot reason about it. See a tag is not a version.
  • Avoid tags that match several classes. An image tagged both release-1.4.2 and ci-77 is kept if either rule keeps it in Harbor, and is matched by only one rule in ECR. Be deliberate about which tags an image carries.
  • Keep prefixes distinct. In ECR the set of rules selecting a storage class must use a unique set of prefixes, so avoid nested prefixes such as rel and release.
  • Use semantic versions for releases. Sorting by push time is fine for counts, but readable versions help humans.

Write the rules before the pipeline

Define the classes, then make the pipeline emit tags that match. Publish the scheme in your contributing guide so every team follows it. Then automate a check that flags tags outside the scheme.

Tags and digests together

Tags are for people and rules. Digests are for deployment and verification. Deploy by digest, record the digest at release, and use tags to organise cleanup. See how should you tag release container images and which image tags in a registry should you scan.

Migrating an existing repository

You rarely start clean. For an existing repository, add the new tags alongside the old ones going forward, write rules for the new prefixes, and leave old tags alone until they age out under a conservative rule. Do not retag history in bulk, since that makes digests and tags harder to reconcile with past records.

Quick check

Should the class be a prefix or a suffix?

A prefix, since the registries reviewed here support prefix matching directly, and prefixes sort together in listings.

Can one image carry two class tags?

It can, but rule results then depend on your registry's overlap logic. Avoid it unless you have tested the outcome.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.