Commit Graph

1452 Commits

Author SHA1 Message Date
Kir Kolyshkin c2b42c5e4f Fix some codespell errors
[NO NEW TESTS NEEDED]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-11-11 10:49:04 -08:00
Ed Santiago e3950407f2 tests: skip two ulimit tests
They compare buildah-bud against podman-run, which breaks if
/usr/bin/podman changes its ulimits, as happened recently
in podman PR 24335.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-11-07 08:24:26 -07:00
openshift-merge-bot[bot] d655c589a7
Merge pull request #5821 from Luap99/lint
tests/tools: update golangci-lint to v1.61.0
2024-11-07 14:32:20 +00:00
openshift-merge-bot[bot] 0f07c3db73
Merge pull request #5804 from edsantiago/para-prep-bud
tests: bud: make parallel-safe
2024-11-07 12:58:49 +00:00
Paul Holzinger 2cba66285e
tests/tools: rebuild tools when we change versions
As I used this locally and the binaires already existed make did not
rebuild. While we could list all go files here nobody should be
modifying files under vendor/ directly so just checking go.mod/sum seems
easiest.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-07 11:06:45 +01:00
Paul Holzinger 3cf2ec21bd
tests/tools: update golangci-lint to v1.61.0
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-07 11:01:48 +01: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
Ed Santiago 9a5b88d3ee tests: bud: make parallel-safe
- all images pushed to a local registry must have a unique name.
  Bring in safename() helper from podman tests.

- all cache tests must use a private TMPDIR

- in force-compression test, use a custom-crafted image with
  no possibility of sharing layers with any other image that
  any other test might push to the registry.

- use a private crun tmpdir in seccomp test, because crun
  does some unexpected caching.

And, forgive me, a little refactoring of unpleasant duplication

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-11-04 06:02:46 -07:00
Ed Santiago 3c4e552eb3 tests: blobcache: use unique image name
Prep work for parallelizing bats tests: when pushing images to
local registry, use a pseudorandom unique name to avoid
possibility of collisions/conflicts with other tests. This
is good practice regardless of whether we run serial or parallel.

Also slight refactor of some duplicate code.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-10-31 05:23:51 -06:00
openshift-merge-bot[bot] 3c43322419
Merge pull request #5803 from edsantiago/para-prep-sbom
tests: sbom: never write to cwd
2024-10-30 16:53:53 +00:00
Ed Santiago 1cd6346b3c tests: sbom: never write to cwd
Write output files only to $TEST_SCRATCH_DIR, never to cwd

Reformat overly-long lines for readability (whitespace only changes)

And, in the last test, the output files are plaintext, not json.
Fix filenames accordingly.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-10-29 10:32:49 -06:00
Ed Santiago 2797d22ab3 tests: mkcw: bug fixes, refactor
Bugs found during testing of parallel bats tests:

 - write randomfiles in $TEST_SCRATCH_DIR, not cwd!
 - remove unused & confusing & broken expectedEnv code

And, I couldn't help myself, improve & refactor one test

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-10-29 09:10:18 -06:00
Nalin Dahyabhai 855ec0f0c5 tests/test_runner.sh: remove some redundancies
This wrapper doesn't need to load anything from helpers.bash, because
the various .bats files already do so on their own.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-10-21 14:39:55 -04:00
Nalin Dahyabhai 5abf038ddc Integration tests: run git daemon on a random-but-bind()able port
Use a listener helper to bind to an available-according-to-the-kernel
listening port and run a command with its stdio more or less tied to the
connection instead of trying to launch a git daemon directly using a
port number that we can only guess is available.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-10-21 14:39:55 -04: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
Daniel J Walsh aeb6ffeece
Add support for COPY --exclude and ADD --exclude options
Fixes: https://github.com/containers/buildah/issues/5678

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-10-16 16:30:16 -04: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
openshift-merge-bot[bot] bd0de14c46
Merge pull request #5755 from k9withabone/manifest-push-all
Make `buildah manifest push --all` true by default
2024-10-03 21:17:32 +00:00
openshift-merge-bot[bot] c68e17b4ff
Merge pull request #5754 from kolyshkin/cap
Don't set ambient caps; switch to moby/sys/capability
2024-10-02 15:27:19 +00:00
Paul Holzinger c7dd90dd7b
tests: add quotes to names
In podman we also run the bud tests, there I noticed a issue with the
podman skip logic as it was unable to fine the build-add-https-retry-ca
test name as it always expects quotes[1]

In general names should be human readable so add quotes and use spaces
over a dash as word separator.

[1] https://github.com/containers/podman/pull/24135

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-10-02 14:57:38 +02: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
Kir Kolyshkin 95f2e1020f vendor: switch to moby/sys/capability
github.com/moby/sys/capability is a fork of the (no longer maintained)
github.com/syndtr/gocapability package.

For the list of changes since the fork took place, see
https://github.com/moby/sys/blob/main/capability/CHANGELOG.md

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-09-30 13:19:03 -07:00
Paul Nettleton d0819591d9 Make `buildah manifest push --all` true by default
Changed the `--all` option of `buildah manifest push` to be true by
default. This matches the behavior of the equivalent Podman option
(`podman manifest push --all`), making it easier to switch between
Podman and Buildah.

Updated buildah.manifest.push.1 docs to reflect this change.

Added test "manifest-push-all-default-true" to `tests/lists.bats`.

Closes: #5547
Signed-off-by: Paul Nettleton <k9@k9withabone.dev>
2024-09-25 18:11:14 -05:00
Matt Heon 5e82f27fb6 Do not error on trying to write IMA xattr as rootless
Rootless users cannot set the `security.ima` xattr on files
(presumably for security reasons, they get an EPERM on trying to
do so). We will normally try and preserve that xattr, so when
trying to add a file with an IMA xattr to a build on a Buildah
without this patch, you get an error. With this patch, the error
is downgraded to a warning, as it's better to successfully build
with a missing xattr than blocking all builds which want to
include the offending file.

The urgency on this has become somewhat higher as it seems like
F41/Rawhide are installing rpm-plugin-ima by default, which is
setting IMA xattrs on some files that Podman relies on - for
example, the catatonit binary we use for pid pause images.
Without this patch, building the pause image as rootless will
always fail on a system with rpm-plugin-ima installed.

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

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-09-19 11:45:03 -04:00
Nalin Dahyabhai 81d1256bd7 imagebuildah.StageExecutor: clean up volumes/volumeCache
Clean up the distinctions between the volumes slice and the volumeCache
and volumeCacheInfo maps so that --compat-volumes will work correctly
when we're building with multiple layers.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-09-12 09:02:22 -04:00
Nalin Dahyabhai 80e15584c5 build: fall back to parsing a TARGETPLATFORM build-arg
If we're not given an explicit platform or arch or os to target for a
build, but someone defined TARGETPLATFORM as a build argument, parse it.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-09-11 14:46:56 -04:00
Nalin Dahyabhai edc43c4e6d `manifest add --artifact`: handle multiple values
Don't error out when `manifest add --artifact` is given multiple files,
and add a test which should have checked that.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-09-11 10:00:10 -04:00
openshift-merge-bot[bot] 19e7088edb
Merge pull request #5438 from danishprakash/add-git-ref
add: add support for git sources
2024-09-09 21:35:55 +00:00
danishprakash 71fc845d0b
tests/bud.bats: add git source
Signed-off-by: Danish Prakash <contact@danishpraka.sh>
2024-09-09 12:45:15 +05:30
Paul Holzinger 5184bf1612
Add support for the new c/common pasta options
We always map 169.254.1.2 with pasta to the host now so ensure the
host.containers.internal entry is set correctly.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-06 17:05:52 +02:00
openshift-merge-bot[bot] f56150a1f9
Merge pull request #5710 from Honny1/vendro-c-common
Vendor `c/common:9d025e4cb348`
2024-09-03 17:42:09 +00:00
Jan Rodák ed881abfeb
Vendor c/common:9d025e4cb348
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-09-03 17:47:42 +02:00
Nalin Dahyabhai 9e374f9fd4 copier: handle globbing with "**" path components
Handle glob patterns with "**" path components by expanding "**" to the
set of subdirectories and calling filepath.Glob() on the results.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-09-03 11:46:24 -04:00
Nalin Dahyabhai f88579d1fe imagebuildah: make scratch config handling toggleable
The default configuration that `docker build` applies to images built
using "scratch" has changed from classic builds to BuildKit.  Add a
toggle for selecting which behavior to mimic.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-28 10:21:16 -04:00
flouthoc d0988936b4
stage_executor: set avoidLookingCache only if mounting stage
set `avoidLookingCache` to `true` if `--mount` is using a freshly built
stage and not for `additional-build-context`.

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-08-20 08:27:48 -07: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 d07c3dfb0e conformance: move weirdly-named files out of the repository
Remove certain weirdly-named files being used by a conformance test out
of the repository and create them at test-time.  Github refused to
generate archives of the repository when they were present in the commit
being requested.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-14 14:59:08 -04:00
Kir Kolyshkin fd3aba9917 *: use gofmt -s, add gofmt linter
1. Use gofmt to format the code:

	git ls-files \*.go | grep -Ev '/?vendor/' | xargs gofmt -w -s

2. Add gofmt to golangci-lint (it's not enabled by default).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-08-09 17:05:58 -07:00
Kir Kolyshkin 24da18800e *: fix build tags
This change is generated by `go1.23rc2 fix ./...`.

Had to use go1.23rc2, since all released go versions have a bug
preventing it from working with `go 1.22.0` in go.mod (opened
https://github.com/golang/go/issues/68825,
https://github.com/golang/go/issues/68824 for awareness).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-08-09 17:05:30 -07:00
openshift-merge-bot[bot] f2156795f4
Merge pull request #5676 from nalind/escape-globs
Add(): re-escape any globbed items that included escapes
2024-08-09 10:54:31 +00:00
Nalin Dahyabhai 3ea43566ac Add(): re-escape any globbed items that included escapes
When collecting items we matched using the passed-in globs during Add(),
be sure that globbing performed by Get() will match the items exactly,
by escaping special matching characters.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-08 16:46:47 -04:00
Nalin Dahyabhai 05da9a7450 conformance tests: use mirror.gcr.io for most images
Use busybox and alpine images from mirror.gcr.io, where possible, to
avoid tripping pull limits in CI.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-08 15:59:06 -04:00
Nalin Dahyabhai ed6dd4227d test/tools/Makefile: duplicate the vendor-in-container target
Add a copy of the vendor-in-container target that the top-level Makefile
has.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-07 10:11:51 -04:00
Nalin Dahyabhai abea603df3 linters: don't end loop iterations with "else" when "then" would
Don't end a loop iteration with an "else" block if the "then" block
would cause the loop iteration to finish, due to a "break", "continue",
or known-to-not-return function call.

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 d01e4ede36 Drop the e2e test suite
They largely duplicate other integration tests.  Add an integration test
to cover the "output from inspect is valid JSON" case.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-07 10:10:33 -04:00
Asutorufa aac50f6618 fix(deps): fix test/tools ginkgo typo
Signed-off-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
2024-08-06 09:49:30 +08:00
Nalin Dahyabhai 5f18ba259a AddAndCopyOptions: add CertPath, InsecureSkipTLSVerify, Retry fields
Add CertPath and InsecureSkipTLSVerify flags to AddAndCopyOptions, and
connect the CLI flag values passed to `buildah add` and `buildah build`
so that Builder.Add() gets those.

Add MaxRetries and RetryDelay fields to AddAndCopyOptions, and connect
them to the values passed on the command line to `buildah add` and
`buildah build`.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-25 17:39:08 -04:00
Nalin Dahyabhai 8aa9a1c225 integration tests: teach starthttpd() about TLS and pid files
Add optional third and fourth arguments to starthttpd() which can
specify a location to store a generated self-signed TLS certificate and
key which will be used to start the helper HTTP server with TLS, and an
optional fifth argument to which it will write its PID.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-25 13:54:35 -04:00
Nalin Dahyabhai 6373be5a1d "build with basename resolving user arg" tests: correct ARG use
Don't expect to be able to resolve an ARG in the FROM instruction for
the second stage if the ARG was only declared in the first stage.  Only
ARGs introduced in the header are available for FROM instructions.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-24 11:05:34 -04:00
Nalin Dahyabhai dcf3ea5fd5 bud-multiple-platform-no-run test: correct ARG use
Don't expect to be able to resolve an ARG in the FROM instruction for
the second stage if the ARG was only declared in the first stage.  Only
ARGs introduced in the header are available for FROM instructions.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-24 11:05:34 -04:00
Nalin Dahyabhai 3e38e5e138 imagebuildah: always have default values for $TARGET... args ready
Always have values for $TARGET... build args ready to be used.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-24 11:05:34 -04:00
Ed Santiago 3ad0fd1ed1 CI: use local registry, part 2 of 2
Make tests pass when using a local cache registry (as triggered
by $CI_USE_REGISTRY_CACHE being non-empty).

Mostly just change images: consolidate to a smaller set, like,
replace the few instances of debian with ubuntu, use $SAFEIMAGE
where we can.

The most significant change was with some s1 (schema 1?) images.
Those exist on quay, but cannot be mirrored locally: the local
registry forbids schema 1 images. I choose to skip these tests
when running against a local registry.

Second most significant change is running containerized tests
with --net=host. We need this to access the registry running
on a localhost port. (One alternative would be to bind the
registry on all interfaces, cringe, then perform sed magic
on the registries-cache.conf file changing 127.0.0.1 to
host.containers.internal, more cringe).

Also, some cleanup.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-07-17 12:26:49 -06:00
Ed Santiago 52df6e0e0f CI: use local registry, part 1 of 2
As of https://github.com/containers/automation_images/pull/357
our CI VMs include a local registry preloaded with all(*)
images used in tests.

 * where "all" means "most".

This commit defines a new registries-cached.conf, used in tests,
that redirects docker and quay to the new local registry. The
hope is that this will reduce CI flakes.

Since tests change over time, and new tests may require new
images, this commit also adds a mechanism for pulling in
remote images at test run time. Obviously this negates
the purpose of the cache, since it introduces a flake
pain point. The idea is: DO NOT DO THIS UNLESS ABSOLUTELY
NECESSARY, and then, if we have to do this, hurry up and
spin new CI VMs that include the new image(s).

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-07-17 12:09:54 -06:00
Nalin Dahyabhai 9bb25a6daf conformance tests: enable testing CompatVolumes
Add flags for specifying which value of CompatVolumes we set, testing
both with and without it set.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-15 09:38:28 -04:00
Nalin Dahyabhai 1861c13207 conformance tests: add a test that tries to chown a volume
Add a conformance test that attempts to "chown" a volume declared in a
base image, which produces different results depending on whether we're
using the BuildKit-based builder or the V1 "classic" builder.  For now,
don't try to change our behavior, and continue imitating the behavior of
the classic builder.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-15 09:38:28 -04:00
Nalin Dahyabhai a7098c776a imagebuildah: make traditional volume handling not the default
Make the traditional handling of volumes (where they're "frozen" and can
only be modified by ADD or COPY, which requires that we cache their
contents and save/restore them before/after RUN instructions) an option
that is not enabled by default.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-15 09:38:28 -04:00
openshift-merge-bot[bot] 0094fd4346
Merge pull request #5599 from nalind/log-platform
imagebuildah.StageExecutor.prepare(): log the --platform flag
2024-06-20 21:21:02 +00:00
openshift-merge-bot[bot] 3ab48aa55a
Merge pull request #5596 from nalind/compat-setparent
commit: set "parent" for docker format only when requested
2024-06-20 21:18:15 +00:00
openshift-merge-bot[bot] 41d879323e
Merge pull request #5595 from nalind/from-comment-first
containerImageRef.NewImageSource(): move the FROM comment to first
2024-06-20 21:12:45 +00:00
Nalin Dahyabhai d79a36faee imagebuildah.StageExecutor.prepare(): log the --platform flag
If FROM was used with a --platform flag, then the imagebuilder.Builder
will have its Platform field set, and we should include it when logging
the instruction.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-20 13:46:32 -04:00
Nalin Dahyabhai 14f19e980b buildah copy: preserve owner info with --from= a container or image
When `buildah copy` is invoked with a `--from` flag, default to
preserving ownerships that were set in the source container or image.
Retain the "set it to 0:0 by default" behavior when `--from` is not
being used.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-18 11:22:21 -04:00
Nalin Dahyabhai bfa84dfcbb conformance tests: enable testing CompatSetParent
Add flags for specifying not just that we use BuildKit, but specifically
which docker builder we request, and which value of CompatSetParent we
set at the same time.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-18 10:15:00 -04:00
Nalin Dahyabhai bfaee577d5 containerImageRef.NewImageSource(): move the FROM comment to first
If we're prepending history entries before the one for "this" commit,
make sure the "FROM $baseimage" comment gets set on the first history
entry that we add, not just the one goes with this (maybe) layer diff.
In layers=false mode, the output was so, so confusing otherwise.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-18 10:03:37 -04:00
openshift-merge-bot[bot] a7bc7b5bc2
Merge pull request #5574 from nalind/common-0.59.1
tests: set _CONTAINERS_USERNS_CONFIGURED=done for libnetwork
2024-06-11 10:31:54 +00:00
openshift-merge-bot[bot] b8148f0543
Merge pull request #5407 from rhatdan/pull
Clarify definition of --pull options
2024-06-11 10:29:10 +00:00
Daniel J Walsh 5afd52fd9d
Clarify definition of --pull options
buildah from and buildah build will now default to --pull=missing
as opposed to --pull=always, which they did before. This better
matches to the defaults in docker and podman.

No longer document --pull=true|false

Fixes: https://github.com/containers/buildah/issues/5406

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-06-10 15:58:37 -04:00
Nalin Dahyabhai 5891afffea conformance: use quay.io/libpod/centos:7 instead of centos:8
Renovate updated references "FROM centos:7" to "FROM centos:8", but we
changed various others references to it to quay.io/libpod/centos:7 some
time ago.  Update these stragglers.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-07 11:32:12 -04:00
Nalin Dahyabhai 56fb08092e Stop setting "parent" in docker format
Newer docker build doesn't set it, so we need to stop.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-07 11:32:12 -04:00
Nalin Dahyabhai ba0947a3d5 conformance: check if workdir trims path separator suffixes
Check "WORKDIR" both with and without path separators at the end of the
instruction argument (e.g. "/foo" and "/foo/").

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-07 11:32:12 -04:00
Nalin Dahyabhai 9565585a61 push integration test: pass password to docker login via stdin
Pass the test registry password to `docker login` using stdin instead of
passing it on the command line.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-07 11:32:12 -04:00
Nalin Dahyabhai afe1a5dd55 Re-enable the "copy with chown" conformance test
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-07 11:32:12 -04:00
flouthoc f552bd57f4
healthcheck: Add support for `--start-interval`
Docker now supports `--start-interval`, start interval
is the time between health checks during the start period.

Ref: https://docs.docker.com/reference/dockerfile/#healthcheck

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-06-06 16:02:25 -07:00
Nalin Dahyabhai 04e5423aed tests: set _CONTAINERS_USERNS_CONFIGURED=done for libnetwork
Starting in common 0.59.1, github.com/containers/common's libnetwork no
longer attempts to detect when it's running in a user namespace to
decide where a lock file that it uses will be.  Since this test is doing
user namespace setup on its own as part of the test, we need to
explicitly tell it to not use the one that belongs to the node's root
user.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-06 09:38:38 -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
Ed Santiago 7602e9e1d6 CI VMs: bump, to debian with cgroups v2
Per consent in 2024-03-20 Planning, remove support for cgroups v1.
And, per discovery on 2024-05-28, systemd 256 no longer even
boots on a cgroups v1 system.

This commit switches to VMs built in:

  https://github.com/containers/automation_images/pull/338

...in which Debian is now cgroups v2 with crun.

Requires disabling two conformance tests which fail when run
against docker 26.1; see #5526 for context on those.

Also requires disabling two bats tests on debian because
something changed there in ulimits. I'll look into them
later but right now this gives us breathing space.

And, latest git on f40 refuses to serve non-root files when
run as root ("dubious ownership"); so, in start_git_daemon(),
chown the extracted files.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-05-29 10:04:49 -06:00
Jonah Bull 939a58b967
fix secret mounts for env vars when using chroot isolation
Before #5083, when running with chroot isolation ro mounts like secrets
from env vars would explicitly have the unix.MS_NOEXEC, unix.MS_NOSUID
and unix.MS_NODEV flags set when they were remounted. Now when running
with chroot isolation ro mounts like secrets from env vars are not
getting those same flags set and so the remount operation fails.
Specifically it looks like we are missing the unix.MS_NOSUID and
unix.MS_NODEV flags.

This change adds special handling for read-only mounts when we need to do
a remount to try to get the desired flags to stick. If we've requested
a read-only mount (unix.ST_RDONLY is set in requestFlags), then we add any
possibleImportantFlags that are set in fs.Flags to remountFlags so the remount
operation doesn't fail because they are missing. I've also added a test to
bud.bats that covers this case.

Signed-off-by: Jonah Bull <jonah.bull@elastic.co>
2024-05-25 15:49:51 -05:00
Nalin Dahyabhai c09e08b53b build: be more selective about specifying the default OS
Only add the default OS to a build target platform struct if the
architecture was specified without one, so that the pull logic doesn't
override our pull policy when it doesn't need to.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-05-23 11:46:52 -04:00
Ed Santiago 183582f030 bud tests: fix breakage when vendoring into podman
1. Difference in error messages, podman does not emit "building
    system context". I think it's OK to just check for the
    "--platform may not be used with" portion.

 2. Very weird: $TESTSDIR (the plural one) was eliminated in April 2022
    but one instance snuck in, probably a PR that was not rebased
    onto main. This is blowing up in podman tests because of course
    there is no $TESTSDIR. But I have **NO IDEA** how this is passing
    in buildah, nor how it passed in podman for two years.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-05-21 06:33:39 -06:00
Nalin Dahyabhai de8510c9db Integration tests: fake up a replacement for nixery.dev/shell
Build a fake layers-but-no-history image that should work more or less
as well for the tests that we were previously using nixery.dev/shell for.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-05-20 16:48:53 -04:00
Nalin Dahyabhai 97382f9288 Don't expand RUN heredocs ourselves, let the shell do it
When handling RUN instructions that use heredoc syntax, don't bother
interpolating environment variables and argument values, and let the
command that's running handle it.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-05-20 09:35:48 -04:00
openshift-merge-bot[bot] b25597170a
Merge pull request #5478 from rhatdan/arch
Setting --arch should set the TARGETARCH build arg
2024-05-15 11:55:28 +00:00
Nalin Dahyabhai d5b2e3c41a Builder.cdiSetupDevicesInSpecdefConfig(): use configured CDI dirs
Use the directories configured in containers.conf, now that
containers/common can tell us what they are, and now that it provides a
place to configure defaults for container tools, always override the
library's default set, even if it's empty, which means we do nothing.

Switch to the default CDI registry instead of the recenty-deprecated
non-global one.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-05-07 09:19:16 -04:00
Daniel J Walsh da4e2d7ad9 Setting --arch should set the TARGETARCH build arg
Also fix a long standing FIXME in the test framework.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-05-06 19:49:09 -04:00
openshift-merge-bot[bot] c917f8dabc
Merge pull request #5497 from nalind/commit-error-reporting
containerImageRef.NewImageSource: merge the tar filters
2024-05-03 11:33:06 +00:00
Nalin Dahyabhai e0077e8c67 Integration tests: switch some base images
Replace some of the base images we've been using (particularly centos:8,
which will EOL soon) with other images hosted on quay.io.

We already use registries.conf at test-time to redirect some image
references there, so this will slightly reduce the number of registries
which we need to be able to reach while running these tests.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-05-02 17:33:41 -04:00
Nalin Dahyabhai fdfd2237d2 containerImageRef.NewImageSource: merge the tar filters
Merge the two tar filters, if we need two, that we use when committing
an image.  Try to improve passing of error information from the writing
end of a pipe to the reader, so that it can be reported better.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-05-02 17:27:38 -04:00
Nalin Dahyabhai 7688d880d0 Disable packit builds for centos-stream+epel-next-8
It's no longer an active release for the rhcontainerbot/podman-next COPR
at https://copr.fedorainfracloud.org/coprs/rhcontainerbot/podman-next/.

Add "adjustments to .packit.yaml" to the list of things we don't require
updated tests for.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-05-01 10:37:15 -04:00
Nalin Dahyabhai c01061e472 integration test: handle new labels in "bud and test --unsetlabel"
Instead of assuming which labels are set in our base image, and using
the --unsetlabel flag to suppress them in a derived image, query the
base image and unset all of them, except for our own version label.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-04-24 17:49:09 -04:00
Nalin Dahyabhai 8bb87aefa0 Integration tests: remove a couple of duplicated tests
Remove a couple of tests which were duplicated as tests which were added
later.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-04-18 11:27:03 -04:00
Nalin Dahyabhai 3e756d507d Integration tests: whitespace tweaks
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-04-18 11:27:03 -04:00
Nalin Dahyabhai 8ee7bebd7e Integration tests: don't remove images at start or end of test
Don't bother removing specific images at the beginning or the end of
tests, since we don't carry over the storage used between tests anyway.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-04-18 11:27:03 -04:00
Nalin Dahyabhai c7f0881422 Integration tests: use cached images more
Attempt to make more thorough use of cached copies of images during
integration tests, except in tests which need to pull a new image while
they're running, either because they test pulling directly, or because
they expect to pull a given image for a non-default platform or for
multiple platforms.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-04-18 11:27:02 -04:00
Nalin Dahyabhai b213c5e7a1 Integration tests _prefetch: use registry configs
When fetching images in the _prefetch() function, use the same registry
configuration (shortname configuration, registry aliases) that we're
already telling buildah to use when we call it, so that we prefetch from
the locations that buildah would subsequently use if we didn't prefetch.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-04-17 17:14:04 -04:00
Giuseppe Scrivano 358814f694
vendor: update containers/(common|storage)
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-12 09:58:13 +02:00
flouthoc 77400c4fc2
heredoc: honor inline COPY irrespective of ignorefiles
If we are copying heredoc files, we need to temporary place
them in the context dir and then move to container via copier
there are cases where .containerignore can have a patterns like
which can match our heredoc files so let's not set any excludes
or IgnoreFile for this copy.

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

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-04-05 07:55:47 -07:00
openshift-merge-bot[bot] dc99fbe888
Merge pull request #5454 from flouthoc/digestfile-source
source-push: add support for `--digestfile`
2024-04-03 17:23:19 +00:00
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
Aaron Lehmann d9129b463d Fix caching when mounting a cached stage with COPY/ADD
A comment states that avoidLookingCache is set when a previous stage
that executed as part of the build is referenced by --mount, to avoid
reusing content from an older build of the stage:

    // Only attempt to find cache if its needed, this part
    // so that if a step is using RUN --mount and mounts
    // previous stages then it uses the freshly built stage
    // of re-using the older stage from the store.

However, stages consisting of COPY/ADD seem to be flagged with
didExecute even if they were fetched from cache instead. I believe
this is an oversight, and these stages should not prevent subsequent
caching.

Also, avoidLookingCache would prevent a cache push, but I think it
should only prevent cache lookups, since populating the cache is still
useful in these caess.

It's very possible I'm misunderstanding something, but I believe the
RUN step in test case I've added wrongly skips cache, and I'd appreciate
some pointers in the right direction if what I've proposed here isn't
the right solution.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2024-04-02 12:57:58 -07:00
Nalin Dahyabhai 5198af7d7c Add support for passing CDI specs to --device
Add support for using CDI to resolve `--device` devices for RUN
instructions during `buildah build`, `buildah from`, and `buildah run`,
as `podman run` does.

This generally requires that we stop resolving device specifications
(arguments passed to --device) earlier and deferring that until it's
time to run a process, because CDI wants to pick over those values,
modify a runtime spec to set up the ones that it knows about, and then
hand back the list of values that it doesn't know about.

We don't want to do a dry run of this during CLI processing because that
would create a window where the underlying hardware state could change,
and that could produce some hard-to-diagnose errors.

Being able to test this is going to require that we add the `--device`
flag to `buildah run` (`--security-opt` affects how we build the
container's layer, so it has to be done at `buildah from`).

The default configured devices list is pulled in by CLI flag processing
during `buildah from` and `buildah build`, so it doesn't also need to be
explicitly passed to `buildah run` or the internal Run() method.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-03-29 16:57:10 -04:00
tomsweeneyredhat 9cf83d8f8d Change RUN to comment in bud.bats
Just before merging #5411, a comment was made
about changing a RUN command to a comment.  This
completes that.

Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
2024-03-18 15:27:27 -04: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
Paul Holzinger 516f9e9a24
correctly configure /etc/hosts and resolv.conf when using network
Previously buildah may have created a incorrect hosts/resolv.conf file,
when netavark, slirp4netns or pasta are used we have to actually
consider their special setup and use the correct nameservers.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-18 14:38:01 +01:00
openshift-merge-bot[bot] 0bcfaa14b3
Merge pull request #5374 from edsantiago/no-tests-via-label
pr-should-include-tests: use GitHub label, not commit text
2024-03-15 22:22:10 +00:00
Ed Santiago 87ef84d3a4 pr-should-include-tests: use GitHub label, not commit text
...to allow bypassing the check. Just like on podman.

Also, bring up to code:
  - grep -F, not fgrep
  - fix regression test script (was using wrong branch envariable)
  - add new test case

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-03-12 17:23:03 -04:00
Paul Holzinger d50122aeb2
tests: enable pasta tests
This should have been done a long time ago and this would have made
clear that it did not work properly. However now that pasta is the
default and we fixed all the remaining problems we can easily enable
them.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-12 11:53:06 +01:00
Nalin Dahyabhai b2504c2636 conformance tests: don't break on trailing zeroes in layer blobs
When analyzing a layer blob's contents, don't break if the blob has more
zeroes padding it out even after the tar reader thinks it's hit the end
of the archive.

Add more detail to the diagnostic error we print when there's a digest
or length mismatch, too, in case it's triggered by something other than
zero padding.

Don't ignore errors which might be encountered when we try to use skopeo
to copy an image to a directory.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-03-06 17:37:49 -05:00
Nalin Dahyabhai a2f0ebef65 Add a conformance test for copying to a mounted prior stage
Add a conformance test for cases where an intermediate stage mounts the
contents of a previous stage in a read-write fashion and modifies it.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-03-04 09:45:18 -05:00
Daniel J Walsh d0ffb9d374
Use retry logic from containers/common
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-02-28 09:44:33 -05:00
Daniel J Walsh e9c3c1666c
Vendor in containers/(storage,image,common)
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-02-28 09:44:33 -05:00
Ed Santiago 4853c00423 tests: skip_if_no_unshare(): check for --setuid
unshare on RHEL8 does not support --setuid. This is causing
gating tests to fail.

Solution: check for option, skip test if unavailable

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-02-27 10:27:31 -07: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 98f8707535 build --all-platforms: skip some base "image" platforms
When figuring out which platforms the base images allow us to build
derived images for, screen out any images with non-empty artifactType
values.  Also screen out any which use empty values or the word
"unknown" in the OS and Architecture platform fields, and any
Architecture values that the compiler hasn't heard of.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-02-12 14:34:04 -05:00
Nalin Dahyabhai aca884a89d `buildah manifest`: add artifact-related options
Add functionality for creating artifact manifests and adding them to
image indexes.  `buildah manifest add` gets a `--artifact` option for
telling it to create artifact manifests, and `--artifact-type`,
`--artifact-config`, `--artifact-config-type`, `--artifact-layer-type`,
`--artifact-exclude-titles`, and `--subject` options to fine-tune the
contents of the artifact manifests it creates.

Add a `--index` flag to `buildah manifest annotate` so that it can be
told to set annotations on the index itself instead of on one of the
entries in the image index.

Add a `--subject` flag to `buildah manifest annotate` for setting the
`subject` field of an image index.

Add a `--annotation` flag to `buildah manifest create` to allow for
adding annotations to the new image index.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-02-07 11:51:58 -05:00
Nalin Dahyabhai 302a798ad8 egrep is obsolescent; use grep -E
In tests/validate/pr-should-include-tests and
tests/validate/whitespace.sh, use grep -E instead of egrep, because
egrep keeps telling us to switch.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-02-07 11:49:17 -05:00
Nalin Dahyabhai 04847f57f6 Set CONTAINERS_CONF in the chroot-mount-flags integration test
... in an attempt to try to get UID 0 in a user namespace to stop trying
to read files from root's home directory, where the permissions error is
treated as a hard failure.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-02-07 11:48:29 -05:00
Nalin Dahyabhai 56e6ef8546 Update to match dependency API update
github.com/docker/docker/client.NewVersionError() takes a context.Context now.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-02-07 11:48:03 -05:00
openshift-merge-bot[bot] db73170f20
Merge pull request #5314 from flouthoc/heredoc-show-summary
build, heredoc: show `heredoc` summary in build output
2024-02-07 13:14:16 +00:00
openshift-merge-bot[bot] 20ae380912
Merge pull request #5275 from rhatdan/ulimit
Make buildah match podman for handling of ulimits
2024-02-05 09:08:37 +00:00
flouthoc 533aac2d4f
tests: retrofit test for heredoc summary
Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-02-02 10:59:45 -08:00
flouthoc 1bfd3336f9
build, heredoc: show heredoc summary in build output
Buildah must show summary of heredoc content in build output so its easy
for developers to understand which heredoc got executed, this is similar
to what buildkit does for heredoc content.

See: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/dockerfile2llb/convert.go#L1853

Sample output of buildah

```console
STEP 1/5: FROM docker.io/library/python:latest
STEP 2/5: RUN <<EOF (echo "Hello" >> /hello...)
STEP 3/5: RUN python3 <<EOF (with open("/hello", "w") as f:...)
STEP 4/5: RUN ls -a
```

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-02-02 10:59:38 -08:00
flouthoc 811ee67975
manifest, push: add support for --retry and --retry-delay
Just like `buildah push`, `buildah manifest push` should also support
`--retry` and `--retry-delay` options, see documentation in same commit
for more details.

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

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-02-02 10:42:07 -08:00
Giuseppe Scrivano 9d516e22e3
imagebuildah: fix crash with empty RUN
fix a crash when RUN is executed without any argument.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-02-01 17:14:33 +01:00
Daniel J Walsh 79fb3c2135
Make buildah match podman for handling of ulimits
Podman currently sets the ulimits of nofile and nproc
to max in rootless mode, if the user does not override.

Buildah on the other hand just passes in the current defaults.

Podman build should match podman run, and this will fix that problem.

Fixes: https://github.com/containers/buildah/issues/5273

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-01-31 15:28:51 -05:00
Daniel J Walsh 34dff20dae
Run codespell on code
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-01-28 07:25:10 -05:00
Ed Santiago e3d043ebf2 Remove a bad FROM line
Some new heredoc test added "FROM blah blah python whatever",
an image that (presumably) exists on docker.io but does not
exist in our cache.

Plus, test was completely broken anyway. It would've found
the "this is the output" lines even without python, as
part of the verbose build.

Solution: don't use python. You don't need python to test a shebang.
You can use anything. 'cat' is traditional, but I choose 'rev'
because that makes it nearly impossible for the test to match
merely due to a build-step echo.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2024-01-24 14:17:29 -07:00
openshift-merge-bot[bot] ec27cc1271
Merge pull request #5255 from flouthoc/heredoc-shebang
stage_executor,heredoc: honor interpreter in heredoc
2024-01-23 15:06:26 +00: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
Tom Sweeney 727e00d9df
Merge branch 'main' into heredoc-shebang 2024-01-19 09:58:14 -05:00
Nalin Dahyabhai b3af07dabf commit: force omitHistory if the parent has layers but no history
If the parent image has layers but no history, force our own omitHistory
setting on.

The alternative is to create a history that only explains the presence
of some of the layers in our output image, which looks broken to
everyone who might consume that image, including ourselves if we try to
use it as a base image later.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-01-17 16:37:12 -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
flouthoc 4cc811f4f7
stage_executor,heredoc: honor interpreter in heredoc
If there are any shebang in heredoc file then buildah must honor that.
Consider a case of

```Dockerfile
FROM python:3.11-slim-bullseye
RUN <<EOF
print('hello world')
EOF
```

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

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-01-12 08:48:15 -08:00
flouthoc 339839d4b0
stage_executor,layers: burst cache if heredoc content is changed
When using buildah with `--layers` then buildah must correctly burst
layer cache if `heredoc` content is changed. Following is achieved via
properly adding `heredoc` content to the history of the built image.

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

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-01-11 10:49:24 -08: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
openshift-merge-bot[bot] b9346c503e
Merge pull request #5226 from nalind/commit-add-files
commit: add a --add-file flag
2023-12-16 11:59:53 +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 041388f87c commit: add a --add-file flag
Add a flag to `buildah commit` which allows adding arbitrary files to
the image while we're committing it.  When not squashing, they'll take
the form of a second new layer.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-12-13 17:17:43 -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
Nalin Dahyabhai 1f9103562b run.bats: use --quiet --pull=false when using a prefetched image
When creating a container using a prefetched image, use --quiet and
--pull=false for the pair of tests which didn't, bringing them in line
with the rest of the tests in the file.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-28 16:43:44 -05:00
openshift-merge-bot[bot] f02b4dc1b8
Merge pull request #5192 from nalind/ancient-unshare
Integration tests: make skip_if_no_unshare check --map-users
2023-11-28 20:49:29 +00:00
Nalin Dahyabhai d10b1e35b7 Integration tests: make skip_if_no_unshare check --map-users
Check if `unshare` supports the `--map-users` option in
`skip_if_no_unshare`, since we're depending on that in the only
integration test that uses `skip_if_no_unshare`.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-28 09:25:51 -05:00
renovate[bot] d4f577b397
fix(deps): update module github.com/onsi/ginkgo to v2
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-11-21 20:38:00 -05:00
Giuseppe Scrivano c174e91624
vendor: update c/{common,image,storage}
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-11-21 14:29:05 +01:00
Aditya R 7aa395489f
test,heredoc: use fedora instead of docker.io/library/python:latest
Signed-off-by: Aditya R <arajan@redhat.com>
2023-11-18 15:50:40 +05:30
openshift-merge-bot[bot] 9bee64bdc6
Merge pull request #5161 from nalind/never-empty-squash-confidential
Never omit layers for emptyLayer instructions when squashing/cwing
2023-11-17 19:57:48 +00:00
Nalin Dahyabhai 2087848c3b Never omit layers for emptyLayer instructions when squashing/cwing
Ignore whether or not the final build instruction should produce a layer
if we're squashing or producing a confidential workload, when we'd still
have to produce a layer containing the contents of the base image.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-17 12:54:34 -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
openshift-merge-bot[bot] f00af6b7d3
Merge pull request #5156 from rhatdan/containers.conf
Stop using DefaultNetworkSysctl and use containers.conf only
2023-11-17 11:59:50 +00:00
openshift-merge-bot[bot] 6622a7b4b6
Merge pull request #5153 from flouthoc/bump-c-image
blobcacheinfo,test: blobs must be resued when pushing across registry
2023-11-17 10:42:52 +00:00
openshift-merge-bot[bot] cb307129e3
Merge pull request #5152 from jfroy/add-checksum
Implement ADD --checksum flag
2023-11-17 10:40:10 +00:00
openshift-merge-bot[bot] 1e6d126e92
Merge pull request #5160 from nalind/unsetenv-no-instructions-commit
StageExecutor.Execute: force a commit for --unsetenv, too
2023-11-17 10:37:19 +00:00
Nalin Dahyabhai fadc0ba081
conformance tests: archive the context directory as 0:0 (#5171)
When uploading a context directory to dockerd, generate the archive
ourselves so that we can force the ownerships in it to 0:0, which
BuildKit seems to expect clients to do.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Co-authored-by: flouthoc <flouthoc@users.noreply.github.com>
2023-11-17 13:36:38 +05:30
Aditya R 3c61dfd4fb
blobcacheinfo,test: blobs must be resued when pushing across registry
It seems we try to reuse blobs only for the specified registry, however
we can have valid known compressed digests across registry as well
following pr attempts to use that by doing following steps.

* `CandidateLocations2` now processes all known blobs and appends them
  to returned candidates at the lowest priority. As a result when
`TryReusingBlob` tries to process these candidates and if the blobs
filtered by the `Opaque` set by the `transport` fail to match then
attempt is made against all known blobs (ones which do not belong to the
current registry).

* Increase the sample set of potential blob reuse to all known
  compressed digests , also involving the one which do not belong to
current registry.

* If a blob is found match it against the registry where we are
  attempting to push. If blob is already there consider it a `CACHE
HIT!` and reply skipping blob, since its already there.

----

```console
$ skopeo copy docker://registry.fedoraproject.org/fedora-minimal docker://quay.io/fl/test:some-tag
$ buildah pull registry.fedoraproject.org/fedora-minimal
$ buildah tag registry.fedoraproject.org/fedora-minimal quay.io/fl/test
$ buildah push quay.io/fl/test
```

```console
Getting image source signatures
Copying blob a3497ca15bbf skipped: already exists
Copying config f7e02de757 done
Writing manifest to image destination
Storing signatures
```

Testing: https://github.com/containers/image/pull/1645

Signed-off-by: Aditya R <arajan@redhat.com>
2023-11-17 12:14:06 +05:30
Nalin Dahyabhai 1fab39559b StageExecutor.Execute: force a commit for --unsetenv, too
When we don't have any instructions to process, but we do have an
unsetEnv or unsetLabel list, force a commit, like we already did if we
were passed an out-of-band labels or annotations list, or if we were
squashing, and now also do so if we're doing a confidential workload.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-16 13:19:08 -05:00
Miloslav Trmač 57d863dfde Add support for --compat-auth-file in login/logout
This mostly just inherits the c/common/pkg/auth implementation,
except that AuthFilePath and DockerCompatAuthFilePath can not be set
simultaneously, so don't always set AuthFilePath. c/common already
defaults to the same locations internally.

Test handle only invalid commands; a true interoperability test
would require a running Docker on the CI systems, which is not currently
available. That interoperability was tested manually
(and is presumed to be integration-tested in the Podman repo).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-11-16 18:51:11 +01:00
Miloslav Trmač dcfbe69a3f Update existing tests for error message change
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-11-16 18:51:11 +01:00
openshift-merge-bot[bot] e2c8519eed
Merge pull request #5159 from nalind/case-insensitive-tee-types
Make TEE types case-insensitive
2023-11-16 13:00:34 +00:00
Nalin Dahyabhai 00e73de716 conformance tests: use go-dockerclient for BuildKit builds
go-dockerclient gained the ability to let us ask for a build kicked off
using its API to be done using BuildKit, so we don't have to work around
that by calling the Docker client package any more when doing
conformance testing.

The go-dockerclient method also reports errors in a way that's easier
for us to consume, which we didn't have fully debugged on the other code
path.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-15 12:54:39 -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
Daniel J Walsh 8df9b760b3
Stop using DefaultNetworkSysctl and use containers.conf only
Also mark uses of DefaultCapabilities as Deprecated.

Fixes: https://github.com/containers/buildah/issues/5155

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-11-13 11:46:04 -05:00
Jean-Francois Roy 99cad6ee1a
Implement ADD checksum flag #5135
See https://docs.docker.com/build/dockerfile/release-notes/#160.

Fixes #5135

Signed-off-by: Jean-Francois Roy <jf@devklog.net>
2023-11-13 08:32:22 -08:00
Nalin Dahyabhai 6552b619ca conformance: use require.NoErrorf() more
Use require.NoErrorf() as a check instead of the more general
require.Nil(), which was both less specific and didn't expect a format
string.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-08 10:58:30 -05: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
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
Nalin Dahyabhai 2a3a956cbb chroot.setupChrootBindMounts: pay more attention to flags
Pay better attention to dev/nodev/exec/noexec/suid/nosuid/ro/rw flags on
bind, overlay, and tmpfs mounts when any of them are specified.  Stop
quietly adding "nodev" when it isn't asked for.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-10-20 09:46:58 -04:00
Aditya R 07d955f277
imagebuildah,multi-stage: do not remove base images
When building a multi-stage image ( without `--layers` ) and a
stage contains only a base-image buildah removes the base-image
itself as part of cleanup process. This is a bug and following commit
fixes that.

Reproducer

```Dockerfile
FROM parent
FROM another-base
COPY --from=0 somefile .
```

`buildah build -t multi-stage .`

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-10-09 15:45:12 +05:30
Benjamin Schubert 249e30c981
bug: Ensure the mount type is always BindMount by default
Previously, when mounting multiple mounts, if any mount had a `type`
specified, it would override the default type for subsequent mounts.

This meant, for example, that having a RUN step like:

```
RUN --mount=type=cache,target=/cache --mount=source=.,target=/src
```

would incorrectly mount the second source as a cache, instead of a
bind-mount.

This fix ensures the default is reset between each iteration of the
loop, ensuring we get the right mount type.

Signed-off-by: Benjamin Schubert <contact@benschubert.me>
2023-09-30 17:26:37 +01:00
Daniel J Walsh 06e63758ff
Merge pull request #5021 from danishprakash/fix-containerignore-buildcontext
imagebuildah: consider ignorefile with --build-context
2023-09-28 14:57:03 -04:00
Aditya R 8b63fa37bf
build,config: add support for --unsetlabel
Just like `--unsetenv` following flag allows to unset image label.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-09-27 10:27:54 +05:30
danishprakash 91f54ed546
tests/bud: add tests
Signed-off-by: danishprakash <danish.prakash@suse.com>
2023-09-26 18:11:39 +05:30
Aditya R ae5f11e451
stage_executor: allow images without layers
`Docker` and `Buildkit` creates no layers when only `FROM scratch` is
used as content for building image, buildah must do the same.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-09-22 11:13:34 +05:30
Nalin Dahyabhai 9dd66e4cbf add/copy: make sure we handle relative path names correctly
Make sure that `add` and `copy` handle relative paths given as input
correctly, both with and without a context directory being specified.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-09-15 16:20:19 -04:00
Daniel J Walsh ccac7ca0bf
Run codespell on code
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-09-14 06:05:57 -04: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 7545685800 Don't try to look up names when committing images
Don't try to look up an image by name when we're committing an image,
because we don't want to accidentally take advantage of any fuzzy
matching that libimage might start doing.  Instead, just use the
normalization call.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-09-05 16:37:14 -04:00
Valentin Rothberg 6ec6f046f5 vendor containers/common@12405381ff
When pulling from an OCI source, make sure to preseve the optional name.
For instance, a podman pull oci:/tmp/foo:quay.io/foo/bar:latest should
pull the image and name it quay.io/foo/bar:latest.

While at it, also fix a bug when pulling an OCI without the optional
name. Previously, we used the path to name the image which will error in
most cases due to invalid characters (e.g., capital ones). Hence, apply
the same trick as for the dir transport and generate a sha.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-31 09:38:26 +02:00
Aditya R df1bc38340
push: --force-compression should be true with --compression-format
With discussion from here:
https://github.com/containers/podman/pull/19640, it was decided that
`--force-compression` must be automatically `true` in case when
`--compression-format` is set.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-08-30 12:02:39 +05:30
Daniel J Walsh 2b57cef2bc
Use buildah repo rather then podman repo
The Podman repo changed and removed a subdir that this tests was relying
on.  Rather then relying on a different repo, it would be better to
stick to buildah repo for github tests.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-08-24 07:44:41 -04:00
Aditya R a3f2aa3c74
executor: build-arg warnings must honor global args
build-arg warnings must honor globally defined arguments and must not
produce warnings if an arguments is already defined globally.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-08-18 16:26:02 +05:30
Aditya R d68d9a237c
buildah/push/manifest-push: add support for --force-compression
Adds support for `--force-compression` which allows end-users to force
push blobs with the selected compresison in `--compression` option, in
order to make sure that `blobs` of other compression on registry are not
reused.

Is equivalent to: `force-compression` here: https://docs.docker.com/build/exporters/#compression
Closes: https://github.com/containers/buildah/issues/4613

Also Implements:
`--compression-format` and `--compression-level` for `manifest push` just like
`podman`'s `manifest push`

Signed-off-by: Aditya R <arajan@redhat.com>
2023-08-15 10:44:06 +05:30
Aditya R ae36f6542e
tests: fix layer-label tests
Some additions and corrections to layer-label tests from comment: https://github.com/containers/buildah/pull/4940#pullrequestreview-1560878587

Co-authored-by: Ed Santiago <santiago@redhat.com>
Signed-off-by: Aditya R <arajan@redhat.com>
2023-08-03 18:03:34 +05:30
Aditya R f888b3d84b
buildah: add --layer-label for setting labels on layers
`--layer-label` allows users to set labels on intermediate labels agnostic
of the labels set on actual image. Since there are use-cases where users
want to perform operation on intermediate images only on the basis of
certain labels.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-08-03 12:09:12 +05:30
Aditya R b9ac8d5e01
manifest/push: add support for --add-compression
Adds support for `--add-compression` which accepts multiple compression
formats and when used it will add all instances in a manifest list with
requested compression formats.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-07-31 20:24:18 +05:30
Daniel J Walsh 135b5a8f03
Fix transition test to work with latest selinux policy
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-06-29 14:21:17 -04:00
Paul Holzinger a8f350fc51
rootless: use default_rootless_network_cmd config
Use the `default_rootless_network_cmd` containers.conf options to know
which rootless network program to use as default. This setting is
important so distros and user can actually set a different default if
they wish.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-28 15:20:39 +02:00
Paul Holzinger b3edcaa062
vendor: update c/{common,image,storage} to latest
includes two test fixes

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-27 10:43:34 +02:00
Paul Holzinger 74b885b9e2
buildah: add pasta(1) support
Like podman allow buildah and therefore podman build to use the network
mode pasta. The pasta integration is very simple and we do not even
need a teardown handler for that as pasta will exit on its own when the
netns path is removed.

However right now this is broken, pasta will fail to open
/proc/$pid/ns/net. I send a patch[1] to fix this upstream in pasta.
I assume this will land quickly so I like to get this in now just so we
have this included in podman v4.6. Thus the test is skipped for now.

[1] https://archives.passt.top/passt-dev/20230623082531.25947-2-pholzing@redhat.com/

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-23 13:58:34 +02:00
Paul Holzinger 11ba328e2b
use slirp4netns package from c/common
This uses the same code as podman for slirp4netns, this means
- ipv6 is enabled by default
- slirp4netns options are read from contianers.conf
- slirp4netns options can now be set on the cli. This required some
small rework on where we parse the network string.

Lastly I updated the --network docs, to document the new slirp4netns
mode. That included fixing up buildah-from and buildah-run pages which
were incomplete in that regard. Now we show the same for all options.

Fixes #3968

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-23 13:57:30 +02:00
Paul Holzinger 14cd28c262
add hostname to /etc/hosts when running with host network
Some tools depend on the hostname being present in /etc/hosts. I would
argue they are broken but its not like we can do anything about that.

This adds the hostname with the local host ip when the host network is
used. For private networking we already add the hostname.

We also now correctly force host networking in chroot mode, it was
silently ignored before thus causing extra confusion here.

Fixes #4446

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-20 16:12:28 +02:00
Daniel J Walsh 13b6e4a0bd
Merge pull request #4832 from kolyshkin/rm-devmapper
Remove device mapper support
2023-06-14 07:12:02 -04:00
Daniel J Walsh 3e44ece0fe
Merge pull request #4746 from rhatdan/docs
Change util.EncryptConfig,DecryptConfig, GetFormat and make it public
2023-06-13 07:38:03 -04:00
Kir Kolyshkin bd32a04c37 Remove device mapper support
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-06-12 12:43:16 -07:00
Chris Evich 261a524b9e
Update tooling to support newer golangci-lint
Golangci-lint < v1.51.1 can't work on systems with golang 1.20.
Updating to 1.51.2 then has dependent modules that require a minimum of
golang 1.17, requiring a re-vendoring of tooling.

Signed-off-by: Chris Evich <cevich@redhat.com>
2023-06-12 11:25:02 -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
Chris Evich d9ecd7c591
[CI:DOCS] Update comment to remove ambiguity
Ref: https://github.com/containers/buildah/pull/4828/files#r1218341500

Signed-off-by: Chris Evich <cevich@redhat.com>
2023-06-06 14:29:58 -04:00
Daniel J Walsh 8543176d56
Merge pull request #4837 from edsantiago/test_better
intermediate-images inherit-label test: make it debuggable
2023-06-05 16:06:37 -04:00
Chris Evich 5a83012c93
Explicitly ref. quay images for CI
Commit beae5647c0 updated the conformance test references to a
deprecated repository.  However, by pointing at the docker-hub it
inadvertantly introduce a significant possibility for flakes.  This is
because anonymous docker hub access is rate-limited by IP.  We cannot
predict the IP used for CI VMs & Containers, any of which could be at or
close to the limit.  Fix this by pointing explicitly at a
`quay.io/libpod/centos` repo. which is excluesively for use by CI, with
static images.

Signed-off-by: Chris Evich <cevich@redhat.com>
2023-06-05 10:56:33 -04:00
Ed Santiago 90f7436ac5 intermediate-images inherit-label test: make it debuggable
Test is currently very hard to debug on failure. Fix that
by adding unique test descriptors and a little whitespace.

Also, fix a broken/NOP test (copypaste artifact)

Signed-off-by: Ed Santiago <santiago@redhat.com>
2023-06-01 09:09:33 -06:00
Aditya R 0766b004bb
executor: apply label to only final stage
In https://github.com/containers/buildah/pull/4673 we made a change were
we were applying labels to end of each stage, which is different than
what we were doing before i.e applying label at the end of the each
step.

However buildkit does not adds label to any stage or steps it only adds
label at the end of final stage so lets do that.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-05-27 07:49:49 +05:30