skip to content

How does an OCI registry running as a pull-through cache decide whether its cached copy of an image tag is still current?

level: middleimportance: should knowfreq 46%

answer

  1. tags move, digests do not
  2. ask the upstream on a tag pull
  3. unreachable versus gone
  4. ttl and retention expire copies

basics

~20 s

On a pull by tag, a pull-through cache asks the upstream which manifest the tag points to now and fetches the new content if the tag moved; a pull by digest names fixed content, so the cached copy needs no freshness check.

solid answer

~40 s

In an OCI registry a **tag** is a movable name for a manifest, while a **digest** names exact bytes, so a pull-through cache treats them differently. The open-source distribution registry in proxy mode checks the remote on a pull by tag and fetches newer content if there is any; cached content expires after `proxy.ttl`, 168 hours by default, and 0 disables expiry. Harbor's proxy cache project checks the image's current manifest in the target registry: unchanged means serve the cache, updated means pull and cache the new image, unreachable means serve the cache, and an image no longer in the target registry means nothing is served. Neither accepts pushes, and Harbor gives each new proxy cache project a 7-day retention policy by default. A pull by digest never needs the freshness question answered.

code

yaml · 6 lines
yaml
proxy:
  remoteurl: https://registry-1.docker.io
  ttl: 168h
storage:
  delete:
    enabled: true

go deeper

for a junior

Recall that a pull-through cache stores images from one upstream on first pull, that tags can move while digests cannot, and that you cannot push to it.

for a middle

Explain how a tag pull triggers an upstream check, how ttl and Harbor's default retention expire copies, and the four outcomes Harbor documents for a cached image.

for a senior

Anticipate the failure modes: an upstream deletion that Harbor honours, credentials that expose private images on an unauthenticated mirror, and a ttl written without a suffix.

for a principal

Decide which images workloads must pin by digest and hold in a registry you control, and which may float on tags through a cache that depends on the upstream.

## Tags, digests and what "current" means In an OCI registry, a **digest** such as `sha256:...` identifies exact content: change one byte and the digest changes. A **tag** such as `1.27` or `stable` is a name that points at a manifest digest and can be moved to another one at any time. "Is my cached copy current?" therefore only has meaning for tags. A cached manifest fetched by digest is the content that digest names, now and forever; there is nothing newer to look for. A **pull-through cache** (also called a proxy cache) is a registry that answers pulls itself, fetching from one upstream registry the first time and serving later pulls from its own storage. The question is what it does on the second pull of a tag. ## The open-source distribution registry in proxy mode The reference registry becomes a pull-through cache when its configuration has a `proxy` section. - **Freshness:** when a pull is attempted with a tag, the registry checks the remote to see whether it has newer content, and fetches and caches it if so. - **Expiry:** `ttl` expires cached content in storage, **168h (7 days) by default**; `0` disables expiration. A value without a suffix is read as nanoseconds, a classic surprise. - **Clean-up needs deletes enabled:** for the scheduler to remove old entries, `delete` must be enabled in the storage configuration, which defaults to false. - **One upstream per instance:** the documentation states it can mirror only one upstream registry at a time, and the mirror URL must be the root of a domain. - **No pushes:** pushing to a registry configured as a pull-through cache is unsupported. - **Credentials leak access:** with an upstream username and password configured, private images that account can see become pullable from the mirror, so the mirror itself must require authentication. ## Harbor's proxy cache project Harbor implements the same idea as a project type. An administrator creates a project with the **Proxy Cache** option and a registry endpoint for the target registry. Clients then pull through a path that adds the Harbor host and the proxy project name in front of the upstream image name. On a later request for an image Harbor checks its latest manifest in the target registry, and documents four outcomes: 1. The image has not been updated upstream: serve the cached image. 2. The image has been updated upstream: pull the new image, serve it and cache it. 3. The target registry is not reachable: serve the cached image. 4. The image is no longer in the target registry: serve no image. Harbor's documentation says that for Docker Hub it fires a HEAD request to find out whether a cached image was updated, and pulls the new image only if it was. A proxy cache project accepts no pushes, and every new proxy cache project gets a 7-day retention policy by default, so images nobody pulls age out. ## Side by side | | Open-source registry, proxy mode | Harbor proxy cache project | |---|---|---| | Tag pull | Checks the remote for newer content | Checks the latest manifest upstream | | Upstream unreachable | Not spelled out in the recipe | Serves the cached image | | Image gone upstream | Not spelled out in the recipe | Serves no image | | Expiry | `proxy.ttl`, default 168h | Tag retention policy, 7 days by default | | Pushes | Unsupported | Not allowed | | Upstreams | One per instance | One registry endpoint per project | ## Operating notes - **Pin digests where reproducibility matters.** A digest pull is served from cache with no freshness question and cannot drift if the upstream tag moves. - **Expect "gone upstream" to bite in Harbor.** An image deleted from the target registry stops being served even though Harbor still holds a copy; a deployment that depends on it needs that image held somewhere you control. - **Expiry is not loss.** Content removed by `ttl` or retention is fetched again on the next pull, as long as the upstream still has it. - **Count the upstream checks.** Every tag pull costs a remote check, which is why mutable tags through a cache are slower and more upstream-dependent than digests. ## Common misconceptions - "Once cached, an image is served forever." `ttl` in the open-source registry and the default retention policy in Harbor both age content out. - "Internal images can be pushed into the cache." Both reject pushes; internal images belong in an ordinary repository or project. - "The cache protects you from upstream deletions." Harbor documents the opposite: an image gone from the target registry is no longer served.

  • Why does the open-source registry's documentation tell you to secure a pull-through cache that has upstream credentials?
    The username and password let the cache fetch private images that account can see, and those images land in the cache's own storage. Anyone who can reach the mirror can then pull them, so without authentication on the mirror, private upstream content becomes available to everyone on your network.
  • Should workloads pull through the cache by tag or by digest?
    By digest where reproducibility matters: the cache serves fixed content with no upstream check, and a moved tag upstream cannot change what you run. By tag where you want new upstream releases to flow in, accepting that each pull costs a remote check and that a tag can point somewhere new tomorrow.

  • A pull-through cache never checks the upstream again once an image is cached.
  • You can push your own images into a pull-through cache.
  • One open-source registry instance in proxy mode can mirror several upstream registries.
  • Harbor's proxy cache keeps serving an image after the upstream deleted it.
  • Images in a pull-through cache never expire unless someone deletes them.