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
flouthoc
5b414ad08f source-push: add support for --digestfile
Allow writing digest of the pushed source to the specified `digestfile`

Closes: https://github.com/containers/buildah/issues/5399

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-04-02 15:13:52 -07:00
tomsweeneyredhat
4304d618f3 CVE-2024-1753 container escape fix
Addresses CVE-2024-1753 which allowed a user to write files to the
`/` directory of the host machine if selinux was not enabled.

Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
2024-03-18 15:21:53 -04:00
Nalin Dahyabhai
4f0b619dd2 Use golang.org/x/exp/slices.Contains
... instead of github.com/containers/common/pkg/util.StringInSlice,
per linters.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-02-07 11:50:41 -05:00
Nalin Dahyabhai
e99960085c Fix a couple of typos in one-line comments
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-02-07 11:49:43 -05:00
Daniel J Walsh
011736e12f Allow users to specify no-dereference
We have this same parsing code in 3 maybe 4 places in our sources,
Someone needs to go through it all and get this to be parsed in less
places.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-01-29 07:12:46 -05:00
Nalin Dahyabhai
cf69e8a187 build,commit: add --sbom to scan and produce SBOMs when committing
Add a --sbom flag to `buildah build` and `buildah commit` which will
scan the rootfs and specified context directories to build SPDX or
CycloneDX SBOMs and lists of package URLs.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-01-19 13:55:57 -05:00
Nalin Dahyabhai
89f50af211 internal/mkcw.Archive(): handle extra image content
When we have extra files to add to the image, handle them by adding them
to the upper overlay layer before creating the plaintext filesystem
image.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-01-15 09:51:13 -05:00
Philip Dubé
a42bfd0191 Replace map[K]bool with map[K]struct{} where it makes sense
Signed-off-by: Philip Dubé <philip@peerdb.io>
2024-01-05 15:58:43 +00:00
Philip Dubé
53c65dd360 Replace strings.SplitN with strings.Cut
Introduced in go 1.18: https://github.com/golang/go/issues/46336

[NO NEW TESTS NEEDED]

Signed-off-by: Philip Dubé <philip@peerdb.io>
2024-01-02 17:15:12 +00:00
openshift-merge-bot[bot]
b535c90832 Merge pull request #5228 from rhatdan/compress
manifest: addCompression use default from containers.conf
2023-12-18 15:27:03 +00:00
Aditya R
4a9dba6472 manifest: addCompression use default from containers.conf
Replaces: https://github.com/containers/buildah/pull/5014

Signed-off-by: Aditya R <arajan@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-12-16 06:50:38 -05:00
Nalin Dahyabhai
81435aadcb mkcw: populate the rootfs using an overlay
When using the working container's rootfs to populate a plaintext disk
image with mkfs, instead of writing .krun_config.json to the rootfs and
then removing it afterward (since we don't want it to show up if the
same working container is later committed to non confidential-workload
image), mount an overlay filesystem using a temporary directory as the
upper and the rootfs as the lower, create the .krun_config.json file in
the overlay filesystem, and use the overlay filesystem as the source
directory for mkfs.

Add the necessary stubs to allow pkg/overlay to at least compile on
non-Linux systems.  Change the naming scheme for a test so that the path
names it uses for temporary directories don't include "," or "=", which
can confuse the kernel.

Creating confidential workload images will now only be possible on Linux
systems, but we exec'd out to sevctl to read platform certificates, and
that requires kernel support with vendor firmware, so I don't know that
anyone will actually be impacted by the change.

Teach pkg/overlay.MountWithOptions() to accept `nil` as a pointer to a
struct parameter that is otherwise optional.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-12-13 14:06:59 -05:00
Daniel J Walsh
471460018b Ignore errors if label.Relabel returns ENOSUP
This is a common mistake by users and is ignored in some places
but not everywhere. This change will help this to be ignored everwhere.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-11-29 06:54:21 -05:00
Nalin Dahyabhai
3b795dd4bc internal/mkcw/embed/entrypoint.gz: rename to include the arch
Include the arch in the name of the static entrypoint binary, in case we
find ourselves needing to support other architectures in the same area
in the future.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-28 16:43:44 -05:00
Nalin Dahyabhai
3a61cc0996 Add OverrideChanges and OverrideConfig to CommitOptions
Add an OverrideChanges and an OverrideConfig field to CommitOptions,
both of which can be used to make last-minute edits to the configuration
of an image that we're committing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-17 12:54:23 -05:00
Aditya R
bbb55b8b81 buildah: add heredoc support for RUN, COPY and ADD
Following PR is a attempt to add `Heredoc` support to buildah.

Once this PR is merged buildah is supposed to honor heredoc syntax while
processing containerfiles

Expected syntax to work

```Dockerfile
FROM docker.io/library/python:latest
RUN <<EOF
echo "Hello" >> /hello
echo "World!" >> /hello
EOF

RUN python3 <<EOF
with open("/hello", "w") as f:
    print("Hello", file=f)
    print("Something", file=f)
EOF

RUN ls -a
RUN cat hello
```

Signed-off-by: Aditya R <arajan@redhat.com>
2023-11-17 21:17:52 +05:30
Nalin Dahyabhai
4f3876d8ec Add godoc for pkg/parse.GetTempDir
Add some godoc for pkg/parse.GetTempDir()

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-15 14:27:21 -05:00
Daniel J Walsh
8f86c5784f Update cirrus and version of golang
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-11-09 14:12:30 -06:00
Daniel J Walsh
3b96b1cafb Use mask definitions from containers/common
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-10-27 13:10:18 -04:00
Valentin Rothberg
02f781b354 container.conf: support attributed string slices
All `[]string`s in containers.conf have now been migrated to attributed
string slices which require some adjustments in Buildah and Podman.

[NO NEW TESTS NEEDED]

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 15:34:23 +02:00
Valentin Rothberg
c536048cac vendor c/common: appendable containers.conf strings, Part 1
This change is the first step of integrating appendable string arrays
into containers.conf and starts with enabling the `Env`, `Mounts`, and
`Volumes` fields in the `[Containers]` table.

Both, Buildah and Podman, read (and sometimes write) the fields of the
`Config` struct at various places, so I decided to migrate the fields
step-by-step.  The ones in this change are most critical ones for
customers.  Once all string slices/arrays are migrated, the docs of
containers.conf will be updated.  The current changes are entirely
transparent to users.

[NO NEW TESTS NEEDED]

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-24 17:00:38 +02:00
Urvashi Mohnani
7c8b51068e Vendor containers/common
Pick up changes to move the platform code to its own directory.

[NO NEW TESTS NEEDED]

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2023-10-16 10:49:31 -04:00
Aditya R
9c99d7ca88 run: use internal.GetTempDir with os.MkdirTemp
Projects which are using buildah as a library and set `TMPDIR` manually
can stumble upon a use-case where `TMPDIR` was set to a relative path.

Such as `export TMPDIR=.` in such case buildah will try to create a
temporary root using `Mkdirtemp` leading to a point where bundle is not
generated correctly since path was relative.

Following use case can be resolved by making sure that buildah always
converts relative path to absolute path and `GetTempDir` does it well.

Example reproducer with podman

```Dockerfile
FROM alpine
RUN echo hello
```

```console
export TMPDIR=.
podman build --no-cache -t test .
```

Expected failure
```console
STEP 1/2: FROM alpine
STEP 2/2: RUN echo hello
error running container: checking permissions on "buildah2341274198": stat buildah2341274198: no such file or directory
ERRO[0000] did not get container create message from subprocess: EOF
Error: building at STEP "RUN echo hello": while running runtime: exit status 1
```

Closes: RHEL-2598

Signed-off-by: Aditya R <arajan@redhat.com>
2023-10-11 21:49:18 +05:30
Aditya R
9c57af8d14 mkcw: remove entrypoint binaries
Remove generated binaries

[NO NEW TESTS NEEDED]

Signed-off-by: Aditya R <arajan@redhat.com>
2023-10-06 13:19:34 +05:30
Nalin Dahyabhai
5bfc7d9a40 Update some comments related to confidential workload
Add siena and turin to the list of generations in a comment.
Drop a double-whitespace in the middle of a comment sentence.

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-10-04 17:04:33 -04:00
Daniel J Walsh
e90b3502b7 GetTmpDir is not using ImageCopyTmpdir correctly
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-09-14 08:12:52 -04:00
Paul Holzinger
0191bc6710 Split GetTempDir from internal/util
With this pkg/parse does not depend on libimage.

[NO NEW TESTS NEEDED]

Based on Miloslav's work: https://github.com/containers/podman/pull/19718

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-09-12 15:21:04 +02:00
Paul Holzinger
6e6827b270 Move most of internal/parse to internal/volumes
internal/parse does not need to depend on libimage.
This allows for a smaller podman remote client.

Based on Miloslav's work: https://github.com/containers/podman/pull/19718

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-09-12 14:29:31 +02:00
Nalin Dahyabhai
e89fac6c9b Add buildah mkcw, add --cw to buildah commit and buildah build
Add a --cw option to `buildah build` and `buildah commit`, which takes a
comma-separated list of arguments and produces an image laid out for use
as a confidential workload:
  type: sev or snp
  attestation_url: location of a key broker server
  cpus: expected number of virtual CPUs to run with
  memory: expected megabytes of memory to run with
  workload_id: a distinguishing identifier for the key broker server
  ignore_attestation_errors: ignore errors registering the workload
  passphrase: for encrypting the disk image
  slop: extra space to allocate for the disk image

At least one of attestation_url and passphrase must be specified in
order for the encrypted disk image to be decryptable at run-time.  Other
arguments can be omitted.  ignore_attestation_errors is intentionally
undocumented, as it's mainly used to permit some amount of testing on
systems which don't have the required hardware.

Add an `mkcw` top-level command, for converting directly from an image
to a confidential workload.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-09-07 14:05:10 -04:00
Nalin Dahyabhai
cc619c28d9 Make sure that pathnames picked up from the environment are absolute
When we read TMPDIR and SSH_AUTH_SOCK from the environment, convert them
to absolute paths before using them.  Call auth.GetDefaultAuthFile()
instead of reading REGISTRY_AUTH_FILE.

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-09-07 11:20:54 -04:00
Miloslav Trmač
62d4057718 Add a missing .Close() call on an ImageSource
[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-07-31 23:57:38 +02:00
Miloslav Trmač
e588986fa6 Create only a reference when that's all we need
Don't create an ImageDestination only to call .Reference() on it. copy.Image
manages its own ImageSource/ImageDestination instances.

- On the pull path, this causes two ImageDestination objects to exist concurrently
  for the same directory. That's not really expected to work (because the implementation
  caches a modified top-level index in memory); luckily it currently doesn't matter
  because we don't make any writes through the manually-managed object, but it's
  a risk for future changes.
- On the push path, this creates a local object when the thing to push just doesn't exist.

Note that the code calls the input "sourcePath" but it can contain a tag, and that
seems to be intentional.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-07-31 23:57:38 +02:00
Miloslav Trmač
fe947ed9cc Add a missing .Close() call on an ImageDestination
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-07-31 23:57:38 +02:00
Daniel J Walsh
6714a79eb0 Make cli.EncryptConfig,DecryptConfig, GetFormat public
We want to share these functions with Podman, Podman currently
has a slightly different version which is correct, so use correct
version in Buildah and vendor it into Podman.

Fixing: https://github.com/containers/podman/issues/18196

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-06-09 11:09:18 -04:00
Miloslav Trmač
b3e39dfd94 Don't decrypt images by default
A non-nil but empty decryption configuration
seems to be valid enough to trigger decryption in some
configurations, per
https://github.com/containers/podman/issues/18196 .

Like in Skopeo and Podman, only decrypt when the user explicitly
instructs us to (e.g. not triggering decryption based on environment
variables).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-06-09 07:45:38 -04:00
Aditya R
6adbfeeb4f GetTmpDir: honor image_copy_tmp_dir from containers.conf
https://github.com/containers/common/blob/main/docs/containers.conf.5.md
contains a field `image_copy_tmp_dir` so `GetTmpDir` must honor that in
case `ENV: TMPDIR` is not found.

Closes: https://github.com/containers/buildah/issues/4787

Signed-off-by: Aditya R <arajan@redhat.com>
2023-06-05 13:33:41 +05:30
danishprakash
c8c37c78fe parse: add support for relabel bind mount option
Signed-off-by: danishprakash <danish.prakash@suse.com>
2023-04-04 13:55:57 +05:30
Daniel J Walsh
4dfb828909 Run codespell on codebase
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-02-09 09:05:03 -05:00
Aditya R
ac7458e70d stage_executor: while mounting stages use freshly built stage
When using `--mount=` in RUN instruction and source is a stage make sure
that freshly built stage is used if the stage selected in source was
just rebuilt.

Closes: https://github.com/containers/buildah/issues/4522

Signed-off-by: Aditya R <arajan@redhat.com>
2023-01-18 16:15:16 +05:30
Aditya R
3566683896 buildah: add prune command and expose CleanCacheMount API
* Just like buildkit buildah must allow cleaning the buildcache and cache
generated on host by `--mount=type=cache` just like buildkit's `prune`
command.

* Also expose `CleanCacheMount` API so other tools like `podman` can use
  it.

See: https://github.com/moby/buildkit#cache
Closes: https://github.com/containers/buildah/issues/4486

Signed-off-by: Aditya R <arajan@redhat.com>
2023-01-05 17:32:42 +05:30
Aditya R
d9578d32cd build, mount: allow realtive mountpoints wrt to work dir
When working with `--mount=type=bind` and `--mount=type=cache` allow
`target` to accept relative paths w.r.t to the configured work dir.

Closes: https://github.com/containers/buildah/issues/4309

Signed-off-by: Aditya R <arajan@redhat.com>
2022-12-15 16:30:34 +05:30
Chris Evich
46eea31588 Replace io/ioutil calls with os calls
In golang 1.19, `io/ioutil` is fully deprecated preventing Buildah from
compiling.  Replace all calls with equivalent calls from the `os`
package.

Signed-off-by: Chris Evich <cevich@redhat.com>
2022-12-06 14:29:32 -05:00
Miloslav Trmač
a1698cde60 Update c/storage after https://github.com/containers/storage/pull/1436
... and update to remove the now-deprecated Locker interface.

[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-12-01 15:39:25 +01:00
Aditya R
e6eb05f757 mount=type=cache: seperate cache parent on host for each user
`mount=type=cache` creates a common cache directory on host in temporary
directory, split this cache directory for each user invocation in order
to prevent overlapping of cache content when `buildah` is invoked by
different users on same host.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-11-18 10:04:55 +05:30
Doug Rabson
646c282901 Use TypeBind consistently to name bind/nullfs mounts
This allows declaring run mounts using e.g. '-mount=type=nullfs,...' on
FreeBSD which makes more sense for FreeBSD users. It is also consistent
with 'podman run' which requires the nullfs mount type on FreeBSD.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-11-07 17:19:56 +00:00
Miloslav Trmač
8356687157 Ensure the cache volume locks are unlocked on all paths
... and use a more traditional error handling model,
where responsibility for the cleanup passes to the caller
_only_ if the called function succeeds.

To reinforce that, hard-code nil returns on error paths
instead of returning the locks.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-20 00:14:18 +02:00
Miloslav Trmač
60382209e3 Simplify the interface of GetCacheMount and getCacheMount
It can return at most one lock, so don't return an array.

Should not change behavior right now, but it will simplify
cleanup.

[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-19 23:23:34 +02:00
Miloslav Trmač
8f955f8019 Fix cache locks with multiple mounts
Maintain a list of _all_ the locks, not just the last one.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-19 23:23:34 +02:00
Miloslav Trmač
cfa10d16c9 Maintain cache mount locks as lock objects instead of paths
They exist in memory anyway, so this is more efficient:
we avoid the need to manually touch the filesystem again,
the associated costs - and the error paths go away.

[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-19 23:23:33 +02:00
Aditya R
f2e0af5c43 mount,cache: lockfiles must not be part of users cache content
`--mount=type=cache` must not add internal lockfiles to cache directory
created by users instead store it in a different central directory with
path as `/base/buildah-cache/buildah-lockfiles`.

There are use-cases where users can wipe cache between the builds so
lockfiles will be removed in unexpected manner and also its not okay to
mix buildah's internal construct with user's cache content.

Helps in: https://github.com/containers/buildah/issues/4342

Signed-off-by: Aditya R <arajan@redhat.com>
2022-10-19 14:27:02 +05:30