Commit graph

1856 commits

Author SHA1 Message Date
John Johansen
27b79a43cc translations: finish merging translation files that were new
Commit
   00591cec4 Merge in Imported translations from launchpad

merged in updated translations but did not merge in the new translation
files. This is the set of new translations.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-02-25 12:17:52 -08:00
John Johansen
00591cec47 Merge in Imported translations from launchpad
This merges back the translations from commit
    d52b301ee ("Merge Import translations from launchpad")
    MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1559

which imports launchpad up to commit

    revno: 2523
    committer: Launchpad Translations on behalf of apparmor-dev
    branch nick: apparmor
    timestamp: Fri 2025-02-21 09:32:26 +0000
    message:
      Launchpad automatic translations update.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-02-24 22:22:24 -08:00
Georgia Garcia
2ed74be1bb Merge utils: test: account for last cmd format change in test-aa-notify
The "last" command, which was supplied by util-linux in older Ubuntu
versions, is now supplied by wtmpdb in Oracular and Plucky. Unfortunately,
this changed the output format and broke our column based parsing.

While the wtmpdb upstream has added json support at
https://github.com/thkukuk/wtmpdb/issues/20, we cannot use it because
we need to support systems that do not have this new feature added.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1508
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit 3b7ee81f04)

afd6aa05 utils: test: account for last cmd format change in test-aa-notify

Co-authored-by: John Johansen <john@jjmx.net>
2025-01-28 12:35:40 +00:00
Georgia Garcia
75ce9020e4 Merge Allow overrides and preservation of some environment variables in utils make check
Our ubuntu packaging builds Python-enabled libapparmor's in the directories `libapparmor/libapparmor.python[version_identifier]`. In order for the util's `make check` to pick up on the correct libapparmor during the Ubuntu build process, we need the ability to override its search path. This patch introduces a `LIBAPPARMOR_BASEDIR` variable to allow for that.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1497
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>


(cherry picked from commit 17a09d2987)

90143494 Allow overrides and preservation of some environment variables in utils make check

Co-authored-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-01-23 19:11:59 +00:00
Georgia Garcia
fe53d6cefe Merge utils: test: various fixes for utils testing in Ubuntu packaging
The first patch fixes a `test-aa-notify.py` `TypeError` when `APPARMOR_NOTIFY` and `__AA_CONFDIR` are both specified, which is something that was broken all this time.

The second patch ensures that `aa-notify` in the test suite is run using the same Python interpreter that the test suite itself is run with, which is necessary for testing the utils under different Pythons.

The third patch does analogous modifications to the minitools tests that launch `aa-audit`, `aa-complain`, etc.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1498
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>


(cherry picked from commit 625a919bb8)

3365e492 utils: test: test-aa-notify: Ensure aanotify_bin is always a list
77cabf7d utils: test: use sys.executable when launching aa-notify in tests
e32c2673 utils: test: use sys.executable when launching minitools in tests

Co-authored-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-01-23 19:07:33 +00:00
Christian Boltz
620e92f39e Merge Support unloading profiles in kill and prompt mode
... in aa-teardown (actually everything that uses rc.apparmor.functions)
and aa-remove-unknown.

Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2093797

I propose this fix for 3.0..master, since the apparmor.d manpage in all these branches mentions the `kill` flag.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1484
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 9629bc8b6f)

1c2d79de Support unloading profiles in kill and prompt mode

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2025-01-14 18:25:12 +00:00
Christian Boltz
fe6604532f Merge python 3.13 fixes/workarounds
Fixes/workarounds for python 3.13 support.

fail.py: handle missing cgitb - workaround for https://gitlab.com/apparmor/apparmor/-/issues/447

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1439
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 5fb91616e3)

434e34bb fail.py: handle missing cgitb

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2024-12-05 17:36:43 +00:00
Christian Boltz
0572659d49 Merge aa-remove-unknown: fix readability check [upstreaming]
I am upstreaming this patch that is part of the nix package of apparmor for close to a year now.
This fixes the issue at https://github.com/NixOS/nixpkgs/issues/273164 for more distros than just NixOS.
The original merge Request on the nix side patching this was https://github.com/NixOS/nixpkgs/pull/285915.
However, people had issues with gitlab, so this never hit apparmor upstream until now. This does however also mean this patch has seen production and seems to work quite well.

## Original reasoning/message of the patch author:

This check is intended for ensuring that the profiles file can actually
be opened.  The *actual* check is performed by the shell, not the read
utility, which won't even be executed if the input redirection (and
hence the test) fails.

If the test succeeds, though, using `read` here might actually
jeopardize the test result if there are no profiles loaded and the file
is empty.

This commit fixes that case by simply using `true` instead of `read`.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1438
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 93c7035148)

b4aa00de aa-remove-unknown: fix readability check

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2024-12-01 16:11:41 +00:00
Christian Boltz
15f263717a Merge test-logprof: Increase timeout once more
Builds for risc64 are much slower than on other architectures (4-5
seconds with qemu-user or on Litchi Pi 4A).

Since the timeout is only meant as a safety net, increase it generously,
and hopefully for the last time.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/463

I propose this patch for 4.0 and master.

Closes #463
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1417
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit 4c32ad8fb7)

508ace45 test-logprof: Increase timeout once more

Co-authored-by: John Johansen <john@jjmx.net>
2024-11-10 16:34:59 +00:00
John Johansen
7ead5556dd Merge utils: catch TypeError exception for binary logs
When a log like system.journal is passed on to aa-genprof, for
example, the user receives a TypeError exception: in method
'parse_record', argument 1 of type 'char *'

This patch catches that exception and displays a more meaningful
message.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/436
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

Closes #436
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1354
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit cb0f84e101)
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-10-21 16:17:56 -03:00
John Johansen
90500d38ab Merge utils: fixes when handling owner file rules
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/429
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/430

Closes #429 and #430
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1320
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 1940b1b7cd)
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-10-07 10:18:46 -03:00
Christian Boltz
f3c1c8ada8 Merge ping: allow reading /proc/sys/net/ipv6/conf/all/disable_ipv6
Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1082190

I propose this patch for 3.0..master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1340
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 4b6df10fe3)

df4d7cb8 ping: allow reading /proc/sys/net/ipv6/conf/all/disable_ipv6

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2024-09-30 21:43:19 +00:00
Christian Boltz
5f2eadc809 Merge apparmor.vim: Add missing units for rlimit cpu and rttime
... and allow whitespace between the number and the unit.

I propose this patch for 3.x, 4.0 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1336
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 247bdd5deb)

9cb591c5 apparmor.vim: Add missing units for rlimit cpu and rttime

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2024-09-30 21:35:54 +00:00
Christian Boltz
3fe2d323fc
MqueueRule: allow / as mqueue name
... and not only `/something`

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/413#note_2008929033
(cherry picked from commit 02edb649fa)
2024-07-21 19:13:50 +02:00
Christian Boltz
f0f7420f6c
test-mqueue: table-format MessageQueueTestParse
(cherry picked from commit 93870323a0,
 adjusted to 4.0 branch)
2024-07-21 19:13:29 +02:00
John Johansen
a07a8e69e0 Merge utils: Ignore/skip disabled profiles
This is needed to avoid a "Conflicting profiles" error if there are two
profiles for an application, with one of them disabled.

This is not a theoretical usecase - for example, apparmor.d ships some
profiles that replace our "userns+unconfined" profiles. These profiles
use a different filename, and apparmor.d also creates a disable symlink
for the "userns+unconfined" profile it replaces.

I propose this patch for 4.0 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1264
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 834c28b5fe)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-07-17 01:25:26 -07:00
Christian Boltz
24a0ebb5ef Merge aa-notify: fix translation of an error message
... which so far was not translatable because it was formatted before
being translated.

I propose this fix for master, 4.0 and 3.x

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1271
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 67021bf911)

c85958da aa-notify: fix translation of an error message

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2024-07-15 19:27:29 +00:00
Christian Boltz
6cad7b889e Merge ask_exec: ignore events for missing profiles
... and not only for events in missing hats.

This fixes a crash if the log contains exec events for a hat where not
even the parent profile exists.

I propose this patch for master, 4.0 and 3.1.

(In 3.0, `aa` is still a `hasher` which avoids the crash, therefore it doesn't really need this patch.)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1265
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 3ea19d5f32)

7928c416 ask_exec: ignore events for missing profiles

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2024-07-11 12:03:36 +00:00
John Johansen
e2aff72f53 Merge test-logprof: increase timeout
... so that slow test environments don't fail.

Fixes: https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/2062138

I propose this fix for 4.0 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1268
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 0785006b41)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-07-07 05:40:17 -07:00
Christian Boltz
98a0a2fee9
MountRule: Add support for empty ("") source
This needs adding of an empty_ok flag in _aare_or_all().

Also add a few tests from boo#1226031 to utils and parser tests.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1226031

(cherry picked from commit 1f33fc9b29,
test-mount.py changes adjusted for 4.0 branch)
2024-06-11 13:36:24 +02:00
Christian Boltz
aada708bc1
MountRule: add support for quoted paths
While on it, make the output for failing tests more verbose for easier
debugging.

(cherry picked from commit 900f233101,
test-mount.py adjusted for 4.0 branch)
2024-06-11 13:36:21 +02:00
Christian Boltz
2a3cf471ab apparmor.vim: add support for userns and the unconfined flag
(cherry picked from commit 4cd39e70a0)
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/396
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-06-04 17:41:29 -03:00
Christian Boltz
c31da2ec55 Merge utils: fix removing unknown profiles that contain spaces
aa-remove-unknown doesn't deal properly with profiles that contain
spaces in their names.

Using profile "MongoDB Compass" as an example, awk's sub returns the
number of matches - either 1 or 0 and replaces the actual string ($0)
with the substitution.  By accessing the return of sub with $, awk
would be accessing $1 which would return only "MongoDB".
Fix this by using $0 instead of $str.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/395

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

Closes #395
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1243
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit 920120ffea)

7ef7704f utils: fix removing unknown profiles that contain spaces

Co-authored-by: John Johansen <john@jjmx.net>
2024-06-04 20:36:10 +00:00
Georgia Garcia
9ec5134322 Merge Fix aa-remove-unknown for 'unconfined' profiles
Without this patch, aa-remove-unknown uses 'profile_name (unconfined)'
when trying to unload unconfined profiles, which fails for obvious
reasons with (picking a random example)

    Removing 'busybox (unconfined)'
    /sbin/aa-remove-unknown: line 112: echo: write error: No such file or directory

I propose this patch for 4.0 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1240
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>


(cherry picked from commit cf5be7d356)

cabd88a9 Fix aa-remove-unknown for 'unconfined' profiles

Co-authored-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-28 19:17:53 +00:00
Maxime Bélair
1f4bba0448 Cherry-pick: MountRule: Aligning behavior with apparmor_parser
Mount Rules with options in { remount, [make-] { [r]unbindable, [r]shared, [r]private, and [r]slave }} do not support specifying a source. This commit aligns utils implementation to apparmor_parser's, which prohibits having a both source and a destination simultaneously, instad of just prohibiting source.

Therefore, both `mount options=(unbindable) /a,` and `mount options=(unbindable) -> /a,` are now supported (and equivalent for apparmor_parser). However, `mount options=(unbindable) /a -> /b,` is invalid.

For the same reason, specifying a fstype in these cases is also prohibited.

Similarly, we prohibit to specify a fstype for bind mount rules.

Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2065685

(cherry picked from commit 60acc4a405)

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2024-05-22 08:31:27 +02:00
Christian Boltz
af88a13712 Merge Include abi/4.0 when creating a new profile
... with aa-genprof or aa-autodep

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/392

I propose this patch for 4.0 and master.

Closes #392
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1231
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 74316fe152)

6c8ef381 Include abi/4.0 when creating a new profile

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2024-05-14 19:11:24 +00:00
Georgia Garcia
8e74855531 Merge Handle mount events/log entries without class
audit.log entries for mount events don't always include `class=mount`,
but can still be the base for mount rules.

Change logparser.py to also consider `operation=mount` as a mount event.

Actually we already had such a log and profile in our collection
(testcase_mount_01), but since it existed years before MountRule was
implemented, it was excluded in test-libapparmor-test_multi.py.
Therefore we didn't notice that it failed to produce a profile rule when
MountRule was introduced.

Remove testcase_mount_01 from the list of known failures so that it gets
tested - and fix the syntax error in the hand-written
testcase_mount_01.profile.

Also add testcase_mount_02 which is a mount event without fstype,
srcname and class.

I propose this fix for 4.0 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1229
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>


(cherry picked from commit 48a936e985)

b475ed0d Handle mount events/log entries without class

Co-authored-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-10 12:31:41 +00:00
Georgia Garcia
eee50538da Merge MountRule: Relaxing constraints on fstype and completing AARE support
- Before this commit, fstype had to match a known fs. However, having and maintaining the exhaustive list of fstypes proved challenging (see !1195 and !1176). Therefore, we add support for any filesystem name.
 - Completing AARE support for fstype (brace expressions like ext{3,4} are now supported).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1198
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit baa8b67248)

dad5ee28 MountRule: Relaxing constraints on fstype and completing AARE support

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2024-05-08 12:58:42 +00:00
Christian Boltz
86be5d35f3
util/test/: Don't rely on argparse saying "options:"
Some argparse versions (for example on openSUSE Leap 15.5) instead say
"optional arguments:"

Don't rely on the "options:" line to allow both wordings.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1226
Approved-by: Steve Beattie <steve+gitlab@nxnw.org>
Cherrypicked-by: Steve Beattie <steve+gitlab@nxnw.org>
2024-05-06 12:24:32 +02:00
Georgia Garcia
b7f9b66cba Merge gitlab-ci.yml: fix pipeline for ubuntu:latest (noble)
Since we are using ubuntu:latest, and noble was released, some tests
are failing.

shellcheck needs python3 to run, which was possibly installed by
default in previous ubuntu images and is no longer the case.

Ignore dist-packages python files during our coverage tests.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/388

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

Closes #388
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1223
Merged-by: Steve Beattie <steve+gitlab@nxnw.org>


(cherry picked from commit 8c9ac7a84e)

731880de gitlab-ci.yml: fix pipeline for ubuntu:latest (noble)
aaad725a apparmor.systemd: fix shellcheck false positive

Co-authored-by: Steve Beattie <steve+gitlab@nxnw.org>
2024-05-02 13:37:53 +00:00
John Johansen
f1173379ff Merge Fix redefinition of _
... which unsurprisingly broke using the translations.

This was a regression introduced in 4f51c93f9d

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/387

This fix is needed in 4.0 and master. (3.x branches are not affected.)

Closes #387
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1218
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 79226675fd)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-04-22 16:42:13 -07:00
John Johansen
c8e25e4689 Merge parser: add network inet mediation documentation to apparmor.d
This updates the man page for the recent inet mediation patch.

This is an extension of MR 1202, it adds a patch that changes the anonymous ip address anon to be ip address none which is a better fit.

This patch adds documentation of the recent network changes which extended all network rules to support access permissions, and added address and port matching for inet and inet6 families.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1213
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit ab9e6311f3)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-04-11 20:54:23 -07:00
Georgia Garcia
1c7127d30d Merge utils: allow mount destination globbing
The abstraction lxc/start-container shipped by the liblxc-common
package uses the following mount rule which was not allowed by our
regexes:

  mount options=(rw, make-slave) -> **,
  mount options=(rw, make-rslave) -> **,

Since in AppArmor regex ** includes '/' but * by itself doesn't, I'm
adding explicit support for **.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/381
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1195
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
(cherry picked from commit e96fdc0f5b)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-04-03 02:23:43 -07:00
Maxime Bélair
dac9d08764 MountRule: Fix _is_covered_localvars 2024-03-14 12:46:01 +00:00
Christian Boltz
d19db55a37
Fix test-aa-notify on openSUSE Tumbleweed (new 'last')
The new 2037-proof `last` on openSUSE Tumbleweed doesn't support the
`-1` option.

Remove it, and cut off the output manually.
2024-03-12 19:37:29 +01:00
Maxime Bélair
021c3248f9 Minor improvements for MountRule 2024-03-07 19:27:03 +00:00
Georgia Garcia
01090dcf1b utils: fix coding style in mount
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 09:24:58 -03:00
Georgia Garcia
3ea2bfec56 Merge Small fixes in MountRule
- Removed unnecessary variable source_is_path in mount rules
- Changed a string to a r-string to avoid an 'invalid escape sequence \s' warning

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1172
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:53:51 +00:00
Georgia Garcia
dfb02cbd93 Merge MountRule: check for unknown fstype and options keywords, and fix issues uncovered by that
* **MountRule: sync flags_keywords with parser code**

    ... based on /mount.cc mnt_opts_table

    Several keywords and aliases were missing in flags_keywords:
    - B
    - M
    - make-private
    - make-rprivate
    - make-rshared
    - make-rslave
    - make-runbindable
    - make-shared
    - make-slave
    - make-unbindable
    - r
    - R
    - read-only
    - w

    Also sort the keywords in the same order as in mount.cc.

    Note: AARE handling is still a TODO.

    After that, update the list of known parsing failures:
    - several valid profiles are now correctly parsed
    - some `"make-*" mount opt and an invalid src` bad profiles are no
      longer detected as being invalid

* **test-mount.py: fix MountRule instance creation**

    If fstype or options is a str, it has to be exactly one keyword, because
    \__init__() / check_and_split_list() won't parse a str.

    Our "normal" code already honors this, and only hands over fstype and
    options as sets or a single-keyword str.

    However, a few tests (wrongly) handed over a str that would need further
    parsing. Adjust the tests to no longer do this.

* **MountRule: check for unknown fstype and options**

    ... now that the previous commits fixed issues that ended up as unknown
    keywords.

    Also add mount/ok_12.sd as known-failing test. It uses fstype=AARE which
    MountRule doesn't support (yet?).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1169
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:52:53 +00:00
Maxime Bélair
0daf3e8c9b Changing string to r-string to avoid warning 2024-03-04 09:02:24 +01:00
Maxime Bélair
a86c1bd45a Remove unnecessary variable source_is_path in mount rules 2024-03-04 09:00:58 +01:00
Christian Boltz
8f4073ecd9
MountRule: check for unknown fstype and options
... now that the previous commits fixed issues that ended up as unknown
keywords.

Also add mount/ok_12.sd as known-failing test. It uses fstype=AARE which
MountRule doesn't support (yet?).
2024-03-03 21:30:49 +01:00
Christian Boltz
8d21f01924
test-mount.py: fix MountRule instance creation
If fstype or options is a str, it has to be exactly one keyword, because
__init__() / check_and_split_list() won't parse a str.

Our "normal" code already honors this, and only hands over fstype and
options as sets or a single-keyword str.

However, a few tests (wrongly) handed over a str that would need further
parsing. Adjust the tests to no longer do this.
2024-03-03 15:52:14 +01:00
Christian Boltz
4e546291a5
MountRule: sync flags_keywords with parser code
... based on /mount.cc mnt_opts_table

Several keywords and aliases were missing in flags_keywords:
- B
- M
- make-private
- make-rprivate
- make-rshared
- make-rslave
- make-runbindable
- make-shared
- make-slave
- make-unbindable
- r
- R
- read-only
- w

Also sort the keywords in the same order as in mount.cc.

Note: AARE handling is still a TODO.

After that, update the list of known parsing failures:
- several valid profiles are now correctly parsed
- some `"make-*" mount opt and an invalid src` bad profiles are no
  longer detected as being invalid
2024-03-03 15:37:59 +01:00
Christian Boltz
8c026077d6
MountRule: make get_clean() more readable
... by getting rid of two mostly-identical, big return statements.

Also add tests for bare umound and remount rules to ensure full test
coverage.
2024-03-03 13:09:43 +01:00
Christian Boltz
5e4c4a0cb3
Make error check more readable 2024-03-03 12:53:49 +01:00
Christian Boltz
9c27a7c435
Fix writing 'mount {options,fstype} in ...' rules
We need spaces around the 'in' keyword.

Also add some tests for this.
2024-03-03 12:49:57 +01:00
Christian Boltz
a367c07437 Merge Add useful error message in test-mount.py
If /proc/filesystems contains a filesystem that is not listed in
MountRule valid_fs, print a useful error message that says what exactly
is going on, instead of only saying "False is not True".

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1166
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-01 21:30:33 +00:00
Christian Boltz
2200013088 Merge Cleanup old handling of mount rules
Now that we have MountRule and MountRuleset, drop the old "just store
the whole rule" code for mount rules.

Also drop some old tests that used that "store the whole mount rule"
code, and adjust the regex_matches tests to import the regex directly
from apparmor.regex.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1165
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-01 21:29:48 +00:00
Christian Boltz
517e7c96c8
MountRule: add '9p' filesystem
This filesystem is available during the build in build.opensuse.org
2024-03-01 21:36:26 +01:00