Commit Graph

39 Commits

Author SHA1 Message Date
CrazyMax
5bc2459bf2 gitutil: add opt-in support for host git config
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-04-02 23:25:40 +02:00
Tonis Tiigi
e6e602641d gitutil: avoid global git config lookup on Windows
Avoid global conf lookup via HOME that fails on Windows.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-04-01 17:38:15 -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
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
b1329b39ab gitsign: fix for RejectExpiredKeys logic
Current RejectExpiredKeys didn't work as CheckDetachedSignature
validates expiration date internally.

It looks like go-crypto library does not allow signature checks
with completely ignoring exipration times (as Github UI allows
for example). With this change we allow (option for) keys to be expired,
but the signature creation time can not be after key expiry.

If we would set the reference time to the key creation time
that would cause a different error where validation would not work
because signatures are created in future.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-12-11 12:20:09 -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
CrazyMax
0888dc458c dfgitutil: FragmentFormat func
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-10-11 12:47:17 +02: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
Tonis Tiigi
c8ce372293 dfgitutil: add querystring style URLs to dfgitutil
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-08-28 15:33:19 -07:00
Akihiro Suda
e6676287ca git url: support query form
Fix issue 4905, but the syntax differs from the original proposal.

The document will be added to
https://github.com/docker/docs/blob/main/content/manuals/build/concepts/context.md#url-fragments

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-08-28 13:50:17 -07:00
Akihiro Suda
2207a88aad mv util/gitutil/git_ref.go frontend/dockerfile/dfgitutil/git_ref.go
The `ParseGitRef` function was only used in `frontend/{dockerfile, dockerui}`,
expect a single occurrence in `solver/llbsolver/history.go`.

The occurrence in `solver/llbsolver/history.go` now uses
`util/gitutil/git_url.go:ParseURL()`.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-08-20 18:09:59 +09: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
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
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
Steeve Chailloux
4f97acfe0f fix git http_proxy ignored
Signed-off-by: Steeve Chailloux <me@steeve.io>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-01-17 10:27:58 -08:00
Tianon Gravi
af719275e9 Add test for IsCommitSHA function
Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2024-11-04 13:52:30 -08: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
ac3eb58262 git: export gitutil helper for identifying commit shas
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-10-21 14:19:54 +01:00
Justin Chadwell
6493fd064c git: ensure exec option is propagated to child git clis
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-07-02 22:09:04 -07:00
Sebastiaan van Stijn
0f89a763aa vendor: github.com/containerd/containerd v1.7.18
Update to containerd 1.7.18, which now migrated to the errdefs module. The
existing errdefs package is now an alias for the module, and should no longer
be used directly.

This patch:

- updates the containerd dependency: https://github.com/containerd/containerd/compare/v1.7.17...v1.7.18
- replaces uses of the old package in favor of the new module
- adds a linter check to prevent accidental re-introduction of the old package
- adds a linter check to enforce using an alias, to prevent accidental use
  of the errdefs package in BuildKit or Moby.
- adds a linter check to prevent using the "log" package, which was also
  migrated to a separate module.

There are still some uses of the old package in (indirect) dependencies,
which should go away over time.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-05 08:54:22 +02:00
Stephen Day
035832e0c9 gitutil: preserve error type when wrapping
Signed-off-by: Stephen Day <stephen.day@docker.com>
2024-05-21 16:34:28 -07:00
Justin Chadwell
8144ab88e7 git: restrict definition of git ref
During git refactoring, git refs accidentally became significantly
broader in definition - specifically, files like "foo.bar/test.git" - is
this a git repo at "foo.bar", or a local git directory?

We need to restrict this a lot more, previously, we only did this clever
conversion for the "github.com" prefix. This restores this previous
behavior.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-04-16 12:42:48 +01:00
Justin Chadwell
95ca25ec7d git: ensure file-looking git refs aren't parsed as URLs
URLs that look like `./path/to/file` and `../path/to/file` definitely
aren't git URLs - so we should bail out early.

This was causing a weird issue where if you copied `./.git` this would
be detected as a valid url parsing with `host = "."` and `path = "/git"`.
The fix for this is to make sure that for these explicit file-like
paths, we *never* parse them as url-refs.

Also some tests to make sure this doesn't break again!

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-03-18 15:21:10 +01:00
Justin Chadwell
3c6f6e4ee1 chore: refactor IsGitTransport to avoid duplication
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-02-01 15:39:16 +00:00
Justin Chadwell
9a51bb0ff1 git: use custom giturl type to preserve original remote
This resolves a regression introduced in
50e75e3565. In this previous patch, I'd
incorrectly assumed that scp-like URLs can express a subset of
"standard"-URLs and so we can always safely convert them for
consistency. This isn't true - the URL "git@example.com:foo" should be
resolved to the home directory of the host, however, the converted URL
"ssh://git@example.com/foo" will be resolved to the root of the host.

To resolve this, we need to not perform this conversion. However, we
also need preserve the behaviour of firm distinction between SCP and
normal URL types (so as to keep proper port parsing).

To do this, we add a new GitURL type to the gitutil package. This new
type contains all useful fields shared in common between the standard
libraries url package and our custom scp-style url parsing package. This
keeps the previous property of a single clean interface to all GitURLs,
while also ensuring that we preserve the original URL to pass to the Git
CLI (making sure we strip fragments out, which are used as
buildkit-level metadata).

As a side-effect of this, the client-side calling code for parsing
git urls is simplified (so we don't have to do fragment wrangling at
every call point).

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-10-12 19:17:11 +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
Justin Chadwell
a8d926a0c7 git: avoid regexp for checking .git suffix
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-22 11:36:35 +01:00
Justin Chadwell
50e75e3565 git: update parsing to clarify between scp-style urls
This should also resolve the ports parsing issue.

Co-authored-by: Aaron Lehmann <alehmann@netflix.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-22 11:36:35 +01:00
Justin Chadwell
e84cc9ea4f tests: tidy up gitutil testing structs
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-22 11:36:35 +01:00
CrazyMax
6a2287eddc fix support for empty git ref with subdir
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-02-08 12:21:43 +01:00
CrazyMax
b5c9183595 gitutil: use subtests
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-02-08 12:21:43 +01:00
CrazyMax
4a15e742d8 update golangci-lint to 1.48.0 (go 1.19 support) and fix linting issues
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-08-19 10:26:52 +02:00
Akihiro Suda
8bfeafaaa1 dockerfile (labs): implement ADD <git ref>
e.g.,

  # syntax=docker/dockerfile-upstream:master-labs
  FROM alpine
  ADD https://github.com/moby/buildkit.git#v0.10.1 /buildkit

Close issue 775

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-08-02 16:44:31 +09:00
Alex Couture-Beil
ca151bceaf Move git protocol detection into seperate util
- the git protocol detection is required by buildx, and should reside in
a seperate exported gitutil package.

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2021-03-31 12:42:57 -07:00