diff options
author | Matthew Heon <matthew.heon@pm.me> | 2021-04-05 15:49:35 -0400 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2021-04-06 09:18:46 -0400 |
commit | 541252afa701850f6691933d575c5c24ed0b17c1 (patch) | |
tree | 4ae3773866ff9ee462c578c0efcbf413b61af3af /libpod/container_validate.go | |
parent | 3fae801a3714ac058c5d19edf7f2288c18e84195 (diff) | |
download | podman-541252afa701850f6691933d575c5c24ed0b17c1.tar.gz podman-541252afa701850f6691933d575c5c24ed0b17c1.tar.bz2 podman-541252afa701850f6691933d575c5c24ed0b17c1.zip |
Ensure that `--userns=keep-id` sets user in config
One of the side-effects of the `--userns=keep-id` command is
switching the default user of the container to the UID of the
user running Podman (though this can still be overridden by the
`--user` flag). However, it did this by setting the UID and GID
in the OCI spec, and not by informing Libpod of its intention to
switch users via the `WithUser()` option. Because of this, a lot
of the code that should have triggered when the container ran
with a non-root user was not triggering. In the case of the issue
that this fixed, the code to remove capabilities from non-root
users was not triggering. Adjust the keep-id code to properly
inform Libpod of our intention to use a non-root user to fix
this.
Also, fix an annoying race around short-running exec sessions
where Podman would always print a warning that the exec session
had already stopped.
Fixes #9919
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/container_validate.go')
-rw-r--r-- | libpod/container_validate.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/libpod/container_validate.go b/libpod/container_validate.go index 245121a91..aae96ae85 100644 --- a/libpod/container_validate.go +++ b/libpod/container_validate.go @@ -126,5 +126,11 @@ func (c *Container) validate() error { } } + // If User in the OCI spec is set, require that c.config.User is set for + // security reasons (a lot of our code relies on c.config.User). + if c.config.User == "" && (c.config.Spec.Process.User.UID != 0 || c.config.Spec.Process.User.GID != 0) { + return errors.Wrapf(define.ErrInvalidArg, "please set User explicitly via WithUser() instead of in OCI spec directly") + } + return nil } |