1
0
mirror of https://github.com/containers/buildah.git synced 2026-02-05 09:45:38 +01:00
Commit Graph

118 Commits

Author SHA1 Message Date
iTrooz
a64396050c return error in switch
Signed-off-by: iTrooz <hey@itrooz.fr>
2026-01-27 15:48:41 -05:00
iTrooz
d543dd9b5c fix stdout error message
Signed-off-by: iTrooz <hey@itrooz.fr>
2026-01-27 15:48:41 -05:00
iTrooz
d130a74ab5 use BuildOutputInvalid
Signed-off-by: iTrooz <hey@itrooz.fr>
2026-01-27 15:48:41 -05:00
iTrooz
ad8478658a only process path for types that need it
Signed-off-by: iTrooz <hey@itrooz.fr>
2026-01-27 15:48:41 -05:00
iTrooz
a96aff95b8 simplify switch
Signed-off-by: iTrooz <hey@itrooz.fr>
2026-01-27 15:48:41 -05:00
iTrooz
2badfa5fb2 use switch/case
Signed-off-by: iTrooz <hey@itrooz.fr>
2026-01-27 15:48:41 -05:00
iTrooz
b1c9ff5f32 feat(build): print error on build flag --output=type=something
Signed-off-by: iTrooz <hey@itrooz.fr>
2026-01-27 15:48:41 -05:00
Nalin Dahyabhai
2f36165aa9 Rename "types" packages to avoid "meaningless name" warnings
These are internal and test packages, so this shouldn't break any of our
API consumers.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-11-13 16:03:47 -05:00
Nalin Dahyabhai
b6098a2c5c internal/mkcw/embed: cross-compile using Go
Use the Go toolchain to cross-compile the "This image is designed to be
run as a confidential workload using libkrun." entrypoint that we add to
confidential workload images.  It's bigger than it was before, but
easier to port and can be built from source every time when desired.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-11-06 10:46:23 -05:00
Nalin Dahyabhai
705ba3b9b6 imagebuildah: try to rein in use of transport names in image specs
Try to limit which image transports we accept in stages, and scope the
ones that use path names to the context directory.  At some point
anything that isn't an image ID or pullable spec should start being
rejected.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-11-04 10:10:29 -05:00
Nalin Dahyabhai
7c58fc17f7 imagebuildah: use a longer-lived overlay over the build context
Mount a read-write overlay directory over the build context directory to
restore the ability to use it as a covert cache of sorts during the
lifetime of each platform's build, but in a way that still ensures that
we don't modify the real build context directory.

N.B.: builds where FROM in one stage referenced a relative path which
had been written to a bind-mounted default build context directory by an
earlier stage broke when we started making those bind mounts into
overlays to prevent/discard modifications to that directory, and while
this extends the lifetime of that overlay so that it's consistent
throughout the build, those relative path names are still going to point
to the wrong location.

Since we need to determine SELinux labeling before mounting the overlay,
go ahead and calculate the labels to use before creating the first
builder, and remove the logic that had whichever stage thought it was
the first one set them in its parent object for use by other stages, in
what was probably a racey way.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-11-03 18:07:34 -05:00
Nalin Dahyabhai
1e6bb467fe Add --metadata-file
Add a MetadataFile field to BuildOptions, to which we write a dictionary
of information about a just-committed image.

Pay more attention to sourceDateEpoch than to timestamp when we're
tagging an existing image with the intended destination name.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-10-21 12:17:11 -04:00
Nalin Dahyabhai
7aedebdccd modernize: JSON doesn't do "omitempty" structs, so stop asking
Drop the "omitempty" tag from the "json" tag on struct members that are
themselves structs, since the JSON encoder doesn't actually do that, per
golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-09-10 13:19:38 -04:00
Nalin Dahyabhai
802b069799 modernize: use maps.Copy() instead of iterating over a map to copy it
Use maps.Copy() instead of iterating over a map's keys and values to
copy the keys and values to a new map.  Overdue from
golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-09-10 13:19:34 -04:00
Nalin Dahyabhai
16680a4dfd modernize: use strings.CutPrefix/SplitSeq/FieldsSeq
Use the CutPrefix(), SplitSeq(), and FieldsSeq() functions from the
strings package when chopping up or iterating over parts of strings, per
golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-09-10 13:11:00 -04:00
Jan Kaluza
a0a9ac6380 Switch common, storage and image to monorepo.
Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-08-29 15:04:28 +02:00
Patrick Stoeckle
9f809a88ff chore(typos): fix typos
Signed-off-by: Patrick Stoeckle <patrick.stoeckle@siemens.com>
2025-06-30 15:45:47 +02:00
Nalin Dahyabhai
865daceebb build: add --source-date-epoch and --rewrite-timestamp flags
Use $SOURCE_DATE_EPOCH as the default for the --source-date-epoch flag
to the "build" CLI.

When a source-date-epoch is set, we'll use it when writing new history
entries, force timestamps in data written for --output to the specified
timestamp, and populate a "SOURCE_DATE_EPOCH" ARG that we treat as
always being set, and which we don't complain about being left unused.
By default, this will not affect timestamps in newly-added layers.

Add a --rewrite-timestamp flag, which "clamps" timestamps in newly-added
layers to not be later than the --source-date-epoch value if the
--source-date-epoch flag is set, but has no effect otherwise.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-05 10:22:56 -04:00
Nalin Dahyabhai
6c82e7eac0 commit: add --source-date-epoch and --rewrite-timestamp flags
Add a --source-date-epoch flag, defaulting to $SOURCE_DATE_EPOCH if set,
which sets the created-on date and the timestamp for the new history
entries, but does not default to modifying the timestamps on contents in
new layers.

Add a --rewrite-timestamp flag, which "clamps" timestamps in the new
layers to not be later than the --source-date-epoch value if both
the --rewrite-timestamp and --source-date-epoch flags were set.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-04 13:02:26 -04:00
Nalin Dahyabhai
4ea64c3871 Add a dummy "runtime" that just dumps its config file
Add a dummy "runtime" that just dumps its runtime config, either the
entirety of it, or a section of it corresponding to each command line
argument.  Tests can use it to ensure that we set the right thing in the
configuration without also depending on the runtime to do as its asked,
which isn't always something we have control over.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-05-29 14:17:37 -04:00
Nalin Dahyabhai
ee0f750ea7 internal/util.SetHas(): handle maps of [generic]generic
Make SetHas() a generic function for checking if a map holds a value of
whatever kind for a key of some comparable kind.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-05-20 17:53:33 -04:00
Aaron Lehmann
cf4635e86b Refactor NewImageSource to add a manifest type abstraction (#5743)
* Refactor NewImageSource to add a manifest type abstraction

Currently, NewImageSource creates a Docker schema2 manifest and an OCI
manifest at the same time. This precludes functionality that isn't
supported by both manifest types, for example zstd compression.
Refactoring this to create only the desired manifest type solves this
and also cleans up the code by separating manifest-type-specific code
into distinct implementations of a "manifest builder".

See discussion in https://github.com/containers/buildah/pull/5452.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>

* Review feedback

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>

* Review feedback, round 2

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>

---------

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
Co-authored-by: flouthoc <flouthoc@users.noreply.github.com>
2025-05-20 13:08:17 -07:00
Kir Kolyshkin
f261d6641c Use maps.Copy
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-08 15:26:09 -07:00
Kir Kolyshkin
76e58eea14 Use slices.Concat
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-08 15:26:09 -07:00
Kir Kolyshkin
0835cb4760 Use slices.Clone
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-08 15:26:09 -07:00
Kir Kolyshkin
84a3905f61 Use slices.Contains
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-08 15:26:01 -07:00
Kir Kolyshkin
17777cf8ac Use for range over integers
Available since Go 1.22 (see https://tip.golang.org/ref/spec#For_range).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-08 10:19:51 -07:00
Kir Kolyshkin
195c6b0c9e internal/mkcw: disable ST1003 warnings
Disable warnings like this one:

> internal/mkcw/workload.go:34:2: ST1003: should not use ALL_CAPS in Go names; use CamelCase instead (staticcheck)
> 	SEV_NO_ES = types.SEV_NO_ES //revive:disable-line:var-naming
> 	^

(

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-07 13:01:56 -07:00
openshift-merge-bot[bot]
81eaf4fc3a Merge pull request #6014 from mtrmac/enforce-digests
Use UnparsedInstance.Manifest instead of ImageSource.GetManifest
2025-03-07 18:34:53 +00:00
Nalin Dahyabhai
264f557dbe internal/mkcw.Archive(): use github.com/containers/storage/pkg/ioutils
Use the AtomicWriteFile() from github.com/containers/storage/pkg/ioutils
instead of the one from github.com/docker/docker/pkg/ioutils.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-03-05 10:54:36 -05:00
Miloslav Trmač
cc4cca08d4 Use UnparsedInstance.Manifest instead of ImageSource.GetManifest
... to validate that the manifests match expected digests, if any.

In some cases, using an UnparsedInstance can also avoid redundant I/O.

Do this everywhere, even where we read local storage which is
mostly trusted, because it is cheap enough and being consistent
makes it less likely for the code to be copied into other
contexts where the sources are not trusted.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2025-02-28 20:16:07 +01:00
Nalin Dahyabhai
24826435f8 Distinguish --mount=type=cache locations by ownership, too
Normally, we select and distinguish --mount=type=cache directories that
we create by either the "id" or "target" value used when mounting them,
but we should also be distinguishing them by the "uid" and "gid" flags,
or lack thereof.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-02-07 13:38:56 -05:00
flouthoc
aadfc5cf30 unit_test: use Parallel test where possible
Add `t.Parallel()` to unit tests whereever its possible without race.

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-02-04 11:07:15 -08:00
Nalin Dahyabhai
3541a3ce2a Accept image names as sources for cache mounts
Allow the "from" option for cache mounts to refer to an image, which, if
we attempt to mount read-write, is mounted using an overlay to avoid
getting errors if the process we're running with the cache mount
attempts to write to it.

Add logic to clean up the bind mount in Builder.getBindMount() that's
triggered if Builder.runSetupVolumeMounts() returns an error.

When creating cache directories for cache mounts, process the
container's ID mappings.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-23 13:38:02 -05:00
Eng Zer Jun
59024c41ad refactor: replace golang.org/x/exp with stdlib
These experimental packages are now available in the Go standard
library since Go 1.21:

	1. golang.org/x/exp/slices -> slices [1]
	2. golang.org/x/exp/maps -> maps [2]

[1]: https://go.dev/doc/go1.21#slices
[2]: https://go.dev/doc/go1.21#maps

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2025-01-24 00:27:55 +08:00
Nalin Dahyabhai
9b9c161ff5 Add more checks to the --mount flag parsing logic
* Make volumes.GetBindMount(), volumes.GetCacheMount(), and
  volumes.GetTmpfsMount() return errors when flags which expect
  arguments are given empty arguments, when flags which don't expect
  arguments are given arguments, and when the "relabel" flag, which
  expects an argument, doesn't get one.
* Make volumes.GetCacheMount() not treat the "U" flag as affecting bind
  propagation.
* Drop the special-case error message when a caller attempts to use
  "src" or "source" options in volumes.GetTmpfsMount(), which would
  already be covered by the general-purpose "unrecognized option"
  default.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-20 17:51:11 -05:00
Nalin Dahyabhai
6e62bd0835 Fix TOCTOU error when bind and cache mounts use "src" values
Fix a time-of-check/time-of-use error when mounting type=bind and
type=cache directories that use a "src" flag.  A hostile writer could
use a concurrently-running stage or build to replace that "src" location
between the point when we had resolved possible symbolic links and when
runc/crun/whatever actually went to create the bind mount
(CVE-2024-11218).

Stop ignoring the "src" option for cache mounts when there's no "from"
option.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-17 09:59:55 -05:00
Nalin Dahyabhai
25a3b385af internal/volume.GetBindMount(): discard writes in bind mounts
When handling RUN --mount=type=bind, where the mount is read-write,
instead of a simple bind mount, create an overlay mount with an upper
directory that will be discarded after the overlay mount is unmounted.
This brings us in line with the expected behavior, wherein writes to
bind mounts should be discarded.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-17 09:59:55 -05:00
Nalin Dahyabhai
50210d51c9 Add internal/volumes.bindFromChroot()
Add a helper that uses the new internal/open package to bind mount a
location inside of a chroot direct to a new temporary location, for
ensuring that the latter is not bind-mounted from outside of the chroot.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-17 09:59:55 -05:00
Nalin Dahyabhai
f7155c0abd Add an internal/open package
Add a package that lets us open a directory in a chroot, pass its
descriptor up, and then bind mount that directory to a specified
location.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-17 09:59:55 -05:00
Daniel J Walsh
adf54cde0e Add support for --security-opt mask and unmask
Fixes: https://github.com/containers/buildah/issues/5881

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2025-01-07 08:46:48 -05:00
Nalin Dahyabhai
77e3570202 Allow cache mounts to be stages or additional build contexts
Allow cache mounts (RUN --mount=type=cache) to refer to other stages or
additional build contexts.

Update the build-check-cve-2024-9675 integration test to use different
directories for its main build context and the additional build context
that it uses for its final run.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-01-06 15:45:50 -05:00
Nalin Dahyabhai
701d6bbe91 Handle RUN --mount with relative targets and no configured workdir
When the target location of a RUN --mount is specified as a relative
path, we normally try to convert it to an absolute path by combining it
with the currently-configured working directory.  If there is no such
value, though, the result is still not an absolute path.  Work around
this by using "/" when the configured working directory is "".

Set this field in the `runMountInfo` struct on FreeBSD, as we already
did on Linux.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-11-04 09:51:20 -05:00
Matt Heon
873beddbab Properly validate cache IDs and sources
The `--mount type=cache` argument to the `RUN` instruction in
Dockerfiles was using `filepath.Join` on user input, allowing
crafted paths to be used to gain access to paths on the host,
when the command should normally be limited only to Buildah;s own
cache and context directories. Switch to `filepath.SecureJoin` to
resolve the issue.

Fixes CVE-2024-9675

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-10-10 11:02:55 -04:00
Nalin Dahyabhai
732f770648 CVE-2024-9407: validate "bind-propagation" flag settings
CVE-2024-9407: validate that the value for the "bind-propagation" flag
when handling "bind" and "cache" mounts in `buildah run` or in RUN
instructions is one of the values that we would accept without the
"bind-propagation=" prefix.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-10-01 11:01:45 -04:00
Nalin Dahyabhai
e8e83bb8bd Update some godocs, use 0o to prefix an octal in a comment
Update some godocs, and update an octal value in a godoc to start with
0o instead of just 0, to match the literal on the next line.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-21 14:22:27 -04:00
Nalin Dahyabhai
8ae99121c1 CI: enable the gofumpt linter
Turn on the gofumpt linter.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-15 13:17:44 -04:00
Nalin Dahyabhai
fdf1c75cd3 linters: unused arguments shouldn't have names
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-07 10:10:35 -04:00
Nalin Dahyabhai
a42019d614 Drop copyStringSlice() and copyStringStringMap()
Use slices.Clone() and maps.Clone() instead of our own non-generic
functions.  We have to be more careful in a couple of places where we
set items in maps which aren't unconditionally initialized.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-05 11:01:07 -04:00
Giuseppe Scrivano
8bdd6a66d4 internal: use fileutils.(Le|E)xists
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-12 09:58:14 +02:00