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

2031 Commits

Author SHA1 Message Date
Christian Boltz
b5894687ed
Check for mount rules with multiple 'fstype'
... and adjust the tools to raise an exception if such a rule is found.
While this is not nice, it's better than the previous behaviour where
only the last 'fstype' was kept, and the others were lost when writing
the rule.
2025-04-06 15:19:30 +02:00
Christian Boltz
171e0b1fa9
Check for mount rules with multiple 'options'
... and adjust the tools to raise an exception if such a rule is found.
While this is not nice, it's better than the previous behaviour where
only the last 'options' was kept, and the others were lost when writing
the rule.
2025-04-06 15:19:01 +02:00
Christian Boltz
7726c86b79
mount: accept fstype and options in any order
Note: If multiple fstype= or options= are given, this is not detected as
an error (to keep the regex simpler). When writing back such a rule,
only one fstype and options will "survive".

Adjust the exclude list in test-parser-simple-tests.py accordingly:
- several valid mount rules no longer fail
- two invalid mount rules which so far accidentally raised an exception
  because of the fstype/options order no longer raise this exception
  (conflicting mount options, which are the real reason why these rules
  are invalid, are not detected in the tools)

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/501
2025-04-05 19:18:09 +02:00
John Johansen
2b9f2d2cb7 utils: tests: mark detached mount as tools wrong
The tools are wrong in parsing the detached mount test.

Until that can be fixed, mark the tools as wrong.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-05 00:19:09 -07:00
John Johansen
abe588cea4 Merge utils: skip user config reading in aa-notify when --configdir is given
--configdir is meant for testing and should override all other configs,
instead of being combined with them. Config combination causes aa-notify
test failures if e.g. the user-local config sets filtering options.

Also supply a notify.conf file for exclusive use during testing.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1610
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2025-04-03 21:36:48 +00:00
Ryan Lee
e949653b1a utils: supply a notify.conf for aa-notify tests
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-04-03 12:20:10 -07:00
Ryan Lee
096c8df52b utils: skip user config reading in aa-notify when --configdir is given
--configdir is meant for testing and should override all other configs,
instead of being combined with them. Config combination causes aa-notify
test failures if e.g. the user-local config sets filtering options.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-04-03 12:17:25 -07:00
Ryan Lee
4623da695e utils: add unprivileged_userns to aa-notify list of special profiles
Both the unconfined profile and unprivileged_userns are part of the
default notify.conf, so the default fallback when no configurations are
present should also match this default.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-04-02 16:48:01 -07:00
John Johansen
3b3dada5d9 Merge util: enhance AARE file path validation
Fixes https://bugs.launchpad.net/apparmor/+bug/2106033

Improve the validation of AARE file paths by introducing a new regex
that supports paths starting with '{' (e.g. '{/,/org/freedesktop/DBus}').
These paths are notably used in snap.lxd.* profiles.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1607
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-04-02 18:03:09 +00:00
John Johansen
0d1c694a66 Merge profiles: allow fusermount3 to mount in directories used by flatpak (LP: 2100295)
These are the default directory mounts used by Flatpak's system cache for mounting revokefs-fuse. Unfortunately, the new rules are quite broad, but we might not be able to do much better than that.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1562
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2025-04-02 17:54:13 +00:00
Maxime Bélair
dbf4c27154 util: enhance AARE file path validation
Fixes https://bugs.launchpad.net/apparmor/+bug/2106033

Improve the validation of AARE file paths by introducing a new regex
that supports paths starting with '{' (e.g. '{/,/org/freedesktop/DBus}').
These paths are notably used in snap.lxd.* profiles.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-04-02 18:32:03 +02:00
John Johansen
305ef867fb Merge utils: fix cleanprof recursion error when child is defined out of parent
If the following scenario was present in a profile, cleanprof
would fail with a RecursionError exception (maximum recursion
depth exceeded)

/parent { }
/parent///child { }

This occured because in aa.py, in the write_piece function, the
wrong depth was being passed, along with a wrong hat. The
formatting of the spaces was also incorrect.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1605
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-04-01 21:03:56 +00:00
John Johansen
60218409cc Merge logprof: add /usr prefixed kernel module path to config for /usr merge
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1598
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>
2025-04-01 20:51:53 +00:00
Georgia Garcia
f0c96c0d68 utils: fix cleanprof recursion error when child is defined out of parent
If the following scenario was present in a profile, cleanprof
would fail with a RecursionError exception (maximum recursion
depth exceeded)

/parent { }
/parent///child { }

This occured because in aa.py, in the write_piece function, the
wrong depth was being passed, along with a wrong hat. The
formatting of the spaces was also incorrect.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-04-01 16:48:24 -03:00
Georgia Garcia
f490480558 utils: add parent to external child profiles
Profiles that are defined like below did not have the parent attribute
set in profile storage:

/parent///child {}

The condition on which child profiles were written was also changed so
they are not removed from the profile if /parent does not exist.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-04-01 16:46:16 -03:00
Christian Boltz
4c3954f13d test-cleanprof: add tests for external child profiles 2025-03-31 15:50:15 -03:00
Georgia Garcia
699d7b5c83 utils: fix cleanprof regression on header generation
Commit c9d41a3ebb introduced a regression on profile header
generation.

This commit removes the name parameter from the get_header function
since the ProfileStorage should already contain all the information
required to generate the header for profiles and hats. The tests
needed to be updated as well to make sure the ProfileStorage object
contained the information needed by the get_header method.

Fixes: c9d41a3ebb ("utils: fix profile and hat header generation")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-03-31 15:50:15 -03:00
Ryan Lee
372dcc8250 logprof: add /usr prefixed kernel module path to config for /usr merge
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-03-27 09:50:11 -07:00
Georgia Garcia
c9d41a3ebb utils: fix profile and hat header generation
The header was being generated incorrectly in 2 cases:
When the profile/hat contained the parent profile in its name, as in

profile firefox//dash {
hat ^firefox//dash {

and in the unit tests, the child profile or hat was being named as the
parent profile. This was not caught by the general case because the
code has not yet been fully adapted to handle multiple nested child
profiles.

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

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-03-26 09:53:08 -03:00
John Johansen
e030ff7ea9 Merge utils/test/test-aa-notify.py: update last cmd for lxd VMs
When doing testing via LXD VMs and in particular when using "lxc exec" to run
commands in the VM, there is no controlling tty and so the output of last is
missing this column of data. Instead try even harder to parse the timestamp from
the output of "last".

Signed-off-by: Alex Murray <alex.murray@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1582
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-03-19 06:17:34 +00:00
Alex Murray
b6654416b0
utils/test/test-aa-notify.py: update last cmd for lxd VMs
When doing testing via LXD VMs and in particular when using "lxc exec" to run
commands in the VM, there is no controlling tty and so the output of last is
missing this column of data. Instead try even harder to parse the timestamp from
the output of "last".

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2025-03-18 17:45:00 +10:30
John Johansen
2fb0fa9964 Merge add support for writing quoted mount source and mountpoints
Add quotes if a mount source or mountpoint includes whitespace.
Also explicitely handle empty mount source (known from
1f33fc9b29c174698fdf0116a4a9f50680ec4fdb)

As usual, some tests can't hurt ;-)

I propose this fix for 4.0..master

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1573
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-03-18 04:56:22 +00:00
John Johansen
e065dfb35a Merge utils: Improve regex for mount source and target
* Make glob_pattern more readable
    - replace filename and variable regex parts with RE_PROFILE_PATH_OR_VAR
    - split to multiline string

* Move `[\w-]+` into inner match group by removing/moving the ')' after the empty source.

* Prepare source_fileglob_pattern and dest_fileglob_pattern to be customizable by moving adding the closing ')))' into each of them.

* Allow empty source and any word only in mount source

See the individual commits for details.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1574
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-03-18 04:55:21 +00:00
John Johansen
e38db72fea Merge parser: add support for attach_disconnected.ipc flag
The attach_disconnected.ipc flag allows the use of disconnected paths
on posix mqueues. This flag is a subset of attach_disconnected, and it
does not allow disconnected paths for all files.

Corresponding kernel patch needed to test in https://gitlab.com/georgiag/apparmor-kernel/-/tree/mqueue-ext
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1577
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-03-13 18:56:30 +00:00
Georgia Garcia
541d3f4489 parser: add attach_disconnected.ipc parser tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-03-13 14:51:18 -03:00
Christian Boltz
1ff9306c93
UnixRule: allow comma as separator in peer=
... and add some tests for it
2025-03-13 17:22:24 +01:00
Georgia Garcia
b0b45b01c0 utils: don't skip disabled profiles for aa-enforce
When running aa-disable and then aa-enforce passing the binary path as
the argument, aa-enforce fails to enforce the profile with the error:

$ sudo aa-disable /home/foo/test
skipping disabled profile test
Profile for /home/foo/test not found, skipping

According to the man page for aa-enforce, it should work for disabled
profiles.

Note that this does not happen when passing the profile directly to
the tools, so there's a workaround for this issue:

$ sudo /aa-enforce /etc/apparmor.d/test
Setting /etc/apparmor.d/test to enforce mode.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-03-13 10:58:30 -03:00
Christian Boltz
ae20b62c31
Allow empty source and any word only in mount source 2025-03-11 21:51:42 +01:00
Christian Boltz
537fec8b36
Move [\w-]+ into inner match group
... by removing/moving the ')' after the empty source.

Also prepare source_fileglob_pattern and dest_fileglob_pattern to be
customizable by moving adding the closing ')))' into each of them.
2025-03-11 21:50:43 +01:00
Christian Boltz
2843c0f155
Make glob_pattern more readable
- replace filename and variable regex parts with RE_PROFILE_PATH_OR_VAR
- split to multiline string
2025-03-11 21:50:43 +01:00
Christian Boltz
d06260859b
add support for writing quoted mount source and mountpoints
Add quotes if a mount source or mountpoint includes whitespace.
Also explicitely handle empty mount source (known from
1f33fc9b29c174698fdf0116a4a9f50680ec4fdb)

As usual, some tests can't hurt ;-)
2025-03-11 21:07:14 +01:00
Christian Boltz
2afdf1b214 Merge utils: Fix mount rule handling for revokefs-fuse
First expand nested `(...)` in glob_pattern. This duplicates a few bytes, but makes the regex easier to read.

With that done, allow `-` in glob_pattern.

One of the possible matches in glob_pattern was `\w+` which matched for example `none`.

However, it doesn't match `revokefs-fuse` because of the `-`. Therefore change `\w+` to [\w-]+.

While on it, add two more tests - one for `none` with some options, and one with `revokefs-fuse`.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1565
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-03-10 20:35:57 +00:00
Bo YU
ca0afa1afb Increase timeout for test_allow_all 2025-03-04 08:36:54 +00:00
Christian Boltz
ce87b44bae
glob_pattern: allow -
One of the possible matches in glob_pattern was `\w+` which matched for
example `none`.

However, it doesn't match `revokefs-fuse` because of the `-`. Therefore
change `\w+` to [\w-]+.

While on it, add two more tests - one for `none` with some options, and
one with `revokefs-fuse`.
2025-02-28 23:47:05 +01:00
Christian Boltz
c1712c882c
Expand nested (...) in glob_pattern
This duplicates a few bytes, but makes the regex easier to read.
2025-02-28 23:20:46 +01:00
Ryan Lee
930218193b utils: remove the skip_*_profiles testing bypass
The utils should be able to skip profiles that it can't parse now,
so this test suite bypass mechanism should no longer be necessary.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-02-27 16:48:46 -08:00
Ryan Lee
e80d5bd3d4 utils: test in test-minitools for resiliency against unparseable profiles
Since all the tools that load profiles go through the same module, this should
be sufficient as a first pass.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-02-27 16:48:41 -08:00
Ryan Lee
e71e27be70 utils: make read_profiles robust against profiles it doesn't understand
This will allow the other tools to continue working on other profiles, even
if some of them use syntax that the utils currently can't handle.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-02-27 16:46:22 -08:00
Ryan Lee
df0358062d utils: test: expand mechanism for ignoring profiles in tests
The utils cannot parse some of the newer profile constructs yet, so
generalize a pre-existing mechanism for skipping profiles to use that mechanism in the other tests that need it

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-02-27 13:05:00 -08:00
Christian Boltz
db7e3109cc
test-translations: include "ignore" in exec prompts
This is a follow-up of adding the "ignore" option to exec prompts in
https://gitlab.com/apparmor/apparmor/-/merge_requests/1543
2025-02-24 13:35:08 +01:00
Christian Boltz
3e7e9bf01f
test-translations: display all hotkey conflicts at once
... instead of erroring out at the first conflict.

Also display all options involved in a hotkey conflict to make fixing it
easier.
2025-02-24 13:35:05 +01:00
John Johansen
2a87a92136 Import translations from launchpad
This imports translations from 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 01:28:04 -08:00
John Johansen
125ef7a8cb utils: genprof/logprof - fix missing newline nit in MR1543
This is a trivial fix for
  MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1543

instead of waiting longer for the auther to fix, the MR was merged
and this manual fixup done.

Fixes: dfe9d713f ("aa-logprof/aa-genprof: allow ignoring executions")
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-02-19 10:53:47 -08:00
John Johansen
71282550bb Merge aa-logprof/aa-genprof: allow ignoring executions
fixes https://gitlab.com/apparmor/apparmor/-/issues/302

Closes #302
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1543
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-02-19 18:48:50 +00:00
John Johansen
a410f347a3 aa-notify: rename polkit files and template info from com.ubuntu
We should be using apparmor controlled domains for these files.

Rename the template file from
  com.ubuntu.pkexec.aa-notify.policy
to
  net.apparmor.pkexec.aa-notify.policy

And update the template file and the install file so that the files
that are generated use net.apparmor instead of com.ubuntu

Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-02-14 11:49:49 -08:00
John Johansen
697e53d752 Merge aa-notify: fix package build install of polkit files
The install of the polkit action files for aa-notify leaks build root
information.

From OBS
  apparmor-utils.noarch: E: file-contains-buildroot (Badness: 10000) /usr/share/polkit-1/actions/com.ubuntu.pkexec.aa-notify.policy

this is present on Ubuntu as well
    <annotate key="org.freedesktop.policykit.exec.path">/build/apparmor-ZUzkoL/apparmor-4.1.0~beta4/debian/tmp/usr/lib/python3/dist-packages/apparmor/update_profile.py</annotate>

this occurs because the {LIB_PATH} template variable is being replaced
with the self.install_lib. Make sure we strip the build prefix if
we are generating the files in a build environment instead of doing
a direct install.

Closes: https://gitlab.com/apparmor/apparmor/-/issues/486
Signed-off-by: John Johansen <john.johansen@canonical.com>

Closes #486
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1540
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: John Johansen <john@jjmx.net>
2025-02-14 19:32:27 +00:00
Sergey Alirzaev
dfe9d713f0
aa-logprof/aa-genprof: allow ignoring executions
fixes https://gitlab.com/apparmor/apparmor/-/issues/302
2025-02-14 17:31:54 +01:00
John Johansen
b4e6f0449b aa-notify: fix package build install of polkit files
The install of the polkit action files for aa-notify leaks build root
information.

From OBS
  apparmor-utils.noarch: E: file-contains-buildroot (Badness: 10000) /usr/share/polkit-1/actions/com.ubuntu.pkexec.aa-notify.policy

this is present on Ubuntu as well
    <annotate key="org.freedesktop.policykit.exec.path">/build/apparmor-ZUzkoL/apparmor-4.1.0~beta4/debian/tmp/usr/lib/python3/dist-packages/apparmor/update_profile.py</annotate>

this occurs because the {LIB_PATH} template variable is being replaced
with the self.install_lib. Make sure we strip the build prefix if
we are generating the files in a build environment instead of doing
a direct install.

Closes: https://gitlab.com/apparmor/apparmor/-/issues/486
Co-Author: Ryan Lee <ryan.lee@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-02-13 16:42:50 -08:00
John Johansen
226ab5f050 Merge utils: aa-genprof fails on lxd with OSError: Read-only file system
On certain lxc containers, when aa-genprof tries to set
printk_ratelimit, it fails with the OSError exception, with the
message "OSError: [Errno 30] Read-only file system" instead of
PermissionError.

Since PermissionError is a subclass of OSError, replace it by broader
OSError exception to include both cases in which running aa-genprof
fails.

Reported-by: Paulo Flabiano Smorigo <paulo.smorigo@canonical.com>
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1539
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-02-13 22:34:22 +00:00
Ryan Lee
2747013d9b utils: allow install locations to be overridden in Makefile
Instead of setting those variables unconditionally, set them if they
aren't externally set by environment variables. This will allow for usages
like DESTDIR=/some/other/dir make install in the utils directory.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-02-13 13:00:51 -08:00