Commit Graph

157 Commits

Author SHA1 Message Date
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
Romain Geissler f949a49ab0
Restore the default meaning of `--pull` (should be `always`).
Now the bud --help output correctly reads that the default behavior when
--pull is not provided at all is "missing", and that the default value
for --pull if explicitly provided but without value is "always".

Fixes #6266.

Signed-off-by: Romain Geissler <romain.geissler@amadeus.com>
2025-07-28 16:21:31 +00:00
Nalin Dahyabhai 962ab4bb1e commit,build: --source-date-epoch/--timestamp omit identity label
When using either --source-date-epoch or --timestamp, default to not
adding a label with our version number in it, since it can change
between builds.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-10 16:18:50 -04:00
flouthoc 56f3171ab0
parse, validateExtraHost: honor Hostgateway in format
Flag `--add-host` should support `host-gateway` when argument is in the
form of `buildah build --add-host=proxyhost:host-gateway .`

This is consistent with podman.

Closes: https://github.com/containers/podman/issues/26034

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-05-30 09:56:35 -07:00
Nalin Dahyabhai 5cfbf72410 pkg/parse.GetBuildOutput(): use strings.Cut()
Use strings.Cut() to make this a little easier to follow.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-05-21 09:44:46 -04:00
Daniel J Walsh 081e9b308d
Support label_users in buildah
Fixes: https://github.com/containers/buildah/issues/6160

label_users tells buildah and podman to maintain the user and role
from the SELinux label, the default is to change the user and role to
system_u:system_r.

With this change we end up with an unconfined_u user running the
container as unconfined_u:unconfined_r.

I don't believe our CI/CD system can test this, because it runs with
system_u:system_r by default.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2025-05-06 07:13:27 -04: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 52001ac4de Use switch to fix QF1003 warnings
These:

> copier/copier.go:1664:2: QF1003: could use tagged switch on hdr.Typeflag (staticcheck)
> 	if hdr.Typeflag == tar.TypeReg {
> 	^
> pkg/parse/parse.go:708:4: QF1003: could use tagged switch on arr[1] (staticcheck)
> 			if arr[1] == "local" {
> 			^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-07 13:01:56 -07: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 6c85740bab Document more buildah build --secret options
Describe the "env" and "type" options in the buildah-build(1) man page.

When parsing the "--secret=" flag for the CLI, instead of ignoring an
option that we don't recognize, return an error.

Even though the set of meaningful "id" values for secrets is passed in
via the command line, don't directly use it to construct a file path.

Change the default mode for SSH agent sockets that we create from 0o620
to 0o600.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-10-17 12:02:29 -04:00
cuishuang c07ae2b4cf fix: remove duplicate conditions
Signed-off-by: cuishuang <imcusg@gmail.com>
2024-09-19 15:30:30 +08:00
Nalin Dahyabhai ca3b80eb0f CI: enable the whitespace linter
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-15 16:09:25 -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 c7b7f12727 Update to spun-out "github.com/containerd/platforms"
In 1.7.19, containerd spun out its platforms package into its own
repository.  Update to use the new repository.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-08 09:30:10 -04:00
Nalin Dahyabhai f52158f0e1 linters: unchecked error
Check a previously-unchecked error.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-07 10:10:35 -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 21fb5ea4f2 Rework parsing of --pull flags
Rework parsing of --pull flags to add "newer" as an alias for "ifnewer",
and to reject unrecognized values instead of treating them as synonymous
with "ifmissing".

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-24 11:02:12 -04:00
Giuseppe Scrivano 441bdc9274
pkg/parse: use fileutils.(Le|E)xists
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-12 09:58:14 +02:00
Daniel J Walsh 63975b5418
Properly handle build --pull=false
buildah build --pull=false is documented to never pull the image, but it
is currently ignored.

Fixes: https://github.com/containers/podman/issues/21783

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-02-26 16:42:14 -05:00
Nalin Dahyabhai 1def7d6de4 Split up error messages for missing --sbom related flags
Split up the diagnostic for missing SBOM generation settings so that we
can more easily tell the difference between "you didn't tell me where to
put the output files" and "I don't know how to generate things".

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-02-07 15:57:55 -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
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
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
Nalin Dahyabhai 0a85c0629f Make TEE types case-insensitive
Make sure that we accept both upper- and lower-cased versions of the
names of TEE types as arguments for `buildah build`'s --cw flag and for
`buildah mkcw`'s --type flag.  We previously only understood lower-case
versions, but the docs always used upper case.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-14 15:04:35 -05:00
Nalin Dahyabhai af394a83d2 pkg/parse.Platform(): minor simplification
Simplify the logic of Platform() a bit.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-08 15:53:52 -05:00
Daniel J Walsh 48a9c43718
Add --no-hostname option to buildah containers
Fixes: https://github.com/containers/buildah/issues/5093

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-10-24 19:43:56 -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
Aditya R 3a351f6032
parse: use GetTempDir from internal utils
Use a common code for `GetTempDir`

[NO NEW TESTS NEEDED]

Signed-off-by: Aditya R <arajan@redhat.com>
2023-06-05 13:34:43 +05:30
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
Aditya R be682de68c
build: validate volumes on backend
Validate build volumes on backend and not on frontend

Closes: https://github.com/containers/podman/issues/17139

[NO NEW TESTS NEEDED]
Exisiting volumes checks must pass. ( Tests might need retrofit in error
message )

Signed-off-by: Aditya R <arajan@redhat.com>
2023-05-15 16:44:53 +05:30
Aditya R a913dc56a0
parse: filter edge-case for podman-remote
podman-remote has a bug where it sends `/` when no platform is set,
patch is there to make sure older clients still work if backend is
updated

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-05-01 12:18:31 +05:30
Aditya R b37c4ee438
build: --platform must accept only arch
Make error message for `--platform` more clear and use
`platforms.Parse(` so `--platform` can automatically detect `OS` if not
specified.

Closes: https://github.com/containers/podman/issues/18194
Closes: https://github.com/containers/buildah/issues/4756

Signed-off-by: Aditya R <arajan@redhat.com>
2023-04-27 13:43:20 +05:30
Aditya R 6a0367ff2d
pkg/parse: expose public CleanCacheMount API
PR https://github.com/containers/buildah/pull/4490 added a new API
`CleanCacheMount` which allows cleaning the buildcache and cache generated
on host by --mount=type=cache just like buildkit's prune command.

Following API is needed to tools like podman can utilize this and
integrate it to the commands like `podman system reset`

[NO NEW TESTS NEEDED]
[NO TESTS NEEDED]
Test already added here: https://github.com/containers/buildah/pull/4490

Signed-off-by: Aditya R <arajan@redhat.com>
2023-02-01 09:04:10 +05:30
Erik Schnetter 4952862a22
Correct minor comment
[NO NEW TESTS NEEDED]

Signed-off-by: Erik Schnetter <schnetter@gmail.com>
2023-01-05 13:16:11 -05:00
Aditya R 7a4702ae25
parse: default ignorefile must not point to symlink outside context
Drop support for remote use-cases when .containerignore or .dockerignore is a symlink pointing to arbitrary location on host.

[NO NEW TESTS NEEDED]
[NO TESTS NEEDED]

Signed-off-by: Aditya R <arajan@redhat.com>
2022-12-19 16:27:44 +05:30
Aditya R ffed850367
remote-cache: support multiple sources and destinations
Buildah must support multiple sources for remote cache when using
`--cache-to` and `--cache-from` so users can distribute and collect
cache from various sources.

We also need for compat with buildkit api which in past broke `podman`
compat build API see: https://github.com/containers/podman/pull/16380

More discussion here: https://github.com/containers/podman/pull/16380

Signed-off-by: Aditya R <arajan@redhat.com>
2022-12-05 12:10:41 +05:30
Daniel J Walsh d4c661a774
Add no-new-privileges flag
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-11-04 11:43:29 -04:00
Daniel J Walsh 8d5d763213
Fix stutters
Podman adds an Error: to every error message. So starting an error
message with "error" ends up being reported to the user as

Error: error ...

This patch removes the stutter.

Also ioutil.ReadFile errors report the Path, so wrapping the err message
with the path causes a stutter.

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-19 07:11:44 -04:00
Aditya R a30b71db2c
build: honor <Containerfile>.containerignore as ignore file
As per buildkit backend documentation when using the BuildKit backend, docker build searches for
a `.dockerignore` file relative to the Dockerfile name. For example, running `docker build -f myapp.Dockerfile .`
will first look for an ignore file named `myapp.Dockerfile.dockerignore`. If such a file is not found, the
`.dockerignore` file is used if present. Using a Dockerfile based `.dockerignore` is useful if a project contains
multiple Dockerfiles that expect to ignore different sets of files.

Following PR introduces this buildkit feature parity.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-09-13 20:37:39 +05:30
Nalin Dahyabhai 4407875a50 Use constants from containers/common for finding seccomp.json
Use values from containers/common for locating seccomp.json.  At the
moment this isn't actually a change, but we don't want to fall out of
step again.

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-09-09 10:25:18 -04:00
Daniel J Walsh 0bdbd1a80e
Buildah should ignore /etc/crio/seccomp.json
[NO NEW TESTS NEEDED]

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2123251

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-04 07:23:58 -04:00
Nalin Dahyabhai 9637a24425 cmd/buildah: add "manifest create --amend"
When `buildah manifest create` is given the `--amend` flag and a list
with the name that was specified for the to-be-created list already
exists, just reuse the list.

Make the `--insecure` flag, if we see it, conflict with `--tls-verify`,
but have the reverse of the effect that `--tls-verify` does, and teach
the `buildah manifest` `add`, `create`, and `push` subcommands about
it.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-08-16 19:43:41 -04:00
Nalin Dahyabhai bb149ea686 Use errors.Is() instead of os.Is{Not,}Exist
If errors for which os.IsExist() or os.IsNotExist() would have returned
true have been wrapped using fmt.Errorf()'s "%w" verb, os.IsExist() and
os.IsNotExist(), not having been retrofitted to use errors.Is(), will
return false.

Use errors.Is() to check if an error is an os.ErrExist or os.ErrNotExist
error instead of calling os.IsExist() or os.IsNotExist().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-07-26 15:36:58 -04:00
Aditya R 6f660bde17
build,cache: support pulling/pushing cache layers to/from remote sources
Following commit

* Initiates `cacheKey` or `layerKey` for intermediate images generated
  for layers.
* Allows end users to upload cached layers with `cacheKey` to remote
  sources using `--cache-to`. `--cache-to` is a optional flag to be used
with `buildah build` which publishes cached layers to remote sources.
* Allows end users to use cached layers from `remote` sources with
  `--cache-from`. `--cache-from` is a optional flag to be used with
`buildah build` and it pulls cached layers from remote sources in a step
by step manner only if is a valid cache hit.

Example
* Populate cache source or use cached layers if already present
```bash
buildah build -t test --layers --cache-to registry/myrepo/cache --cache-from registry/myrepo/cache .
```

Future:
* `cacheKey` or `layerKey` model is only being used when working with
  remote sources however local cache lookup can be also optimized if its
is altered to use `cacheKey` model instead of iterating through all the
images in local storage. As discussed here

References:
* Feature is quite similar to `kaniko`'s `--cache-repo`: https://github.com/GoogleContainerTools/kaniko#--cache-repo

Closes: issues#620

Signed-off-by: Aditya R <arajan@redhat.com>
2022-07-26 01:49:13 +05:30
Sascha Grunert ce384684c0
Switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of
the deprecated github.com/pkg/errors package.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-07 11:41:47 +02:00
Aditya R 5686018e79
build: support OCI hooks for ephemeral build containers
Following PR adds support for OCI hooks attached to each of ephemeral
build contains which are created by `RUN` step invoked during `buildah
build` command.

Following PR also adds `--hooks-dir` flag to `buildah build` option
which allows end-users to specify one or more configuration directories
for OCI-hooks.

Note: Following PR migrates `pkg/hooks` from `podman` to `buildah` so
buildah could implement this feature and once merged `podman` can start
using `buildah/pkg/hooks`.

For usage see man-page and example test-case.

See: https://github.com/opencontainers/runtime-spec/blob/main/config.md#posix-platform-hooks

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-06-28 11:21:28 +05:30
Aditya R 20c5c5c6d8
build, userns: add support for --userns=auto
Buildah now supports `--userns=auto` which can automatically pick an empty range and create an user namespace for the container.

The `--userns=auto` flag, requires that the user name containers and a range of subordinate user ids that the build container is allowed to use be specified in the /etc/subuid and /etc/subgid files.

Example: `containers:2147483647:2147483648`.

Buildah allocates unique ranges of UIDs and GIDs from the containers subordinate user ids. The size of the ranges is based on the number of UIDs required in the image. The number of UIDs and GIDs can be overridden with the size option.

Valid auto options:

    * gidmapping=CONTAINER_GID:HOST_GID:SIZE: to force a GID mapping to be present in the user namespace.

    * size=SIZE: to specify an explicit size for the automatic user namespace. e.g. --userns=auto:size=8192. If size is not specified, auto will estimate a size for the user namespace.

    * uidmapping=CONTAINER_UID:HOST_UID:SIZE: to force a UID mapping to be present in the user namespace.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-06-20 13:08:02 +05:30