25 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
8533ea0004 Privileged containers can now restart if the host devices change
If a privileged container is running, stops, and the devices on the host
change, such as a USB device is unplugged, then a container would no
longer start. Previously, the devices from the host were only being
added to the container once: when the container was created. Now, this
happens every time the container starts.

I did this by adding a boolean to the container config that indicates
whether to mount all of the devices or not, which can be set via an option.

During spec generation, if the `MountAllDevices` option is set in the
container config, all host devices are added to the container.

Additionally, a couple of functions from `pkg/specgen/generate/config_linux.go`
were moved into `pkg/util/utils_linux.go` as they were needed in
multiple packages.

Closes #13899

Signed-off-by: Jake Correnti <jcorrenti13@gmail.com>
2022-06-06 14:14:22 -04:00
b22143267b linter: enable unconvert linter
Detects unneccessary type conversions and helps in keeping the code base
cleaner.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-05-19 13:59:15 +02:00
d106b294b4 Switch all calls to filepath.Walk to filepath.WalkDir
WalkDir should be faster the Walk, since we often do
not need to stat files.

[NO NEW TESTS NEEDED] Existing tests should find errors.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-03-27 07:18:25 -04:00
bb6b69b4ab linter: enable wastedassign
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-22 13:04:34 +01:00
6336e1ff1e rootless: drop permission check for devices
commit 350ede1eeb6ab33bce2918d7768b940c255e63c6 added the feature.

Do not check whether the device is usable by the rootless user before
adding to the container.

Closes: https://github.com/containers/podman/issues/12704

[NO NEW TESTS NEEDED] it requires changes on the host to test it

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-27 09:35:02 +01:00
bd09b7aa79 bump go module to version 4
Automated for .go files via gomove [1]:
`gomove github.com/containers/podman/v3 github.com/containers/podman/v4`

Remaining files via vgrep [2]:
`vgrep github.com/containers/podman/v3`

[1] https://github.com/KSubedi/gomove
[2] https://github.com/vrothberg/vgrep

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2022-01-18 12:47:07 +01:00
8fac34b8ff Pod Device Support
added support for pod devices. The device gets added to the infra container and
recreated in all containers that join the pod.

This required a new container config item to keep track of the original device passed in by the user before
the path was parsed into the container device.

Signed-off-by: cdoern <cdoern@redhat.com>
2021-09-20 23:22:43 -04:00
4fd1965ab4 Add filepath glob support to --security-opt unmask
Want to allow users to specify --security-opt unmask=/proc/*.
This allows us to run podman within podman more securely, then
specifing umask=all, also gives the user more flexibilty.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-05-04 14:40:43 -04:00
1a33b76489 replace local mount consts with libpod/define
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
2021-03-07 12:03:34 +01:00
5dded6fae7 bump go module to v3
We missed bumping the go module, so let's do it now :)

* Automated go code with github.com/sirkon/go-imports-rename
* Manually via `vgrep podman/v2` the rest

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-22 09:03:51 +01:00
78b419909b Enable more golangci-lint linters
Cleanup the golangci.yml file and enable more linters.

`pkg/spec` and `iopodman.io` is history. The vendor directory
is excluded by default. The dependencies dir was listed twice.

Fix the reported problems in `pkg/specgen` because that was also
excluded by `pkg/spec`.

Enable the structcheck, typecheck, varcheck, deadcode and depguard
linters.

[NO TESTS NEEDED]

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-02-12 18:20:28 +01:00
8452b768ec Fix problems reported by staticcheck
`staticcheck` is a golang code analysis tool. https://staticcheck.io/

This commit fixes a lot of problems found in our code. Common problems are:
- unnecessary use of fmt.Sprintf
- duplicated imports with different names
- unnecessary check that a key exists before a delete call

There are still a lot of reported problems in the test files but I have
not looked at those.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-01-12 16:11:09 +01:00
176be90e0a security: honor systempaths=unconfined for ro paths
we must honor systempaths=unconfined also for read-only paths, as
Docker does:

proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-12-09 19:26:23 +01:00
0334b61958 Add mask and unmask option to --security-opt
Add the mask and unmask option to the --security-opt flag
to allow users to specify paths to mask and unmask in the
container. If unmask=ALL, this will unmask all the paths we
mask by default.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2020-12-02 16:07:18 -05:00
bce8f851c1 specgen: add support for ambient capabilities
if the kernel supports ambient capabilities (Linux 4.3+), also set
them when running with euid != 0.

This is different that what Moby does, as ambient capabilities are
never set.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-11-02 14:36:39 +01:00
831d7fb0d7 Stop excessive wrapping of errors
Most of the builtin golang functions like os.Stat and
os.Open report errors including the file system object
path. We should not wrap these errors and put the file path
in a second time, causing stuttering of errors when they
get presented to the user.

This patch tries to cleanup a bunch of these errors.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-30 05:34:04 -04:00
4f7da3274b spec: open fuse with --device .*/fuse
If the container uses the /dev/fuse device, attempt to load the fuse
kernel module first so that nested containers can use it.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-10-02 10:12:58 +02:00
2ac37f10b4 Fix up some error messages
We have a lot of 'cannot stat %s' errors in our codebase. These
are terrible and confusing and utterly useless without context.
Add some context to a few of them so we actually know what part
of the code is failing.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-08-27 15:05:12 -04:00
a5e37ad280 Switch all references to github.com/containers/libpod -> podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 08:23:45 -04:00
6054985f87 Mask out /sys/dev to prevent information leak from the host
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-14 13:16:56 -04:00
5c6002bf9d Remove dependency on github.com/opencontainers/libpod/configs
We are using these dependencies just to get the device from path.
These dependencies no longer build on Windows, so simply cloning
the deviceFromPath function, we can eliminate the need for this
vendoring.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-09 10:03:40 -04:00
8489dc4345 move go module to v2
With the advent of Podman 2.0.0 we crossed the magical barrier of go
modules.  While we were able to continue importing all packages inside
of the project, the project could not be vendored anymore from the
outside.

Move the go module to new major version and change all imports to
`github.com/containers/libpod/v2`.  The renaming of the imports
was done via `gomove` [1].

[1] https://github.com/KSubedi/gomove

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-06 15:50:12 +02:00
339ffd8ade specgen: fix segfault
we should not access the devices without checking if the resources are there

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2020-05-27 14:52:17 -04:00
ba430bfe5e podman v2 remove bloat v2
rid ourseleves of libpod references in v2 client

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-04-16 12:04:46 -05:00