Skip to content

About

Peer-to-peer OCI image cache for Kubernetes, enabling container image pulls from neighboring nodes

Topics

Resources

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Steady Image Cache (SIC)

A node-local, peer-assisted OCI registry cache for Kubernetes/containerd, designed for disconnected and air-gapped clusters.

Project website and documentation: https://steadyinfra.com/sic/

Status

SIC is a young project: the first release was on 2026-10-24. What is covered so far: unit and race-detector tests, fuzzing of request and pod-list parsing, fault-injection tests of the cache, and end-to-end tests on kind clusters with a real containerd (see "End-to-end test"): peers, real registries behind a private CA and with passwords, the sample mirror configuration, the Helm chart with cert-manager and certificate renewal, rolling back to the previous release and forward again, and containerd 1.7 and 2.x nodes. The alert rules have unit tests (promtool). What is not covered yet: clusters beyond a handful of nodes (the cost of gossip is computed and measured on a model, see "Large clusters", but not on a real cluster of that size), a pod killed in the middle of a download, long-running soak tests, and containerd versions beyond the two named. Measurements of registry traffic exist, and they are small: kind clusters of two and of four workers (plus the control-plane node, which runs SIC too), one run each, no real rollout. The CI job "pilot" (MODE=pilot test/e2e/run.sh) preloads public.ecr.aws/docker/library/python:3.12 on one node, from the registry (411,950,619 bytes), and then on the other, which took the same 411,950,619 bytes from the first node and none from a registry: 100% of the second node's bytes were not fetched from the registry. With four workers, one after another, the registry was asked for 411,950,619 bytes in all and the peers served 1,235,851,857: 75% of the workers' bytes not fetched from the registry, which is the most possible with four nodes ((N-1)/N). All four at once, with coordination on, for python:3.11-slim (45,608,782 bytes), depends on SIC_COORDINATE_ANONYMOUS_TOKEN and is still not stable. Without it, three runs of the same job took 61,395,794 bytes from the registries in all (1.35 times the image; 66% of the workers' bytes not fetched from a registry), 166,735,941 (3.66 times; 8%) and 91,236,068 (2.0 times; 50%), against 182,435,128 if every node had gone to the registry; in the third the nodes took 10 blobs from a coordinator and 6 times had to do without one, because public.ecr.aws and ghcr.io refuse a coordinator that has no credentials ("Simultaneous pulls"). With it, three runs on the main branch took 15,797,634 bytes (0.35 times the image; 91%), 45,637,659 (1.0 times; 74%) and 31,188,038 (0.68 times; 82%), with no node having to do without a coordinator. Three runs on one kind cluster, two public registries and four nodes are a small sample and the figure still varies threefold between runs; a registry figure below the image size is probably layers that were already on a node from the earlier preload, which was not checked. So a rollout that starts everywhere in the same second saved between three quarters and nine tenths of the registry traffic here when the option was on, and the claim in "Simultaneous pulls" that the registry sees about one request per layer is supported by this measurement only for these registries and this cluster. Peers are asked one after another ("Peer requests"), so a larger cluster will do worse than these. Numbers for rollout time do not exist yet, so measure on your own cluster before relying on it for one.

Things to know before deploying, each described in the section named:

  • Unless a registry is listed in SIC_PROTECTED_REGISTRIES (and then only for what is cached after it was listed: start with an empty cache), every client can read the whole cache, private images included. Whoever holds a node's certificate and key can read what the nodes hold, protected content too; but a protected registry's content is given only to a node that protects that registry itself, so set SIC_PROTECTED_REGISTRIES the same on every node. The sample shares one certificate between all nodes ("Upstream fallback", "TLS").
  • Peers are asked one after another, a few per miss, so on a large cluster a blob held by few nodes is often fetched from the registry instead, and a node can share a download only once it has received its first bytes, so nodes that all miss in the same instant mostly go to the registry ("Peer requests", "Streaming a miss").
  • Peer discovery asks the Kubernetes API from every node: one list (answered from the API server's cache) and then a watch, so a steady cluster costs the API server almost nothing, but every node still receives an event for every pod change, so a rolling restart of a very large DaemonSet costs the square of the node count in events. It is not tested beyond a few hundred nodes ("Health and metrics" describes it).
  • The containerd import keeps a second copy of every blob on the node unless containerd's content directory is mounted into the pod, which the sample does ("The import without a second copy").
  • With SIC as the only registry host, an upgrade needs the new image on the node first ("Upgrading").

The settings, the metric names and the HTTP paths are the public interface and follow semantic versioning (see CHANGELOG.md); anything not listed there may change in a minor release.

Highlights

  • OCI manifest and blob proxy/cache with containerd ?ns= registry namespace handling.
  • Kubernetes-native peer discovery (DaemonSet peers discovered through the Kubernetes API).
  • mTLS for containerd→SIC and SIC→SIC traffic.
  • Prometheus-format /metrics endpoint.
  • Direct containerd gRPC integration through /run/containerd/containerd.sock; no ctr subprocess and no read-only scraping of containerd's on-disk layout. SIC walks the containerd content store, verifies/imports content by digest, and imports image-name → target-digest aliases from the k8s.io namespace.
  • Single-flight downloads: concurrent requests for the same missing blob or manifest are coalesced into one peer/upstream fetch per SIC process.
  • HTTP byte-range support for cached blobs/manifests via Go http.ServeContent, including GET, HEAD, Range, Accept-Ranges, and 416 handling.
  • Upstream fallback remains optional and is disabled by default. When enabled it only contacts registries listed in SIC_UPSTREAM_REGISTRIES.
  • Streaming. A layer that is not cached is passed to containerd while it downloads, and to other nodes asking for it, so a rollout does not wait for the first node to finish.
  • Integrity. Every blob is verified against its digest when written and re-checked in the background; content that fails is never served.
  • Bounded disk use. Least-recently-used eviction with a size cap and a free-space reserve.
  • Tags that stay current, with the registry deciding what a tag is; peers only share content by digest.
  • Images for linux/amd64 and linux/arm64; sic --version prints the build.

How SIC differs from Spegel, Dragonfly and Kraken

All four move image content between nodes so that the registry is asked less. They differ in what they assume and in what they are for. This is from their own documentation as of November 2026 (linked), not from running them side by side; check their pages for anything that may have changed.

SIC Spegel Dragonfly Kraken
Shape One DaemonSet; each node serves a registry interface to containerd and to other nodes One DaemonSet; each node serves a registry mirror interface Manager, scheduler, seed peers and a peer daemon on each node Agents on each host plus origins, trackers, build-index and proxy; blobs in pluggable storage
Where peers are found Kubernetes API (pods, optionally EndpointSlices) Kademlia DHT, with a leader-elected bootstrap Scheduler chooses parents Tracker returns peer lists
Where content lives SIC's own cache directory, filled by the import from containerd's content store (hard-linked when the directory is mounted) containerd's content on each node Peer daemon's cache Agents and origins
If no peer has it Registry fallback is optional and off by default; with it off the pull fails, which is the point in an air-gapped cluster 404, and containerd goes to the registry Scheduler tells the peer to go to the source Origin (backed by the storage)
Needs besides the DaemonSet Nothing Nothing A control plane to run A tracker, origin and build-index tier

What SIC is for, and where it is narrower than the others:

  • A registry that must not be reachable, or must not be trusted with more than it needs. With _default as the only containerd host, SIC is the only path to content, and nothing leaves the cluster unless you allow it per registry. The others are built to speed up or shield pulls that otherwise reach a registry.
  • Credentials stay with the client. SIC never holds registry credentials: it passes the registry's WWW-Authenticate challenge to containerd and forwards the Authorization containerd then sends, and drops it on a cross-origin redirect ("Upstream fallback"). Protected registries ("Upstream fallback", SIC_PROTECTED_REGISTRIES) ask the registry per layer before giving private content to a client. The pages of the other projects linked above do not describe how they handle private registries; read their documentation before relying on either.
  • Tags. SIC confirms a tag with the registry (a HEAD) and fetches by digest, and says what it does when the registry is unreachable ("Tags: staying current, and who is believed").
  • Where it is narrower. SIC has no scheduler or piece-level swarming: a node copies a whole blob from one peer, so Dragonfly and Kraken are the better fit for very large artifacts and very large simultaneous fan-out, which they document at far larger scale than SIC has been tested ("Status"). SIC is young (the others are older and, Kraken in production at Uber since 2018 by its own account, longer tested); Spegel is lighter to run if you only want a mirror on top of containerd and have no air-gapped or private-registry requirement.

Pull flow

containerd -> local SIC -> local cache
                         -> peer SIC(s) -> peer cache/containerd-imported content
                         -> optional upstream

On startup and periodically, SIC connects to the node's containerd socket. Existing content is copied into SIC's content-addressed cache (or linked to, when containerd's content directory is mounted: "The import without a second copy") and image references are imported as aliases. This means a newly joined air-gapped node can obtain content that existed on older nodes before SIC was deployed.

Containerd integration

Mount the socket into SIC:

- name: containerd-socket
  hostPath:
    path: /run/containerd/containerd.sock
    type: Socket

Relevant environment variables:

SIC_CONTAINERD_IMPORT=true
SIC_CONTAINERD_ADDRESS=/run/containerd/containerd.sock
SIC_CONTAINERD_NAMESPACE=k8s.io
SIC_CONTAINERD_CONTENT_DIR=/var/lib/containerd/io.containerd.content.v1.content
SIC_IMPORT_INTERVAL=5m

A blob or image name that cannot be imported does not stop the import: the rest is still imported, and the failures are logged at the end of each run (the first few, with a count) and counted in sic_containerd_import_errors_total. Blobs that containerd's garbage collector deletes while the import runs are ignored. If the cache has no room left (see SIC_MIN_FREE_BYTES) the copying stops for that run, the image names are still imported, and the run reports the full cache.

The containerd account/socket permissions must allow the SIC process to call the content and image services. The supplied DaemonSet runs the container as UID 0 for that reason; tighten this if your containerd socket group/ACL permits it.

Peer requests

Requests that SIC sends to its peers carry an X-SIC-Peer header. A SIC that receives one answers from its own cache only and never forwards it to other peers or upstream, so two nodes that both miss cannot ask each other in a loop.

A peer that does not accept a connection and start answering within SIC_PEER_TIMEOUT (default 5s) is skipped for SIC_PEER_BACKOFF (default 30s; 0 disables skipping), so a dead node slows one request instead of every miss. Peers discovered through Kubernetes must be Ready and not terminating.

Rollouts. A peer is also served a blob that this node is still downloading, as long as the download has already delivered bytes: when a new image goes out, the first node's pull is passed down the line while it runs, instead of every other node waiting for it to finish and then going to the registry. A peer is never made to wait for a download to start, so two nodes cannot end up waiting for each other. A request for a blob that is neither cached nor started gets a 404, as before. sic_peer_streams_total counts peer requests answered this way. The last-byte rule from "Streaming a miss" applies to peers as well, and a peer that stops halfway is replaced by the next one for later requests.

How many peers a miss asks. Peers are asked one after another, in random order, and a miss asks at most SIC_PEER_MAX_TRIES of them (default 4; 0 asks all). Without a limit, a blob that nobody has costs one round trip per node before it reaches the registry. The price is that on a cluster larger than the limit, a blob that only a few nodes hold can be missed: with N peers of which k hold the blob, a miss that asks m of them finds one with probability 1 - C(N-k, m) / C(N, m); for a single holder that is m/N, so one holder among 50 peers is found by 4 in 50 misses. During a rollout the number of holders grows with every pull, which is what the limit relies on. Choosing whom to ask is cheap: copying, shuffling and cutting the list takes about 5 µs at 100 peers, 32 µs at 1 000 and 120 µs at 5 000 (160 KiB of allocation), and with a 64 KiB digest filter per peer 215 µs at 1 000 (go test ./internal/proxy -run '^$' -bench PeerOrder, one 2.1 GHz Xeon core), against the milliseconds of one request to a peer. It is not the cost to worry about. Raise it if your registry is slow or expensive and your nodes are close together. sic_peer_cap_reached_total counts misses that were cut short, and sic_peers is the number of peers this node would currently ask. Kubernetes discovery lists the pods every 30 seconds and keeps only Ready ones, so a node that starts together with the others (a new DaemonSet, a cluster coming up) lists them before they are Ready. To avoid being blind for the rest of the interval, a miss that finds no known peers asks discovery to list again at once. The listing runs in the background, so that miss still goes to the registry (or fails, if upstream fallback is off) but the next one sees the peers. A node lists the pods at most once every 5 seconds however often it asks, and a node that really has no peers (a single-node cluster) lists at most that often while it is missing blobs.

Simultaneous pulls. A node that is already downloading a blob shares it with its peers while it arrives, but a rollout starts on many nodes in the same second, before any of them has a byte to share, and each would go to the registry. To prevent that, every digest has one coordinator node, picked by all nodes without talking to each other: the node whose address hashes highest together with the digest (rendezvous hashing, so different layers have different coordinators and the load is spread). A node that misses asks the coordinator first. The coordinator starts one download, from its peers and then the registry, and streams it to everyone who asked, so the registry sees one request per layer instead of one per node. If the coordinator is down, slow to start (SIC_COORDINATE_WAIT, default 20s) or disagrees about who the coordinator is (the node lists can differ for a moment), the asking node fetches on its own as before, and nobody waits on a node that does not think it is the coordinator, so waits cannot form a cycle. The price is a second copy: the coordinator keeps what it fetched for others, so a blob pulled on one node can also end up on its coordinator, which never asked for it. The cache's size limit and eviction apply to it like to any blob. The coordinator has no one's registry credentials and fetches without them, so private content is still fetched by the node that holds the credentials (the asking node retries with its own). The same holds for a registry that wants a token even for public content (Docker Hub, public.ecr.aws and ghcr.io do): the coordinator is refused (a node that asked it logs coordinator ... answered 404 ...; fetching without it) and each asking node fetches for itself, so there coordination helps only for a blob the coordinator already holds or is already downloading for its own client; in the pilot ("Status") four nodes preloading at once took the image from the registry between 1.35 and 3.66 times in three runs for this reason, and between 0.35 and 1.0 times in three runs with the option below. SIC_COORDINATE_ANONYMOUS_TOKEN=true (off by default) lets the coordinator do what an anonymous client does: ask the registry's token service for a token with no credentials, for the service and scope the registry named, and ask again. Public content then comes through the coordinator. The option is off by default, because it makes SIC call a token service; the pilot supports turning it on for registries like these, once their token service host is in SIC_UPSTREAM_REGISTRIES. Private content does not: the token service gives an anonymous client nothing, the registry refuses it, the coordinator keeps nothing and the asking node fetches with its own credentials as before. The coordinator calls only a token service whose host is itself on SIC_UPSTREAM_REGISTRIES (the realm of public.ecr.aws and ghcr.io is on their own host; Docker Hub's is auth.docker.io, which you add to the list to use this with it; a node logs when a realm is not listed), never for a registry in SIC_PROTECTED_REGISTRIES, only over https, follows no redirect from it, sends no credential of any client, and keeps a token for 75% of the time the service gives (at least 10 seconds), per registry, service and scope, at most 256 of them. A token request has 5 seconds. When the token service or the registry refuses an anonymous client (a 4xx other than 408 and 429), the coordinator does not ask again for that registry, service and scope for 60 seconds; after a network error, a 5xx, a 408 or a 429 it waits 5 seconds. The same 5 seconds apply when the registry answers the retried request with a new challenge instead of accepting the token. Misses that start together share one token request. sic_coordinator_anonymous_tokens_total counts the tokens used. Coordination needs the node's own address, which it takes from HOST_IP with Kubernetes discovery (the sample DaemonSet sets it); without it, or with SIC_COORDINATE=false, each node fetches on its own. sic_coordinator_hits_total counts blobs a node got from a coordinator, sic_coordinator_served_total the requests a node answered as coordinator, and sic_coordinator_fallbacks_total the times a node had to do without one.

Redirects. A peer never legitimately redirects: it has the blob or it does not. SIC does not follow a peer's redirect, which would let a node with a valid certificate send this one to any address, plain HTTP included. A peer that answers with one is treated as faulty, logged, and skipped for SIC_PEER_BACKOFF. A registry's redirects, on the other hand, are normal (blobs often come from a CDN or an object store), so SIC follows up to 5 of them, over https only; a redirect to plain HTTP or a longer chain fails the fetch and is logged. As usual with net/http, the Authorization header is not sent to a different host than the one it was meant for.

Streaming a miss

A layer that is not cached is passed on to containerd while it is still being downloaded, so the pull starts at once instead of waiting for the whole layer to arrive first. Everyone asking for the same blob shares one download, which goes on if a client leaves, and every one of them is fed from the file as it is written.

The digest can only be checked at the end, so the last byte of a response is held back until the check has passed. If it fails, or the source breaks off, the response stops one byte short and the connection is closed: containerd sees an error and retries, and the bad content is never stored. The earlier bytes were sent unverified; containerd checks every layer against its digest itself. A request with a Range header needs the whole blob and waits for it. A HEAD for a blob that is not cached and not being downloaded is passed to the peers and then the upstream registry as a HEAD, and their size is relayed; it never starts a download. A HEAD while a download is running waits for it. sic_streamed_responses_total counts streamed responses and sic_stream_aborts_total those that were cut short.

When a source fails after the status line has been sent, the client gets a broken response and not the 404 it would have got before.

Resuming. A source that breaks off partway does not throw away what it delivered. The bytes stay in the partial file, and the next source (the next peer, or the registry again) is asked for the rest with Range: bytes=N-; a source that answers 206 with a Content-Range that starts exactly there completes the blob, and one that answers 200 sends all of it and replaces the start. A client that was being streamed from the first source goes on with the continuation and does not notice, because the bytes it already has are part of the same file, and the last-byte rule still holds: nothing is complete until the digest of the whole blob has been checked, so a source that lied about the start is caught at the end, and the partial file is discarded. A client whose source is replaced by one that starts over is cut off as before. A registry that breaks off is asked again up to 3 times while each try gets further than the one before. The kept bytes live only as long as the download: when it ends, with or without the blob, they are deleted (and any left over by a crash at the next start), so a client's later retry starts over unless the blob was completed. sic_resumed_downloads_total counts the continuations and sic_resumed_bytes_total the bytes that did not have to be fetched again. Resuming needs a source that honours Range: a peer that holds the whole blob does, one that is still downloading it does not (it is passed over), and registries and their CDNs generally do.

Download limits

A digest can only be checked once a download has finished, so SIC bounds what it will accept before then:

  • A blob from a peer or registry must declare its Content-Length; that length is the most SIC will write, and it must fit on the disk.
  • A manifest may be at most 4 MiB. Its digest is computed from its content; a Docker-Content-Digest header is only cross-checked, never required.
  • SIC_MIN_FREE_BYTES (default 1 GiB, 0 for none) and SIC_MIN_FREE_PERCENT (default 20, 0 for none) are the free disk space that has to remain after a download; the larger of the two applies. When a download would break that, SIC first makes room (see below) and only then refuses it.
  • Responses are never decompressed on the way in, so the stored bytes are exactly what the digest covers.

Integrity

A blob is hashed while it is written, so it is known to be good when it lands in the cache. SIC remembers that (the blob's inode, size and modification time, in verified.json in the cache directory, saved every 30 seconds and on shutdown), and serves such a blob without hashing it again, also after a restart. A blob whose file changed, or that SIC has no record of, is hashed the first time it is opened; if it does not match its digest it is deleted and fetched again.

Hashing on the request path made the first read of every blob wait for a full pass over the file, and made every restart re-read the whole cache. To still find blobs that were damaged on disk without their metadata changing, a background scrubber checks every blob against its digest, slowly, and deletes the ones that do not match (logged, and counted in sic_corrupt_blobs_total):

  • SIC_SCRUB_INTERVAL (default 24h, 0 turns it off) is the time between complete passes. The time of the last pass is saved, so restarts do not start a new one; a store that was never scrubbed waits ten minutes after start-up.
  • SIC_SCRUB_RATE (default 32 MiB/s, in bytes per second) limits how fast it reads.

Whatever consumes a blob verifies it as well: containerd checks layer digests, and a peer hashes what it receives.

Cache size and eviction

The cache no longer grows until the disk is full. When a download would leave less free space than the reserve above, or would take the cache over SIC_MAX_CACHE_BYTES (default 0: no limit), SIC removes the least recently used blobs until it fits, a little more than needed so that the next downloads do not each have to scan the cache. Only if even removing everything would not be enough does the download fail with 507; SIC does not empty the cache in vain.

  • The default reserve of 20% of the filesystem keeps SIC clear of the kubelet's own thresholds: with the usual defaults it starts evicting pods and garbage-collecting images when the image filesystem is less than 15% free. SIC's cache directory is normally on the same filesystem as containerd's. Lower SIC_MIN_FREE_PERCENT only if you know the node's eviction thresholds.
  • "Used" means stored or served. A blob stored or served in the last minute is never evicted, and neither is a blob that is being read or written at that moment. The time is kept in verified.json, not in the file's modification time, so it survives a restart.
  • The containerd import never evicts: it copies content that containerd already holds, so when the cache is full it stops for that run instead of pushing out blobs fetched for a pull. It also does not copy back what was evicted.
  • Exposed as sic_cache_bytes, sic_evicted_blobs_total and sic_evicted_bytes_total.

An evicted tag still resolves; the manifest is fetched again from a peer when somebody asks. Image names and their digests in aliases.json are removed only to keep the record to 50,000 names: past that, the ones confirmed longest ago (and those only imported from containerd) go first, and a name that was dropped resolves again only once something supplies it: the registry (with upstream fallback on), a peer, or a later containerd import. Until then a pull by that tag fails, even if its manifest is still cached.

Cost of an eviction: it reads the blob directory, stats every file and sorts them, then removes about 5% (the slack), so it runs once per 5% of growth, not once per download. Measured on a CI runner with 1 KiB blobs (SIC_EVICT_COST=1 go test ./internal/store -run TestEvictScanCost -v): 10 000 blobs 24 ms, 50 000 blobs 135 ms, 100 000 blobs 298 ms. A download that needs room waits for it, but no other request does. An in-memory index of sizes and last use would remove that wait at the price of keeping it correct against files that change on disk; it is not worth it below hundreds of thousands of blobs, and none has been added.

Upstream fallback

Set SIC_UPSTREAM_ENABLED=true and list the registries SIC may contact in SIC_UPSTREAM_REGISTRIES (comma separated, e.g. docker.io,ghcr.io). The registry is taken from the ?ns= parameter of the request; a registry that is not listed is refused. Upstream connections are verified against the system CA roots (the peer CA is only used between SIC nodes). The image carries the public roots of its build image, so Docker Hub, GHCR and the like work as they are.

A registry with a private CA (the usual case in an air-gapped cluster) needs that CA to be trusted too. SIC honours SSL_CERT_FILE and SSL_CERT_DIR for its upstream connections, and when either is set it trusts only what they name: the image's own public bundle is no longer loaded alongside. Put a bundle that holds your CA and any public roots you still need in a ConfigMap or Secret, mount it in the pod and point SSL_CERT_FILE at it. A setting that names no certificate stops SIC at startup instead of widening the trust. For example, for a bundle mounted at /etc/sic-roots/ca-bundle.crt:

env:
- {name: SSL_CERT_FILE, value: /etc/sic-roots/ca-bundle.crt}
volumeMounts:
- {name: upstream-ca, mountPath: /etc/sic-roots, readOnly: true}

Registries that need a token

Most registries, Docker Hub and GHCR among them, answer an anonymous request with 401 and a WWW-Authenticate challenge that says where to get a token. SIC passes that challenge on, unchanged, to containerd (up to four values of at most 4 KiB each). containerd fetches a token from the registry's own authentication service and repeats the request with Authorization: Bearer ..., which SIC forwards to the registry. The content is then cached like any other. Credentials never rest in SIC: the Authorization header is only passed on, and is not stored or logged. A rejected or expired token gets the challenge again. sic_upstream_auth_challenges_total counts the challenges relayed; they are not logged, since every anonymous pull starts with one.

A 401 without a WWW-Authenticate header cannot be acted on, so it ends as a 404 (which sends containerd on to its next host) and is logged.

By default the cache does not check who is asking. Once a blob or tag has been fetched with someone's credentials, any client that can reach this node's SIC, and knows the digest or tag, gets it without credentials. For private images that means every client the listener accepts can read them: with mTLS, every holder of a certificate signed by your CA; with SIC_INSECURE=true, anyone who can reach the port.

Protected registries. List a registry in SIC_PROTECTED_REGISTRIES (comma separated; each must also be in SIC_UPSTREAM_REGISTRIES with SIC_UPSTREAM_ENABLED=true, or startup fails) and SIC stops taking that for granted. Before it answers a client's request for a blob or manifest of that registry, from its cache or the registry, it sends the registry a HEAD for the same path with the client's own Authorization. Only a success lets the request go on. A client with no credentials, or ones the registry refuses, gets the registry's own answer (its 401 and challenge, so containerd fetches a token and asks again; or 403/404). A yes is remembered for 60 seconds per credential and request path, so a client is never given from the cache what the registry would not give it for that path, and a repeated request does not ask again; revoked access is felt within a minute. A pull of many layers asks once per layer. If the registry cannot be reached, a request without an unexpired yes (see above) is answered 503: SIC cannot confirm anyone, so it does not pass them. That is the price of the check, and the reason it is opt-in: do not protect a registry that you need SIC to serve while the registry is down. The namespace of a request is the client's word, so content that came from a protected registry is guarded wherever it is asked for: a blob or manifest that was given out under a protected registry carries a mark on disk, and asked for under any other namespace it is handed over only if that registry (which must be an upstream one) confirms the client for it, so a layer shared with a public image costs one extra HEAD. The mark is made before content is stored or given out (also when another node asks for it), is never removed (not at an eviction, not at a restart: the same bytes may come back from another node or from containerd, and are still that registry's), and costs an empty file (an inode) per digest ever given out under a protected registry, which SIC_MAX_CACHE_BYTES does not count: provision the cache volume's inodes for it, and if that volume runs out, protected content is refused with 503 rather than given out unmarked. A tag of another namespace that leads to such a digest is treated the same way, and so is a download that was marked while a client was joining it. Start protecting a registry on an empty cache: what was cached before has no mark. With mutual TLS a node is told from a client by its certificate ("TLS"), not by the X-SIC-Peer header, which anyone can send: a request counts as coming from another node only if its verified client certificate carries SIC's name. Nodes are not asked for credentials (the node that has the client in front of it has asked the registry already, and says so in the X-SIC-Protects header of its request: a node that does not protect the registry, such as one not yet updated while protection is being switched on, is refused, so set SIC_PROTECTED_REGISTRIES the same on every node), and protected content is shared between them like any other, so a blob that a node already holds is not downloaded again. The one-download-per-cluster coordination does not carry over: the coordinator sends no credentials, so for a registry that needs them a node that cannot get the blob from a peer fetches it from the registry itself, with the client's credentials, and nodes that miss at the same moment each do so. The price is the one stated at the top of this section: whoever holds a node's certificate and key can read what the nodes hold, so give each node its own certificate and keep it in that node's pod. Without TLS (SIC_INSECURE=true, development only) a peer cannot be told from a client: protected content is then not shared between nodes at all, and the header opens nothing. sic_access_checks_total and sic_access_denied_total count the checks and the refusals. Without the setting, keep upstream fallback off for registries whose content must not be shared on the node.

Tags: staying current, and who is believed

A digest never changes, but a tag such as latest does, and a tag has no digest to check an answer against. SIC handles the two ways a cached tag can be wrong.

Out of date. When the tag's registry can be asked (upstream fallback on, registry listed), a cached tag older than SIC_TAG_TTL (default 10m; 0 never asks again) is confirmed first: SIC sends the registry a HEAD for the manifest, which returns the digest and, on Docker Hub, does not count against pull rate limits. If the tag still points at the same digest it is served and the clock restarts; if it moved, the new manifest is fetched. sic_tag_checks_total counts the checks and sic_tag_changes_total the tags found to have moved. An alias that came from containerd was never confirmed, so it is checked at its first use, and the periodic import never replaces an alias the cache already has.

False. One faulty or compromised node could otherwise tell every other node that latest is some other image. So when the registry can be asked, it says what a tag points at; the manifest is then fetched by digest, from a peer if one has it, and checked against that digest. Peers decide what a tag means only when the registry cannot be asked: air-gapped nodes, or a registry that is not listed. There the CA that vouches for the peers is the trust boundary.

When the registry cannot confirm a tag (unreachable, or it wants credentials the client did not send), SIC serves the cached one rather than fail the pull, logs it at most once a minute, and counts it in sic_stale_tags_served_total. A tag the registry no longer has stays cached. Requests from other nodes are answered from the cache whatever the tag's age, since they cannot be sent anywhere better. The time of each confirmation is kept with the record of verified blobs; losing it only means tags are checked again.

Failures

When SIC cannot cache something it says why, instead of answering 404 as if the image did not exist:

  • 507 when the free disk space would drop below SIC_MIN_FREE_BYTES (or the disk is full); counted in sic_disk_full_total.

  • 500 when the cache directory cannot be written; counted in sic_store_errors_total.

  • 429 when an upstream registry is rate limiting: the status and a safe Retry-After are passed on, so containerd knows to back off. A cached tag is served instead, as for any registry that cannot confirm it.

  • 400 for a repository name that is not valid per the OCI distribution spec. This is the caller's mistake and does not take any peer out of rotation.

  • 503 for content of a protected registry when the registry cannot be reached and the client has no unexpired yes ("Upstream fallback", "Protected registries"). This is by design, and it means SIC is never the way to pull private images while their registry is down: to keep private content available through an outage you must not protect that registry, and then everyone who holds a client certificate can read it. You cannot have both with SIC; choose per registry. There is no "last known good" window, on purpose: it would keep serving a layer to a client whose access was just revoked.

Both conditions, and non-404 answers from peers and upstream registries, are logged at most once per minute per cause, with a count of the lines held back.

Settings

All settings are environment variables. A value that cannot be parsed (a duration without a unit, a negative size) is ignored and the default is used, so check the startup log after changing one. The sections above explain the ones that need explaining; this is the complete list.

Variable Default Meaning
SIC_LISTEN :5000 Address of the registry listener.
SIC_ADMIN_LISTEN unset Plain-HTTP address for /healthz, /readyz and /metrics; use a loopback address.
SIC_CACHE_DIR /var/lib/steady-image-cache Where blobs, manifests and the records live.
SIC_TLS_CERT, SIC_TLS_KEY, SIC_TLS_CA unset Server certificate, key and the CA that client certificates must come from. Required unless SIC_INSECURE=true.
SIC_TLS_CLIENT_CERT, SIC_TLS_CLIENT_KEY the server pair Certificate this node presents to its peers.
SIC_TLS_SERVER_NAME steady-image-cache DNS name a peer's certificate must carry.
SIC_INSECURE false Run without TLS or client authentication. Development only.
SIC_KUBERNETES_DISCOVERY true Find peers through the Kubernetes API. Needs POD_NAMESPACE, POD_NAME and NODE_NAME.
SIC_POD_LABEL_SELECTOR app=steady-image-cache Which pods are peers.
SIC_PROTECTED_REGISTRIES unset Registries whose content is served only to a client the registry itself confirms (see "Protected registries"). Each must also be an upstream registry.
SIC_PEERS unset Fixed peer URLs, comma separated, instead of or in addition to discovery. They must be https:// unless SIC_INSECURE=true; startup fails otherwise.
SIC_PEER_PORT 5000 Port on which discovered peers listen.
SIC_PEER_TIMEOUT, SIC_PEER_BACKOFF, SIC_PEER_MAX_TRIES 5s, 30s, 4 See "Peer requests".
SIC_PEER_WATCH true Follow pods with a watch instead of listing every 30s. See "Health and metrics".
SIC_COORDINATE, SIC_COORDINATE_WAIT, SIC_COORDINATE_ANONYMOUS_TOKEN true, 20s, false One fetch per digest for nodes that miss at the same moment. See "Simultaneous pulls".
SIC_ENDPOINTSLICE_DISCOVERY false Experimental. List peers from EndpointSlices as well as pods, for clusters of some hundreds of nodes. See "Large clusters".
NODE_ZONE unset Experimental. This node's zone: peers in it are asked first. See "Large clusters".
SIC_DIGEST_GOSSIP, SIC_GOSSIP_INTERVAL false, 3m Experimental. Nodes exchange filters of the blobs they hold, and a miss asks the likely holders first. See "Large clusters".
SIC_UPSTREAM_ENABLED false Fetch misses from registries.
SIC_UPSTREAM_REGISTRIES unset The registries that may be contacted, comma separated. Anything else is refused.
SIC_UPSTREAM_TIMEOUT 30s Bounds connecting to a registry, and how long a transfer may go without receiving data (peers and registries alike).
SIC_TAG_TTL 10m See "Tags".
SIC_MIN_FREE_BYTES, SIC_MIN_FREE_PERCENT, SIC_MAX_CACHE_BYTES 1073741824, 20, unset See "Cache size and eviction".
SIC_SCRUB_INTERVAL, SIC_SCRUB_RATE 24h, 33554432 See "Integrity" (the rate is bytes per second).
SIC_CONTAINERD_IMPORT true Import containerd's content and image names.
SIC_CONTAINERD_CONTENT_DIR unset containerd's content directory as the pod sees it (it holds blobs/sha256/). A blob that is a file there is linked into the cache instead of copied. See "The import without a second copy".
SIC_CONTAINERD_ADDRESS, SIC_CONTAINERD_NAMESPACE /run/containerd/containerd.sock, k8s.io Where to find containerd.
SIC_IMPORT_INTERVAL 5m How often the import runs.

Health and metrics

With mTLS enabled the main listener requires a client certificate on every path, including /healthz, which kubelet cannot present. Set SIC_ADMIN_LISTEN (the sample DaemonSet uses 127.0.0.1:5001) to serve /healthz, /readyz and /metrics over plain HTTP on that address as well.

/healthz answers 200 while the HTTP server can answer at all; it is the liveness probe, and only a hung process should fail it. /readyz answers 503, with the reason, when the cache directory cannot be written (read-only, unmounted, permissions) and 200 otherwise; it is the readiness probe from the first release that has it; the sample manifest switches to it with that release, because a probe for a path the pinned image lacks would mark every pod NotReady. Other nodes list peers by pod readiness, so a node whose cache is broken leaves their lists at their next listing instead of failing their requests. The node keeps serving containerd while unready. A full disk is not a failure here: a node that cannot store more can still serve what it holds, and the disk-full counters and 507 answers report it.

Metrics on the admin (or main) listener, all counters unless noted: sic_local_hits_total, sic_peer_hits_total, sic_upstream_hits_total and sic_misses_total count how each blob request ended; sic_peer_errors_total peers that failed or were slow; sic_verify_errors_total content refused because it did not match its digest or its declared length; sic_containerd_imported_blobs_total and sic_containerd_imported_bytes_total what the import copied, sic_containerd_linked_blobs_total what it linked instead. Bytes. The hit counters count requests; four counters count the traffic itself, for blobs and manifests: sic_bytes_to_clients_total (sent to containerd on this node, for a range request only the range; a layer streamed while it downloaded and then failed verification counts what was sent before it was cut off), sic_bytes_to_peers_total (sent to other SIC nodes), sic_bytes_from_peers_total and sic_bytes_from_upstream_total (read from peers and from registries). The two "from" counters count what was read, so content that was then refused or cut short is included: that is the traffic it cost. Bytes the containerd import copied are in sic_containerd_imported_bytes_total. Two sums over all nodes answer the question the cache exists for: sum(rate(sic_bytes_to_clients_total[1h])) is what the cluster's pulls asked for, sum(rate(sic_bytes_from_upstream_total[1h])) is what the registries had to send, and the first minus the second is the traffic SIC kept away from them (it excludes blobs that containerd already had, which never reach SIC). The share served inside the cluster is sum(rate(sic_bytes_to_peers_total[1h])) against the first.

The others are named where their behaviour is described above.

Pre-packaged Prometheus alerting rules (deploy/monitoring/prometheus-rules.yaml) and an enterprise Grafana dashboard (deploy/monitoring/grafana-dashboard.json) are available in the repository.

sic_peers is the number of peers this node would currently ask. Kubernetes discovery lists the pods once (with resourceVersion=0, which the API server answers from its cache instead of reading etcd) and then follows them with a watch, keeping only Ready ones, so a neighbour that becomes Ready, or goes away, is known within moments. The watch needs the watch verb on pods, which the sample RBAC grants; without it the node says so in its log and lists every 30 seconds instead. It lists again when the server ends the watch (after five minutes), when the server says it has lost the point to resume from, and when a miss finds no peers (at most every 5 seconds). SIC_PEER_WATCH=false always lists every 30 seconds. While a list or watch cannot be made, the node keeps the peers it knew.

Large clusters

Three optional features, all off by default, for clusters where asking peers at random gets expensive. All three are experimental: they are tested on kind clusters and a computed cost model, not on a real cluster of the size they are for, and their behaviour or settings may change in a minor release until they are measured there. Do not turn them on for a production cluster without measuring on a copy of it first; the base peer protocol needs none of them.

  • EndpointSlice discovery (SIC_ENDPOINTSLICE_DISCOVERY=true) reads the peers from the EndpointSlices of a Service that selects the SIC pods (SIC_POD_LABEL_SELECTOR is the label selector the slices are listed by; a slice carries the labels of its Service, so the Service needs the labels the selector names), watched like pods, instead of from every pod object. It runs next to the pod discovery, whose peers it adds to. The node needs get, list and watch on endpointslices in discovery.k8s.io, which the sample RBAC does not grant; and HOST_IP, so that it leaves itself out.

  • Zones (NODE_ZONE): peers in this node's zone are asked first, then those whose zone is not known, then the others. A peer's zone is learned from its EndpointSlice endpoint, so it works with EndpointSlice discovery only. The zone of the node itself has to be given: a pod cannot read its node's labels through the downward API, so set it per node pool or from your own tooling.

  • Digest gossip (SIC_DIGEST_GOSSIP=true): every node keeps a counting Bloom filter (64 KiB) of the blobs it holds, rebuilt from the cache every minute, and fetches the filters of its peers every SIC_GOSSIP_INTERVAL (a 304 when nothing changed). A miss asks the peers whose filter has the digest first, then those it has no filter for, then those whose filter says no. It only orders the peers: a filter can be minutes old and has false positives (under 1% at 10 000 blobs, more when the cache holds many more), so nothing is skipped, and SIC_PEER_MAX_TRIES is what keeps a miss short. The filter is served on the registry listener at /sic/index to other nodes only (the certificate check of "TLS"; a client gets 403), never on the admin listener.

    What gossip costs (measured by internal/peer/costmodel_test.go; SIC_COST_TABLE=1 go test ./internal/peer -run TestGossipCostModel -v prints the tables). The filter has a fixed size, so its usefulness depends on how many blobs a node's cache holds, not on the cluster size:

    blobs in a node's cache 1 000 5 000 10 000 25 000 50 000 100 000
    false positives 0% 0.01% 0.3% 8.7% 44% 89%

    A false positive ranks a peer that lacks the blob among those asked first, and SIC_PEER_MAX_TRIES is spent on it. Past about 20 000 blobs per node the order is mostly noise, and the feature is then close to asking in random order, as without it: a miss that asks only SIC_PEER_MAX_TRIES peers can use them on peers that lack the blob and miss the one that has it, and then goes to the registry, or fails when SIC_UPSTREAM_ENABLED is off; a cache of 100 GiB with typical layers holds a few thousand blobs, a cache of many terabytes of small blobs more. A node holds one 64 KiB filter per peer and asks every peer once per interval, so a cluster of N nodes costs each node N * 64 KiB of memory (65 MB at 1 000 nodes, 330 MB at 5 000) and N / interval requests per second (5.5 per second at 1 000 nodes with the default 3 minutes). Most answers are 304; a full answer is 87 KB before TLS, so while caches are changing quickly, as in a cold rollout, the worst case is N * 87 KB per node per interval (87 MB at 1 000 nodes). Up to a few hundred nodes this is small; beyond that, raise SIC_GOSSIP_INTERVAL. What is not measured is the effect on pull time and registry traffic in a real cluster of that size; until it is, treat the feature as one for clusters of tens to a few hundred nodes.

Registry mirror

Two sample configurations, to be installed on each node with the certificate paths adjusted for your environment. In both, client names containerd's own client certificate and key, a client-only pair from the same CA (see "TLS"), not the files of the SIC pod: do not copy the DaemonSet's tls.key to the node for this.

  • deploy/containerd/mirror-hosts.toml is the one to start from when the nodes can reach the registries (or an internal registry). Install it as /etc/containerd/certs.d/<registry>/hosts.toml, once per registry you want cached. SIC is a mirror: containerd asks it first and goes on to the registry when SIC does not answer or does not have the content. A node whose SIC pod is down, restarting or being upgraded still pulls, and SIC's own image is never held hostage by SIC. The sample advertises only the pull capability, not resolve: containerd asks the registry which digest a tag names, then fetches the manifest and layers by digest from SIC. A tag that has moved is therefore never answered from an old cached or imported alias, which SIC cannot rule out when it has no way to ask the registry itself. Add resolve only when upstream fallback is enabled for that registry (SIC_UPSTREAM_ENABLED=true and the registry in SIC_UPSTREAM_REGISTRIES); SIC then confirms tags against it after SIC_TAG_TTL. A registry with a private CA also needs a root-level ca entry in its hosts.toml (commented in the sample): the ca under the SIC host trusts SIC only, so without one the fallback to the registry fails TLS verification. To have SIC fetch and cache what no node has yet, enable upstream fallback for that registry; without it a miss is a 404 and containerd takes the content from the registry directly, uncached.
  • deploy/containerd/hosts.toml makes SIC the only host for every registry (_default). Use it only when nothing but the peers can supply images, as in an air-gapped cluster without an internal registry. containerd cannot fall through to anything else then, so read "Upgrading" below first.

Automated containerd setup (sic init-node)

Setting up /etc/containerd/certs.d and client certificates manually across many nodes can be automated using sic init-node. When run on a node or as an initContainer in a DaemonSet, it automatically copies client certificates with secure permissions (0600 for keys, 0644 for certs) and generates hosts.toml for the configured registries:

# Direct run on a node:
sic init-node

# Or inside an initContainer with host root mounted at /host:
SIC_INIT_HOST_PREFIX=/host SIC_INIT_REGISTRIES=docker.io,ghcr.io sic init-node

The Helm chart in charts/steady-image-cache includes this init container enabled by default. It copies containerd's client pair from its own Secret (initContainer.clientTLS.secretName, mounted at /tls-client), never from the DaemonSet's tls Secret: that key is the node's identity, and a certificate that lists tls.serverName would make containerd count as another SIC node (see "TLS"). With tls.certManager.enabled the chart creates that client-only certificate (client auth, no DNS name); otherwise create the Secret (ca.crt, tls.crt, tls.key) yourself. A sidecar (initContainer.refreshInterval, default 5 minutes, 0 for none) repeats the setup, so a renewed certificate reaches the node's copy before the old one expires: sic init-node does that itself when SIC_INIT_INTERVAL is set, keeping the previous files when a run fails. The chart derives the probe port from config.adminListen; serviceMonitor.enabled needs an adminListen that Prometheus can reach (it refuses the loopback default) and creates the headless Service the monitor selects. The admin paths have no authentication: limit who can reach them.

The import without a second copy

The import reads containerd's content through its API, which hands over bytes, not files, so by default it copies every blob into SIC's cache and an image lies on the disk twice. With SIC_CONTAINERD_CONTENT_DIR set to containerd's content directory, mounted read-only into the pod (the sample does this; the path is containerd's root, /var/lib/containerd by default, plus io.containerd.content.v1.content, and differs on k3s and others), SIC makes the blob's place in its cache a symbolic link to containerd's file. Nothing is copied, sic_containerd_linked_blobs_total counts it, and it does not count against SIC_MAX_CACHE_BYTES or the free-space limits, because it is not the cache's space.

What that means in use:

  • A linked blob is read, and verified against its digest, like any other, once and again whenever the file changes. A file that does not match costs the link, never containerd's file, which SIC cannot write to.
  • The blob lives as long as containerd keeps it. When containerd's garbage collector removes it (the image was deleted), the link is removed the next time it is looked at, and the blob is a miss like any other: fetched from a peer or the registry when somebody asks. Deleting an image therefore also takes it out of what this node offers its peers.
  • A linked blob is never evicted, since evicting it would free nothing. A cache of linked blobs can be bigger than its limit; its own blobs are still evicted to stay within it.
  • The import is unchanged when the directory is not set, is not mounted, or does not hold the blob (a different root, say): it copies, and sic_containerd_imported_blobs_total counts. If sic_containerd_linked_blobs_total stays at zero on a node that has images, the path is wrong.
  • The link is by name, so the cache directory and the mount path must be the same on every start of the pod; with a changed path the old links dangle and are removed, and the content is copied or linked again.
  • While SIC_PROTECTED_REGISTRIES is set, everything the import adds, linked or copied, is marked as protected content (see "Protected registries"): containerd's content has no origin the cache knows, and may be a private image. It is handed to a client only after the registry of the request's namespace confirms that client, which costs one extra HEAD per layer, and it is not shared between nodes under an unprotected namespace. A blob that cannot be marked is not imported; content the cache held before is left as it was.

TLS

The sample DaemonSet expects a steady-image-cache-tls Secret containing:

  • tls.crt
  • tls.key
  • ca.crt

What the certificate must contain

A node uses one certificate for three things, and each has a requirement that fails with a handshake error that does not say why:

Used for Requirement
Peers calling this node A DNS SAN equal to SIC_TLS_SERVER_NAME (default steady-image-cache). Peers are found by IP address but verify this name, so no IP SAN is needed for peers. The extended key usage must allow server auth.
This node calling peers The same certificate is presented as a client certificate, so the extended key usage must also allow client auth. cert-manager's default usages do not include it. A certificate with no extended key usage at all is allowed for everything.
containerd calling this node Both sample hosts.toml files name SIC as https://127.0.0.1:5000, and containerd checks that address: the certificate needs the IP SAN 127.0.0.1. (hosts.toml has no setting to check a name instead.)

The name is also what makes a request a node's. The certificate must list SIC_TLS_SERVER_NAME itself as a DNS name (compared without regard to case): a wildcard (*.example.com for sic.example.com) is not enough, and a client certificate with a wildcard that would match is not taken for a node's either. The same holds the other way: a node that asks a peer for something (a tag, a blob) refuses a server whose certificate does not list the name, so a holder of the wildcard cannot pose as a peer. A client certificate that carries the DNS name SIC_TLS_SERVER_NAME is a node: its requests with the X-SIC-Peer header are served from the cache without credentials, and for content of a protected registry also with the X-SIC-Protects header, which a node sends only for a registry it protects itself; without that header such a request is refused. Give containerd (and any other client) a certificate that does not carry that name, as the sample's client-only pair does. Each node can, and should, have a certificate of its own (same name, its own key, same CA): then one node's key leaking does not mean re-issuing everything at once, and with an issuer that can issue per pod (cert-manager's csi-driver, say) nothing but the pod ever holds its key. The sample Secret shares one pair between all nodes because it is the simplest thing that works. The Helm chart does the same: with tls.certManager.enabled it asks cert-manager for one certificate and every pod mounts that one Secret, so whoever can read it (anything that can read Secrets in the namespace, or any pod that mounts it) holds a key that every node accepts. Per-pod certificates need an issuer that can issue per pod, such as cert-manager's csi-driver; the chart has no option for that yet, so in a cluster where that matters use the csi-driver and mount its volume in place of the Secret by patching the DaemonSet, and restrict who can read the Secret in the meantime.

All of them must be signed by the CA in ca.crt (an intermediate CA is fine if tls.crt carries it after the certificate) and be in date.

SIC checks its own certificate when it starts and after every rotation, and logs what it finds as tls: certificate problem: ..., with what to change. It still uses the certificate: a warning does not stop a pull that works. The IP SAN message is only a warning because only containerd needs it. A certificate that expires within 14 days is reported too, which shows that renewal has stopped.

A certificate that satisfies all of this, made with OpenSSL (a throwaway CA; use your own PKI in production):

openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 3650 -subj "/CN=sic-ca" \
  -addext "basicConstraints=critical,CA:TRUE" -addext "keyUsage=critical,keyCertSign" -keyout ca.key -out ca.crt
openssl req -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -subj "/CN=steady-image-cache" -keyout tls.key -out tls.csr
openssl x509 -req -in tls.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 365 -out tls.crt -extfile <(printf '%s\n' \
  'subjectAltName=DNS:steady-image-cache,IP:127.0.0.1' 'extendedKeyUsage=serverAuth,clientAuth' 'keyUsage=critical,digitalSignature')
kubectl -n kube-system create secret generic steady-image-cache-tls --from-file=tls.crt --from-file=tls.key --from-file=ca.crt

With cert-manager, the part that matters in a Certificate is:

spec:
  secretName: steady-image-cache-tls
  dnsNames: [steady-image-cache]
  ipAddresses: [127.0.0.1]
  usages: [digital signature, key encipherment, server auth, client auth]

containerd presents a client certificate too (client in hosts.toml), from files on the node (/etc/steady-image-cache/ in the sample). Getting them there is up to your node provisioning; the Secret is only mounted into the pod. Give containerd a certificate of its own from the same CA, with only the client auth usage, rather than a copy of the node's server key: the files are readable by anything on the node that can read /etc.

SIC refuses to start unless mutual TLS is fully configured: SIC_TLS_CERT, SIC_TLS_KEY and SIC_TLS_CA are all required (SIC_TLS_CLIENT_CERT and SIC_TLS_CLIENT_KEY default to the server certificate). Without them it would either serve plain HTTP on every interface or accept any client. For local development only, SIC_INSECURE=true turns TLS and authentication off completely and logs a warning.

The certificate, key and CA files are re-checked every 10 seconds and reloaded when they change, for the listener and for connections to peers alike, so a rotated Secret takes effect without restarting the pod. If a new set is unusable (a half-finished rotation, say) SIC logs it and keeps the previous one. The Kubernetes service account token used for peer discovery is likewise read afresh for every request.

A cache serves any client that presents a valid certificate. Unless the registry is listed in SIC_PROTECTED_REGISTRIES ("Upstream fallback") it does not check registry credentials, so a blob that was pulled with credentials can be read by anyone holding a client certificate and the blob's digest. Treat the client CA as the access boundary.

Build

go mod download
go test ./...
docker build -t steady-image-cache:dev .
docker run --rm steady-image-cache:dev --version

The release build stamps its version with --build-arg VERSION=...; without it the binary reports dev. go.mod names the Go version the tests and linters use; the Dockerfile builds the release with the Go 1.27 image. SIC reads containerd through the github.com/containerd/containerd/v2 client library, which works against containerd 1.7 and 2.x daemons.

How a change is made, what CI checks and what a release needs are in CONTRIBUTING.md and RELEASING.md.

End-to-end test

test/e2e/run.sh runs SIC on a three-node kind cluster, deployed from deploy/daemonset.yaml with a real containerd. One worker already has an image; SIC imports it. The other worker pulls the image by digest through SIC, with no registry reachable at all, so the pull can only succeed if peer discovery, mutual TLS and the import all work. It then checks the peer-hit counters. It needs docker, kind, kubectl and openssl, takes a few minutes, and runs in CI (.github/workflows/e2e.yml) when code or deployment files change. KEEP=1 test/e2e/run.sh leaves the cluster up for inspection.

A second phase puts a real registry (registry:2, served over HTTPS with a certificate from the test CA) behind SIC as the upstream. It checks that the private CA reaches SIC through SSL_CERT_FILE; that a pull by tag goes to the registry once and the next node gets the blobs from its peer, which the registry's own log confirms; that a tag moved in the registry is not served at its old digest; and that when the registry is gone a cached tag is still served and counted in sic_stale_tags_served_total.

A third phase puts a second registry that wants a password (HTTP Basic) behind SIC. A pull with no credentials or the wrong ones is refused and nothing is fetched; with the right ones it works, the password is found neither in SIC's cache directory nor in its logs, and the next node gets the blobs from its peer. The same phase pins the boundary described under "Upstream fallback": a node that has fetched an image with credentials serves its tag to a client that has none, a node that has fetched nothing cannot, and a digest is handed over by any peer that has it.

A fourth phase installs the sample mirror configuration, deploy/containerd/mirror-hosts.toml (only the registry's name and its CA filled in), for a registry that SIC is not allowed to contact. It checks that containerd goes on to the registry when SIC has nothing, over the registry's own CA through the sample's root-level ca; that what it fetched there reaches SIC through the containerd import, so the next node gets it from its peer and the registry serves no blob twice; that a pull still works, straight from the registry, while SIC's port refuses connections on the node, as it does when its pod is gone; and that a moved tag is followed with the sample's pull-only capabilities. It also pins the hazard the sample warns about: with resolve added and no way for SIC to check tags, a node is handed the old digest by a peer's imported alias.

MODE=registries test/e2e/run.sh (the workflow e2e-registries.yml, run on release tags, weekly and by hand, not on every pull request) deploys the same way and pulls from public ECR and GHCR through their own anonymous token services, then from a second node through the first. Public registries throttle shared addresses, so a registry that keeps answering 429 is skipped with a warning and the others still decide the result; the run fails if every registry was throttled, since then nothing was checked. It does not cover Docker Hub or private images behind a token service; the relay of their challenges is tested in the unit tests against a fake registry.

MODE=operations test/e2e/run.sh (the workflow e2e-operations.yml, on changes to the code or the manifest) is the upgrade test: on a cluster whose nodes already hold a cache it replaces the pods with the previous release's image (the newest vX.Y.Z tag older than the one the manifest names), a node at a time, and then with the current build again. After each step every node must still serve, from its cache alone (the registry is paused), a manifest and a layer whose bytes match their digests; with the first node upgraded and the others not, a pull by digest on one must be served by the cluster, both ways, while the registry is unreachable. It checks what a rollback or a rolling upgrade could lose; it does not kill a pod during a download, which needs a registry slow enough to catch it.

e2e-containerd.yml runs the same test on kind nodes with containerd 1.7 (kindest/node:v1.30.0) and 2.x (kind's default image); each leg prints the version its nodes have and fails if it is not the one it names. It found that the sample hosts.toml for _default was refused by containerd 1.7.15 (see the changelog).

test/e2e/helm.sh (the workflow e2e-helm.yml, on changes to the chart or the code) does the same for the Helm chart: it installs cert-manager and the chart with helm install on a kind cluster, checks what sic init-node left on every node (files, modes, hosts.toml, a client-only certificate that does not name SIC and is not the pod's key), pulls an image on one node from another through the mirror it configured, then has cert-manager issue both certificates again and checks that every node's copy follows, that SIC presents the new server certificate, and that a pull afterwards still works. test/helm/test.sh renders the chart; test/monitoring/test.sh runs promtool on the alert rules (both copies) with unit tests of the alerts, and parses every expression of the Grafana dashboard.

Endpoints

  • GET /v2/
  • GET|HEAD /v2/<repo>/blobs/<digest> (including byte ranges)
  • GET|HEAD /v2/<repo>/manifests/<reference>
  • GET /metrics
  • GET /healthz
  • GET /readyz

Deployment

Helm Chart (Recommended)

A production-ready Helm chart is provided under charts/steady-image-cache and published as an OCI artifact to GitHub Packages. It supports automated containerd hosts.toml configuration via an init container, cert-manager integration, ServiceMonitors, and PrometheusRules:

# Install directly from GitHub Container Registry (OCI):
helm install steady-image-cache oci://ghcr.io/steadyinfratech/charts/steady-image-cache \
  --version 1.3.3 \
  --namespace kube-system \
  --set initContainer.enabled=true \
  --set config.upstreamEnabled=true \
  --set config.upstreamRegistries="{docker.io,ghcr.io}"

# Or from local source:
helm install steady-image-cache ./charts/steady-image-cache \
  --namespace kube-system \
  --set initContainer.enabled=true \
  --set config.upstreamEnabled=true \
  --set config.upstreamRegistries="{docker.io,ghcr.io}"

Manifest

deploy/daemonset.yaml is a starting point, not a finished product; it needs the TLS secret steady-image-cache-tls and an image reference you have chosen. What it does, and why:

  • Image. The manifest names the release image ghcr.io/steadyinfratech/steady-image-cache:v1.3.3; pin the tag you have tested, or an @sha256: digest. (:main is the branch build and is not meant for production; :latest follows the newest release.) Images are published for linux/amd64 and linux/arm64. imagePullPolicy stays IfNotPresent (see Bootstrap).
  • Root, with nothing else. The container runs as root only because containerd's socket is normally root:root 0660. It drops every capability, cannot gain privileges, has a read-only root file system and the runtime's default seccomp profile. If you turn the containerd import off (SIC_CONTAINERD_IMPORT=false) it needs no socket and can run as a non-root user that owns the cache directory.
  • Resources. Requests of 50m CPU and 64Mi memory; a memory limit of 512Mi to catch a leak. There is no CPU limit on purpose: hashing a layer is bursty, and throttling only makes pulls slower.
  • Probes. Readiness uses /readyz and liveness /healthz, both on the plain-HTTP admin port, because kubelet cannot present the client certificate the main port wants. The liveness probe waits for a minute of failures before restarting: a restart interrupts transfers under way.
  • Scheduling. system-node-critical, so node pressure does not evict the cache, and a toleration for every taint, so it also runs on control-plane, GPU and spot nodes. Narrow the toleration to keep it off some nodes. If you lower the priority class, a node that is short of memory may lose its cache pod; pulls still work, but go to the registry.
  • Cache size. Unset, the cache may use the disk until 20% and 1 GiB remain, then evicts (see "Cache size and eviction"). A commented SIC_MAX_CACHE_BYTES shows how to cap it.

CI validates the manifest against the Kubernetes schemas (strictly, for 1.28 and 1.31) and runs deploy/check_manifest.py, which checks that ports, probes and labels agree with each other and with SIC's settings and that the security settings stay in place.

Bootstrap

With deploy/containerd/hosts.toml as the _default configuration, SIC is the only host containerd tries. If SIC is not running on a node, nothing can be pulled there, SIC's own image included. So after a node restart or a node-image upgrade the image must already be on the node: keep imagePullPolicy: IfNotPresent, pin the tag or digest so a changed tag does not need a pull, and bake the SIC image into the node image or pre-pull it before hosts.toml is installed. Using deploy/containerd/mirror-hosts.toml for the registries you cache instead of _default removes the problem: containerd falls back to the registry, and the registry that holds SIC's image can simply be left without a hosts.toml.

Upgrading

The DaemonSet uses the host network and a fixed port, so a new pod cannot start next to the old one (no surge): the old SIC stops, then the new one starts and needs its image. What that costs depends on the configuration:

  • Mirror configuration (mirror-hosts.toml). Nothing special. While SIC restarts, containerd pulls from the registry; the new image comes from the registry too. Raise maxUnavailable (for example 10%) to roll out faster, since a restarting node only loses its cache for a moment.

  • SIC as the only host (_default). The new image has to be on the node before the old pod stops, or the new pod sits in ImagePullBackOff with nothing able to pull it. Pulling it through SIC works only when SIC can get it from somewhere: from a peer that already has it, or from the registry if upstream fallback is enabled for the registry that holds it. With the sample's SIC_UPSTREAM_ENABLED=false no node has it yet, a crictl pull gets a 404, and nothing falls through. So seed it first:

    1. On one node, load the image into containerd's k8s.io namespace from an archive made with docker save or ctr images export: ctr -n k8s.io images import sic-vX.Y.Z.tar. By default this loads only the platform of the node it runs on (--all-platforms is off for ctr images import and ctr images export), so on a cluster with more than one CPU architecture seed one node per architecture; a node of another architecture asks for a manifest and layers that no peer has, and with upstream off that pull fails.
    2. SIC copies containerd's content and image names into its cache when it starts and every SIC_IMPORT_INTERVAL (five minutes by default), one blob at a time. Do not go on until crictl pull of the exact image reference you will deploy succeeds on a second node of the same architecture that does not have it. sic_containerd_imported_blobs_total is not a signal for this: it counts every blob of the whole content store, so it rises for unrelated blobs, and for this image's manifest, before its layers are in SIC.
    3. Pull it on every other node: crictl pull ghcr.io/steadyinfratech/steady-image-cache:vX.Y.Z. Each is served by a peer. Asking is capped at SIC_PEER_MAX_TRIES peers per miss, so on a cluster larger than that, seed a few nodes per architecture, or load the archive on every node. (Enabling upstream fallback for the registry that holds the image makes steps 1 and 2 unnecessary.)

    With the Helm chart, the pre-pull DaemonSet does step 3 for you and needs no node access. It takes two upgrades, because Helm does not wait for a DaemonSet in a hook. The first must leave SIC itself exactly as it is: a newer chart brings newer default image tags, so pin the tags you run now and keep your other settings (--reset-then-reuse-values needs Helm 3.14 or later; it takes the new chart's defaults, then your last values):

    helm get manifest "$REL" -n "$NS" > before.yaml
    helm upgrade "$REL" <chart> --version <new chart version> -n "$NS" --reset-then-reuse-values \
      --set image.tag=<tag you run now> --set initContainer.image.tag=<tag you run now> \
      --set prepull.image.tag=<the new release's tag>@$DIGEST
    helm get manifest "$REL" -n "$NS" > after.yaml
    diff before.yaml after.yaml   # only the pre-pull DaemonSet (and chart labels) may differ; the SIC DaemonSet's pod template must not

    $DIGEST is the digest of the new release that you resolved and verified with cosign verify ("Verifying a release"); the value is the tag and the digest together, v1.3.3@sha256:..., so every node pulls the image you checked, not whatever the tag points to later. The pre-pull image comes from image.repository unless you set prepull.image.repository, so a mirrored or private repository is used for both. If initContainer.image.repository is a different repository (it is a separate setting), the pre-pull DaemonSet runs a second container from that repository with the same tag, so the init container's image is on every node too; set both repositories and both tags to the same verified value for the second upgrade.

    Then wait for the pre-pull DaemonSet, which is named like SIC's own plus -prepull (kubectl get daemonset -n "$NS"; with fullnameOverride that is the override plus -prepull): kubectl rollout status daemonset/<that name> -n "$NS". Done means every node has pulled the image, through the old SIC, so it depends on the same seeding of steps 1 and 2. The second upgrade sets image.tag and initContainer.image.tag to that same value and an empty prepull.image.tag, which removes the DaemonSet. The pre-pull pods run sic idle, take no resources to speak of, and are not peers (they do not carry SIC's labels). Only then change the tag in deploy/daemonset.yaml and roll out one node at a time (maxUnavailable: 1, the default), watching sic_peers and the pull errors on the first node before going on. A node that is already stuck without the image can be given it with ctr -n k8s.io images import from the same archive.

Either way, change the image tag (or digest) in the DaemonSet and nothing else in the same rollout, so that a problem is attributable.

Preloading an image before a rollout (sic preload)

sic preload pulls images through this node's own SIC, so the cache already holds them when a rollout asks. It uses the registry API as containerd does (with ?ns= naming the registry), so single-flight, peer fetches, protected-registry checks, the disk reserve and verification all apply; it adds no other way into the cache. Run it on a node, or in a Job with the node's certificate files mounted:

sic preload registry.example.com/team/app:v1.4.0 ghcr.io/org/worker@sha256:...
sic preload -f images.txt -admin http://127.0.0.1:5001 -platform linux/arm64
  • Names must include the registry (docker.io/library/nginx:1.27, not nginx:1.27): SIC has to be told which registry the content is of.
  • Platform: for a multi-platform image only the manifest for -platform (the node's by default) and its blobs are pulled.
  • Certificates: it connects as a client, with the files sic init-node leaves on the node (/etc/steady-image-cache/ca.crt, tls.crt, tls.key; flags -ca, -cert, -key, and -server-name if the certificate names SIC differently). -plain-http is for SIC_INSECURE=true only.
  • Credentials: SIC never holds them. If a registry answers with a token challenge, the command takes the credentials from the auths of the Docker config file of whoever runs it ($DOCKER_CONFIG/config.json, else ~/.docker/config.json; -docker-config names another file; in a pod, mount a Secret of type kubernetes.io/dockerconfigjson), per registry, or from SIC_PRELOAD_USERNAME and SIC_PRELOAD_PASSWORD in the environment (not on the command line), which win for their registry. The token is fetched by the command and forwarded by SIC, as with containerd. A credential is for one registry only: the environment pair is for the registry of the images if they all share one, otherwise name it with -credential-registry; an auths entry is for the registry it names. While pulling from any other registry neither is sent (a token realm is named by whoever answers for the registry), and only to an https realm. For a protected registry this is the only way it can work. Credential helpers and stores (credsStore, credHelpers) and identity tokens are not supported: the command says so when the file names one, and only auths entries with a user name and password (or auth) are used.
  • Where the bytes came from: with -admin, it prints what the node took from peers and from registries while it ran (the two byte counters of "Health and metrics"). That is also the registry-bytes-saved number for a real rollout: preload on one node, then on the others.
  • It checks every blob against its digest, runs -parallel (4) blobs at a time, and exits non-zero if any image failed.

It does not pin anything: a preloaded blob is eligible for eviction like any other once it is a minute old, so run it shortly before the rollout, not days.

Verifying a release

From 1.3.2 on, the image and the Helm chart of every release are signed with cosign without a key: the signature is made by the release workflow's own GitHub identity, and the certificate says which workflow and which tag. Verify with the identity of that release's tag, exactly, not a pattern: a pattern would also accept the signature of another release, and a registry writer could then point one tag at another release's image. Replace v1.3.3 below by the release you are verifying. A tag can be moved, so resolve it to a digest once, verify that digest, and use only the digest from then on: verifying the tag and then deploying the tag could hand you a different image than the one you checked.

IMAGE=ghcr.io/steadyinfratech/steady-image-cache
set -euo pipefail
DIGEST=$(docker buildx imagetools inspect "$IMAGE:v1.3.3" --format '{{printf "%s" .Manifest.Digest}}')

cosign verify \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  --certificate-identity https://github.com/SteadyInfraTech/steady-image-cache/.github/workflows/release.yml@refs/tags/v1.3.3 \
  "$IMAGE@$DIGEST"

Deploy only if cosign verify exited successfully (it exits non-zero when the signature or the identity does not match, and in a script set -e makes that stop the run), and deploy $IMAGE@$DIGEST, not $IMAGE:v1.3.3. In deploy/daemonset.yaml, use it as the image. In the chart, the image is built as repository:tag, so put the tag and the digest together in the tag value (Kubernetes accepts v1.3.3@sha256:... and then pulls by the digest), and do it in both places that run SIC, image.tag for the main container and initContainer.image.tag for the init containers; setting only one leaves the other on the tag you did not verify:

helm upgrade --install steady-image-cache ... \
  --set "image.tag=v1.3.3@$DIGEST" \
  --set "initContainer.image.tag=v1.3.3@$DIGEST"

The signature is on the digest, so the digest is what the check vouches for. The image index also holds, for each of the two platforms, a software bill of materials (SPDX) and the build's provenance, covered by the same signature (the chart has none); read them from the same digest:

docker buildx imagetools inspect "$IMAGE@$DIGEST" --format '{{ json .SBOM }}'
docker buildx imagetools inspect "$IMAGE@$DIGEST" --format '{{ json .Provenance }}'

The chart (its version is the tag without the v; the workflow is helm.yml) works the same way: resolve the digest once (crane digest, or oras resolve), verify it with the helm.yml identity, and install from the digest (helm install ... oci://ghcr.io/steadyinfratech/charts/steady-image-cache@$CHART_DIGEST, which needs a Helm version that accepts digests; otherwise helm pull the digest and install the file):

CHART=ghcr.io/steadyinfratech/charts/steady-image-cache
CHART_DIGEST=$(crane digest "$CHART:1.3.3")

cosign verify \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  --certificate-identity https://github.com/SteadyInfraTech/steady-image-cache/.github/workflows/helm.yml@refs/tags/v1.3.3 \
  "$CHART@$CHART_DIGEST"

Releases before 1.3.2 are not signed. The signing was built and checked with cosign 3.1.4; use a current cosign. A signature proves where an image was built, not that the code is free of defects: it is one input to a decision, next to govulncheck in CI and the SBOM.

Production notes

SIC verifies every imported or downloaded blob against its SHA-256 digest before accepting it. The containerd store is only accessed through its gRPC API; SIC does not modify containerd content. Its own cache is independent under /var/lib/steady-image-cache.

Known limits: without SIC_CONTAINERD_CONTENT_DIR the containerd import copies every blob into SIC's own cache, so each image occupies disk space twice on a node. A blob's declared length (from a peer or registry) is used to make room before the bytes arrive, so a peer that holds a valid certificate and lies about the length of a blob can make a node evict older blobs; the blob itself is refused at the digest check, and the evicted content is fetched again when needed.

Peer discovery is simple by default: a miss asks a bounded number of peers, in random order. For large clusters there are optional, off-by-default aids (EndpointSlice discovery, zone preference, digest gossip): the "Large clusters" section describes what each does and its limits, and gives measured cost figures for digest gossip only, from a model; none of the three has been measured on a real cluster.

About

Peer-to-peer OCI image cache for Kubernetes, enabling container image pulls from neighboring nodes

Topics

Resources

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages