40 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
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
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
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
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
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
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
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
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
f1f56c2b77 golangci-lint: v2 upgrade
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-02 12:19:17 -07: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
Tonis Tiigi
44b1aca26a git: fix caching git commit through multiple refs
This fixes current issue when a Git commit is accessed
multiple times through different refs or ref is added
after commit has already been pulled once.

When keep-git-dir option is true, then program can
try to resolve the current reference via .git directory
and because old cache key was only the git commit, previous
.git directory can be reused without any refs inside.

There is no change to the behavior if keep-git-dir is
false as then requests through multiple refs yield to
identical content.

Only the reference in the user provided identifier is added
to the cache key, and that is the only one that can be
expected in .git because of the shallow fetches. We do not
do extra request to find named refs for a commit SHA if that is
provided in the identifier.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-10-23 16:59:22 -07:00
Justin Chadwell
90d2d8b1c6 git: allow cloning commit shas not referenced by branch/tag
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-10-22 11:38:04 +01:00
Justin Chadwell
ac7caa8f3b chore: use a better root for computing free disk space
We shouldn't use the cachemount root, we should actually properly
use the worker's specified root which is propagated from the config.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-09-25 10:49:52 +01:00
Tonis Tiigi
899cac1697 git: add file mode verification to tests
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-02 22:41:07 -07:00
Tonis Tiigi
dff03a24fa git: fix pulling commit SHA only referenced from a tag
On commit SHA input we currently do a full fetch of
remote so we can pick up the commit by SHA later. This
only pulls in tags that are also part of branches. Extra
flag is needed to also get the tags that are not part of
branches.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-21 16:05:55 -07:00
Tonis Tiigi
03c7a6d769 lint: fix some testifylint warnings
This does not cover all warning yet but split
into chunks to ease review.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-05-30 11:32:55 -07:00
Justin Chadwell
7eb8713972 Merge pull request #4473 from jedevc/fix-git-sha-conflict 2023-12-13 19:48:57 +00:00
Justin Chadwell
6a8d2ca2bd git: ensure that pin matches checked-out commit
Previously, it was very possible for the CacheKey function to return a
sha key that was *not* the checked out commit.

There are two cases that I've encountered where this can happen:
- An annotated tag will have the pin of the tag, and not the underlying
  commit, which will be HEAD after the checkout.
- If multiple tags have the same path component (e.g. "mytag" and
  "abc/mytag") then the first alphabetical tag will be selected when (in
  this case "abc/mytag").

To avoid this kind of case, we can't just search for a single match in
the results for ls-remote. There's no way to filter for just an exact
match, so we need to scan through the output ourselves. Additionally, we
need to dereference the annotated tags by also selecting refs ending in
"^{}" - which have the commit that the tag points at.

Finally, I've improved the test suite around this to check that:
- The cache-key pin is equivalent to the checked out commit
- We can check out non-master branches
- That full ref syntax like "refs/heads/<branch-name>" and
  "refs/tags/<tag-name>" (or even "refs/<anything>") can be used.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-12-13 10:06:42 +00:00
Tonis Tiigi
8a2a3e83ec replace context.WithCancel with WithCancelCause
Keep stack traces for cancellation errors where possible.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-12-06 22:15:06 -08:00
Justin Chadwell
319130de80 test: git tag test should not sign tags
Co-authored-by: Alex Suraci <suraci.alex@gmail.com>

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-24 12:22:15 +01:00
Justin Chadwell
d34b2471cd git: centralize git cli operations
Move all of the git command line logic into a single object, inspired by
the object already in buildx.

The basic implemenation allows for configuring a git cli for a specific
repository, along with various authorization settings and custom
binaries. Commands can be run for that repository, and a few helpers are
provided for accessing data on it - more to come in the future
hopefully.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-24 12:22:15 +01:00
Alex Suraci
6b27487fec source: make sources pluggable
Sources are a pretty neat extension point, except there are a few code
paths that hard-code against each type. This moves code around and
adjusts interfaces so that Source implementations are self-contained and
merely need to be registered with the source.Manager.

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
2023-08-16 09:57:55 +01:00