140 Commits

Author SHA1 Message Date
Tonis Tiigi
93999f4071 sourcepolicy: normalize parsed source identifiers
Render parsed source identifiers back to their canonical SourceOp form before
source policy evaluation. This lets Git subdir cleanup use the existing source
parser and avoids policy-specific Git parsing.

Add String methods for source identifiers and cover them with unit tests, plus
a client integration regression for canonical Git subdir policy matching.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-07-22 11:36:47 +02: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
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
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
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
Tonis Tiigi
80766cdd4b http: fix release race between cache and snapshot
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-13 19:56:53 -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
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
58d2224960 cache: add cache debug plaintext for image manifest and http
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-08-12 12:10:17 +03:00
liulanzheng
c097f43378 Support for building overlaybd images
Signed-off-by: liulanzheng <lanzheng.liulz@alibaba-inc.com>
2025-05-12 14:20:20 +08: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
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
Brian Goff
94ddeb7dbe Support OS version in platform string
This allows platforms following the new `platforms.FormatAll` function,
which allows for setting the `OSVersion` field of the platform with
`<os>(<ver>)/<arch>`.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2025-01-14 09:27:19 -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
Tonis Tiigi
e05a89e0b8 improve stacks of cancels from defers
In this case the current stack trace points to the line
where the context was created. Instead the stack should be
captured when the defer is running so the return path to
the defer call is also part of the stack.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-11-19 18:40:00 -08:00
Justin Chadwell
08bd6398fe otel: add wrapping "resolving" spans for ResolveImageConfig
Without this, a single ResolveImageConfig may emit many
"remotes.docker.resolver.HTTPRequest" spans. These can be difficult to
track and organize, especially if a single client performs multiple of
them.

To make traces a bit easier to navigate, these are now grouped under one
top-level span, instead of cluttering up the top-level.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-07-23 15:53:12 +01:00
Sebastiaan van Stijn
175973babc switch to github.com/containerd/platforms module
Switch to use github.com/containerd/platforms module, because containerd's
platforms package has moved to a separate module. This allows updating the
platforms parsing independent of the containerd module itself.

The package in containerd is deprecated, but kept as an alias to provide
compatibility between codebases.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-02 22:59:12 +02:00
Sebastiaan van Stijn
316b5f5a10 ociLayoutResolver.info: remove use of reference.SplitObject
We already have a `reference.Spec` and `reference.Spec.Digest()` does
exactly this. In addition, buildkit was the only external consumer of
the `reference.SplitObject` function, and it may be deprecated and removed
for containerd 2.0.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-27 12:14:55 +02:00
Tõnis Tiigi
ff1674a396 Merge pull request #5031 from tonistiigi/context-withoutcancel
ensure context.WithoutCancel in defer funcs
2024-06-18 12:56:04 -07:00
Tonis Tiigi
4103099d94 ensure context.WithoutCancel in defer funcs
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-12 19:18:32 -07:00
Tonis Tiigi
dfc35271ae simplify with maps pkg functions
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-12 18:33:30 -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
Tonis Tiigi
1f9988911f lint: unusedparams fixes
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-09 07:23:16 -07:00
Tonis Tiigi
eb942eae5b unify ReadAt to ReadCloser conversion
Also removes dependency from pkg/ioutils

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-05 16:24:40 -07:00
CrazyMax
94e2370023 provenance: move types to a dedicated package
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-02-25 20:39:50 +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
Tonis Tiigi
09648f4d29 replace WithTimeout with WithTimeoutCause
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-12-06 22:15:12 -08:00
Paul "TBBle" Hampson
98e0d8dcff Whenever copying OCI Platform data, include OSVersion and OSFeatures
Trivially created by looking for every reference to .Variant and adding
OSVersion and OSFeatures, except the ones related to the string
representation of a Platform instance.

I then went through and ensured every assignment of OSFeatures that
might leak out, i.e., not local-only or for marhsalling purposes, uses
the append-to-nil idiom to avoid sharing the slice storage and allowing
accidental mutation after-the-fact.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2023-11-03 12:19:29 +09: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
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
Tonis Tiigi
8ffc03b8f0 move flightcontrol to use generics
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-28 23:44:05 -07: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
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
Justin Chadwell
2c3637fb26 named contexts: prefix oci named contexts with "oci:"
This mirrors the structure of the names for the local cache directory,
as well as the names for the oci exporter (when using a content store).
This ensures that we cannot encounter name collisions (intentionally or
unintentionally).

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-11-16 12:43:43 +00:00
Justin Chadwell
b9fbfa5b69 source: avoid hang if no session id for oci-layout
In the scenario with no session id, then the oci-layout resolver would
still attempt to load a caller with the empty session id. This
inevitably failed, and would fallback to any caller, but this would take
5 seconds to fail with the configured timeout.

In a fresh pull of an OCI image context, this could take up to 15
seconds, as 3 separate calls to the relevant functions would be made.

This patch fixes the issue by correctly identifying this case, and
directly falling through to any caller. Additionally, if a session id is
present, it will always be loaded with no fallback available. To do
this consistently, the helper methods are refactored into a more
consistent withCaller function.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-09-16 16:18:16 +01:00
CrazyMax
00ee28175c progress: mutualize OneOff helper
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-08-08 12:52:59 +02:00
Tonis Tiigi
6644f165cc fix cancellation error not being detected and erroneously cached
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-06-23 08:25:21 -07: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
Kohei Tokunaga
bed5a44d52 Enalbe estargz-based lazy pulling on registry cache importer
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2022-02-17 10:44:14 +09:00
Erik Sipsma
0566b9a345 Add support for progress groups.
This allows clients to specify that LLB states should be grouped in
progress output under a custom name. Status updates for all vertexes in
the group will show up under a single vertex in the output.

The intended use cases are for Dockerfile COPY's that use MergeOp as a
backend and for grouping some other internal vertexes during frontend
builds.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2022-02-08 11:27:49 -08:00
Tonis Tiigi
dc21885891 hack: enable more linters
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-01-19 12:20:30 -08:00
Erik Sipsma
d73e62f878 Add initial MergeOp implementation.
This consists of just the base MergeOp with support for merging LLB
results that include deletions using hardlinks as the efficient path
and copies as fallback.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2021-11-18 11:10:48 -08:00
Erik Sipsma
03ed0548ef cache: Replace Parent method with LayerChain.
The Parent method will no longer make sense with forthcoming Merge and
Diff support as refs will become capable of having multiple parents. It
was also only ever used externally to get the full chain of refs for
each layer in the ref's chain.

The newly added LayerChain method replaces Parents with a method that
just returns a slice of refs for each layer in the ref's chain. This
will work more seamlessly with Merge and Diff (in which case it returns
the "flattened" ancestors of the ref) in addition to being a bit easier
to use for the exiting cases anyways.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2021-11-17 11:02:16 -08:00
CrazyMax
5fcc94454f Generate and embed build sources
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-09-18 01:39:35 +02:00