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

8273 Commits

Author SHA1 Message Date
John Johansen
ad16a5c5c0 Merge parser: refactor variables and symbols table into their own class
While symtab for now has only static members, it will allow for a
change in the future for each profile to have their own symbols like
profile_name, etc.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1711
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-07-17 23:08:39 +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
Christian Boltz
630fd1c285 Merge 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>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1735
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-07-16 12:32:26 +00: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
1c2f3582fe Merge 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.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1720
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-07-15 21:49:48 +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
1c9dc33949 Merge Split test classes
Create separate classes for tests not fitting under *TestParseInvalid

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1736
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-07-15 19:00:26 +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
b2bfde5af0 Merge Introduce AATest.parseInvalidRule()
... and change all *TestParseInvalid classes to use it, instead of
having (nearly) the same function in every test-*.py.

Also move tests not matching the rule regex into tests array (which now supports this case).

While at it, enable the tests for abi and include rules.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1728
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-07-15 18:31:00 +00:00
Christian Boltz
fc636c7ff3 Merge Profiles: dovecot add access for dovecot 2.4 doveconf paths
Dovecot 2.4 now creates a "binary" version of its config via doveconf. This needs new access rules, as it otherwise prevents all Dovecot processes from accessing this new configuration.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1733
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-07-15 18:15:56 +00:00
Christian Pfeiffer
021f701e59
Profiles: dovecot add access for dovecot 2.4 doveconf paths 2025-07-13 23:26:26 +02:00
Louis Sautier
f16dd60f14
lsblk: allow access to PCI buses with hex chars
This fixes the following error when a block device's PCI bus starts with
a non-decimal hex character and `lsblk /dev/nvme2n1` is executed:
```
audit: type=1400 audit(1751394406.516:554): apparmor="DENIED" operation="open" class="file" profile="lsblk" name="/sys/devices/pci0000:a0/0000:a0:01.1/0000:a1:00.0/nvme/nvme2/nvme2n1/" pid=164652 comm="lsblk" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
```
I used hex4 and hex2 as it matches the example from
https://docs.kernel.org/PCI/sysfs-pci.html and also because lspci(8)
says:
> domains are numbered from 0 to ffff
>
> bus (0 to ff)

Bug: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2111604
Signed-off-by: Louis Sautier <sautier.louis@gmail.com>
2025-07-01 21:07:35 +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
Georgia Garcia
dfbd2dc4b1 parser: refactor variables and symbols table into their own class
While symtab for now has only static members, it will allow for a
change in the future for each profile to have their own symbols like
profile_name, etc.
2025-06-25 12:29:17 -03:00
Georgia Garcia
0ea74cd19d parser: add test for when slash should not be filtered
According to commit cce5bd6e95ae9a9f01caceea0d5d75b612dd3fbc, the
apparmor_parser does not collapse consecutive / characters in the
beginning of paths, since it indicates posix namespaces. Add a
equality test to make sure we maintain this behavior.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-25 12:29:17 -03:00
Christian Boltz
0f76632aec Merge 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.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1718
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-06-24 16:32:15 +00: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
Maxime Bélair
83e9be1035 Merge Add free profile
Basic AppArmor profile for the free binary, tested on Ubuntu 24.04.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1629
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-06-23 14:11:07 +00:00
Maxime Bélair
91c5e9639c Merge Add curl profile
In order to test the profile, I did the following inside an oracular VM:

- `curl https://ubuntu.com/ -o /tmp/ubuntu`
- `curl 'https://ubuntu.com/security/{CVE-2024-12797,CVE-2025-24032}' -o '#1'`
- `curl -u dlpuser:rNrKYTX9g7z3RgJRmxWuGHbeu ftp://ftp.dlptest.com/`

Finally, I ran the package's testsuite:
```
apt source curl
cd curl-8.9.1
./configure --without-ssl # SSL has been tested using the above
make
cd test/server
make
cd ..
./runtests.pl -c $(which curl)
```

The only test which should fail should be the last one, since the build was configured with support for less protocols than the ones provided by the binary we're using (this is expected and happens regardless of whether the profile is loaded or not).

A spread smoke-test is also provided as part of this MR.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1560
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-06-23 13:49:24 +00:00
Octavio Galland
37a4b6cb81 Add curl profile 2025-06-23 13:49:23 +00:00
Maxime Bélair
a431a6e80b Merge profiles/apparmor.d: add mosquitto profile
Adds apparmor profile for https://mosquitto.org/ `plucky 2.0.20-2`.

In a production and customized environment, this profile would need overriding as many configuration options in `mosquitto.conf` are file paths which can point anywhere. This profile adds all sensible defaults required for mosquitto to work out of the box with TLS.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1506
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-06-23 13:28:55 +00:00
Maxime Bélair
61a3a4862e Merge Add profile for mbsync tool
Source package isync

Let me know if you think we should better handle any mail or different mbsyncrc location that the user might have.
As well if I should simplify the network access to `include <abstractions/nameservice>` or if that's too much.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1372
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-06-23 13:25:41 +00:00
Maxime Bélair
2c685c0a17 Merge Add dnstracer profile
Add profile for `dnstracer`. The profile has been tested with `dnstracer` for oracular i.e. version `1.9-8build1`.

Signed-off-by: vyomydv <vyom.yadav@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1366
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-06-23 08:09:56 +00: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
John Johansen
17f91ba6e2 Merge profiles: restore exec path rules from profiles where they were removed
Fixes: 6e9ff1fa6 ("profiles: update the rest of the profiles to use @{exec_path}")

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1721
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-06-17 18:22:03 +00:00
Ryan Lee
9a04cd58a6 profiles: restore exec path rules from profiles where they were removed
These profiles don't have an attachment so the path needs to be hardcoded

Fixes: 6e9ff1fa6 ("profiles: update the rest of the profiles to use @{exec_path}")
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-06-17 10:53:14 -07:00
Christian Boltz
c35d5eb6b2 Merge utils test cleanup
Various test cleanups, see the individual commits for details.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1717
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-06-16 19:31:40 +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
Christian Boltz
a606397417 Merge Update utils/aa-notify to add running in the foreground and continue on "read_profiles" permission error
Hello!

I run AppArmor daily on my personal machine and use `aa-notify` to receive alerts for any audit events. I wanted to submit two features and one bugfix for problems that I've seen while running `aa-notify`.

### Here are the two features in this merge request:

1. Allow `aa-notify` to run in the foreground.
   I understand that `aa-notify` is ment to be run as a background notification daemon, however there are situations when running in the foreground would be better suited. One example is any startup "launcher" that creates and monitors it's child processes (my setup basically does this) and when `aa-notify` forks, the launcher percieves it as crashing on startup.
   This merge request adds an option "-F"/"--foreground" to prevent background forking and perserves the default behavior, while allowing `aa-notify` to run like a standard foreground application. The test cases in `utils/test/test-aa-notify.py` are also updated to reflect the argument changes.

2. Prevent `aa-notify` from exiting with a fatal error when the AppArmor profiles directory cannot be read.
   During startup, `aa-notify` will attempt to read the AppArmor profiles from the profile directory using the `aa.read_profiles` function. If this function fails due to a permissions check, `aa-notify` will exit with an error. In my setups, the standard user does not have any read access to the AppArmor profiles directory (reasoning: as an attacker, I could read the profiles to find something that would have the weakest permissions for explitation, but with that route blocked, this becomes significantly harder). In this merge request, an optional paramater `skip_perm_error` that is by-default False, is added to the `read_profiles` function call in `aa-notify`. In `aa.py`, this function has two added lines, which are under `except (OSError, TypeError):`. The extra code checks if `skip_perm_error` is True, and if so will print a warning out using the `aaui.UI_Info` function and returns cleanly. During my test cases, I have not run into any issues running `aa-notify` without reading any profiles.

### BugFixes

1. Crash during `aa-notify` polling during audit events that cause `rl.parse_record(event)` to return None
   I've noticed certain events will cause `aa-notify` to crash, specifically the ones in the attached log snipped will cause `ev` to be `None`.
   In this merge request, I've added a simple `if ev is None:` check before attempting to read from `ev`. If `ev` is None, it will fall into `continue` and prevent a crash from occuring. The crash log is also attached for additional information.

Please let me know if there's any additional questions or information you may need! And thank you for all your hard work on this project!

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1706
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-06-14 15:07:44 +00: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
Georgia Garcia
0dfa2fb9f2 Merge Deduplicate example rules in apparmor.d manpage
foo.pid is also matched by foo.* (which has broader permissions)

Reported in https://gitlab.com/apparmor/apparmor/-/work_items/524#note_2555705082

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1715
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-12 15:54:20 -03:00
Georgia Garcia
af396a46ee profiles: add mount permissions to fusermount3 needed by flatpak-builder
There were failures in the flatpak-build autopkgtests due to missing
mount permissions:

[   60.822732] audit: type=1400 audit(1749737394.684:168): apparmor="DENIED" operation="mount" class="mount" info="failed mntpnt match" error=-13 profile="fusermount3" name="/var/tmp/test-flatpak-uuKcEE/.flatpak-builder/rofiles/rofiles-JxeDhQ/" pid=3150 comm="fusermount3" fstype="fuse.rofiles-fuse" srcname="rofiles-fuse" flags="rw, nosuid, nodev"
[   60.825556] audit: type=1400 audit(1749737394.686:169): apparmor="DENIED" operation="mount" class="mount" info="failed mntpnt match" error=-13 profile="fusermount3" name="/var/tmp/test-flatpak-uuKcEE/.flatpak-builder/rofiles/rofiles-JxeDhQ/" pid=3151 comm="fusermount3" fstype="fuse" srcname="/dev/fuse" flags="rw, nosuid, nodev"
[  918.564687] audit: type=1400 audit(1749738252.435:186): apparmor="DENIED" operation="umount" class="mount" profile="fusermount3" name="/var/tmp/test-flatpak-AI4MsP/.flatpak-builder/rofiles/rofiles-vIM7ok/" pid=7093 comm="fusermount"

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-12 15:08:07 -03:00
Georgia Garcia
9d2aca7945 profiles: add ix permissions for mount and umount on fusermount3 profile
After an upgrade to libfuse 3.17.1-rc0, autopkgtests started to fail
due to a missing x permission for /usr/bin/mount. After looking at the
source code for fusermount, I noticed that it does call /bin/mount and
/bin/umount in certain cases. These uses were already there in
previous versions of libfuse but I'm still not sure why it hasn't
triggered before.

To reproduce it:
sudo autopkgtest-buildvm-ubuntu-cloud -v -r questing
autopkgtest archivemount -U --apt-pocket=proposed=src:fuse3 --shell-fail -- qemu autopkgtest-questing-amd64.img

After the test fails, enter the vm by

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022 ubuntu@localhost

You can reproduce the test by running

cd /tmp/autopkgtest.*/build.*/src/
/tmp/autopkgtest.*/build.*/src/debian/tests/test

Note that ix for mount and umount were enough to make the autopkgtest
failures to start passing, but there could be issues in the future
regarding the use of fs specific mount binaries like
/usr/sbin/mount.fuse

Fixes: http://bugs.launchpad.net/bugs/2111845
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-12 14:23:32 -03:00
Maxime Bélair
d068678112 Merge initial john the ripper
@jjohansen had mentioned to me when he suggested this profile that there was smth he noticed about john that gave him the impression it was a good candidate for confinement. I think that would be the only thing I'd want to call out - wondering whether something like this captures that spirit or if there's something else worth including.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1662
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-06-12 05:56:26 +00:00
Christian Boltz
fbea9f00df
Deduplicate example rules in apparmor.d manpage
foo.pid is also matched by foo.* (which has broader permissions)

Reported in https://gitlab.com/apparmor/apparmor/-/work_items/524#note_2555705082
2025-06-11 14:34:20 +02:00
Eduardo Barretto
3d25f1c80f
profiles: mbsync: Allow mmap as it is needed for other architectures 2025-06-11 11:33:34 +02:00
Eduardo Barretto
a7003f4d49
profiles: mbsync: Use openssl abstraction instead 2025-06-11 11:33:30 +02:00
Eduardo Barretto
bb422c1f01
profile: mbsync: Move vim tag 2025-06-11 11:33:27 +02:00
Eduardo Barretto
76338c29f2
mbsync: Add read to gss
This was needed when testing the profile in Oracular
2025-06-11 11:33:23 +02:00
Eduardo Barretto
00a1152700
mbsync: Add missing write permission to create any folders existent 2025-06-11 11:33:20 +02:00
Eduardo Barretto
5f0fcfcae9
profiles: mbsync: make use of nameservice-strict abstraction
Signed-off-by: Eduardo Barretto <eduardo.barretto@canonical.com>
2025-06-11 11:33:16 +02:00