2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 01:57:43 +00:00

2098 Commits

Author SHA1 Message Date
Maxime Bélair
ba336533ac utils: Add tests for get_local_include
Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-08-15 13:51:32 +02:00
Maxime Bélair
0d34f12d7e utils: Move get_local_include to ProfileStorage
Move get_local_include from aa.py to ProfileStorage, a more logical
location.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-08-15 13:51:26 +02:00
Maxime Bélair
fcbf8e34ec aa-notify: Make --local commandline option override use_local_profiles
If both the --local commandline option and use_local_profiles
configuration are specified, the commandline now takes precedence.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-08-14 10:01:03 +02:00
Maxime Bélair
eae49bf8de test-aa-notify: Update help test
Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-08-11 18:16:53 +02:00
Maxime Bélair
144d782ae8 aa-notify: Update config with use_local_profiles
aa-notify configuration now supports use_local_profiles, and this option
is documented in the manual.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-08-11 18:16:53 +02:00
Maxime Bélair
df1a4c8782 aa-notify: Allow writing to local profiles
The new option --local allows user to write new rules to local profiles
instead of system profiles, enabling cleaner profile deployment.

This option support the values (yes, no and auto)

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-08-11 18:16:53 +02:00
Maxime Bélair
4c30a0ac65 utils: Allow writing to profile includes
This patch allows writing write in include files and save them to disk.
This is particularly helpful for local includes (generally used in
profiles through `include if exists <local/foo>`), and keeps the base
profile clean, avoiding breakages when the system updates profiles.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-08-11 18:16:22 +02:00
Ryan Lee
67382dcf15 utils: fix typo in aa-show-usage man page
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-08-01 12:20:18 -07:00
Maxime Bélair
63ce02c01d Merge logparser: add support for change_onexec logs
Add support for change_onexec logs by converting them to change_profile.
Fix associated test.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1745
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-30 08:27:43 +00:00
Maxime Bélair
9ac6047f6c aa-notify: Explicitly import tkinter.font
import tkinter does not automatically import tkinter.font so calls to
the latter fail if the execution environment does not already contains
it.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-29 13:14:18 -07:00
Maxime Bélair
73f4f650e7 aa-notify: Reduce profiles updates to reduce overhead.
Profiles are now updated only at initialization and when aa-notify
itself updates a profile.

A future MR will come to read profiles individually only when an event
for this profile comes to reduce overhead, as more and more profiles are
created.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-29 13:14:18 -07:00
Maxime Bélair
12e3557896 aa-notify: Support regexes in userns_special_profiles
It is now possible to use regexes to define special profiles. unpriv_.*
is used by default.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-29 13:14:18 -07:00
Maxime Bélair
d8c57da6ba Allow aa-notify to use the priority mechanism
Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-29 13:14:18 -07:00
Maxime Bélair
4de3b64e52 Add tests for get_event_type
Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-29 13:14:18 -07:00
Maxime Bélair
71a71e0fa7 Create get_event_type instead of customized_message['userns']['cond']
This improves the code readability

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-29 13:14:18 -07:00
Maxime Bélair
2448655188 logparser: add support for change_onexec logs
Add support for change_onexec logs by converting it to change_profile.
Fix associated test.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-24 13:32:13 +02:00
John Johansen
ab46c224cb Merge Move annoying "skipping disabled profile" log to debug.
Those messages appear in various context and do not provide any useful feedback to the user, diverging from UNIX philosophy of staying quiet when there's nothing of importance to say.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1738
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-07-24 10:44:49 +00:00
Maxime Bélair
380dbb84b8 utils: Fix priority checking for is_covered
MR !1735 mistakenly assumed that x.is_covered(y) means "x is covered by
y" when the opposite is true

Fix the logic of is_covered and associated tests.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-17 11:00:24 +02:00
Jérôme Poulin
000b56a323
Move annoying "skipping disabled profile" log to debug.
Signed-off-by: Jérôme Poulin <jeromepoulin@gmail.com>
2025-07-16 16:33:08 -04:00
Maxime Bélair
f78aa36547 Add tests for priority is_covered/is_equal fix
Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-16 12:13:41 +00:00
Maxime Bélair
ab9d359405 utils: Improve rule priority support in is_covered/is_equal
- `is_covered` was not checking priorities when checking if a rule is
  covered. With this fix, a rule of lower priority can no longer cover a
  higher priority one.
- Fixes `is_equal(strict=False)` so that priority=0 matches implicit
  priority (as it is defaulted to zero)

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-07-16 12:13:41 +00:00
Christian Boltz
ccf74a7d0c Unify get_directory_contents(), and delete unused copy
Copy the optimized version from common.py to easyprof.py (shouldn't
change the behaviour).

Since get_directory_contents() is only used in easyprof.py, delete the
unused copy from common.py.
2025-07-15 19:16:30 +00:00
Christian Boltz
9696d9e13f
test-mount: move some tests to MountTestIsEqual
... and rename some other tests so that their name matches better what
they do.
2025-07-15 20:36:53 +02:00
Christian Boltz
a833528f36
Split test classes
Create separate classes for tests not fitting under *TestParseInvalid
2025-07-15 20:34:33 +02:00
Christian Boltz
66cb0af47c
*TestParseInvalid: move tests not matching regex into tests array 2025-06-29 18:26:10 +02:00
Christian Boltz
2a37040415
Introduce AATest.parseInvalidRule()
... and change all *TestParseInvalid classes to use it, instead of
having (nearly) the same function in every test-*.py.

While at it, enable the tests for abi and include rules.
2025-06-29 17:35:48 +02:00
Christian Boltz
a13d8cfffb
utils: move tests for invalid priority to test-*
... instead of having them in test-modifiers.py for all rule types

Also add a few additional tests while on it.
2025-06-24 18:11:14 +02:00
Christian Boltz
7a8a28d47a Merge Drop unused AAParseTest class and setup_regex_tests()
In the past, this class and function were used by test-signal_parse.py -
which was deleted in April 2016 (5f58d7f124139784b9ba70ce37cc26716bbc4e0f).

Maybe there were also other users, but none of them survived.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1719
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-06-17 18:29:10 +00:00
Christian Boltz
6648f2cbeb
Drop unused AAParseTest class and setup_regex_tests()
In the past, this class and function were used by test-signal_parse.py -
which was deleted in April 2016 (5f58d7f124139784b9ba70ce37cc26716bbc4e0f).

Maybe there were also other users, but none of them survived.
2025-06-15 21:02:44 +02:00
Christian Boltz
f977530f39
Move some tests to class ChangeProfileTestParseInvalid
... to reduce code duplication
2025-06-15 18:53:40 +02:00
Christian Boltz
58f5c2b7e8
ChangeProfileTestParseInvalid: allow tests that match the regex
(even if the existing tests all don't match it)
2025-06-15 18:53:40 +02:00
Christian Boltz
6d2a0f6ba7
InvalidChangeProfileInit: fix testing for missing params
- use valid values for given params
- add testcase with two given / one missing params
2025-06-15 18:53:40 +02:00
Christian Boltz
fd89e3185c
test-capability: switch CapabilityTestParseInvalid to tests array 2025-06-15 18:53:40 +02:00
Christian Boltz
237b17329f
test-mount: test invalid fstype via tests array
... instead of duplicating the logic
2025-06-15 18:22:52 +02:00
iDigitalFlame
b4ab583520 Update utils/aa-notify to add running in the foreground and continue on "read_profiles" permission error 2025-06-14 15:07:44 +00:00
John Johansen
520227e4ea Merge Remove global declarations when variables are only read
... but don't get a new value assigned.

Found by pyflakes 3.3.2 / python 3.13.3

While on it, remove some obsolete, commented out debugging code.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1708
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-06-05 23:17:20 +00:00
Christian Boltz
ba5e007287
Fix parsing of mount options to honor full words
Parsing mount options (also) accepted partial matches as long as the
option started with the right characters. For example, 'options=syncfoo'
was parsed as 'sync'. This is also the reason why the list of mount
options was re-ordered so that 'r' and 'w' came last to give longer
options a chance to match (otherwise, 'rw' would be interpreted as 'r').

Fix parsing by adding a lookahead match so that the regex enforces that
the mount option is followed by whitespace, or is at the end of
rule_details.

Note that this issue only affected the options=foo syntax.
options=(foo) worked correctly even without this fix.

Now that this is fixed, move 'r' and 'w' back to their original position
in the list of mount options.

Also add a test where a mount rule ends with 'options=rw,' to ensure
that the '$' lookahead works.
2025-06-04 22:42:34 +02:00
Georgia Garcia
1009a66e0c Merge Improve error message for unknown mount options
Parsing `mount options=x` results in "Passed unknown options keyword to
MountRule: x", while parsing `mount options=xy` results in "Can't parse mount rule".

This difference happens because the code checks (besides the list of
known options) for a regex `([A-Za-z0-9])` which only matched a
single-character unknown option.

Change that regex to also match multiple characters, and also allow to
match `-` (used in some known mount options, so it's likely that it also
gets used in so far unknown mount options)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1710
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-04 17:28:14 -03:00
Christian Boltz
9a035cb0ee
Improve error message for unknown mount options
Parsing `mount options=x` results in "Passed unknown options keyword to
MountRule: x", while parsing `mount options=xy` results in "Can't parse mount rule".

This difference happens because the code checks (besides the list of
known options) for a regex `([A-Za-z0-9])` which only matched a
single-character unknown option.

Change that regex to also match multiple characters, and also allow to
match `-` (used in some known mount options, so it's likely that it also
gets used in so far unknown mount options)
2025-06-04 20:47:14 +02:00
Christian Boltz
d223751de0
simplify mount_condition_pattern
The whole pattern already has `(...)*`, therefore there's no need to
make option_pattern optional.

Before this change, mount_condition_pattern could have matched
- on empty strings (it still can, thanks to the trailing `*` which can
  also mean "zero matches") or
- whitespace-only strings (which is covered by the two regexes using
  mount_condition_pattern - they both have `\s*` and/or `\s+` around it)
2025-06-04 19:38:56 +02:00
Christian Boltz
2bfdcb780f
Remove global declarations when variables are only read
... but don't get a new value assigned.

Found by pyflakes 3.3.2 / python 3.13.3

While on it, remove some obsolete, commented out debugging code.
2025-06-04 19:29:16 +02:00
John Johansen
23deb55149 Merge utils: add support for multiple options and fstypes in mount rules
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1693
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-06-03 23:43:40 +00:00
Maxime Bélair
e637884554 logprof: improve LOGPROF-SUGGEST metadata for abstractions
Improve #LOGPROF-SUGGEST metadata to support a set of space-separated
regexes. If this tag is present, the abstraction is only proposed to
aa-logprof if one of the regexes is matched.

If this abstraction should not be proposed to any profile, it is
possible to tell #LOGPROF-SUGGEST: no

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-05-28 15:47:03 +02:00
Maxime Bélair
b46f7a426c Add support for --show-matching-path and xattrs
The new option --show-matching-path shows a path that matches in the host
filesystem, to prove that the profile is indeed used.

Also, profiles' xattrs are now parsed into a dict and are taken in
consideration when looking for matching profiles.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-05-26 20:08:38 +00:00
Maxime Bélair
db376c0458 Refactor to use cmd everywhere
Many test provide their own implementation of cmd(). This commit makes
all of them rely on common.py implementation of cmd()

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-05-26 20:08:38 +00:00
Maxime Bélair
29b4716377 Add a manual entry for aa-show-usage
Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-05-26 20:08:38 +00:00
Maxime Bélair
229811de9a Add tests for aa-show-usage
Add new tests for aa-show-usage and regex.py, that is internally used by
aa-show-usage

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-05-26 20:08:38 +00:00
Maxime Bélair
b850f19622 utils: add aa-show-usage for profile usage analysis
Introduce aa-show-usage, a new helper allowing to determine which
profiles on the system are used and which are not. A profile is marked as
used when at least one file installed in the machine matches the attach point
specified in the profile.

This tool supports filtering options, allowing users to, for example,
display only unconfined profiles that are currently in use. This can
notably help sysadmins to evaluate the security of their systems.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-05-26 20:08:38 +00:00
Georgia Garcia
2e7da63183 utils: add support for multiple fstypes in mount rules
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-05-22 15:51:45 -03:00
Georgia Garcia
79f2ea72b0 utils: add support for multiple options in mount rules
The tools don't support having multiple options specified in mount
rules as it is allowed in the parser.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-05-21 17:55:54 -03:00