374 Commits

Author SHA1 Message Date
Tõnis Tiigi
174f4f07dd Merge pull request #6760 from crazy-max/session-empty-fallback
resolver: allow anonymous auth while preserving local image fallback
2026-06-03 08:40:56 -07:00
Tonis Tiigi
fa1ba86389 source/http: fix resolver cache ref lookup
Use the resolver-cache ref ID directly when loading a cached HTTP snapshot.
This avoids dereferencing missing metadata for cache entries found during a
concurrent solve.

Reset the unauthorized checksum race request counter per solve iteration so
each retry applies the intended first-request delay.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-01 21:12:23 -07:00
CrazyMax
ca9bcf049c containerimage: preserve local fallback for default image resolution
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-05-29 17:17:04 +02:00
Tonis Tiigi
e5cd9ab898 source/http: release resolver cache lock on errors
Move the HTTP snapshot resolver-cache lookup into a helper so the lock
release is deferred after acquisition. This keeps invalid cache entries
and digest mismatch errors from returning while the cache lock is held.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-05-28 17:46:00 -07:00
Tonis Tiigi
10872e1722 http: fix resolver cache nil race
Avoid storing typed nil HTTP metadata in the resolver cache after failed
metadata resolution. Also make resolver cache release functions consistently
callable when no error is returned.

Add a client integration test covering concurrent same-URL HTTP sources with
and without checksum when the server returns 401.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-05-20 12:48:07 -07:00
Bryce Gibson
74e64aa293 Ensure that a wrapped nil isn't returned as it causes a SIGSEGV.
Signed-off-by: Bryce Gibson <bgibson@limepoint.com>
2026-05-20 15:54:35 +10:00
Tonis Tiigi
98e1113c6d lint: modernize Go lint findings
Update non-generated code for the newer lint recommendations by using typed
atomic values, strings.Cut, and slices.Backward where applicable.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-05-14 10:13:21 -07:00
Tonis Tiigi
bd3608ddc9 lint: update golangci-lint to v2.12.2
Update golangci-lint and adjust code for new gosec diagnostics. Use
root-scoped filesystem operations where appropriate, preserve explicit
user path behavior for SSH keys, and avoid background contexts in
request-scoped cleanup paths.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-05-14 10:13:15 -07:00
Tonis Tiigi
45e34b96e0 git: fix sha256 detection for bundles
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-04-27 14:30:14 +02:00
Tonis Tiigi
9a0c5cb021 git: add git bundle source support
Support importing git sources from OCI or registry-backed bundle blobs
and exporting resolved checkouts as single-file git bundles.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-04-27 14:30:11 +02:00
Tõnis Tiigi
c1b5264bfd Merge pull request #6681 from tonistiigi/compat-version
solver: add compatibility-version support
2026-04-27 14:21:38 +02:00
Tonis Tiigi
8100e1edab source/git: add fetch-by-commit support
Allow git sources to fetch a pinned commit without resolving the ref
against the remote tip, while preserving cache keys for canonical
branch refs and covering the behavior with tests.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-04-16 16:10:30 -07:00
Tonis Tiigi
5fde446dee solver: add compatibility-version support
Add solve-wide compatibility-version support for image and oci
exports, with historical goldens and release compatibility tests.

Backfill version 10 for v0.13-v0.14 git artifact behavior, keep
version 20 as current, and reject unsupported zstd on v10.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-04-10 09:24:11 -07:00
Tonis Tiigi
4e1c8acd57 dockerfile: support SOURCE_DATE_EPOCH=context
Resolve SOURCE_DATE_EPOCH=context in the Dockerfile frontend from the
main build context and pass the resolved numeric epoch through normal
ARG handling and exporter metadata.

Use git commit time for git contexts, HTTP Last-Modified when present,
and newest archive entry mtime for HTTP archives. Leave local contexts
unset.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-04-08 15:27:20 -07:00
Tõnis Tiigi
1fc2d12b71 Merge pull request #6600 from tonistiigi/git-mtime-commit
source: add git.mtime attr for commit-time mtimes
2026-03-25 12:23:22 -07:00
Tonis Tiigi
475491f95d source/git: scope path access to roots
Use os.OpenRoot for git dir and checkout subdir access, and share root-
relative path normalization between validation and open paths.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-03-25 08:14:30 -07:00
Tonis Tiigi
701cddc10b source/http: use os.Root for read-path file operations
Open the snapshot mount as an os.Root and perform file reads
through root-relative APIs in verifySignature and
computeChecksumResponse, consistent with the write path.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-03-25 08:14:30 -07:00
Tonis Tiigi
446e8c84f6 git: harden ref arg handling
Validate user-provided refs once during identifier construction and reject
option-like refs with leading '-'. There is no known attack related to
previous core, patch is to make ref handling more robust and improve
errors.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit e7f8093e1b386ffe711c8468ca8cdde8cfea0c72)
2026-03-25 08:14:30 -07:00
Tonis Tiigi
d19ecc730c git: normalize and validate subdir paths
Normalize Git subdir fragments and validate checkout subdir components
so each segment must be a real directory, preventing traversal and symlink escapes.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 8c994eb561a2646b35352e5663afecd225306214)
2026-03-25 08:14:30 -07:00
Tonis Tiigi
7cf63df2a7 source: extract SafeFileName into shared pathutil package
Move safeFileName from source/http to source/util/pathutil
and apply it to the containerblob source as well. Harden
containerblob/pull.go to use os.OpenRoot for file writes,
preventing path traversal via crafted filenames.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 3d6e587655d72c343f6fdc7268480a900ba45b0c)
2026-03-25 08:14:30 -07:00
Tonis Tiigi
be0dc4e898 source/http: use os.Root for saved file operations
Open the snapshot mount as an os.Root and perform file write/chown/chtimes
through root-relative APIs to keep operations constrained to the mount root.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit d568881c97278d87e4f6f01a1f8a67ad807152bb)
2026-03-25 08:14:30 -07:00
Tonis Tiigi
4f26c2023c source/http: sanitize downloaded filenames
Add safeFileName and route all getFileName sources through it.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 9d117af5ab1e1032f75658884384328fea440843)
2026-03-25 08:14:30 -07:00
Tonis Tiigi
508dd62bf7 source: add git.mtime attr for commit-time mtimes
Add git.mtime=commit option that normalizes all file, symlink,
and directory mtimes in a git snapshot to the resolved commit
timestamp. This enables reproducible builds from git sources.

When SOURCE_DATE_EPOCH is set in the Dockerfile frontend, the
git context automatically uses commit-time mtimes. The URL
query parameter ?mtime=commit|checkout can override this.

New LLB attr (git.mtime) and capability (source.git.mtime) are
registered as experimental. Cache keys include the mtime policy
so that commit-time and checkout-time snapshots are distinct.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-03-23 11:58:24 -07:00
Brian Ristuccia
ea11d20e58 source/git: checkout before submodule update
The `git checkout tree-ish -- pathspec` command run by buildkit to
populate the work tree defaults to overlay mode, so it won't delete objects
which exist in the work tree but don't exist in the tree-ish. It's not a
problem for ordinary file and directory objects because the work tree
starts out empty, but in the case where submodules are deleted or
renamed it will leave stale gitlink references in the index. The
subsequent `git submodule update ...` command will then fail with an
eror like 'No url found for submodule path ... in .gitmodules' as seen
in #4260.

Adding `--no-overlay` ensures that any deleted gitlink references are
removed from the index before the submodule update runs.

Signed-off-by: Brian Ristuccia <brian@ristuccia.com>
2026-03-11 13:07:40 -04:00
Tonis Tiigi
8874679130 source: add support for oci-layout+blob schema
Matching the docker-image+blob implementation.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-02-24 08:05:42 -08:00
Tonis Tiigi
9d821a3c12 source: update imageblob to new docker-image+blob and ref_type naming
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-02-24 08:05:42 -08:00
Tonis Tiigi
e12905644d source: imageblob source implementation
Image blob source in LLB allows addressing a single blob
from a container image registry. The difference from the image
source is that image source needs to point to a manifest that
internally points to an array of layer blobs that are all extracted
on top of each other to form a root FS. Contrary, image blob
points to a single blob that is not extracted but downloaded
as a single file into an empty snapshot, similarily how
the HTTP source works.

The main use case for this source is to pin snapshots of
HTTP URLs, upload the downloaded blob into container registry,
and then use a source policy to map a HTTP URL (whose content
might be changed) to the copy of the source as image blob
to ensure immutability.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-02-24 08:05:38 -08:00
Tonis Tiigi
e3fba18b63 source/http: add PGP verification and shared pgpsign
Add detached PGP verification for HTTP sources during metadata resolution
and expose LLB options/caps/attrs for signature validation.

Extract shared OpenPGP verification/parsing logic into util/pgpsign and
reuse it from git signing, plus add integration and source-level tests.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-02-20 08:13:38 -08:00
Tonis Tiigi
7f2cbc61ba http: add support for checksum requests for http sources
These requests allow computing additional checksum algorithms
for the payload of HTTP sources.

Optionally suffix can be passed that is added to payload. This
is needed to make validation of PGP signatures possible remotely.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-02-20 08:13:32 -08:00
Tonis Tiigi
ffcb2974e6 gitsign: support combined public keys for verification
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-02-12 17:11:25 -08:00
Tonis Tiigi
b0ba823284 containerimage: add resolve attestation support
Allow ResolveSourceMetadata to resolve specific bytes
from the attestation manifest.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-02-09 15:27:33 -08:00
Tonis Tiigi
a50e8a126d source: avoid error when attestation asked from non-index
Instead return that no attestation was found.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-01-16 12:05:37 -08:00
Tonis Tiigi
3402a0c281 containerimage: fix missing lease on fetching attestationchain
Without a lease, the manifest may get be deleted by GC
before the SetGCLabels() gets called, causing "not found" error.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-01-14 17:18:18 -08:00
Tonis Tiigi
a8b83196f3 ci: update golangci to v2.8.0
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-01-13 22:09:20 -08:00
Tonis Tiigi
2324e72342 git: handle updated error message in git 2.52
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-01-12 23:43:48 -08:00
Tonis Tiigi
7e17a06aa6 contentutil: add pull through cache for attestations chain resolve
Currently attestation chains were always loaded directly from
registry on each pull.

This adds cache capability to resolver so all the pulled manifests
are first pulled to content store and kept there with GC labels
references from the root manifest.

If blob or referrers request already exists in the content store
then local response is used without registry requests.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-12-19 17:46:35 -08:00
Tonis Tiigi
9a3333c4d2 resolver: auth refactor for better readability
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-12-10 18:08:59 -08:00
Tonis Tiigi
a372e4e65e client: enable git signature checks via policy
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-11-07 16:00:21 -08:00
Tonis Tiigi
2fc7854e44 image: remove image manifest content from attestation chain
Image manifest content is not needed for signature verification as
the verification is against the top index root. Still report
image manifest digest for more info about the reported attestation
subject but clients need to re-resolve it from the root manifest
for signature verification.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-11-05 14:15:49 -08:00
Tonis Tiigi
a13afb53c1 image: add attestationchain resolving to resolvesourcemeta
Attestation chain can be used by the client to verify
signature identity of the image.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-11-05 14:15:43 -08:00
Tonis Tiigi
b1118d8929 image: move image source resolver away from old interface
ResolveImageConfig was changed to ResolveSourceMetadata long time
ago for cross-source implementation but the worker implementation
was still using old method name with conversions.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-11-05 14:15:42 -08:00
Tõnis Tiigi
29900deace Merge pull request #6313 from grey3228/fix/close_metadata_resp_body
fix metadata resp.Body leak
2025-11-05 10:47:39 -08:00
Mikhail Dmitrichenko
739a8a766f fix metadata resp.Body leak
In (*httpSourceHandler).resolveMetadata method there is
a potential resp.Body leak in case when response status code is not
valid (< 200 or >= 400). Also resp.Body is not closed before exiting
if status code is okay.

This commit adds resp.Body closing before exiting from resolveMetadata
method.

Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com>
2025-10-31 16:22:31 +03:00
Tonis Tiigi
81a79837c3 git: add signature verification to CacheKey and ResolveMetadata
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-22 10:12:10 -07:00
Tonis Tiigi
aade64489a git: test SSH signature verification
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-22 10:10:59 -07:00
Tonis Tiigi
7d8cd252c5 git: test PGP signature verification
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-22 10:10:59 -07:00
Tonis Tiigi
5f6a7ef751 source: add raw commit/tag object access to resolveMetadata
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-17 16:45:08 -07:00
Tonis Tiigi
a248127a90 git: separate remoteFetch from checkout for better reuse
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-17 16:45:08 -07:00
Tonis Tiigi
1cff633ba5 git: add resolvercache support to git source
Make sure remote ref does not change to different commit  if
git repo changes in the middle of the build.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-17 10:29:55 -07:00
Tonis Tiigi
df4d2aee3d solver: add ResolverCache support
New ResolverCache interface in JobContext allows build jobs to
memorize and synchronize accesses to mutable remote resources.

This is to make sure that when multiple parts of the same build
job, or build job and source metadata resolver access the same
remote resources, it remains the same for the duration of the
single build request, even if data happens to change on the remote side.

Fix such a possible case in the HTTP source. Even if the server
now returns completely different data, if the same URL was accessed
once for the ongoing build, then the initial contents are always
used until the build completes.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-17 10:29:55 -07:00