Commit graph

107 commits

Author SHA1 Message Date
Stéphane Graber
659a187687
parser/rc.apparmor: Handle Incus
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
2023-10-12 00:55:03 -04:00
intrigeri
06f86e2a02 rc.apparmor.functions: only use systemd-detect-virt if it's present
This is a follow-up on !812, which added a call to systemd-detect-virt.
Everywhere else we don't assume that program is present,
and first check if it's there before we run it.
Let's do the same here.
2022-07-06 06:41:35 +00:00
intrigeri
56dd267a24 Mark variables as dummy in a way that shellcheck 0.7.0 supports
The "_" prefix is only supported in shellcheck > 0.7.2.
2022-02-13 19:43:48 +00:00
intrigeri
fb94661937 rc.apparmor.functions: mark intentionally unused variable as dummy
Thanks, shellcheck!
2022-02-13 19:43:48 +00:00
intrigeri
2e0fb86a94 rc.apparmor.functions: check command exit status directly
Thanks, shellcheck!
2022-02-13 19:43:48 +00:00
intrigeri
0bae8bf82a rc.apparmor.functions: disable shellcheck false positive 2022-02-13 19:43:48 +00:00
intrigeri
8eeb8c48c5 rc.apparmor.functions: quote to prevent word splitting and syntax error on empty output
Thanks, shellcheck!
2022-02-13 19:43:48 +00:00
Chris Novakovic
7f64db1f19 Display improvements in rc.apparmor.functions
* Don't call aa_log_action_end after calling aa_log_failure_msg, because
  a generic "failure" message will be outputted twice by the Red Hat and
  Slackware init scripts.
* Don't append a space to the initial output from apparmor_stop, in line
  with other usages of aa_log_daemon_msg.
2022-02-13 16:53:27 +00:00
Christian Boltz
db0a8aacd5
Drop now-unused profiles_names_list() from rc.apparmor.functions
The only user was aa-remove-unknown - until the previous commit.
2022-02-11 22:59:01 +01:00
John Johansen
e726ebe376 Merge Drop unused failstop_system() from rc.apparmor.functions
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/835
Acked-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-11 08:28:07 +00:00
Christian Boltz
8e1a4924d5
Drop unused failstop_system() from rc.apparmor.functions 2022-02-10 23:45:20 +01:00
Christian Boltz
8476786252
Drop skip_profile()
Its last user was profiles_names_list(), but since the previous commit
it lets apparmor_parser do this job.

Related to https://gitlab.com/apparmor/apparmor/-/issues/148
2022-02-10 22:56:16 +01:00
Christian Boltz
d38376c9c4
Simplify profiles_names_list()
... which is used by aa-remove-unknown.

apparmor_parser can read a whole directory, therefore we don't need to
do the directory listing, excluding *.rpmnew etc. ourself.

Related to https://gitlab.com/apparmor/apparmor/-/issues/148
2022-02-10 22:53:48 +01:00
Christian Boltz
5527c20833
Drop now-obsolete comment about skip_profile()
... which became superfluous after dropping use of xargs as fallback
when loading profiles in 0b8ea047e8
2022-02-09 18:32:51 +01:00
John Johansen
72c06c4d35 Merge Enable AppArmor to run properly under WSL/systemd
The AppArmor systemd scripts correctly detect the Windows Subsystem for Linux as a container, since all Linux distros executing under WSL 2 are containerized; however, unlike the majority of containers (since there is no accessible host distribution above them trying to set AppArmor policies that might interfere), AppArmor itself functions without problems in the WSL environment.

This patch adds WSL detection to the is_container_with_internal_policy function, allowing AppArmor to be started and operate normally in a WSL-plus-systemd environment.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/812
Acked-by: John Johansen <john@jjmx.net>
2022-02-04 10:25:14 +00:00
John Johansen
0b8ea047e8 rc.apparmor: drop use of xargs as fallback when loading profiles
LP:1377338 <https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1377338>

has been fixed for quite awhile and we don't need to call xargs as
a fallback when loading policy fails.

In addition we really don't want to be doing this because we want to
be moving to atomic profile loads where if one profile fails the
whole load fails. This is a step in that direction.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2022-02-04 02:22:39 -08:00
Dominique Martinet
76163f801d init: make xargs invocation busybox-compatible
busybox xargs does not have -d nor long --max-procs options,
instead use -0 (and separate arguments with printf "%s\0")
and -P which are more portable.
While we are here, also add -r (--no-run-if-empty, which also has
no long equivalent for busybox) as we likely don't want to run
anything if no profile were found

This is useful for alpine systems where findutils is not installed by
default, but busybox xargs is available.
2022-01-27 11:48:05 +09:00
Alistair Young
a6360d9db2 Add explicit WSL detection to is_container_with_internal_policy 2021-11-08 21:21:09 +00:00
John Johansen
692f78cf3f init: Add note about snapd policy and early boot to rc.apparmor.functions
Snapd now loads its own policy via its own systemd unit
https://github.com/snapcore/snapd/pull/8467

If A distro is not using snapd systemd unit then dropping snapd policy
from the apparmor unit is a breaking change, distros will either need
to use the snapd systemd unit or revert

0164fd05 init: stop loading snap policy

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-22 12:23:17 -07:00
Jamie Strandboge
0164fd05d6 init: stop loading the snap policy
snapd now loads its snap policy via its own systemd unit, so stop
loading the snap policy in /var/lib/snapd/apparmor/profiles

Fixs: https://launchpad.net/bugs/1871148
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-22 12:09:47 -07:00
Christian Boltz
61c27d8808
Fix and simplify setting SFS_MOUNTPOINT
Instead of setting SFS_MOUNTPOINT in is_apparmor_loaded() (which is
called in most cases) and in is_container_with_internal_policy() (which
covers/fixes the remaining cases), set it globally.

This also fixes a bug in is_container_with_internal_policy() (introduced
in f10e72a14f) where the variable
definition tried to use the no longer existing $MODULE variable and
therefore got a wrong path for $SFS_MOUNTPOINT.

Besides this bug, there's a minor behaviour change / improvement if
securityfs isn't mounted - "file not found" error messages will now
contain the full/correct path ;-)

This change/cleanup is a follow-up of
https://gitlab.com/apparmor/apparmor/merge_requests/363 and some IRC
discussions 2019-04-16.
2019-06-21 19:22:15 +02:00
Jamie Strandboge
f10e72a14f set SFS_MOUNTPOINT in is_container_with_internal_policy()
is_container_with_internal_policy() is called independently of
apparmor_*() in the systemd unit and potentially other consumers of
rc.apparmor.functions. When the unit and rc.apparmor.functions functions
were rewritten, they were written so that SFS_MOUNTPOINT was only set in
is_apparmor_loaded(), but this is only called in apparmor_start(),
remove_profiles(), apparmor_kill(), apparmor_restart(), apparmor_try_restart()
and apparmor_status() and not is_container_with_internal_policy().

While it is clear that is_container_with_internal_policy() is meant to
be called before apparmor_start(), is is unclear why SFS_MOUNTPOINT is
only defined in is_apparmor_loaded(). There are several ways to fix
this:

1. update is_container_with_internal_policy() to call is_apparmor_loaded()
2. identify the callers of is_container_with_internal_policy() and have
   them call is_apparmor_loaded()
3. reorganize the code to remove duplicate calls and assignments
4. define SFS_MOUNTPOINT along with SECURITYFS and MODULE, at the top
   level
5. also define SFS_MOUNTPOINT in is_container_with_internal_policy()

'1' would result in redundant calls in many common cases since the
systemd unit would call is_apparmor_loaded() both in
is_container_with_internal_policy() and prior to other calls.

'2' would like break consumers of rc.apparmor.funcions, like
Debian/Ubuntu's profile-load.

'3' is perhaps ok, but requires more effort and is regression-prone.

'4' seems the simplest, most correct fix

'5' is what this patch implements, which is as simple as '4' but tries
to maintain the original author's intent of when to set SFS_MOUNTPOINT.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/363
Signed-off-by: Jamie Strandboge <jamie@strandboge.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-13 21:21:21 -07:00
Emerson Bernier
fe6fc458e7 parser/rc.apparmor.functions: fix minor issues detected by shellcheck/shellharden 2019-04-22 15:02:45 +02:00
John Johansen
9eb738e5f1 Get rid of $MODULE, replace usage with hardcoded "apparmor"
I slightly ;-) doubt we'll change the module name.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/354
Signed-off-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-21 08:10:12 +00:00
Christian Boltz
7b68d820ea
Add quotes around several variables
Note that $PARSER_OPTS has to stay without quotes because it can
sometimes be empty, and would (if quoted) be interpreted as empty
filename by apparmor_parser
2019-03-18 19:30:37 +01:00
Christian Boltz
5f46dedd6e
replace deprecated egrep with grep -e 2019-03-18 19:17:16 +01:00
Christian Boltz
6c42cd9eae
skip_profile: make tests posix-compatible
[ foo -o bar ] isn't supported everywhere, replace it with
[ foo ] || [ bar ]
2019-03-18 19:05:47 +01:00
Christian Boltz
e20e49c130
Get rid of $MODULE, replace usage with hardcoded "apparmor"
I slightly ;-) doubt we'll change the module name.
2019-03-18 18:53:42 +01:00
Christian Boltz
75dc438823 Merge branch 'cboltz-deprecate-kill' into 'master'
drop most of apparmor_kill()

See merge request apparmor/apparmor!351

Acked-by: Eric Chiang <ericchiang@google.com>
2019-03-18 17:49:59 +00:00
Christian Boltz
be02f008c3
remove_profiles(): Fix returning $retval
Extend the subshell so that the actual (possibly non-zero) value of
$retval gets returned. Before, the changed value was lost at "done"
(= leaving the subshell), and the initial $retval=0 was returned.

(found with shellcheck)
2019-03-15 23:12:17 +01:00
Christian Boltz
0e3d6ee43a
drop most of apparmor_kill()
AppArmor can't be built as a kernel module since years, which also means
it's impossible to unload it.
2019-03-15 22:55:51 +01:00
intrigeri
775835db64 Fix is_apparmor_present() regression which breaks the Debian initscript.
Commit 0d5ab43d59 removed support for loading
modules and introduced a caller, in apparmor_start(), that passes no argument to
is_apparmor_present(), which breaks that function when /bin/sh → /bin/dash.

Passing a module name as argument does not make sense since we dropped support
for the long obsolete "subdomain" module, so let's simplify
is_apparmor_present() and adjust its callers accordingly.

Bug-Debian: https://bugs.debian.org/917874
2019-01-01 17:55:48 +00:00
intrigeri
1bd401bb35 Stop looking for apparmor.conf.
As per the discussion that starts at
https://gitlab.com/apparmor/apparmor/merge_requests/252#note_125983293,
apparmor.conf was never documented nor explicitly supported.
It's not really clear what problem it was meant to solve.
2018-12-28 16:34:17 +00:00
intrigeri
93f0c2d9ca Don't call the obsolete configure_owlsm function.
It was removed in commit 94ff870f.
2018-12-28 16:27:58 +00:00
intrigeri
3b997c79b4 Don't try to list files in a non-existent directory.
Thanks to Jamie Strandboge for spotting this during review.
2018-12-27 17:54:11 +00:00
intrigeri
10ba242b89 Make control flow clearer.
Let's add a safety net if we ever add another return code to skip_profile.
2018-12-27 17:46:43 +00:00
intrigeri
5865d01449 Remove dead code.
Since 04eb2fe3, __parse_profiles_dir can only return 0 or 1, so $STATUS can only
be 0 or 1, so trying to reset this variable to 0 when its value is 2 can only
cause confusion.
2018-12-16 21:05:06 +00:00
intrigeri
45bc0b8eb7 Merge remote-tracking branch 'origin/master' into prepare-rc.apparmor.functions-for-Debian-and-Ubuntu 2018-12-16 20:36:53 +00:00
Christian Boltz
228b92ce5a
Ignore *.orig and *.rej files when loading profiles
or: get rc.apparmor.functions in sync with the tools and libapparmor.

This was "accidently" reported by Ralph on the opensuse-support
mailinglist.
2018-11-28 22:50:09 +01:00
Christian Boltz
7ba8dc7e2e
Drop APPARMOR_ENABLE_AAEVENTD
This is another trace of aa-eventd which is deprecated since years.
2018-11-12 15:51:15 +01:00
Christian Boltz
3a89e9811f
Remove traces of aa-eventd
aa-eventd and its initscripts have been moved to deprecated/ in 2014 and
didn't get any serious updates for several more years, so it's most
probably useless and/or broken nowadays.

This also means we don't need to keep the AA_EV_BIN and AA_EV_PIDFILE
variables in rc.apparmor.functions anymore.
2018-11-09 17:22:17 +01:00
John Johansen
94ff870f78 remove subdomainfs support
It has been over 10 years since transition from subdomainfs to
using securityfs. Lets drop this deprecated code.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/258
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: seth.arnold@canonical.com
2018-11-08 18:23:21 -08:00
John Johansen
0d5ab43d59 rc.apparmor.functions: drop module loading support
The apparmor kernel "module" has not been a loadable module for more
than a decade, it must be built into the kernel and due configuration
requirements it will never go back to being a loadable module.

Remove the long unfunctioning load_module support from the init script.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/257
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: seth.arnold@canonical.com
2018-11-08 18:22:09 -08:00
Christian Boltz
29da17310e
replace -1 return codes with 255
Technically "return -1" returns 255, so we should write it that way.

(found by shellcheck)
2018-11-02 17:00:33 +01:00
intrigeri
73e124d4fb rc.apparmor.functions: add is_container_with_internal_policy() function.
Imported from the Debian/Ubuntu packaging. We need this function so that
Debian/Ubuntu can switch to using this shell library instead of their own code.
2018-10-30 16:37:02 +00:00
intrigeri
f58c96699a rc.apparmor.functions: add support for an additional profiles directory, defaulting to /var/lib/snapd/apparmor/profiles.
We need this support so that Debian/Ubuntu can switch to using this shell
library instead of their own code.
2018-10-30 16:36:55 +00:00
intrigeri
13d9512287 rc.apparmor.functions: warn when the profiles directory cannot be found.
We do this for apparmor.conf so let's be consistent.
2018-10-30 15:30:01 +00:00
intrigeri
ff617819aa rc.apparmor.functions: delete disabled profile handling code.
It duplicates the parser's default behaviour.
2018-10-30 15:30:01 +00:00
intrigeri
222943eb3b rc.apparmor.functions: suppress warnings when booting in quiet mode. 2018-10-30 15:30:01 +00:00
intrigeri
04eb2fe345 rc.apparmor.functions: take benefit from the parser's automatic parallelization. 2018-10-30 13:37:05 +00:00