Commit Graph

161 Commits

Author SHA1 Message Date
Tonis Tiigi
f83dedd8dd source/git: reject option-like refs in git bundle operations
Validate the default branch returned by ls-remote before using it, so a
malicious remote cannot advertise a HEAD symref such as  that would
later be reused as an argument to other git commands.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit a838953fe8776d68379d32a7af0776d538215763)
(cherry picked from commit eb63c321e8)
2026-07-16 17:36:38 -07: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
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
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
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
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
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
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
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
7bb92310aa solver: add cleanup function to jobctx and pass through sources
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-13 17:39:53 -07:00
Tonis Tiigi
70e5929715 git: add git commit support to ResolveSourceMeta
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-13 07:59:09 -07:00
Tonis Tiigi
32cbdcd475 git: make Source struct public
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-13 07:59:08 -07:00
Tonis Tiigi
95762546cf git: fix potential difference between cache and snapshot
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-08 20:07:42 -07:00
Tonis Tiigi
9f5cf396f6 git: fix possible conflict on mutated branches
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-01 22:52:08 -07:00
Tonis Tiigi
d9183cb92e git: handle tag changes in upstream
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-01 10:43:56 -07:00
Tonis Tiigi
80c6fb96c4 git: allow checksum of annotated tag ref match either tag or commit sha
This is more flexible as from the user standpoint it might not
be easy to know if a version tag is annotated or not.

Downside of this change is that we can't create a cache key
automatically when checksum was set and no keep-git-dir as we
don't know which checksum is being used.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-30 12:57:14 -07:00
Tonis Tiigi
299b9cdd86 git: fix annotated tag pinning and cache keys
Pin of annotated tag should be tha SHA of tag, not
the commit it is pointing to.

Cache key of annotated tag should be SHA of the tag
if keep-git-dir is enabled and SHA of underlying
commit otherwise.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-30 12:22:08 -07:00
Tonis Tiigi
ef8e5f97db git: fix issue with checking out annotated tags by full ref
If tag was already pulled by --tags or without refs/tags
that creates ambigous reference in the shared repository.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-25 08:38:17 -07:00
Tonis Tiigi
4645296cb7 git: add sha256 commits support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-05 16:34:55 -07:00
Tianon Gravi
4bdec93057 git: partial integration tests for SHA-256
This fails in `gitSourceHandler` because it can't handle *both* SHA-1 and SHA-256 before Git 2.45 (see PR comments), and there's not a simple way to fix that without newer Git or larger refactoring.

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-05 16:34:31 -07:00
Tonis Tiigi
3765fe3587 dockerfile: add submodules controls to git URLs
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-08-28 22:31:40 -07:00
Tonis Tiigi
cf599d45ee git: fix subdir filter on submodule dir
Because subdir filter happened before the submodule update it
resulted in empty directory being filtered and submodule update
being skipped because .gitmodules was already missing.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-08-28 06:36:24 -07:00
Akihiro Suda
f8447d305c git url: rename GitURLFragment to GitURLOpts
No substantial code change.
Non-fragment data can be added in this structure too.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-06-05 15:12:44 +09:00
Tonis Tiigi
58f956b807 git: verify checksum early and more tests
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-18 21:38:49 +09:00
Akihiro Suda
6cbf02ae5b git source: add AttrGitChecksum
Not integrated to util/giturl, as PR 5974 is not merged yet.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-05-18 21:38:45 +09:00
Tonis Tiigi
9fcedf9807 update gopls to go1.24 compatible version
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-07 18:23:20 -07:00
Tonis Tiigi
69d3d44145 lint: add unconvert
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-02 12:44:01 -07:00
Tonis Tiigi
f1f56c2b77 golangci-lint: v2 upgrade
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-02 12:19:17 -07:00
Jonathan A. Sternberg
66016a8c63 vendor: switch from idtools to moby/sys/user
Convert usages of `github.com/docker/docker/pkg/idtools` to
`github.com/moby/sys/user` in order to break the dependency between
buildkit and docker.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-04-02 10:22:02 -05:00
Tonis Tiigi
91b55e89e5 solver: fix reading secrets from any session
The current logic was incorrect in some places so that if first
session randomly chosen by `Any()` returned NotFound then other
sessions were not attempted.

For the main use case of mounting secrets as files the logic
was correct, but it was incorrect for example for the case of
adding secrets as environment variables.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-03-11 15:25:15 -07:00
Tonis Tiigi
b5286f8dcb apply x/tools/modernize fixes
Autogenerated with couple of manual patches.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-03-07 08:18:45 -08:00
Marat Radchenko
5be7edb69c Upgrade to containerd 2
Co-authored-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2025-01-13 16:42:48 -08:00
Sebastiaan van Stijn
698acd328f migrate to github.com/moby/sys/reexec
The github.com/docker/docker/pkg/reexec package was moved to
a separate module; migrate to use that module instead.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-18 21:11:07 +01:00