90 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Tonis Tiigi
aa003bef56 llb: add checksum option to llb.Image
This allows images to be pulled by tag and then
checked against the digest. If digest is added directly
to the image reference, then tag is ignored.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-19 17:40:40 -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
8ef9b54fda llb: document fragment parameter in llb.Git
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-08-28 19:31:05 -07:00
Tonis Tiigi
81599425cb llb: update Git to allow normalized property passing
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-08-28 19:24:39 -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
Tonis Tiigi
7ae0d6a903 source: add metadata-only transfer option for local source
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-04-11 07:38:29 -07:00
Dan Duvall
e19af64fe3 http: Support additional request headers
Support additional request header fields for HTTP sources, "Accept" and
"User-Agent" as a start.

The "Accept" header is required in some cases and some servers may vary
the response body based on the header value.

The "User-Agent" header may be useful in custom frontends and
potentially other cases.

 - llb: Add `llb.Header` and `HTTPInfo.Header` to allow `client/llb`
   users to set these header fields on HTTP sources. The argument to
   `llb.Header` is a struct to effectively limit header fields to a
   subset.
 - llb: Define and flag new `source.http.header` capability when
   `llb.Header` is used.
 - solver: Define new `http.header.` source attribute prefix. Giving
   each header field its own attribute (opposed to JSON encoding the
   header struct) will allow source policy to make assertions on
   individual header fields.
 - source/http: Parse `http.header.` attributes into a sorted slice and
   include them in cache key digest.
 - source/http: Set request headers accordingly.

Signed-off-by: Dan Duvall <dduvall@wikimedia.org>
2025-02-21 10:08:59 -08:00
Dan Duvall
ab1e99e19a http: Support authentication
Support authentication for HTTP sources.

 - llb: Define general `llb.AuthOption` interface composed of
   `HTTPOption` and `GitOption`.
 - llb: Refactor `llb.AuthHeaderSecret` to return an `llb.AuthOption` so
   it may be used with both `llb.Git` and `llb.HTTP`.
 - llb: Define `HTTPInfo.AuthHeaderSecret`.
 - llb: Define and flag new `source.http.auth` capability when
   `HTTPInfo.AuthHeaderSecret` is set.
 - solver: Define new `http.auth` source attribute.
 - source/http: If an `http.auth` attribute is specified, resolve a
   secret named by its value and set the "Authorization" request header.

Signed-off-by: Dan Duvall <dduvall@wikimedia.org>
2025-02-20 12:12:55 -08:00
Tonis Tiigi
30413b5de7 llb: avoid concurrent map write on parallel marshal
Calling marshal changes the internal state of the op, for example
addCap() helper adds capability constraints. These can race with
same map being read by another Marshal call. Locking the Marshal
function itself also makes sure that the cache is not recomputed
in this case.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-12-06 17:53:59 -08:00
Jonathan A. Sternberg
d59218e6e6 llb: deterministic marshaling for protobuf and store results from multiple constraints
This fixes a problem with the new protobuf marshaling with the standard
library. LLB digests are now forced into deterministic marshaling to
ensure they produce the same digest when marshaled multiple times.

In addition, the marshal cache has also been fixed to work in
multi-threaded frontends with multiple different constraints.
Previously, if an LLB vertex was used in multiple goroutines and
marshaled concurrently, the cache would be broken. This could cause
certain problems when a specific node was used multiple times in the
same LLB tree.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-10-02 11:17:45 -05:00
Jonathan A. Sternberg
1a3fc0aa15 protobuf: remove gogoproto
Remove gogoproto in favor of the standard protobuf compiler. This
removes any nonstandard extensions that were part of gogoproto such as
the custom types.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-09-26 12:57:45 -05:00
CrazyMax
8cf12ae9d4 client: expose git auth header and token keys
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-03-28 15:28:03 +01:00
Tonis Tiigi
30c069cb03 replace resolveimageconfig with generic sourcemetaresolver
This is more versatile function that works for any source,
not just images.

It can be used together with a policy that switches
between input and output source as well as for adding
additional metadata for other sources in the future.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-02-11 22:06:23 -08: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
Sebastiaan van Stijn
2d3722e50a migrate to github.com/distribution/reference v0.5.0
The "reference" package was moved to a separate module, which was extracted
from b9b19409cf

Also updating docker/docker, which also switched to this new module;

vendor: github.com/docker/docker 032797ea4bcb (v25.0.0-dev)

full diff: afd4805278...032797ea4b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-09-05 15:29:27 +02: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
892dedfa6d git: update llb.Git doc comment
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-22 11:36:35 +01:00
Brian Goff
330cf7ae7d Fix ResolveImageConfig to evaluate source policy
Before this change, ResolveImageConfig was unaware of source policies.
This means that:

1. Images for denied sources may be resolved
2. Image configs may get pulled for sources that are later converted to
   a different image

The update makes it so the image resolver first runs a given ref through
the source policy and uses any mutated ref for the actual resolve
(instead of the original ref).
It also returns the mutated ref so it can be used correctly by the
frontend (e.g. don't want to do llb.Image(oldRef@resolvedDigest)).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-07-10 17:44:50 +00:00
Brian Goff
552e0e7c37 Adding more docs to client/llb
Just some more method/fn documentation for various llb opts/options.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-06-09 17:01:44 +00:00
Brian Goff
206b3a1eeb Add some doc strings for LLB functions
This is just a first round of "would have been useful to me" sort of
documentation and examples for the LLB client API.
This is not in any way exhaustive.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-05-15 22:22:09 +00:00
Justin Chadwell
a925cd7c4c solver: attach store id as explicit property of source
This breaking api change refactors the LLB API to prevent reference
mangling and demangling throughout OCI access. Once the session and
store IDs have been determined in the dockerfile frontend, we keep them
the same, and attach them as additional properties.

This has the additional effect of making the actual reference used in
the image resolution arbitrary, since we only parse and access the
digest. The rest of the name can be selected to optimize for log
readability.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-12-13 11:41:30 -08:00
Justin Chadwell
d81928a72f solver: delete caps for additional oci properties
We don't need multiple caps for a single feature - the caps that these
were copied by were addded over time, we don't immediately need all of
them to start with, only the main feature one is initially required.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-12-13 11:38:50 -08:00
Justin Chadwell
6340184df6 source: refactor reference parsing for oci-layout
Instead of using custom parsing mechansisms for references in
oci-layout, we use containerd's reference.Parse or docker distribution's
reference.Parse (depending on where we do the parsing, and what's
consistent with the file where it's already done). These operations are
neater than manually parsing, and have hopefully more consistent error
messages, and better handling of labels (for if/when those are
introduced).

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-11-23 14:05:55 +00:00
Petr Fedchenkov
9447acedcd Add oci-layout to platformSpecificSource
oci-layout source is platform-scpecific, we should use provided
platform to resolve correct image.

Signed-off-by: Petr Fedchenkov <giggsoff@gmail.com>
2022-07-21 18:16:39 +03:00
Avi Deitcher
1fe66075b7 Add OCI source
Signed-off-by: Avi Deitcher <avi@deitcher.net>
2022-06-15 23:04:11 +03:00
Tonis Tiigi
5ac05cb482 Allow pulling partial layer chains from an image
Adds a new `WithLayerLimit` option to `llb.Image`
only pulls specified number of layers instead of
full image.

This can be used in combination with DiffOp/MergeOp
to pull any subset of layers from an image in any order.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-04-21 21:54:13 -07:00
Akihiro Suda
be8ab28a0a Merge pull request #2081 from tonistiigi/local-differ-none
Allow none differ on local source to avoid false Dockerfile matches
2021-07-01 09:42:24 +09:00
Tonis Tiigi
ee39f5dd68 dockerfile: use none differ for dockerfile/dockerignore
This avoids wrong metadata matches on small files

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-06-29 16:17:08 -07:00
Tonis Tiigi
01b50a3df1 llb: ensure meta resolver uses platform form constraints
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-06-22 21:49:07 -07:00
Tonis Tiigi
e0124e192c llb: add constraints to async llb
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-06-22 21:34:43 -07:00
Tonis Tiigi
b4935eb79a llb: add constraints to vertex and validate
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-06-22 18:47:32 -07:00
Tonis Tiigi
a7b155e30c llb: don't allow content diff for now
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-06-11 21:15:10 -07:00
Tonis Tiigi
baa4fcdb0f add differ support for local source
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-06-11 21:15:07 -07: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
Alex Couture-Beil
3a5bdf0710 Move prefix check to isGitTransport
- rename IsSSHTransport to IsImplicitSSHTransport
- add testing for NewGitIdentifier

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2021-01-04 11:09:56 -08:00
Alex Couture-Beil
3fa063dcf3 move ssh regexp test to common location
- include testing
- improve hostname checking

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2020-12-10 17:10:38 -08:00
Alex Couture-Beil
23af9dcb86 require a username for git over ssh
Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2020-12-10 17:10:38 -08:00
Tonis Tiigi
a6baa678ea fix building from git url without a protocol
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-12-09 18:40:34 -08:00
Alex Couture-Beil
4bf1852a08 differentiate git protocol vs git over ssh protocol
Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2020-11-16 15:04:37 -08:00