Skip to content

remotecache: split the import blob size limits (manifest 4 MiB, cache config 16 MiB) - #7126

Open
dsloane-easygo wants to merge 1 commit into
moby:masterfrom
dsloane-easygo:remotecache-import-blob-limits
Open

dsloane-easygo wants to merge 1 commit into
moby:masterfrom
dsloane-easygo:remotecache-import-blob-limits

Conversation

@dsloane-easygo

Copy link
Copy Markdown

readBlob in cache/remotecache/import.go refuses any blob over 1 MiB, and it is used for both reads the importer makes: the cache manifest (or index) and the cache config blob (application/vnd.buildkit.cacheconfig.v0). The manifest comes from the registry's manifest endpoint, which registries cap at a few MiB, so a ceiling there is reasonable. The cache config is served from the blob endpoint and has no such ceiling; a mode=max export of a large multi-stage build on a busy shared daemon produces a config of 1 to 2 MiB, and from then on every import fails with

importing cache manifest from <registry>/<repo>:buildcache
ERROR: blob sha256:... is too large (1618088 > 1048576)

and the build silently loses its registry cache (the export succeeds, the import never does). Measured on one shared buildkitd v0.30.0: 2,664 records, 127 layers, 960,778 bytes one export and 1,618,088 bytes the next, for the same Dockerfile.

This follows the direction in #3719 ("raising the limit to 4MB for the manifest and maybe ~12MB for the cache config"): readBlob takes a per-call limit, the manifest read passes maxManifestBlobSize (4 MiB) and the cache-config read passes maxCacheConfigBlobSize (16 MiB). The error text is unchanged.

import_test.go pins both ceilings: a 1 MiB + 1 byte config (the previously refused case) imports, blobs above either ceiling are refused before being read, a manifest within its ceiling reads. Reverting either constant to 1 << 20 fails the test.

Fixes #3719
Fixes #4916

… config 16 MiB)

readBlob refused any blob over 1 MiB, for the cache manifest and the cache
config alike. The manifest comes from the registry's manifest endpoint, which
registries cap at a few MiB; the cache config (application/vnd.buildkit.cacheconfig.v0)
is served from the blob endpoint and has no such ceiling, and a mode=max export
of a large multi-stage build on a busy shared daemon produces a config of 1-2
MiB, after which every import fails with "blob ... is too large" and the
build silently loses its registry cache.

Give readBlob a per-call limit: 4 MiB for the manifest read, 16 MiB for the
cache config read, as discussed in moby#3719. Add a unit test that pins both
ceilings and covers the previously refused 1 MiB + 1 byte config.

Fixes moby#3719
Fixes moby#4916

Signed-off-by: Damian Sloane <d.sloane@easygo.io>
require.True(t, strings.Contains(err.Error(), "is too large"), err.Error())
})

t.Run("manifest over its ceiling is refused before reading", func(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests don't seem to do much as they just check the variable that is directly passed in. This would pass even if the actual manifest reader doesn't use these vars at all. Better to remove I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

buildkit remote cache fails if manifest is larger than 1MB Allow to configure remote cache maxBlobSize

2 participants