Commit Graph

140 Commits

Author SHA1 Message Date
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
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
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
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
Josh Soref c7963db369 Spelling
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-12-21 16:47:18 -05: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
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
baude 34e7eba408 allow podman to build a client for windows
the podman remote-client for windows pulls in some buildah code for
things like commit and build.  we need to perform some slight
refactoring of buildah code to accomodate that build.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #1551
Approved by: rhatdan
2019-04-26 19:16:11 +00:00
Daniel J Walsh 135542ecf0 Move Host IDMAppings code from util to unshare
This will make vendoring in pkg/unshare easier into other
packages like skopeo.

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

Closes: #1532
Approved by: TomSweeneyRedHat
2019-04-18 19:46:22 +00:00
James Cassell cd1b62a9ad auto pass http_proxy to container
- pass all proxy env vars
- --http-proxy option for bud and from
- bash_completion and docs

Signed-off-by: James Cassell <code@james.cassell.me>

Closes: #1525
Approved by: giuseppe
2019-04-17 14:33:46 +00:00
Qi Wang d43787be28 add --dns* flags to buildah bud
use --dns* flags to change /etc/resolv.conf in the container during the build.
Signed-off-by: Qi Wang <qiwan@redhat.com>

Closes: #1491
Approved by: rhatdan
2019-04-12 21:01:30 +00:00
Giuseppe Scrivano ac66d785d4 unshare: move to pkg/
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1475
Approved by: rhatdan
2019-04-05 03:04:46 +00:00
Daniel J Walsh 3d74031301 Move pkg/chrootuser from libpod to buildah.
We don't want to vendor anything from libpod into Buildah.
We want to switch this around.  Moving pkg content from libpod
to Buildah allows us to fix this.

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

Closes: #1400
Approved by: giuseppe
2019-03-26 15:45:33 +00:00
Valentin Rothberg d1c75eabb6 bump github.com/containernetworking/cni to v0.7.0-rc2
The {Add,Del}NetworkList APIs were extended with a context parameter,
which require adjustments in the code.

Fixes: #1433
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

Closes: #1434
Approved by: rhatdan
2019-03-22 22:24:13 +00:00
Giuseppe Scrivano c6ae5c5a0c rootless: by default use the host network namespace
if --net is not specified, default to use the host network namespace.

It is still possible to use slirp4netns with --network container.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1690209

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

Closes: #1421
Approved by: rhatdan
2019-03-21 18:21:22 +00:00
Giuseppe Scrivano a986f34af5 slirp4netns: set mtu to 65520
it improves significantly the performance of the slirp4netns network:

777bdcccef (iperf3-netns---host)

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

Closes: #1404
Approved by: vrothberg
2019-03-15 08:56:49 +00:00
Giuseppe Scrivano 042a249e73
rootless: honor --net host
when running in rootless mode, do not use slirp4netns if --net host is
specified.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-12 13:48:02 +01:00
Daniel J Walsh 36605c29eb Prepend a comment to files setup in container
setup.rpm attempts to modify /etc/hosts, if it thinks
it has never been modified.  By adding a #comment to the
front of the file, it should prevent this from blowing up
the build.

Also add hostname to the /etc/hosts file linked to localhosts

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

Closes: #1313
Approved by: vrothberg
2019-03-09 14:24:50 +00:00
Daniel J Walsh e7e4122e1f Move secrets code from libpod into buildah
Starting to remove dependency on libpod from buildah.
secrets is used so that builds can access RHEL subscriptions
so this makes more sense to be in buildah then libpod.

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

Closes: #1366
Approved by: vrothberg
2019-02-26 13:34:18 +00:00
Miloslav Trmač c8727b4033 Fix a few issues found by tests/validate/gometalinter.sh
For some reason, the CI does not report any of these; on macOS
I see many more reports (including complaints about the standard
library), this only cleans up the trivial cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1365
Approved by: rhatdan
2019-02-25 10:27:46 +00:00
Nalin Dahyabhai fa8653314a run: ignore EIO when flushing at the end, avoid double log
When reading the last of the output from a child process, ignore an EIO,
since we already got the HUP indication.

Avoid double-logging errors in our I/O loop when using isolation other
than chroot (spotted by @afbjorklund).

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

Closes: #1273
Approved by: rhatdan
2019-01-12 12:04:54 +00:00
Anders F Björklund 5d22f3ced9 Make rootless work under no_pivot_root
Previously only done for root isolation

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>

Closes: #1261
Approved by: rhatdan
2019-01-10 13:15:42 +00:00
Daniel J Walsh 3cb835dfef Properly handle Hostname inside of RUN command
This will get buildah bud to follow docker build handling of
hostname environment variable and hostname command properly

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

Closes: #1242
Approved by: giuseppe
2018-12-19 12:24:57 +00:00
Giuseppe Scrivano 48cede4ed0 rootless: do not specify --rootless to the OCI runtime
runc has a good "auto detect" mode to find out when running in
rootless mode.  It also makes easier to plug another OCI runtime,
since --rootless is not part of the OCI specs.

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

Closes: #1145
Approved by: TomSweeneyRedHat
2018-11-08 15:57:52 +00:00
Giuseppe Scrivano 3cebe4f2c4 run: bind mount /etc/hosts and /etc/resolv.conf if not in a volume
change the logic for bind mounting /etc/hosts and /etc/resolv.conf in
the container.  Now they are not bind mounted when they are specified
as volumes, so it is still possible to have them writeable in the
container.

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

Closes: #1156
Approved by: rhatdan
2018-11-08 10:16:30 +00:00
Giuseppe Scrivano 68ee943fac rootless: use slirp4netns to setup the network namespace
If slirp4netns is available, use it to configure the network for the
rootless isolation mode.

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

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

Closes: #1156
Approved by: rhatdan
2018-11-08 10:16:30 +00:00
Nalin Dahyabhai ff57e92d44 rootless: only discard network configuration names
When changing settings for rootless containers, only discard the part of
the networking configuration that specifies which networks we want to
configure, and preserve whether or not we want to use the host's network
namespace.

If we were told to create an empty network namespace or to just attach
to another namespace, go ahead and try to do that.

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

Closes: #1146
Approved by: rhatdan
2018-11-06 22:10:28 +00:00
Nalin Dahyabhai 5a011dbe5f run: only set up /etc/hosts or /etc/resolv.conf with network
Only set up bind mounts of copies of the host's /etc/hosts and
/etc/resolv.conf files if we're not just going to create a new,
unconfigured network namespace.

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

Closes: #1146
Approved by: rhatdan
2018-11-06 22:10:28 +00:00
Nalin Dahyabhai 87cb532ab3 runSetupBuiltinVolumes(): break up volume setup
Break setup for built-in volumes into independent steps where we create
the volume's mount point, the directory that will hold its contents, and
if there is content under the mount point, populate the volume with the
mount point's contents.

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

Closes: #1126
Approved by: rhatdan
2018-10-25 12:46:34 +00:00
TomSweeneyRedHat aeac8e9647 Check for empty buildTime in version
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #1107
Approved by: rhatdan
2018-10-19 12:46:52 +00:00
Nalin Dahyabhai 46c577c87d ReserveSELinuxLabels(): handle wrapped errors from OpenBuilder
ReserveSELinuxLabels() checks if an error returned by OpenBuilder() is a
does-not-exist error, but OpenBuilder() returns wrapped errors now, and
it wasn't checking the root cause error.

When newBuilder() fails, check the right error value when deciding
whether or not deleting the partially-constructed container failed.

OpenBuildersByPath() shouldn't choke on non-buildah containers, so have
it handle does-not-exist errors the same way OpenAllBuilders() does.

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

Closes: #1109
Approved by: rhatdan
2018-10-17 21:20:29 +00:00
TomSweeneyRedHat 31064fcda1 Set WorkingDir to empty, not / for conformance
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #1098
Approved by: rhatdan
2018-10-16 18:41:39 +00:00
Anders F Björklund 7deca81e41 Add the --no-pivot flag to the run command
--no-pivot: "do not use pivot root to jail process inside rootfs.
  This should be used whenever the rootfs is on top of a ramdisk"

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>

Closes: #1071
Approved by: rhatdan
2018-10-15 16:01:14 +00:00
Zhou Hao 9956ba8416 Optimize redundant code
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>

Closes: #1084
Approved by: rhatdan
2018-10-12 19:28:25 +00:00
Nalin Dahyabhai bc2ea08003 Make sure we log or return every error
Make sure that when attempting to diagnose an error, if we encounter an
error during the diagnostic attempt, we return the original error rather
than the error encountered in trying to diagnose it.  Log that one.

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

Closes: #1072
Approved by: rhatdan
2018-10-07 12:07:09 +00:00
Daniel J Walsh 8d3ee96abc
Builtin volumes should be owned by the UID/GID of the container
When creating a building VOLUME for a container we need to create it
with the ownership/permsissions of the directory that we will be mounting on.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-09-19 08:48:34 -04:00
Daniel J Walsh ba012ddec6
Move buildah from projecatatomic/buildah to containers/buildah
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-09-18 08:06:11 -04:00
Daniel J Walsh 8ead4d2eca Retain bounding set when running containers as non root
We need to be able to run sudo commands inside of Dockerfile's
even when containers are setup with non root.

This patch retains the bounding set for containers run with non root user.

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

Closes: #1001
Approved by: vrothberg
2018-09-12 17:13:29 +00:00
Nalin Dahyabhai d54f0eaf30 run: clear default seccomp filter if not enabled
When seccomp is not enabled, make sure to clear any default setting
which runtime-tools supplied for us.  Likewise, if SELinux is not
enabled, don't set a process label or a mount label.

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

Closes: #988
Approved by: rhatdan
2018-09-05 20:34:41 +00:00
Nalin Dahyabhai e4ec46aaa0 stdin: on HUP, read everything
When we're polling to handle stdio for a container, when we detect a HUP
on our stdin, read all that we can from stdin before closing it, instead
of reading only, at most, a single chunk of bytes.

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

Closes: #980
Approved by: rhatdan
2018-09-04 20:08:20 +00:00
Nalin Dahyabhai 347478cccd chroot isolation: chroot() before setting up seccomp
Make the chroot() call before applying a seccomp filter, which might not
allow us to do it.  Add more debugging messages.

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

Closes: #979
Approved by: rhatdan
2018-08-31 13:46:10 +00:00
Daniel J Walsh e8c123cc03 Change references to projectatomic/libpod to containers/libpod
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #928
Approved by: umohnani8
2018-08-15 20:13:50 +00:00
Nalin Dahyabhai f94159340b Don't bother with --no-pivot for rootless isolation
When running outside of a container, --no-pivot isn't necessary, and
when running inside of a container, it's not enough to solve any of the
difficulties we're seeing there.  It may trigger an EPERM for unshare()
calls inside of the container that we launch, and we don't want that, so
drop it, for now at least.

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

Closes: #921
Approved by: rhatdan
2018-08-10 13:28:49 +00:00
Nalin Dahyabhai 86ced70386 Add and implement IsolationOCIRootless
Add an IsolationOCIRootless that runs the OCI runtime with its
--rootless flag, with network and UTS namespaces disabled, with IPC,
PID, and user namespaces forcibly enabled.  In this mode, we don't
attempt to set the container's hostname (because we don't have our own
UTS namespace), and we don't try to set any supplemental groups.  The
/sys directory is replaced with a bind mount of the host's /sys rather
than a fresh sysfs instance.

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

Closes: #873
Approved by: rhatdan
2018-08-03 19:49:19 +00:00
Nalin Dahyabhai 40bb4a5b47 Add a value for IsolationOCIRootless
Add a new Isolation value: IsolationOCIRootless, for which we add a
global --rootless=true flag and a local --no-new-keyring flag when
creating a runtime container, and make some changes to the mounts list,
default namespacing configurations, and supplemental groups list.

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

Closes: #873
Approved by: rhatdan
2018-08-03 19:49:19 +00:00
Nalin Dahyabhai 38ef1231f2 Add and implement IsolationChroot
Add an IsolationChroot that trades flexibility and isolation for being
able to do what it does in a host environment that's already isolated to
the point where we're not allowed to set up some of that isolation,
producing a result that leans more toward chroot(1) than runc(1) does.

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

Closes: #836
Approved by: rhatdan
2018-08-01 14:04:59 +00:00
Daniel J Walsh 02f54e4b1e Allow ping command without NET_RAW Capabilities
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #818
Approved by: nalind
2018-07-31 19:41:44 +00:00
Daniel J Walsh e5f7539420 Remove default dev/pts
This allows us to run buildah without being root

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

Closes: #883
Approved by: giuseppe
2018-07-25 12:48:43 +00:00
Nalin Dahyabhai 826733af7f Avoid a stall in runCollectOutput()
Before calling runCollectOutput() to read error information from pipes,
make sure we've closed our handles to the writing ends of the pipes.

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

Closes: #872
Approved by: rhatdan
2018-07-19 19:51:38 +00:00
Daniel J Walsh 3fb864bb93 Block use of /proc/acpi and /proc/keys from inside containers
/proc/acpi allows containers to modify certain settings on the host, without
SELinux enabled.

/proc/keys allows information about keys on the host to leak into the containers.

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

Closes: #853
Approved by: rhatdan
2018-07-08 10:58:27 +00:00