Commit Graph

20 Commits

Author SHA1 Message Date
Giuseppe Scrivano 3689b944f0 apparmor: use fileutils.(Le|E)xists
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-10 12:23:07 +02:00
Oleksandr Redko ba4c7c98bb chore: remove outdated build constraints
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-03 22:56:00 +02:00
Valentin Rothberg e71bf4ce52 apparmor: fix parsing beta/alpha version
Copied from github.com/moby/moby who already has a fix for it.
Tested manually on a Ubuntu 23.10 (beta) VM.

Fixes: #containers/podman/issues/20278
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-06 11:41:58 +02:00
Valentin Rothberg ed3ac2cb8e Revert "Revert "Revert "Allow rootless containers to use AppArmor profiles"""
This reverts commit d2e1497ce1 because it
was merged prematurely.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-17 10:16:55 +02:00
Will Shand d2e1497ce1 Revert "Revert "Allow rootless containers to use AppArmor profiles""
This reverts commit ae50de4ddf.

Signed-off-by: Will Shand <wss2ec@g.ucla.edu>
2023-07-20 22:12:26 +00:00
Sascha Grunert 426d69c00f Switch to golang native error wrapping
`github.com/pkg/errors` is deprecated since quite some time so we now
use the native error wrapping for more idiomatic golang.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-12 10:54:07 +02:00
Paul Holzinger cc110440e4 enable unparam, exportloopref and revive linters
unparam and exportloopref already work without changes.
For revive I had to silence many naming issues. I decided to silence them
instead of changing the name because I didn't want to break any code.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-05-06 13:32:35 +02:00
Kir Kolyshkin b951b72412 Gofumpt the code
gofumpt is a stricter version of gofmt, basically making the code more
readable, and fixing the gocritic's octalLiterar warnings like this one:

	pkg/util/util_supported.go:26:17: octalLiteral: use new octal literal style, 0o722 (gocritic)
		return (perm & 0722) == 0700
			       ^

Generated by gofumpt -w .

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-04-09 16:50:11 -07:00
Valentin Rothberg ae50de4ddf Revert "Allow rootless containers to use AppArmor profiles"
This reverts commit 6994271ca4 since
it does not pass Podman CI (i.e., the rootless Ubuntu job fails).

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-18 13:31:11 +01:00
Valentin Rothberg 095aded91c go fmt: use go 1.18 conditional-build syntax
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-18 11:04:40 +01:00
kernelmethod 6994271ca4 Allow rootless containers to use AppArmor profiles
Previously, Podman would print an error if you tried to run a container
with an AppArmor profile as a non-root user, e.g.

    $ podman run --security-opt apparmor=my-profile ...
    Error: Apparmor profile "my-profile" specified, but Apparmor is not
    enabled on this system

In fact, the only thing that Podman needs root privileges for is reading
/sys/kernel/security/apparmor/profiles to see if the profile is already
loaded, which isn't strictly necessary.

This commit removes the 'IsLoaded()' check that occurs when you try to
specify an AppArmor profile as a non-root user, as well as the other
checks in pkg/apparmor/ for whether the program is running as UID 0. The
check for whether the AppArmor profile is loaded should now be deferred
to the container runtime at the point where it writes to either
/proc/self/attr/exec or /proc/self/attr/apparmor/exec, since the write
should fail if the profile is not loaded.

Closes #958.

Signed-off-by: kernelmethod <17100608+kernelmethod@users.noreply.github.com>
2022-03-11 13:57:50 -07:00
Daniel J Walsh 7c76968b10 Standardize on capatalize logrus messages, remove stutters
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-24 14:35:52 -04:00
Sascha Grunert 89b399d4cf Fix all gocritic lints
This enables the missing gocritic checks and fixes all of the lints.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-25 20:58:15 +02:00
Sascha Grunert b1670784f9 Add FindAppArmorParserBinary() helper
This function will be now used internally to get the correct path to the
`apparmor_parser` binary.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-20 09:22:27 +02:00
Sascha Grunert fa66b56024 Add mock'able unit tests and move package to `internal`
This adds internal strucutres and fakes to be able to mock the former
`isSupproted` function.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-19 10:19:01 +02:00
Sascha Grunert 29747623fd Validate that apparmor_parser is available on the system
If AppArmor is enabled, then we now check if the `apparmor_parser`
binary is either in `/sbin` or in `$PATH`.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-19 09:29:13 +02:00
Sascha Grunert 73aa297b0c Wrap AppArmor errors to provide more debug information
Mostly all AppArmor errors are now wrapped to provide additional context
to the user what actually went wrong. We now only use the spelling
`AppArmor` rather than `apparmor` to give the errors a uniform look.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-17 12:20:25 +02:00
Sascha Grunert 2a2476fcfd Omit apparmor_parser warnings when parsing the version
The `execAAParser()` function also takes `stderr` into account when
parsing the output. This function is right now only called by the
`getAAParserVersion()` function. Depending on the system configuration,
it might be possible that `apparmor_parser` prints a warning, for
example if `/etc/apparmor/parser.conf` does not exist on the system. To
thake this input not into account for the version parsing, we now just
use `stdout` as the returned result.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-17 09:49:58 +02:00
Sascha Grunert 4a58c879e2 Change AppArmor profile prefix and fix name-check
The default AppArmor profile is now prefixed with
`container-default-$VERSION`, whereas the version is now part of a new
`version` package.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-06-23 18:11:28 +02:00
Daniel J Walsh ed25ff4eb6 Add more utils for returning defaults
Move pkg/sysinfo and pkg/apparmor out of libpod into containers/common.

This will allow other packages to use these libraries without requiring all of libpod.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-04-01 08:39:44 -04:00