Commit Graph

102 Commits

Author SHA1 Message Date
OpenShift Merge Robot 00aa7f01d3
Merge pull request #2867 from rhatdan/master
Drop log message on failure to mount on /sys file systems to info
2020-12-22 10:52:43 -05:00
Daniel J Walsh 67cfd28430
Drop log message on failure to mount on /sys file systems to info
If you are in a rootless environment using chroot builds, you are
likely to get failures when mounting /sys file systems onto your
container. The problem is certain directories are not able to be
mounted on by rootless users.  Since we are logging at Warn level
now, and users can not do anything to fix this situation, I am
dropping this message to info.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-12-21 17:34:34 -05:00
Daniel J Walsh 580356f0c3
SELinux no longer requires a tag.
It should work fine on linux and not linux boxes. Since there
is no glibc added, we can safely compile and run this code
on non SELinux boxes.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-12-21 15:24:28 -05:00
bors[bot] b3f6ed83a5
Merge #2644
2644: chroot: fix handling of errno seccomp rules r=rhatdan a=nalind

#### What type of PR is this?

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

When converting seccomp rules from the runtime spec to the structure that we can feed to libseccomp, combine the prescribed errno value with the action when we're mapping the "return an errno" action from one to the other.

#### How to verify it

Currently, chroot isolation hits an error processing this seccomp rule:
```
                {
                        "names": [
                                "socket"
                        ],
                        "action": "SCMP_ACT_ERRNO",
                        "args": [
                                {
                                        "index": 0,
                                        "value": 16,
                                        "valueTwo": 0,
                                        "op": "SCMP_CMP_EQ"
                                },
                                {
                                        "index": 2,
                                        "value": 9,
                                        "valueTwo": 0,
                                        "op": "SCMP_CMP_EQ"
                                }
                        ],
                        "comment": "",
                        "includes": {},
                        "excludes": {
                                "caps": [
                                        "CAP_AUDIT_WRITE"
                                ]
                        },
                        "errnoRet": 22
                },
```
on Fedora 33.

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

None

#### Special notes for your reviewer:

Definitely going to need to backport this to older branches.

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

```
None
```



Co-authored-by: Nalin Dahyabhai <nalin@redhat.com>
2020-09-25 08:44:08 +00:00
Nalin Dahyabhai 533bf95d1e chroot: create bind mount targets 0755 instead of 0700
Create the target mountpoints for bind mounts, when they don't already
exist, with 0755 permissions, for better consistency with runc.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-09-23 19:41:28 -04:00
Nalin Dahyabhai ecb40a48b4 chroot: fix handling of errno seccomp rules
When converting seccomp rules from the runtime spec to the structure
that we can feed to libseccomp, combine the prescribed errno value with
the action when we're mapping the "return an errno" action from one to
the other.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-09-23 18:06:58 -04: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
Giuseppe Scrivano c43ab20444
chroot, run: not fail on bind mounts from /sys
some file systems under /sys might not be accessible to an
unprivileged user.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-15 08:01:57 +02:00
Giuseppe Scrivano 2b1ad123a3
chroot: do not use setgroups if it is blocked
if setgroups is blocked to set up the user namespace, do not attempt
to use it to clear the additional groups.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-14 23:06:00 +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
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
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
Nalin Dahyabhai 1033abccb7 chroot: handle slightly broken seccomp defaults
When a seccomp rule includes multiple equality checks for the same
argument for a syscall, they can never ALL be satisfied.  Because that's
how they're supposed to be treated, libseccomp returns an error when we
try to add them as part of the same conditional rule.  Try to detect
this exact case, and if we detect it, treat each condition as its own
rule.

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

Closes: #2105
Approved by: rhatdan
2020-01-28 21:16:07 +00: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
Nalin Dahyabhai 2d5701d790 chroot: Unmount with MNT_DETACH instead of UnmountMountpoints()
Unmounting the rootfs with MNT_DETACH should unmount everything below
it, so we don't need to use the more exhaustive method that our bind
package uses for its bind mounts.

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

Closes: #1996
Approved by: rhatdan
2019-12-06 12:01:30 +00:00
Daniel J Walsh 60c008890f Fix handling of /dev/null masked devices
If a masked object is already a /dev/null device then don't mask over it.

This logic is backwords and is breaking SELinux.

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

Closes: #1776
Approved by: @TomSweeneyRedHat
2019-08-09 15:04:38 +00:00
Sascha Grunert 6b214d2921 Add golint linter and apply fixes
This commit enabled to golint linter in golangci-lint and applies all
necessary fixes.

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

Closes: #1740
Approved by: rhatdan
2019-07-27 09:45:49 +00:00
Sascha Grunert 8e58ba3cdb
Add unconvert linter and apply fixes
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-07-18 10:37:38 +02:00
Sascha Grunert 5d723ff5ab Add errcheck linter and fix missing error check
This commit enabled the errcheck linter and fixes an uncovered stat to
`os.DevNull`. Beside this, we disable go modules within the
`tests/tools/Makefile` to allow independent offline builds.

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

Closes: #1713
Approved by: vrothberg
2019-07-10 13:03:22 +00:00
Daniel J Walsh 254a3d2e1c On Masked path, check if /dev/null already mounted before mounting
We do not want to mount /dev/null over a masked path, if the path is
already /dev/null.

This prevents an containers running buildah from requiring additional privs
to mount on a /dev/null, when the target is already mounted.

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

Closes: #1705
Approved by: TomSweeneyRedHat
2019-07-04 10:34:44 +00:00
Valentin Rothberg 9bf7586a1e chroot/run_test.go: export funcs to actually be executed
Reported by golangci-lint.

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

Closes: #1678
Approved by: rhatdan
2019-06-19 11:33:36 +00:00
Valentin Rothberg 37001d67e6 rm chroot/util.go
The last remaining function is not being used anymore.

Reported by golangci-lint.

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

Closes: #1678
Approved by: rhatdan
2019-06-19 11:33:36 +00:00
Valentin Rothberg 2e485df336 fix "ineffectual assignment" lint errors
Reported by golangci-lint.

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

Closes: #1678
Approved by: rhatdan
2019-06-19 11:33:36 +00:00
Valentin Rothberg 2c4f388bdf chroot: only log clean-up errors
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

Closes: #1624
Approved by: TomSweeneyRedHat
2019-06-17 18:45:00 +00:00
Valentin Rothberg 113dffd78b chroot: fix error handling in deferred funcs
errors.Wrap(err) and friends will return nil if err is nil, so make
setting the error conditional.

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

Closes: #1624
Approved by: TomSweeneyRedHat
2019-06-17 18:45:00 +00:00
Valentin Rothberg 7234f342e4 chroot/run_test.go: check errors
Reported by golangc-lint.

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

Closes: #1624
Approved by: TomSweeneyRedHat
2019-06-17 18:45:00 +00:00
Valentin Rothberg 8c18a2e628 chroot/run.go: check errors in deferred calls
Reported by golangci-lint.

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

Closes: #1624
Approved by: TomSweeneyRedHat
2019-06-17 18:45:00 +00:00
Giuseppe Scrivano dc7b50c9da run: fix hang with run and --isolation=chroot
make the stdin pipe not blocking, so that it won't hang if the other
end is not reading from it.

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

Closes: #1668
Approved by: rhatdan
2019-06-13 13:26:46 +00:00
Giuseppe Scrivano ac346461d3 chroot: drop unused function call
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1668
Approved by: rhatdan
2019-06-13 13:26:46 +00:00
TomSweeneyRedHat e43b864952 Add default /root if empty on chroot iso
Checks to see if the $HOME envvar has been set
and if not, trys to set it as best as possible.

Fixes: #1592

Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #1594
Approved by: rhatdan
2019-05-22 06:53:33 +00:00
Daniel J Walsh bcc5e51a94 Add support for Overlay volumes into the container.
Overlay mounts allow buildah bud and buildah from to
specify a directory on the disk that will be mounted
as an overlay into the container, where the overlay can be written to
but when the RUN or buildah run exits, the modified files will dissapear.

The basic idea is to be able to mount cache from the disk for things like yum/dnf/apt
to be able to be used and modified in the contianer on a run command, but to be
kept fresh for each RUN.

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

Closes: #1560
Approved by: giuseppe
2019-05-20 12:54:10 +00:00
Nalin Dahyabhai 0160a7757b run: check if SELinux is enabled
When we're built with support for SELinux, refrain from setting process
and mount labels if SELinux isn't detected as enabled at runtime.

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

Closes: #1542
Approved by: rhatdan
2019-04-25 17:50: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
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
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
Daniel J Walsh 18309de5b7 Allow cgroups to be passed into chroot, read/only
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1130
Approved by: rhatdan
2018-11-16 02:34:55 +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 0a971ebeec chroot: set up seccomp and capabilities after supplemental groups
Move the setting of capabilites and the seccomp filter to after we've
set the supplemental groups list and set our primary GID.

Set capabilities after we set the seccomp filter, because we won't be
able to set a filter if we're dropping CAP_SYS_ADMIN.  Set them as the
very last thing before dropping to the runtime UID.  Leave CAP_SETUID in
if we're going to become an unprivileged user, so that we'll be allowed
to switch UIDs -- the capability will be dropped then anyway.

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

Closes: #1069
Approved by: rhatdan
2018-10-05 13:03:02 +00:00
Nalin Dahyabhai 289c512c0d chroot: fix capabilities list setup and application
Correctly handle setting capabilities: the Clear() and Apply() methods
on the Capabilities interface take a bitmask of capability kinds, not
specific capability types.

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

Closes: #1069
Approved by: rhatdan
2018-10-05 13:03:02 +00:00
Nalin Dahyabhai 0a8af543b2 chroot: only create user namespaces when we know we need them
When running with chroot isolation, only create a new user namespace
when we have mappings to set.

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

Closes: #1069
Approved by: rhatdan
2018-10-05 13:03:02 +00: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
Nalin Dahyabhai 2358d51e74 chroot: create missing parent directories for volume mounts
When ensuring that the target for a volume mount is present, be sure to
create any leading directories which are also not yet present.

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

Closes: #997
Approved by: rhatdan
2018-09-14 14:11:39 +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
Nalin Dahyabhai 9175ccea84 chroot: correct a comment
We're specifying the MS_RDONLY flag, so don't suggest that we're doing a
read-write mount.

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

Closes: #923
Approved by: rhatdan
2018-08-10 15:45:26 +00:00
Nalin Dahyabhai ba23b7f106 chroot: bind mount an empty directory for masking
In chroot isolation, when we attempt to mask a directory, use a
read-only bind mount of an empty directory instead of a read-only mount
of a fresh tmpfs with size=0, which is more likely to be be denied by
mandatory access controls.

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

Closes: #923
Approved by: rhatdan
2018-08-10 15:45:26 +00:00
Daniel J Walsh 2cafe11229 unshare: make adjusting the OOM score optional
The OOM score adjustment is an optional field in the runtime spec, so
only try to set it if it's set in the spec.

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

Closes: #906
Approved by: rhatdan
2018-08-03 13:24:47 +00:00
Nalin Dahyabhai 35a37f36d3 chroot: handle raising process limits
When using chroot isolation, if we're configured to raise any process
limits above their current values, do so in the grandparent process,
before it transfers execution to a child that it starts in a user
namespace, which won't have the privileges to do so.

The child can still lower resource limits and set limits to the values
that it inherited, so let it continue to do so.

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

Closes: #891
Approved by: rhatdan
2018-08-03 09:02:08 +00:00
Nalin Dahyabhai 3160f5479e chroot: make the resource limits name map module-global
Move the resource limits name map out of the setRlimits() function, and
use it to set up a reverse of the same map in init().

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

Closes: #891
Approved by: rhatdan
2018-08-03 09:02:08 +00:00
Nalin Dahyabhai 8b9fc6e8b6 Set BUILDAH_ISOLATION=chroot when running unprivileged
When we're run by an unprivileged user, default to BUILDAH_ISOLATION=chroot.

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

Closes: #836
Approved by: rhatdan
2018-08-01 14:04:59 +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