Commit Graph

147 Commits

Author SHA1 Message Date
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
Nalin Dahyabhai 3b38b8ebbc Don't pass a nil error to errors.Wrapf()
Don't pass a nil error value to errors.Wrapf() when we want to report an
error, since it's documented as returning nil for that case.

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

Closes: #856
Approved by: rhatdan
2018-07-07 09:19:12 +00:00
baude 5cd9be61ef allow buildah cross compile for a darwin target
the goal here is to allow ourselves to cross compile buildah for a darwin
target.  we are doing this to eventually protect from regressions that could
creep into buildah so we don't dig ourselves a deeper hole.

the simplified and non-variable approach to the make darwin was done with
intent to keep this simple until we can exploit things a little more.

once this PR merges, i will create a CI test that will test for regressions
on a make darwin.  we should also be doing a gofmt with a darwin target so the
!linux|darwin tagged files are also checked for completeness.  initially the
test can be optional for passing with the long-term idea that it be made
a firm requirement at the buildah maintainers behest.

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

Closes: #840
Approved by: rhatdan
2018-07-01 09:13:39 +00:00
Nalin Dahyabhai b965fc4cdb runConfigureNetwork(): remove an unused parameter
Remove the configureNetwork parameter from runConfigureNetwork(), which
was only called if the value was true, and which runConfigureNetwork()
itself never used.

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

Closes: #834
Approved by: rhatdan
2018-06-28 22:18:33 +00:00
Nalin Dahyabhai b319442a51 Force ownership of /etc/hosts and /etc/resolv.conf to 0:0
Explicitly force the owner of /etc/hosts and /etc/resolv.conf to 0:0 in
the container, instead of attempting to let ID maping implicitly handle
it, since when we're being run unprivileged, the owners of the source
files are already unmapped IDs.

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

Closes: #823
Approved by: rhatdan
2018-06-28 18:22:36 +00:00
Daniel J Walsh 5faedde701 Reduce the complexity of the buildah.Run function
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #831
Approved by: nalind
2018-06-27 15:39:27 +00:00
Daniel J Walsh 7919c96a69
Merge pull request #828 from baude/vendorruntimetools
vendor in latest runtime-tools
2018-06-27 05:52:56 -04:00
Nalin Dahyabhai 29359f0d0b Implement basic recognition of the "--isolation" option
Add the basics of handling the "--isolation" option, though at the
moment, the only recognized option is "oci", which is our default.

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

Closes: #822
Approved by: rhatdan
2018-06-26 22:37:38 +00:00
Nalin Dahyabhai 46c395a44e Run(): try to resolve non-absolute paths using $PATH
Try to resolve commands which aren't given as absolute paths using the
$PATH environment variable and the mounted rootfs.  If we don't have a
configured $PATH, add one.

We can't resolve symbolic links with absolute values reliably without
using chroot(), so we just take it on faith that a link, or a non-link
with the execute bit set, will work.

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

Closes: #820
Approved by: rhatdan
2018-06-26 21:52:23 +00:00
Nalin Dahyabhai ce02da9b9b Run(): don't include any default environment variables
When copying environment variables from the image's configuration to the
spec that we'll pass to the runtime, clear out any defaults that the
generate package might be supplying.  Currently, that's "$TERM".

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

Closes: #820
Approved by: rhatdan
2018-06-26 21:52:23 +00:00
baude f2e8f65c22 build without seccomp
If the seccomp build tag is disabled, build without it.

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

Closes: #819
Approved by: rhatdan
2018-06-26 21:52:14 +00:00
baude b599244cd1 vendor in latest runtime-tools
The latest runtime-tools is aware of other OS's than Linux.  Libpod needs the newer
version to compile on darwin.  Unfortunately, the API for generator.New() changed
and requires a string representation of the OS; furthermore, it also returns a
a generator and an error so code had to be adjusted for this too.

Signed-off-by: baude <bbaude@redhat.com>
2018-06-26 15:49:39 -05:00
Daniel J Walsh 16a33bd7cf Fix ARGS parsing for run commands
Currently we are not adding the ARGS passed in via Dockerfile
or --build-args into the running container as environment variables.

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

Closes: #816
Approved by: umohnani8
2018-06-25 16:17:09 +00:00
Nalin Dahyabhai da7be32737 Use the right formatting when adding entries to /etc/hosts
Append address+"\t"+hostname to the hosts file instead of the
"hostname:address" format that we picked up from the command line.

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

Closes: #798
Approved by: rhatdan
2018-06-19 18:47:41 +00:00
Nalin Dahyabhai 9930e031ca Run(): simplify runCopyStdio()
Rework runCopyStdio() to remove the "reading" variable, and to reduce
cyclomatic complexity.

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

Closes: #795
Approved by: rhatdan
2018-06-19 13:06:32 +00:00
Nalin Dahyabhai a4cc906be7 Run(): handle POLLNVAL results
Handle POLLNVAL status from poll() (invalid request, descriptor is not
open) by removing the descriptor from the list that we poll on.

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

Closes: #795
Approved by: rhatdan
2018-06-19 13:06:32 +00:00
Nalin Dahyabhai 153d9d5e4c Run(): tweak terminal mode handling
Default to using a controlling terminal if all three stdio descriptors
are terminals, not just stdout.

Don't try to set stdin to raw mode while running a container if it's not
a terminal, in which case it doesn't support terminal modes.

Don't try to read the window size of stdin if it's not a terminal, in
which case it doesn't have a window size.  Provide a way to explicitly
set it for those cases.

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

Closes: #795
Approved by: rhatdan
2018-06-19 13:06:32 +00:00
Nalin Dahyabhai 898b18ebdd Run(): rename 'copyStdio' to 'copyPipes'
Rename a variable.

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

Closes: #795
Approved by: rhatdan
2018-06-19 13:06:32 +00:00
Nalin Dahyabhai 292569b931 Run(): don't set a Pdeathsig for the runtime
Don't try to set the Pdeathsig attribute on the runtime process when we
call the runtime.  Whether we should try to do that is debatable, and it
seems to cause us to interact badly with strace(1).

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

Closes: #802
Approved by: rhatdan
2018-06-19 12:30:29 +00:00
Nalin Dahyabhai 2064b29f40 Run(): add options for adding and removing capabilities
Add RunOptions and BuildOptions flags for modifying the list of granted
capabilities from the default.

Default to granting the current (as of this writing) defaults from
runtime-tools, with CAP_NET_RAW removed:
* CAP_AUDIT_WRITE
* CAP_CHOWN
* CAP_DAC_OVERRIDE
* CAP_FOWNER
* CAP_FSETID
* CAP_KILL
* CAP_MKNOD
* CAP_NET_BIND_SERVICE
* CAP_SETFCAP
* CAP_SETGID
* CAP_SETPCAP
* CAP_SETUID
* CAP_SYS_CHROOT

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

Closes: #799
Approved by: rhatdan
2018-06-18 21:07:08 +00:00
Nalin Dahyabhai 5574235daf Run(): don't use a callback when a slice will do
moreCreateArgs() doesn't need to be a function; it can just be a slice.

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

Closes: #797
Approved by: rhatdan
2018-06-18 20:31:14 +00:00
Nalin Dahyabhai e9a11cdf6a setupSeccomp(): refactor
Rework setupSeccomp() to use switch{} instead of multiple if{} tests
when deciding how to set the Seccomp configuration for a container.

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

Closes: #793
Approved by: rhatdan
2018-06-18 19:54:31 +00:00
Nalin Dahyabhai ea182a70e1 Change RunOptions.Stdin/Stdout/Stderr to just be Reader/Writers
Change RunOptions.Stdin from a ReadCloser to a Reader, since we weren't
closing it.  Likewise, change RunOptions.Stdout and .Stderr from
WriteClosers to Writers, since we weren't closing them, either.

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

Closes: #792
Approved by: rhatdan
2018-06-18 19:16:27 +00:00
Nalin Dahyabhai edce842f54 Break out getProcIDMappings()
Break getProcIDMappings() out of run.go and turn it into
util.GetHostIDMappings(), and add util.GetSubIDMappings() and
util.ParseIDMappings().

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

Closes: #796
Approved by: rhatdan
2018-06-18 18:38:54 +00:00
Nalin Dahyabhai 002c18a3bb Break out SetupIntermediateMountNamespace()
Break runSetupIntermediateMountNamespace() into its own package.
Move stringInSlice(), getHostIDs(), and getHostRootIDs() into the util
subdirectory and export them.

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

Closes: #796
Approved by: rhatdan
2018-06-18 18:38:54 +00:00
Nalin Dahyabhai 261e129c83 Separate stdio buffering from writing
When relaying stdio data to and from a container, separate the "reading
and buffering from a read descriptor" step from the "relaying to a write
descriptor" step, so that we can try to flush buffers that have data in
them even when there's no new data to be read.

Treat EAGAIN as a recoverable error when writing, since we're now able
to come back and try again later.

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

Closes: #787
Approved by: rhatdan
2018-06-14 10:23:08 +00:00
Daniel J Walsh 3a849c02a6 Add environment variable BUILDAH_RUNTIME
Allow user to setup alternate runtimes to use rather then
runc.

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

Closes: #786
Approved by: rhatdan
2018-06-13 07:40:46 +00:00
Nalin Dahyabhai ae27963cb0 Add(): learn to record hashes of what we add
Add a field to AddOrCopyOptions that can take an io.Writer, more often a
hash.Hash returned by digest.Digester's Hash() method, to calculate a
sum over what we add or copy.

Make the help output summarizing the arguments that "buildah add" and
"buildah copy" accept more closely match their man pages.

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

Closes: #766
Approved by: rhatdan
2018-06-11 12:39:05 +00:00
Daniel J Walsh 821f2d3652 Drop capabilities if running container processes as non root
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #764
Approved by: umohnani8
2018-06-08 14:11:46 +00:00
Nalin Dahyabhai c94d2afdab runCopyStdio(): don't close stdin unless we saw POLLHUP
When polling for input on stdin (in Terminal == false cases), don't
close the write end of the pipe that we're using to relay data from
stdin to the container unless poll() tells us that we got a POLLHUP.

Assuming that was the case when POLLIN wasn't set meant that we'd close
it as soon as poll() returned and there was no activity on the
descriptor, and if poll() only returned because we had output from the
container to relay back, we were doing so prematurely.

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

Closes: #756
Approved by: rhatdan
2018-06-06 18:09:07 +00:00
Nalin Dahyabhai 69b0a82b77 runCollectOutput(): just read until the pipes are closed on us
runCollectOutput() tries to read error messages that may have been
written to pipes by the container runtime.  Instead of setting them to
non-blocking and producing an error when we fail to read data, leave
them blocking so that we wait until the write end of a pipe is closed
before we give up on reading from it.

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

Closes: #754
Approved by: rhatdan
2018-06-06 13:17:25 +00:00
Nalin Dahyabhai c66def9aeb Run(): provide redirection for stdio
Provide RunOption fields for callers to give us stdio as an
io.ReadCloser and a pair of io.WriteClosers, or nil to use
os.Stdin/os.Stdout/os.Stderr.

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

Closes: #754
Approved by: rhatdan
2018-06-06 13:17:25 +00:00
Nalin Dahyabhai 70641ee2f0 run.bats: check that we can run with symlinks in the bundle path
Make sure that we don't trigger error messages in runc when $TMPDIR,
which affects os.TempDir(), is itself a symbolic link.

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

Closes: #746
Approved by: rhatdan
2018-06-02 09:10:51 +00:00
baude 01a443f738 use absolute path for bundlePath
When running buildah code on Atomic Hosts, we need to make sure
the absolute path for the bundlePath is used or operations
will fail.

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

Closes: #745
Approved by: nalind
2018-06-01 19:24:31 +00:00
Nalin Dahyabhai 73bfd79ef6 Run(): process RunOptions.Mounts, and its flags
RunOptions.Mounts has been mistakenly ignored since #700; handle them.

Process the options on the bind mounts in RunOptions.Mounts the same way
we handle the ones in Builder.CommonBuildOpts.Volumes, so that flags
that control read-only/read-write usage, SELinux labeling, and mount
propagation will work.

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

Closes: #739
Approved by: rhatdan
2018-05-31 21:45:40 +00:00
Nalin Dahyabhai 1567db3fcb Run(): only collect error output from stdio pipes if we created some
If the runtime's "create" command fails, we try to collect error
messages from the pipes that we hooked up to its stdio in anticipation
of running a container without a TTY.  We should only bother with that
when the container isn't attached to a TTY, which is the only time those
pipe descriptor slices are populated, so that we don't panic when we try
to read an item from an empty slice.

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

Closes: #740
Approved by: rhatdan
2018-05-31 21:38:48 +00:00
Nalin Dahyabhai 4874ad3365 Run: set supplemental group IDs
In Run(), when the userspec doesn't specify a group, if the specified
user has supplemental group memberships, pass them along to the runtime.

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

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:01 +00:00
Nalin Dahyabhai d2c27ab993 Run: use a temporary mount namespace
Move the thread that launches the runtime helper into its own OS thread,
have it create its own mount namespace, and bind mount anything that we
want to eventually bind mount into the container, into a subdirectory of
the bundle directory, before running the helper.

When deciding what to bind mount in, make the volumes specified by the
user our highest priority, in case they've been specified in order to
override our default settings for a given location.  This required
breaking up setupMounts() to keep the complexity tests from complaining.

When we use a user namespace with the host IPC namespace, bind mount
/dev/shm and /dev/mqueue instead of mounting fresh copies.
If we're told to use a user namespace with the host PID namespace,
return an error, because that doesn't work.
When we use a user namespace with the host network namespace, bind mount
/sys instead of mounting a fresh one.
When we use the host UTS namespace, don't try to set a hostname.

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

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:01 +00:00
Nalin Dahyabhai 00fafcf9cb Use CNI to configure container networks
Use CNI to configure networks for containers for which we create new
network namespaces.

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

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:01 +00:00
Nalin Dahyabhai aa5cf3115e add/secrets/commit: Use mappings when setting permissions on added content
Use ID mapping information when setting permissions on content that we
add to the container, and on secrets that we copy in, on pipes that we
use for stdio, and when extracting the whole filesystem as a "layer".

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

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:01 +00:00
Nalin Dahyabhai 0afa60eb05 Add CLI options for specifying namespace and cgroup setup
Add options to the CLI that specify which cgroups we execute "run"
commands under, and controlling how we set up namespaces for them.
Pass them down to Builders that we create, and allow them to be
overridden by options passed to Builder.Run().

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

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:01 +00:00
Nalin Dahyabhai dfc4c676d0 Always set mappings when using user namespaces
If we're creating a user namespace, we always need to supply at least
one mapping for the UID and GID maps.  If we're not given any mappings,
map the ranges that are available to us, instead of assuming we can map
all possible values, in case we're already in a user namespace.

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

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:00 +00:00
Nalin Dahyabhai d326f3a392 Run(): break out creation of stdio pipe descriptors
Break out creation of our stdio descriptors to keep the complexity down.

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

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:00 +00:00
Nalin Dahyabhai 1395e1805a Read UID/GID mapping information from containers and images
Read UID/GID mapping information when creating or importing containers,
and if there is mapping information, use it when building runtime
configurations.

Mounting sysfs in a user namespace requires that we also have our own
network namespace, so default to creating one for that case.

Switch permissions on files that we bind in so that they're writable
from inside of the container.

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

Closes: #700
Approved by: rhatdan
2018-05-24 14:10:00 +00:00
Daniel J Walsh a96820bbb7
Merge pull request #701 from rhatdan/hosts
Handle /etc/hosts and /etc/resolv.conf properly in container
2018-05-19 20:03:04 -04:00
Nalin Dahyabhai 7d141c8630 Manage "Run" containers more closely
Instead of using the runtime's "run" command to have it handle the
entire life cycle of a process when we need to launch one, do it
ourselves, and handle passing the data between our stdio and the
container's.

This will make it possible for us to set up networking using CNI between
the "create" and "start" phases, and head off permissions problems when
the process in the container can't read or write to the invoking user's
terminal or stdio.

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

Closes: #708
Approved by: rhatdan
2018-05-19 07:55:09 +00:00
Nalin Dahyabhai 302586a1a9 Break Builder.Run()'s "run runc" bits out
Break Builder.Run()'s "running runc" parts into their own method, in
preparation for making that part larger.

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

Closes: #708
Approved by: rhatdan
2018-05-19 07:55:09 +00:00
Daniel J Walsh ff6a0c554d Handle /etc/hosts and /etc/resolv.conf properly in container
We are currently volume mounting /etc/hosts and /etc/resolv.conf into the
container, SELinux is preventing these files from being written while in the
container.  THis patch will create a temporary hosts and resolv.conf, that
will be labeled correctly and volume mounted into the container.

This will also fix an issue where if you used buildah bud --host it was
modifying the real /etc/hosts file.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-05-18 16:00:58 -04:00
Nalin Dahyabhai 1ad8dc0c24 Documentation fixes
Update some comments and a couple of man pages.

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

Closes: #709
Approved by: rhatdan
2018-05-18 19:58:31 +00:00
Nalin Dahyabhai 1254c5bf5e API cleanup: PullPolicy and TerminalPolicy should be types
Make the PullPolicy field in BuilderOptions structures and the the
Terminal field in RunOptions their own types.

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

Closes: #705
Approved by: rhatdan
2018-05-18 17:25:07 +00:00
pixdrift a0f9fa7b4c Remove buildah run cmd and entrypoint execution
Signed-off-by: pixdrift <support@pixeldrift.net>

Closes: #656
Approved by: rhatdan
2018-05-06 11:05:59 +00:00
umohnani8 c50c287aa5 Add FIPS mode secret to buildah run and bud
If the host is in FIPS mode and /etc/system-fips exists
/run/secrets/system-fips is created in the container so that
the container can run in FIPS mode as well.
Vendor in libpod/pkg/secrets and remove the duplicate secrets code
in buildah.
Also remove the hidden --default-mounts-file flag that was being used for test,
as it is not needed anymore and makes the code simpler.

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #603
Approved by: rhatdan
2018-04-27 18:28:39 +00:00
pixdrift 4a98b552d6 Revert update of entrypoint behaviour to match docker
Signed-off-by: pixdrift <support@pixeldrift.net>

Closes: #614
Approved by: rhatdan
2018-04-24 13:11:18 +00:00
pixdrift 15e1054820 Update entrypoint behaviour to match docker
Signed-off-by: pixdrift <support@pixeldrift.net>

Closes: #577
Approved by: rhatdan
2018-04-12 16:27:11 +00:00
Daniel J Walsh 5ce80091ba Add support for shell
Also vendor in the latest imagebuilder code and all the packages
that come with it.

Note: imagebuilder.NewBuilderForReader has been removed from imagebuilder
so I had to split the function up into two different calls.

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

Closes: #517
Approved by: rhatdan
2018-04-03 22:25:56 +00:00
Boaz Shuster 66c752bc54 Add unit tests to run.go
* Changed addHostsToFile to make it easy to test
* Changed .travis.yml and Makefile to run all unit tests except ./tests/
* Added unit-tests to addHosts, addHostsToFile and addRlimits

Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>

Closes: #529
Approved by: rhatdan
2018-03-22 11:32:58 +00:00
Daniel J Walsh 9bf5a5e52a Breaking change on CommonBuildOpts
Just have to refuse to use previous created containers when doing a run.

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

Closes: #500
Approved by: rhatdan
2018-02-27 00:05:12 +00:00
Daniel J Walsh 873ecd8791 If commonOpts do not exist, we should return rather then segfault
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #498
Approved by: TomSweeneyRedHat
2018-02-26 22:49:44 +00:00
umohnani8 4bbe6e7cc0 Implement --volume and --shm-size for bud and from
Add the remaining --volume and --shm-size flags to buildah bud and from
--volume supports the following options: rw, ro, z, Z, private, slave, shared

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #491
Approved by: rhatdan
2018-02-23 17:53:00 +00:00
Giuseppe Scrivano 9d163a50d1 run: do not open /etc/hosts if not needed
Avoid opening the file in write mode if we are not going to write
anything.

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

Closes: #487
Approved by: rhatdan
2018-02-22 13:04:38 +00:00
umohnani8 93a3c89943 Add the following flags to buildah bud and from
--add-host
	--cgroup-parent
	--cpu-period
	--cpu-quota
	--cpu-shares
	--cpuset-cpus
	--cpuset-mems
	--memory
	--memory-swap
	--security-opt
	--ulimit

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #477
Approved by: rhatdan
2018-02-19 17:00:29 +00:00
Daniel J Walsh a586779353 We are copying a directory not a single file
When populating a container from a container image with a
volume directory, we need to copy the content of the source
directory into the target.  The code was mistakenly looking
for a file not a directory.

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

Closes: #471
Approved by: nalind
2018-02-12 15:57:23 +00:00
TomSweeneyRedHat 2dbb2a13ed Make bud be really quiet
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #408
Approved by: rhatdan
2018-01-24 15:11:30 +00:00
Nalin Dahyabhai 81dfe0a964 When we say we skip a secrets config file, do so
When we warn about not processing a secrets configuration file, actually
skip anything we might have salvaged from it to make our behavior match
the warning.

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

Closes: #380
Approved by: rhatdan
2018-01-05 16:09:53 +00:00
Daniel J Walsh 01f8c7afee Remove chrootuser handling and use libpod/pkg
I have made a subpackage of libpod to handle chrootuser,
using the user code from buildah.

This patch removes user handling from buildah and uses
projectatomic/libpod/pkg/chrootuser

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

Closes: #377
Approved by: nalind
2018-01-03 15:36:10 +00:00
Daniel J Walsh 38d3cddb0c Make sure builtin volumes have the correct label
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #339
Approved by: nalind
2017-11-28 21:44:17 +00:00
Daniel J Walsh fb99d85b76 Need to block access to kernel files systems in /proc and /sys
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #333
Approved by: TomSweeneyRedHat
2017-11-22 16:13:50 +00:00
Daniel J Walsh 3e8ded8646 Add secrets patch to buildah
Signed-off-by: umohnani8 <umohnani@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-11-08 00:01:57 +00:00
Daniel J Walsh 966f32b2ac Add proper SELinux labeling to buildah run
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #294
Approved by: nalind
2017-11-07 22:40:29 +00:00
Daniel J Walsh 8ecefa978c Vendor in changes to support sirupsen/logrus
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-10-10 17:30:11 +00:00
Nalin Dahyabhai 0de0d23df4 Run: don't complain about missing volume locations
Don't worry about not being able to populate temporary volumes using the
contents of the location in the image where they're expected to be
mounted if we fail to do so because that location doesn't exist.

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

Closes: #248
Approved by: rhatdan
2017-08-24 10:41:29 +00:00
Nalin Dahyabhai 8eb7d6d610 Run(): create the right working directory
When ensuring that the working directory exists before running a
command, make sure we create the location that we set in the
configuration file that we pass to runc.

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

Closes: #241
Approved by: rhatdan
2017-08-10 20:14:54 +00:00
Nalin Dahyabhai b37a981500 Stop trying to set the Platform in runtime specs
run: The latest version of runtime-spec dropped the Platform field, so
stop trying to set it when generating a configuration for a runtime.

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

Closes: #201
Approved by: rhatdan
2017-07-20 18:38:19 +00:00
Nalin Dahyabhai 8efeb7f4ac Handle "run" without an explicit command correctly
When "run" isn't explicitly given a command, mix the command and
entrypoint options and configured values together correctly.

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

Closes: #160
Approved by: rhatdan
2017-06-26 13:21:53 +00:00
Nalin Dahyabhai 303a8df35d Ensure volume points get created, and with perms
Ensure that volume points are created, if they don't exist, when they're
defined in a Dockerfile (#151), and that if we create them, we create
them with 0755 permissions (#152).

When processing RUN instructions or the run command, if we're not
mounting something in a volume's location, create a copy of the volume's
initial contents under the container directory and bind mount that.

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

Closes: #154
Approved by: rhatdan
2017-06-24 10:37:13 +00:00
Nalin Dahyabhai 0d13621874 Add a --volume flag to "buildah run"
Add a --volume/-v flag to "buildah run" to allow volume bind mounts to
be specified on the command line.

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

Closes: #144
Approved by: rhatdan
2017-06-13 21:43:40 +00:00
Dan Walsh 8ced1276e5 Change functions that use a fmt.Errorf to wrap an err to error.Wrapf
Impove error reporting by wrapping all returned err functions with
error.Wrapf

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

Closes: #124
Approved by: nalind

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

Closes: #125
Approved by: nalind
2017-06-02 14:17:04 +00:00
Nalin Dahyabhai 80ca77674c Tweak volume handling in Run()
Make sure that we don't mount a tmpfs in volume locations where Run()
has been told to mount something else.

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

Closes: #121
Approved by: rhatdan
2017-05-31 20:12:07 +00:00
Nalin Dahyabhai 3748b31c04 Defaul to the configured hostname in Run()
If Run() isn't passed a hostname to set, but we have one that was set
directly or inherited from the source image, use that value.

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

Closes: #121
Approved by: rhatdan
2017-05-31 20:12:07 +00:00
Nalin Dahyabhai fc880bcc86 Maintain multiple working container configs
Maintain the container configuration in multiple formats in the Buildah
object, initializing one based on the other, depending on which format
the source image used for its configuration.

Replace directly manipulated fields in the Buildah object (Annotations,
CreatedBy, OS, Architecture, Maintainer, User, Workdir, Env, Cmd,
Entrypoint, Expose, Labels, and Volumes) with accessor functions which
update both configurations and which read from whichever one we consider
to be authoritative.  Drop Args because we weren't using them.

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

Closes: #102
Approved by: rhatdan
2017-05-18 18:28:44 +00:00
Nalin Dahyabhai b7a598ca21 Fixup metalinter errors
Fix a number of issues flagged by gometalinter.

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

Closes: #62
Approved by: rhatdan
2017-04-12 21:25:35 +00:00
Nalin Dahyabhai 96d15578e4 Fixup golint warnings
Fix a number of issues flagged by golint.

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

Closes: #62
Approved by: rhatdan
2017-04-12 21:25:35 +00:00
Nalin Dahyabhai b1bb73e01c Teach "Run" to dig user IDs out of containers
When we have cgo, use fgetpwent() to try to look up user IDs and primary
GIDs in containers.  If that fails for any reason (or if we don't have
cgo), fall back to doing what we were doing before (i.e., trying to look
up the information on the host).

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

Closes: #63
Approved by: rhatdan
2017-04-11 18:41:54 +00:00
Nalin Dahyabhai ccfa6a8bd4 Make Run() use a terminal only if it has one
Make Run() default to running the command with a PTY if we're being run
with stdout connected to terminal, and provide options to force the
decision one way or the other.

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

Closes: #64
Approved by: rhatdan
2017-04-11 16:55:52 +00:00
Nalin Dahyabhai e96ba381a2 Add some more options for Run
Add options to Run() for passing in additional environment variables,
overriding the default command, user, and working directory, and a flag
for controlling whether or not we attach to the host's network.

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

Closes: #46
Approved by: rhatdan
2017-03-27 19:07:38 +00:00
Nalin Dahyabhai c6a4a06454 Bind mount /etc/hosts, /etc/resolv.conf in Run()
When we run a command in Run(), since it's sharing the host's network
namespace, also have it share the host's DNS settings.

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

Closes: #34
Approved by: rhatdan
2017-03-24 20:37:06 +00:00
Nalin Dahyabhai e202577172 Make Run() commands share the host's network
Make commands we run in Run() use the host's networking.

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

Closes: #34
Approved by: rhatdan
2017-03-24 20:37:06 +00:00
Nalin Dahyabhai ae1fffb3fd Always make sure the working directory exists
Always make sure the working directory exists before attempting to run
anything inside of it, and before attempting to copy contents into it or
one of its subdirectories.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-03-23 14:57:00 -04:00
Nalin Dahyabhai 691266d40c Handle volumes in "run"
Default to mounting tmpfs over a container's volume mount points.  Add a
RunOption for adding mounts to a run container, and use it as the
default set, adding any volume mounts and others that don't conflict
with them to it before running the container.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-02-17 13:58:34 -05:00
Nalin Dahyabhai c46716525c Make the runtime for "run" more configurable
Provide RunOptions which can be used to change the runtime to something
other than "runc", and add an option that allows passing in additional
global arguments for the runtime.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-02-17 13:58:11 -05:00
Nalin Dahyabhai 2963474e17 Add a "run" command, using runc
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-02-13 17:21:45 -05:00