19 Commits

Author SHA1 Message Date
41528739ce golangci-lint: enable nolintlint
The nolintlint linter does not deny the use of `//nolint`
Instead it allows us to enforce a common nolint style:
- force that a linter name must be specified
- do not add a space between `//` and `nolint`
- make sure nolint is only used when there is actually a problem

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-06-14 16:29:42 +02:00
7680211ede Remove error stutter
When podman gets an error it prints out "Error: " before
printing the error string.  If the error message starts with
error, we end up with

Error: error ...

This PR Removes all of these stutters.

logrus.Error() also prints out that this is an error, so no need for the
error stutter.

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-03-25 21:47:04 -04:00
06dd9136a2 fix a number of errcheck issues
Numerous issues remain, especially in tests/e2e.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-22 13:15:28 +01:00
0f12b6fe55 linter: enable nilerr
A number of cases looked suspicious, so I marked them with `FIXME`s to
leave some breadcrumbs.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-22 13:04:35 +01:00
c2c0d50582 rootless: improve automatic range split
sort.Search returns the smallest index, so provide the available IDs
in decreasing order.

It fixes an issue when splitting the current mappings over multiple
available IDs.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-05 18:03:10 +02:00
127400880a [NO TESTS NEEDED] Shrink the size of podman-remote
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-03-29 09:49:45 -04:00
ef2fc90f2d Enable stylecheck linter
Use the stylecheck linter and fix the reported problems.

[NO TESTS NEEDED]

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-02-11 23:01:29 +01:00
ecedda63a6 rootless: automatically split userns ranges
writing to the id map fails when an extent overlaps multiple mappings
in the parent user namespace:

$ cat /proc/self/uid_map
         0       1000          1
         1     100000      65536
$ unshare -U sleep 100 &
[1] 1029703
$ printf "0 0 100\n" | tee /proc/$!/uid_map
0 0 100
tee: /proc/1029703/uid_map: Operation not permitted

This limitation is particularly annoying when working with rootless
containers as each container runs in the rootless user namespace, so a
command like:

$ podman run --uidmap 0:0:2 --rm fedora echo hi
Error: writing file `/proc/664087/gid_map`: Operation not permitted: OCI permission denied

would fail since the specified mapping overlaps the first
mapping (where the user id is mapped to root) and the second extent
with the additional IDs available.

Detect such cases and automatically split the specified mapping with
the equivalent of:

$ podman run --uidmap 0:0:1 --uidmap 1:1:1 --rm fedora echo hi
hi

A fix has already been proposed for the kernel[1], but even if it
accepted it will take time until it is available in a released kernel,
so fix it also in pkg/rootless.

[1] https://lkml.kernel.org/lkml/20201203150252.1229077-1-gscrivan@redhat.com/

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-01-07 09:42:27 +01:00
09f4cc6fc3 rootless: add function to retrieve uid mappings
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-01-07 09:41:06 +01:00
fcc04fbaba rootless: add function to retrieve gid mappings
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-01-07 09:41:01 +01:00
07546cca18 rootless: use sync.Once for GetAvailableGids()
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-10-02 09:05:34 +02:00
baef6eff36 rootless: move GetAvailableGids to the rootless pkg
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-10-02 08:53:54 +02:00
83764b84ec fix lint in pkg/rootless
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-08 15:44:30 +01:00
2ceb03d05e rootless: automatically recreate the pause.pid file
if the pause process cannot be joined, remove the pause.pid while
keeping a lock on it, and try to recreate it.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-09 16:02:21 +02:00
72382a12a7 rootless: use a single user namespace
simplify the rootless implementation to use a single user namespace
for all the running containers.

This makes the rootless implementation behave more like root Podman,
where each container is created in the host environment.

There are multiple advantages to it: 1) much simpler implementation as
there is only one namespace to join.  2) we can join namespaces owned
by different containers.  3) commands like ps won't be limited to what
container they can access as previously we either had access to the
storage from a new namespace or access to /proc when running from the
host.  4) rootless varlink works.  5) there are only two ways to enter
in a namespace, either by creating a new one if no containers are
running or joining the existing one from any container.

Containers created by older Podman versions must be restarted.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-01 15:32:58 +02:00
f31ba2929b rootless: support a custom arg to the new process
let the process running as euid != 0 pass down an argument to the
process running in the user namespace.  This will be useful for
commands like rm -a that needs to join different namespaces, so that
we can re-exec separately for each of them.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-11 11:48:25 +01:00
83968de28c rootless: Merge rootless.go back into rootless_linux.go
The files were split apart by b96be3af (changes to allow for darwin
compilation, 2018-06-20, #1015), but the C import and two functions
left in rootless.go are all Linux-specific as well.  This commit moves
all of the pre-b96be3af rootless.go into rootless_linux.go, just
adding the '// +build linux' header (b96be3af also scrambled the + in
that header) and keeping the new GetRootlessUID from a1545fe6
(rootless: add function to retrieve the original UID, 2018-07-05, #1048).

Signed-off-by: W. Trevor King <wking@tremily.us>

Closes: #1034
Approved by: baude
2018-07-06 00:48:39 +00:00
b96be3af1b changes to allow for darwin compilation
Signed-off-by: baude <bbaude@redhat.com>

Closes: #1015
Approved by: baude
2018-06-29 20:44:09 +00:00
5ff90677c8 rootless: add management for the userNS
When running podman as non root user always create an userNS and let
the OCI runtime use it.

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

Closes: #936
Approved by: rhatdan
2018-06-27 14:07:17 +00:00