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

8266 Commits

Author SHA1 Message Date
John Johansen
ac81cafa4f Merge added lsusb profile
AppArmor profile for the lsusb binary, developed and tested on Ubuntu 22.04. 

Signed-off-by: Federico Quattrin <federico.quattrin@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1433
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-06-09 18:33:26 +00:00
Federico Quattrin
bf207941ad update pci sys devices rules 2025-06-06 13:56:39 -07:00
Federico Quattrin
ec2c363125 added basic integration test 2025-06-06 13:56:39 -07:00
Federico Quattrin
61d5f1a56f removed abstractions/nameservice and added network netlink raw 2025-06-06 13:56:39 -07:00
Federico Quattrin
2634352a75 update lsusb profile name 2025-06-06 13:56:39 -07:00
Federico Quattrin
7af7fd35e5 include local lsusb profile if exists
Signed-off-by: Federico Quattrin <federico.quattrin@canonical.com>
2025-06-06 13:56:39 -07:00
Federico Quattrin
65f8bd4d82 added a few more rules for lsusb to cover verbose mode
Signed-off-by: Federico Quattrin <federico.quattrin@canonical.com>
2025-06-06 13:56:39 -07:00
Federico Quattrin
22023ce70b added lsusb profile
Signed-off-by: Federico Quattrin <federico.quattrin@canonical.com>
2025-06-06 13:56:39 -07: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
John Johansen
f9c20e4786 Merge parser: set progname explicitly for tst_regex
Otherwise tst_regex would log as being from parser_common.c instead of
being from the actual source of parser_regex.c

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1707
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-06-05 23:14:48 +00:00
Georgia Garcia
9fceca5b88 Merge 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.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1712
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-05 09:33:06 -03: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
9a9f290099 Merge 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)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1709
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-06-04 19:35:58 +00: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
Ryan Lee
6e643a1dab parser: set progname explicitly for tst_regex
Otherwise tst_regex would log as being from parser_common.c instead of
being from the actual source of parser_regex.c

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-06-04 12:05:48 -04:00
Julia Sarris
3c6db7c14b Merge branch apparmor:master into master 2025-06-04 14:27:35 +00: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
e426cc983d Merge Allow lsblk to access Xen PVH disk devices
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2111604

Signed-off-by: Christian Kujau <launchpad@nerdbynature.de>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1702
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-06-03 14:53:55 +00:00
Julia Sarris
b019f9ef08 Merge branch apparmor:master into master 2025-06-03 14:18:41 +00:00
John Johansen
f8b5e5d9a4 Merge profiles: provide backwards compat for hwctl profile
The hwctl profile is being carried upstream, so we can keep it in
sync, but is being packaged from the regular profile set so that it
can be part of a package that is SRUed (ubuntu stable release update)
separate from the rest of apparmor, and its profiles.

Provide backwards compat with older parser to reduce the amount of
distro patching that is needed.

Signed-off-by: John Johansen <john.johansen@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1705
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2025-06-02 21:43:59 +00:00
Julia Sarris
d9d1776579 add owner back to rule lines 2025-06-02 16:29:57 -04:00
Julia Sarris
edf42d4f79 nameservice strict 2025-06-02 09:58:53 -04:00
Julia Sarris
f382920950 private files strict 2025-06-02 09:50:44 -04:00
Julia Sarris
3356f5ea0a Merge branch apparmor:master into master 2025-06-02 13:50:13 +00:00
John Johansen
e80ebea43f Merge Allow noexec mounts in fusermount3 profile
The permissive flags should be revisited once we have rule delegation

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1704
Approved-by: John Johansen <john@jjmx.net>
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2025-06-01 05:24:31 +00:00
John Johansen
df41185eb2 profiles: provide backwards compat for hwctl profile
The hwctl profile is being carried upstream, so we can keep it in
sync, but is being packaged from the regular profile set so that it
can be part of a package that is SRUed (ubuntu stable release update)
separate from the rest of apparmor, and its profiles.

Provide backwards compat with older parser to reduce the amount of
distro patching that is needed.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-05-30 13:24:17 -07:00
John Johansen
421558041b Merge Add additional mount regression tests for options= options in combo
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1703
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2025-05-30 18:26:10 +00:00
Christian Boltz
d315f2b279 Merge logprof: improve LOGPROF-SUGGEST metadata for abstractions
Many profile MRs created with aa-logprof come with abstractions
unrelated to the confined application. This MR allow to restrict
proposed abstractions to related profiles.

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>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1696
Approved-by: Christian Boltz <apparmor@cboltz.de>
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-05-28 15:52:35 +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
Ryan Lee
f826e1dbea Allow noexec mounts in fusermount3 profile
The permissive flags should be revisited once we have rule delegation

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-05-27 15:40:21 -04:00
Ryan Lee
6e16efe703 Add additional mount regression tests for options= options in combo
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-05-27 14:40:26 -04:00
Christian Boltz
0ee95d7e38 Merge utils: Introduce 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>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1612
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-05-26 20:46:56 +00: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
9f4dfdd57e Merge profiles: remove dpkg and lsb_release usage in usr.bin.hwctl
The [hardware-api client project](https://github.com/canonical/hardware-api/tree/main/client) has been simplified, so now we don't use `dpkg` and `lsb_release` there
This PR removes the sub-profiles for these executables.

Also, some denials were detected while running the `hwctl` binary in lxc, so the profile has been updated to fix it as well. See https://github.com/canonical/hardware-api/issues/319 for more

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1701
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-05-26 08:58:44 -03:00
Zygmunt Krynicki
2dacf287f2 Merge ci: build test images explicitly when requested
The recent change to make CI pipeline build test images on a manual
trigger masks the outcome of the pipeline. Let's use the new inputs [1]
feature to allow manually triggering the pipeline with an explicitly
built image instead.

[1] https://docs.gitlab.com/ci/inputs/

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1700
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: Zygmunt Krynicki <me@zygoon.pl>
2025-05-25 19:32:30 +02:00
Christian Kujau
34d889f6e9 Use @{int} instead of ranges
Thanks @cboltz for the hint!
2025-05-25 13:06:08 +00:00
Christian Kujau
1e74ae32ea Allow lsblk to access Xen PVH disk devices
For details, please see:
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2111604
2025-05-23 22:37:45 +00:00
Nadzeya H
cd7586776c
remove dpkg and lsb_release usage in usr.bin.hwctl 2025-05-23 17:16:55 +02: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
Zygmunt Krynicki
5aed9e8a50 ci: build test images explicitly when requested
The recent change to make CI pipeline build test images on a manual
trigger masks the outcome of the pipeline. Let's use the new inputs [1]
feature to allow manually triggering the pipeline with an explicitly
built image instead.

[1] https://docs.gitlab.com/ci/inputs/

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2025-05-22 08:41:15 +02: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
Maxime Bélair
97dc70606b Merge add apparmor profile for dig
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1525
Approved-by: Ryan Lee <rlee287@yahoo.com>
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-05-21 14:48:05 +00:00
Shishir Subedi
be143350fd add apparmor profile for dig 2025-05-21 14:48:05 +00:00