Commit Graph

168 Commits

Author SHA1 Message Date
Aditya Rajan 719b660462
buildkit: add from field to bind and cache mounts so images can be used as source
Following commit adds buildkit like support for `from` field to `--mount=type=bind`
and `--mount=type=cache` so images and stage can be used as mount source.

Usage looks like
```dockerfile
RUN --mount=type=bind,source=.,from=<your-image>,target=/path ls /path
```
and
```dockerfile
RUN --mount=type=cache,from=<your-image>,target=/path ls /path
```

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2022-01-08 16:58:38 +05:30
Daniel J Walsh 1c67aad88f
Use config.ProxyEnv from containers/common
This table is being used in multiple different places, so consolidating
it in containers/common

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-01-07 14:31:16 -05:00
Paul Holzinger f9cff07b81
use libnetwork from c/common for networking
Podman uses the new netavark network stack. Buildah should be able to do
the same. Both projects should use the same networking code which was
move to c/common/libnetwork. The new network interface can use either
CNI or netvavark. Using the same code for podman and buildah is
important to ensure that both use the same backend. Mixing CNI and
netavark is not supported.

This also fixes some outstanding CNI issues, e.g. buildah trying to
connect all cni networks.

[NO NEW TESTS NEEDED]

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-07 18:10:26 +01:00
Paul Holzinger 5e11770c19
setup the netns in the buildah parent process
Do not configure the netns in the runtime child process, this removes
the need to send the network options to the child. This will be needed
for the new libnetwork network interface which cannot be transfered as
json.

To synchronize this between the child and parent we use two pipe pairs.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-07 15:05:08 +01:00
Daniel J Walsh 300d9d1de1
Allow rootless buildah to set resource limits on cgroup V2
First move podman/pkg/cgroups into Buildah.
Only set resources to nil on non cgroupsv2 systems in rootless mode.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-12-14 12:36:03 -05:00
Daniel J Walsh 05d5d22dc6
Grab all of the containers.conf settings for namespaces.
Buildah is mainly building with Host Namespaces, this changes most
namespaces to be private matching Podman and using containers.conf

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-30 10:24:00 -05:00
Daniel J Walsh 1d74137908
Make LocalIP public function so Podman can use it
[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-22 10:00:50 -05:00
Nalin Dahyabhai 9b6a02f3af run: ensure that stdio pipes are labeled correctly
Label stdio pipes to ensure that processes we run can read through
/dev/stdin and write through the /dev/stdout and /dev/stderr links.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-11-19 10:55:50 -05:00
Giuseppe Scrivano b798e6a21a
rootless: do not bind mount /sys if not needed
if the container is using a private network namespace, we can mount a
fresh /sys.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-04 14:34:21 +01:00
OpenShift Merge Robot ecd74746cc
Merge pull request #3598 from ashley-cui/envs
Add support for env var secret sources
2021-10-31 09:58:44 +00:00
Aditya Rajan 37377e6827
run: honor --network=none from builder if nothing specified
This commit makes sure we honor NetworkDisabled in `runs` if
`--network=none` was specified while building the container and no
configuration was specified in while running the container.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-10-27 14:50:11 +05:30
Ashley Cui 326edb312e Add support for env var secret sources
Run secrets can now be created from an environment variable. The
environment variable is read and is briefly stored as a file on /dev/shm
when it's being used, and the file is removed after the RUN command is
finished.

Fixes: #3524

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-10-26 13:18:00 -04:00
OpenShift Merge Robot d6b04349fe
Merge pull request #3593 from rhatdan/group
Rootless containers users should use additional groups
2021-10-21 17:45:42 +00:00
Daniel J Walsh 08b55f91cc
Rootless containers users should use additional groups
Fixes https://github.com/containers/buildah/issues/3592

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-20 14:22:42 -04:00
chenk008 03186a3307 Support overlayfs path contains colon
In linux, directory can contains colon.
Add support to mount path contains colon.

buildah run --volume /root/a\\🅱️/root/test:O

Signed-off-by: chenk008 <kongchen28@gmail.com>
2021-10-20 14:40:38 +08:00
OpenShift Merge Robot e4a4f2c0d4
Merge pull request #3586 from rhatdan/docs
Add support for host.containers.internal in the /etc/hosts
2021-10-15 01:08:56 +02:00
Daniel J Walsh f8c152694c
Add support for host.containers.internal in the /etc/hosts
Also switch default hostname from truncated ContainerID to Container
name.

It makes more sense that a user would know the name of the container
versus the generated id, so we should use this as a default.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-14 13:21:25 -04:00
Aditya Rajan fc69aa68c2
buildkit: add support for mount=type=cache
Following PR inroduces a new mount type=cache in parity to buildkit
which allows users to share persistant cache between different builds.

Allowing users to cache content generated by bussiness logic or enhance
build performance by caching components across builds.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-10-14 16:07:11 +05:30
Ashley Cui b9b3184632 Default secret mode to 400
Fixed a bug where buildah bud mounted secrets permissions were incorrect due to a decimal/octal conversion error. buildah bud mounted secrets now have a default permission of 400. Fixes #3557

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-10-12 16:00:23 -04:00
Aditya Rajan e96df7060c
buildkit: Add support for --mount=type=tmpfs
Following PR adds supports for buildkit like `--mount=type=tmpfs` which
allows end users to mount a chunk of volatile memory instead of a persistent storage device.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-10-08 13:29:57 +05:30
Aditya Rajan f0d3140e5a
build: Add support for buildkit like --mount=type=bind
Following commit adds support for using buildkit like
`--mount=type=bind` with `RUN` statements. Mounts created by `--mount`
are transient in nature and only scoped to current RUN statements.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-10-06 13:45:53 +05:30
OpenShift Merge Robot bc718ca758
Merge pull request #3540 from rhatdan/log-level
Plumb the remote logger throughut Buildah
2021-09-30 03:52:31 -04:00
OpenShift Merge Robot 455f2f11d9
Merge pull request #3525 from flouthoc/cleanup-run-directory-after-step
build: Cleanup transient mount destinations with every RUN step
2021-09-28 17:18:26 -04:00
Daniel J Walsh 00ba17b37a
Plumb the remote logger throughut Buildah
Users are not seeing Warnings when doing podman --remote build.
We need to wire the logrus messages all the way through the system.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-28 14:48:16 -04:00
Nalin Dahyabhai c6e2a5e87d Replace fmt.Sprintf("%d", x) with strconv.Itoa(x)
Replace calls to fmt.Sprintf("%d", x) with strconv.Itoa(x), which is
slightly faster.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-09-27 18:27:22 -04:00
Aditya Rajan 4cb43961b8
Run: Cleanup run directory after every RUN step
Following commit ensures that we cleanup dangling `/run` after every RUN
command and make sure that it does not persists on physical image. Ensure
parity with how docker behaves with `.dockerenv`.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-09-27 19:59:20 +05:30
Nalin Dahyabhai a314d2a6ca Makefile: turn on race detection whenever it's available
Check if `go test` supports the -race flag on the build platform, and if
so, use it for unit tests instead of just assuming that it's always
available.

Use sync/atomic to safely use a uint32 instead of a bool to keep track
of whether or not the process we started for RUN has stopped.

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-09-16 14:19:19 -04:00
Nalin Dahyabhai 1ec4983d50 Replace golang.org/x/crypto/ssh/terminal with golang.org/x/term
The golang.org/x/crypto/ssh/terminal package has been deprecated and
replaced upstream by golang.org/x/term, so switch to that.  It's a
simple 1:1 replacement.

[NO NEW TESTS NEEDED]

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-08-24 15:35:12 -04:00
Nalin Dahyabhai 32c68951a4 imagebuildah: handle --manifest directly
When we're told to add built images to a manifest list, manipulate the
list ourselves, so that if we're creating a list, we won't have a
partially-populated list if some of the builds fail.

This also lets us include all of the platform information (including
variant info, which we can't sniff out after the fact) that we were
given when we started building the images.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-08-17 11:05:28 -04:00
openshift-ci[bot] c6908de514
Merge pull request #3424 from Luap99/resolv
Fix resolv.conf content with run --net=private
2021-08-10 17:29:29 +00:00
openshift-ci[bot] 88f55c8f15
Merge pull request #3409 from ashley-cui/sshagent
Implement SSH RUN mount
2021-08-06 22:35:40 +00:00
Ashley Cui 3a5635f90b Implement SSH RUN mount
Allow ssh socket from host or certain ssh keys to be exposed to a
certain RUN instruction, but not any other instructions, as well as not
showing up in the final image.
This is done by spawining a new agent from buildah and mounting
the listening socket inside the run. SSH_AUTH_SOCK inside the container
will be set to the socket mountpoint. The defualt mountpoint is
/run/buildkit/ssh_agent.{i}

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-08-06 09:00:06 -04:00
Paul Holzinger f90481d03a
Fix resolv.conf content with run --net=private
Make sure to use the correct resolv.conf in case of systemd-resolved.
Also filter out 127... nameserver when run in private netns.

Fixes #2780

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-08-06 12:32:43 +02:00
Valentin Rothberg 078efc2197 run: fix nil deref using the option's logger
[NO TESTS NEEDED] since I've no idea how to force it.

Reported-in: containers/podman/issues/11148
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-08-06 11:13:01 +02:00
Daniel J Walsh bb738d4406
Allow dst and destination for target in secret mounts
Fixes: https://github.com/containers/buildah/issues/3396

Patch from @mixedCase

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-07-22 14:47:22 -04:00
Daniel J Walsh 902d579a1f
Turn stdio back to blocking when command finishes
Fixes: https://github.com/containers/buildah/issues/3152

Sometimes after running buildah run in a terminal, commands executed afterwards which try to read from stdin fail with EAGAIN. This is because it sets O_NONBLOCK on the FD:

[NO TESTS NEEDED] Since I don't know how to test this.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-06-25 03:14:26 -04:00
Matthew Heon fdf344c651 Add support for default network creation
As part of the podman-machine work, we need to stop distributing
the default CNI configuration that has traditionally been
supplied by Podman, 87-podman.conflist. Buildah (as root) also
uses this file, and will be unable to set up container networking
without it.

The replacement we've introduced is the ability to automatically
create said configuration file using a package in
containers/common. This has already been added to Podman, and
this PR adds it to Buildah.

[NO TESTS NEEDED] as there's no real easy way to verify that
Buildah made the network - no explicit command for listing
networks.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2021-06-23 14:32:52 -04:00
Daniel J Walsh d7d078561c
Send logrus messages back to caller when building
We want Info, Warning and Debug logrus messages to be writen to the
buildah stderr. this way when podman-remote is using build, it will
get the messages back on the client side.

[NO TESTS NEEDED] Since this will be tested in Podman.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-05-15 03:55:05 -04:00
Daniel J Walsh 79bdccafb9
Fix race condition
Ed has found situations where the container exits, before we can check
the state causing a failure, where I think we can complete successfully.

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

[NO TESTS NEEDED] since I have no way to generate this race condition.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-05-10 07:18:09 -04:00
OpenShift Merge Robot baae671fb5
Merge pull request #3187 from nalind/relay-errors
runUsingRuntime: when relaying error from the runtime, mention that it's from the runtime
2021-04-28 18:41:06 -04:00
Nalin Dahyabhai f6cd687a80 runUsingRuntime: when relaying error from the runtime, mention that
Mention that errors we relay from the runtime are from the runtime, to
hopefully reduce confusion when troubleshooting.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-04-28 15:48:29 -04:00
Nalin Dahyabhai 3f78f33dc5 Run(): avoid Mkdir() into the rootfs
Replace a call to idtools.MkdirAllAndChownNew() with a call to
copier.Mkdir().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-04-27 16:54:32 -04:00
Ashley Cui c8002d9739 Add support for secret mounts
Add support for secrets. Secrets is a two-part flag that allows secret files to
be accessed for a certain RUN instruction, but not any other
instructions, as well as now showing up in the final image.

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-04-23 09:19:43 -04:00
Ashley Cui 1c0e033a35 Rename rhel secrets to subscriptions
rename secrets to subscriptions and remove unused subscription package

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-04-22 13:45:30 -04:00
OpenShift Merge Robot 18c5ab79a1
Merge pull request #3117 from rhatdan/mounts
Sort all mounts by destination directory
2021-04-02 14:14:09 +02:00
Urvashi Mohnani 3598ffb167 Check for symlink in builtin volume
Check if a builtin volume is a symlink. If it is,
follow the symlink and ensure that the destination
exists.
Add tests for symlink and no symlink case.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2021-04-01 13:38:46 -04:00
Daniel J Walsh d29b04dba7
Sort all mounts by destination directory
Currently depending on the sort order of mount points, we can overmount
a volume specified from the user. Podman has a function sortMount that
sorts all mounts based on destination directory to ensure all mounts
show up. This PR moves the function from Podman to Buildah. Once merged
I will change Podman to use the buildah function.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-03-31 16:26:09 -04:00
Nalin Dahyabhai 0b4d973238 COPY --chown: expand the conformance test
Expand conformance test coverage for COPY --chown, and correct our
behavior when the argument is a single number: instead of assuming the
number is the UID and GID = 0, the GID should be the same as the UID.

This means that we can't quite use the same function for parsing the
arguments for COPY --chown and USER, as they evidently have different
defaults for the case where the argument is a single number.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-03-22 16:37:12 -04:00
Daniel J Walsh 514a3f1a91
Shrink the vendoring size of pkc/cli
This PR removes the pkg/auth which brings in docker/docker
since it really is not needed, and was only there to help users
discover the settings of where the authfile was, when the environment
variables were set.  Would almost never be of any value.

Move imagebuildah.BuildOptions to define.BuildOptions

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-03-03 14:18:35 -05:00
Daniel J Walsh 4704e6cb3f
Eliminate the use of containers/building import in pkg subdirs
We want to shrink the size of the import when importing pkg from
buildah. This should help us shrink the size of the golang bindings
in podman.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-02-12 12:43:08 -05:00
Daniel J Walsh 3446328c77
build(deps): bump github.com/containers/common from 0.34.0 to 0.34.2
Bumps [github.com/containers/common](https://github.com/containers/common) from 0.33.1 to 0.34.2.
- [Release notes](https://github.com/containers/common/releases)
- [Commits](https://github.com/containers/common/compare/v0.33.1...v0.34.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-02-08 18:06:36 -05:00
Eduardo Vega b1ae9c1f3a Use chown function for U volume flag from containers/common repository
Signed-off-by: Eduardo Vega <edvegavalerio@gmail.com>
2021-02-08 08:04:29 -06:00
Giuseppe Scrivano 4026fa9696
run: fix check for host pid namespace
check the pidns is shared with the host only when the pidns mode is
specified.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-02-05 19:51:10 +01:00
Josh Soref c7963db369 Spelling
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-12-21 16:47:18 -05:00
Eduardo Vega 1f4e751770 Add U volume flag to chown source volumes
Signed-off-by: Eduardo Vega <edvegavalerio@gmail.com>
2020-12-16 14:07:26 -06:00
Daniel J Walsh d9a7f13665
Add container information to .containerenv
We have been asked to leak some container information
and image information into the container to be used
by certain tools. (Toolbox and others)

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-11-24 15:56:38 -05:00
Daniel J Walsh 2099ad769f
Switch to using containers/common pkg's
pkg/secrets has been moved and slightly been rewrittin
in containers/common, along with pkg/umask.

Convert Buildah to use these packages rather then internal
packages.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-11-20 15:46:30 -05:00
Nalin Dahyabhai 002c88e256 Run: don't forcibly disable UTS namespaces in rootless mode
I can't remember why we disabled UTS namespaces for rootless isolation,
but it doesn't look necessary.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-11-12 14:46:06 -05:00
Nalin Dahyabhai 21397a1be2 Run: correctly call copier.Mkdir
Make sure the directory we're creating is explicitly below the chroot we
want to create it under.

Fix a similar incorrect call in imagebuildah.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-11-06 16:53:36 -05:00
Daniel J Walsh e8f92e09a1
(*Builder).Run: MkdirAll: handle EEXIST error
It is not entirely correct to always ignore EEXIST here. It should only
be ignored in one special case: when a working directory already exists,
and is an absolute symlink to another directory under container root.

MkdirAll reports an error because the symlink is broken in the host
context (without chroot).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-11-03 20:29:48 -05:00
Daniel J Walsh dc03c3e2f6
fix MkdirAll usage
This subtle bug keeps lurking in because error checking for `Mkdir()`
and `MkdirAll()` is slightly different wrt `EEXIST`/`IsExist`:

 - for `Mkdir()`, `IsExist` error should (usually) be ignored
   (unless you want to make sure directory was not there before)
   as it means "the destination directory was already there";

 - for `MkdirAll()`, `IsExist` error should NEVER be ignored.

This commit removes ignoring the IsExist error, as it should not
be ignored.

[v2: skip patching (*Builder).Run]

For more details, a quote from opencontainers/runc PR #162:

-quote-

TL;DR: check for IsExist(err) after a failed MkdirAll() is both
redundant and wrong -- so two reasons to remove it.

Quoting MkdirAll documentation:

> MkdirAll creates a directory named path, along with any necessary
> parents, and returns nil, or else returns an error. If path
> is already a directory, MkdirAll does nothing and returns nil.

This means two things:

1. If a directory to be created already exists, no error is
returned.

2. If the error returned is IsExist (EEXIST), it means there exists
a non-directory with the same name as MkdirAll need to use for
directory. Example: we want to MkdirAll("a/b"), but file "a"
(or "a/b") already exists, so MkdirAll fails.

The above is a theory, based on quoted documentation and my UNIX
knowledge.

3. In practice, though, current MkdirAll implementation [1] returns
ENOTDIR in most of cases described in #2, with the exception when
there is a race between MkdirAll and someone else creating the
last component of MkdirAll argument as a file. In this very case
MkdirAll() will indeed return EEXIST.

Because of #1, IsExist check after MkdirAll is not needed.

Because of #2 and #3, ignoring IsExist error is just plain wrong,
as directory we require is not created. It's cleaner to report
the error now.

Note this error is all over the tree, I guess due to copy-paste,
or trying to follow the same usage pattern as for Mkdir(),
or some not quite correct examples on the Internet.

> [1] https://github.com/golang/go/blob/f9ed2f75/src/os/path.go

-end-quote-

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-11-03 15:39:21 -05:00
Daniel J Walsh 39f4cfb79d
Stop excessive wrapping
Golang built in functions like os.Create and others print the name of
the file system object when they fail.  Wrapping them a second time
with the file system object, makes the error message look like crap
when reported to the user.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-15 14:03:13 -04:00
Nalin Dahyabhai bf41a3d707 Makefile: tweak the cross-compile target
What `go tool dist list` says the toolchain supports changes, so this
change removes these attempted cross-compile build targets.
* GOOS=darwin, GOARCH unspecified
* GOOS=darwin, GOARCH=386

Replace our use of slices of
github.com/opencontainers/runc/libcontainer/configs.Device structures
with a locally-defined type alias so that we can avoid importing the
package on non-Unixy systems.  The result is not going to be a very
useful binary on non-Linux systems, but it helps ensure that our
subpackages won't break compilation for other projects who consume us as
a library.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-09-24 12:09:48 -04:00
Nalin Dahyabhai 72e0721b2b Run(): ignore containers.conf's environment configuration
The hardwired default for containers.conf now includes a TERM variable,
and passing it through to commands that we "RUN" during a build can
subtly cause the resulting image to be different from one that `docker
build` would create, so stop using it there.

When a runtime runs the image we eventually produce, it'll consult the
configuration file, so the variable will still be set, even when it
isn't set in the image.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-09-17 14:43:37 -04:00
bors[bot] f39d40e632
Merge #2560
2560: Rework ADD/COPY to use the copier package r=giuseppe a=nalind

#### What type of PR is this?

/kind failing-test 

#### What this PR does / why we need it:

Use the copier package for ADD, COPY, and for ensuring that a specified directory exists in the working container's rootfs.  This should improve our speed when a .dockerignore file is being used, and correctness all around.

When evaluating cache for content that's being copied/added in, switch from (digest the data, check for a cache entry, then maybe copy the data and create the new layer) to (copy the data and create the new layer, digesting as we go, check for a cache entry, either commit or discard the new layer).  This reduces the amount of data that we read from disk, which helps when the data being read doesn't all fit in the kernel's cache, and if we end up keeping the result, costs us nothing compared to what we were doing before.

#### How to verify it

More of our conformance tests should pass, and existing tests should continue to pass.  (We do update a couple of integration tests, but I believe they were expecting incorrect behavior before.)

#### Which issue(s) this PR fixes:

Fixes #574.
Fixes #2476.

#### Special notes for your reviewer:

This is another part of #2480.

#### Does this PR introduce a user-facing change?

```
ADD and COPY should be faster when a .dockerignore file is being used.
```

Co-authored-by: Nalin Dahyabhai <nalin@redhat.com>
2020-08-22 11:49:27 +00:00
Nalin Dahyabhai 3835460c3b Use pipes for copying
Use the copier package to rework how we handle ADD and COPY.

When evaluating cache for content that's being copied/added in, switch
from (digest the data, check for a cache entry, then maybe copy the data
and create the new layer) to (copy the data and create the new layer,
digesting as we go, check for a cache entry, either commit or discard
the new layer).

Use the copier package for ADD, COPY, and for ensuring that a specified
directory exists in the working container's rootfs.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-08-21 12:34:00 -04:00
Giuseppe Scrivano 62dcf0c40c
run: include stdout in error message
improve the error message by including the command stdout, if any.
Stderr is already handled.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-08-21 14:11:57 +02:00
Giuseppe Scrivano e613e90e32
run: use the correct error for errors.Wrapf
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-08-21 13:59:41 +02:00
Daniel J Walsh 07732c3eab
Fix errors found in coverity scan
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-08-13 09:04:36 -04:00
TomSweeneyRedHat e3da008aea Don't bind /etc/host and /etc/resolv.conf if network is not present
If there's no network present in the container, don't bind
the /etc/hosts file as any changes to from the caller will
be lost when run exits. Ditto the /etc/resolv.conf file.

Addresses: #2478

Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
2020-08-01 17:34:22 -04:00
Nalin Dahyabhai 92e0c3fdcf Rework conformance testing
Move the conformance tests from ginkgo to using the default testing
package and github.com/stretchr/testify/require, preserving the existing
tests and adding more.

Add conformance tests to our Cirrus configuration, currently marked as
an allowed failure.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-07-23 15:30:58 -04:00
Daniel J Walsh d2e0cd8988
Merge pull request #2434 from giuseppe/no-kill-error
linux: skip errors from the runtime kill
2020-07-14 13:29:07 -04:00
bors[bot] 0bad47cf24
Merge #2465
2465: Deduplicate environment variables r=rhatdan a=nalind

#### What type of PR is this?

> /kind cleanup

#### What this PR does / why we need it:

When combining lists of environment variables read from base images with defaults supplied from our own configuration, ensure that the resulting environment we produce only contains one value for any given variable.  While adding variables to a runtime spec using `github.com/opencontainers/runtime-tools/generate.Generator.AddProcessEnv()` ensures that later values in the list override values that occur earlier, we shouldn't be depending on that.

#### How to verify it

#### Which issue(s) this PR fixes:

None

#### Special notes for your reviewer:

Related to https://github.com/openshift/imagebuilder/pull/169.

#### Does this PR introduce a user-facing change?

```
None
```

Co-authored-by: Nalin Dahyabhai <nalin@redhat.com>
2020-07-14 16:37:29 +00:00
Nalin Dahyabhai abda6f3156 Deduplicate environment variables
When combining lists of environment variables, or environment variables
combined with build arguments, always deduplicate sets of values.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-07-13 18:09:57 -04:00
Daniel J Walsh 68389aa4ec
Mask out /sys/dev to prevent information leak
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-13 16:18:37 -04:00
Giuseppe Scrivano ddf7f01876
linux: skip errors from the runtime kill
fix a race condition where the container process could exit before the
runtime sends the signal, causing the command to fail.

Part of: https://github.com/containers/crun/issues/422

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-09 22:44:56 +02:00
Daniel J Walsh c00b434cd2
Mask over the /sys/fs/selinux in mask branch
This is required so that the mount point shows up when buildah
is vendored into Podman.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-08 14:03:47 -04:00
dependabot-preview[bot] 9fb931ca7a
Bump github.com/containers/common from 0.14.0 to 0.15.2
Bumps [github.com/containers/common](https://github.com/containers/common) from 0.14.0 to 0.15.2.
- [Release notes](https://github.com/containers/common/releases)
- [Commits](https://github.com/containers/common/compare/v0.14.0...v0.15.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-08 05:23:48 -04:00
Brandon Lum 40df1c6e3b Fix errorf conventions
Signed-off-by: Brandon Lum <lumjjb@gmail.com>
2020-04-04 01:12:25 +00:00
Daniel J Walsh b2e7110255
vendor in latest containers/storage 1.18.0 and containers/common v0.7.0
This vendor moves containers/common/pkg/unshare to containers/storage/pkg/unshare

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-31 09:56:18 -04:00
Nick Carboni 7535471ff6 Don't add args to the RUN environment from the Builder
The correct args are already contained in the RunOptions.
They were resolved by the imagebuilder library's Step
(edcddd8483/builder.go (L311-L317))
function

This was previously adding args that should not have been accessible
in the current stage as they were not first referenced by an ARG
command

Signed-off-by: Nick Carboni <ncarboni@redhat.com>
2020-03-26 13:43:49 -04:00
Daniel J Walsh 8bcc55a5ee
Fix FORWARD_NULL errors found by Coverity
Error: FORWARD_NULL (CWE-476): [#def50]

These errors could lead to crashes in the code.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-10 10:16:14 -04:00
Giuseppe Scrivano 5723277f23
run_linux: fix tight loop if file is not pollable
do not attempt again to poll the file if it is not pollable and the
the errno is not syscall.EINTR or syscall.EAGAIN.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-02 13:30:26 +01:00
TomSweeneyRedHat 31cffe9040 Search for local runtime per values in containers.conf
After determining the type of runtime to use,
either "runc" or "crun" dependent upon the system, search
the list of that type of runtime in the containers.conf
file.  It includes the location of those runtimes in a
number of different architectures.  Once found, set the
runtime to use to that value.

Fixes: #2113

Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
2020-02-26 19:35:37 -05:00
bors[bot] c9e5ff00e5
Merge #2173
2173: Update to containers/common v0.3.0 r=vrothberg a=rhatdan

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

Co-authored-by: Daniel J Walsh <dwalsh@redhat.com>
2020-02-19 10:26:43 +00:00
Daniel J Walsh fc6baddc97
Update to containers/common v0.3.0
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-02-18 17:45:01 -05:00
Nalin Dahyabhai f3a5653c92 run: adjust the order in which elements are added to $PATH
When building the slice of environment variables to add to the
configuration for a container that we're about to run, in case of
conflicts, we want the values from the base image or working container
to override the global defaults, and we want values that were passed to
us through the API to override them both.

In cases of conflicts, values which occur later in the slice override
values which occurred earlier, so we want to add them in this order:
* values from containers.conf
* values from the base image or working container
* values passed to us through the API

We previously applied the containers.conf defaults after the base image
or working container's value, and that meant that containers.conf's
values always took precedence over the values in the image.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-02-17 15:40:42 -05:00
Daniel J Walsh cca09881c3
Repair buildah so it can use containers.conf on the server side
In porting containers.conf to libpod, we found that buildah needed
to handle the containers.conf on the server side rather then from
the CLI.

Since the `podman-remote build` would probably not have the same content
as containers.conf on the server, the processesing of the defaults needs
to be handled in imagebuildah.  The CapAdd and CapDrop values need to be
passed in.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-02-10 09:41:31 -05:00
Daniel J Walsh 09d1c24e3d Add support for containers.conf
This is a rework of Qi Wang's patches.
Import package pkg/config from containers/common to read containers.conf
This patch allows users to specify default values stored in containers.conf
that will modify the behaviour of buildah tool.

Signed-off-by: Qi Wang <qiwan@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #2011
Approved by: TomSweeneyRedHat
2020-01-15 17:24:36 +00:00
Daniel J Walsh 41b7852611 Rework overlay pkg for use with libpod
Podman uses the overlay mounts differently then in buildah.  Specifically the
overlay mount points can be used over and over again when starting and stopping
the container.  Since the paths are backed into the contianer config, we have
to be able to cleanout just the Upper and Merged directory rather then destroying
and recreating the overlay directories on each container start.

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

Closes: #1822
Approved by: vrothberg
2019-12-22 12:04:13 +00:00
Daniel J Walsh fb7d2b6bd6
Add support for FIPS-Mode backends
If host is running in fips mode, then RHEL8.2 and beyond container images
will come with a directory /usr/share/crypto-policies/back-ends/FIPS.
This directory needs to be bind mounted over /etc/crypto-policies/back-ends in
order to make all tools in the container follow the FIPS Mode rules.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-12-19 08:53:56 -05:00
Daniel J Walsh 8fc5b0116f Start using containers/common
We have moved share code from buildah, podman and others into containers/common.

Specifically for this PR we are moving to use containers/common/pkg/unshare and
containers/common/pkg/cgroups.

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

Closes: #2010
Approved by: QiWang19
2019-12-06 14:37:27 +00:00
Urvashi Mohnani 54ef0073bc Add disableFips option to secrets pkg
If disableFips is set, then we don't mount the FIPS
secret even if the machine is in FIPs mode. This is
to help users run workloads that are not fips compliant
in openshift even if their machine is in FIPs mode.
This is needed in CRI-O.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2019-10-31 10:04:01 -04:00
Daniel J Walsh 20a33e0791 Add --devices flag to bud and from
Some Dockerfiles (fuse-overlay) require additional devices to be in the
build environment.

This patch allows the user to specify additional devices.

Also I noticed that CapAdd and CapDrop was not working in buildah bud situations,
so this patch also fixes this.

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

Closes: #1820
Approved by: @TomSweeneyRedHat
2019-09-07 17:32:43 +00:00
Daniel J Walsh 7f0b60c6f7
Add support for /run/.containerenv
Container processes want to check for the existence of this file
to determine if they are running inside of a container.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-09-06 11:56:27 -04:00
Nalin Dahyabhai 6b5f8badc1 Correctly detect ExitError values from Run()
Correctly detect ExitError error values returned by buildah.Run().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1816
Approved by: TomSweeneyRedHat
2019-08-22 18:29:17 +00:00
Nalin Dahyabhai db2b3e48ac add: add a DryRun flag to AddAndCopyOptions
Add a DryRun flag to AddAndCopyOptions, so that we can "copy" content to
digest it.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1792
Approved by: TomSweeneyRedHat
2019-08-16 20:16:40 +00:00
Giuseppe Scrivano 7180312fdf run_linux: fix mounting /sys in a userns
fix the detection code for running in a user namespace.  When buildah
is running in rootless mode, a user namespace is automatically created
even if there are no mappings configured.

Closes: https://github.com/containers/libpod/issues/2972

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1775
Approved by: rhatdan
2019-08-11 12:41:51 +00:00
Nalin Dahyabhai be51b9bd24 Update to match updated runtime-tools API
Some method argument types changed in runtime-tools. Compensate.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #1720
Approved by: vrothberg
2019-07-17 12:41:32 +00:00
Sascha Grunert 16e301031e Add unparam linter and apply fixes
This commit enabled the `unparam` linter and applies all reported issues.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>

Closes: #1719
Approved by: rhatdan
2019-07-16 21:21:32 +00:00