Commit graph

6281 commits

Author SHA1 Message Date
Christian Boltz
b904fe78a7 Merge Make BaseRule a proper abstract base class
This closes #277 by introducing the following changes:
1. `BaseRule` was made a "proper" abstract base class in that it now enforces that subclasses implement all abstract methods.
2. As a consequence of this change, `BaseRule` can no longer be directly instantiated; tests were changed accordingly.
3. These test changes led to test failures, the reason being that many rule methods hardcoded class names, breaking inheritance. I made a commit to address this.
4. Once tests were passing, code coverage regressed due to the fact that there was now effectively-unreachable code in abstract instance methods. This code, which was only raising `NotImplementedError`s, was removed. I say "effectively-unreachable" here because it could be reached by calling `super()` via a subclass.
5. There are three "bonus" commits as well; one bug fix, one typo fix, and one cleanup.

Closes #277
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/930
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-11-15 21:14:19 +00:00
Christian Boltz
50074a3c01 Merge Catch PermissionError when trying to write a profile
... and re-raise it as AppArmorException so that only the actual error
(without a backtrace) gets displayed.

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

I propose this patch for 3.0..master.

Closes #282
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/946
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-11-15 20:45:59 +00:00
Christian Ehrhardt
c159d0925a Allow access to possible cpus for glibc-2.36
Glibc in 2.36 and later will [1] access sysfs at
/sys/devices/system/cpu/possible when usig sysconf
for _SC_NPROCESSORS_CONF.

That will make a lot of different code, for example
anything linked against libnuma, trigger this apparmor
denial.

  apparmor="DENIED" operation="open" class="file" ...
  name="/sys/devices/system/cpu/possible" ...
  requested_mask="r" denied_mask="r" fsuid=0 ouid=0

This entry seems rather safe, and it follows others
that are already in place. Instead of fixing each
software individually this should go into the base
profile as well.

Initially reported via
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1989073
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/267
MR: none - ML
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-11-14 21:45:55 -08:00
Christian Boltz
d0ec2acaf2
Catch PermissionError when trying to write a profile
... and re-raise it as AppArmorException so that only the actual error
(without a backtrace) gets displayed.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/282
2022-11-14 22:50:27 +01:00
Mark Grassi
7bb9f45047 Empty enforced abstract instance methods 2022-11-13 19:56:53 -05:00
Mark Grassi
436a5774be Fix typo 2022-11-13 19:41:48 -05:00
Mark Grassi
0b625e92b7 Fix AttributeError missed in Python 3 migration 2022-11-13 19:41:48 -05:00
Mark Grassi
8300615833 Remove hardcoded class names 2022-11-13 19:41:48 -05:00
Mark Grassi
852169948f Make BaseRule a proper abstract base class 2022-11-13 19:32:01 -05:00
John Johansen
9107a0d891 sync library version with 3.1 release
The 3.1 release bumped its library version, and for consistency
needs to be bumped here as well.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-11-08 11:35:41 -08:00
Christian Boltz
1c04b4e2bd Merge utils: add userns python tool support
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/944
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-11-04 15:57:38 +00:00
Georgia Garcia
4fb9b3d42b utils: add userns python tool support
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-04 12:39:18 +00:00
John Johansen
6151a917ce Merge Support rule qualifiers in regression tests
This allows regression tests to generate profiles that use rule qualifiers,
such as allow, deny, and audit. Qualifiers can be specified for a rule by
prepending 'qual=', followed by a comma-separated list of rule qualifiers,
then a ':', then the rule itself.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/925
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-11-04 10:32:36 +00:00
Jon Tourville
f6bfd141bd Support rule qualifiers in regression tests
This allows regression tests to generate profiles that use rule qualifiers,
such as allow, deny, and audit. Qualifiers can be specified for a rule by
prepending 'qual=', followed by a comma-separated list of rule qualifiers,
then a ':', then the rule itself.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2022-11-04 09:27:17 +00:00
Georgia Garcia
5e82f522c1 Merge add user namespace regression tests
These tests run for both root and user, and for that I'm using @jontourville's !941 

Test cases were based on the description in the [unprivileged_userns_restriction](https://gitlab.com/apparmor/apparmor/-/wikis/unprivileged_userns_restriction) wiki page

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/943
Approved-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-04 09:10:01 +00:00
Georgia Garcia
0727da47b3 tests: add userns regression tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-04 08:29:45 +00:00
Georgia Garcia
ffd74aadb1 tests: extend kernel_features to support check for feature in file
The test kernel_features only checked if the feature file exists, but
there are cases when we need to check if the feature is part of the
file's content. For example, we might want to check if a mode is present
in the feature "mask" file.

This is already supported by libapparmor's aa_features_supports.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-04 08:29:07 +00:00
John Johansen
571cec5036 Merge Add regression test summary
Print out a summary of the tests that passed and failed at the end of the
regression tests. Merge the tests and alltests make targets since they
only differ in which tests are run.


Signed-off-by: Jon Tourville <jon.tourville@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/942
Approved-by: Steve Beattie <gitlab@nxnw.org>
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-11-03 13:20:20 +00:00
John Johansen
f044d92166 Merge Add ability to execute tests as different users
This update to the regression test framework allows a test script to
execute a test binary as a different user by passing '-u <username>'
to the settest function.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/941
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-11-03 13:19:08 +00:00
Jon Tourville
e30696c484 Add regression test summary
Print out a summary of the tests that passed and failed at the end of the
regression tests. Merge the tests and alltests make targets since they
only differ in which tests are run.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2022-11-03 12:44:21 +00:00
Jon Tourville
f525706407 Add ability to execute tests as different users
This update to the regression test framework allows a test script to
execute a test binary as a different user by passing '-u <username>'
to the settest function.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2022-11-01 15:40:18 +00:00
John Johansen
8fa77e9e6c Merge Adds WSL programmatic management of /etc/resolv.conf.
When WSL automatically generates a resolv.conf for an instance, the /etc/resolv.conf file is a symlink to /mnt/wsl/resolv.conf. This patch adds an entry for this to the other policies to handle such management.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/935
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-10-29 12:51:42 +00:00
John Johansen
37f0f77425 Merge Allow reading /sys/devices/system/cpu/possible
... in the dnsmasq//libvirt_leaseshelper profile

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

I propose this patch for 3.0, 3.1 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/917
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2022-10-29 12:50:44 +00:00
John Johansen
e049b31c04 Merge syslog-ng: allow reading *.journal in flatter directory structure
On openSUSE Leap 15.4 (and probably also 15.3), the journal lives in
/var/log/journal/*.journal - without an additional subdirectory level.

I propose this patch for 2.13..master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/932
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-10-28 12:45:48 +00:00
John Johansen
299a7386f4 Merge tests/regression: Add simple e2e test
This adds a single e2e test to check that raw_data of a loaded
policy matches the generated policy (cached).

Signed-off-by: Spyros Seimenis <spyros.seimenis@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/929
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-10-28 12:44:31 +00:00
John Johansen
bed1471144 Merge Hardcode and check the expected libapparmor.so name/number
... to prevent wrong/unexpected numbering (like
https://gitlab.com/apparmor/apparmor/-/issues/266) in future releases.

I propose this patch for master and 3.1.

Backporting to 3.0 and 2.x might also make sense, but of course needs a different .so number.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/915
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-10-28 12:35:53 +00:00
John Johansen
7f83444f93 Merge Add test for nfs file access
Add test to verify that file access on a mounted NFS share is determined
by file rules and not network rules. This relies on a kernel patch, so
the tests are marked xpass.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/895
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-10-28 12:34:31 +00:00
John Johansen
b911ca16d9 Merge add userns log entry in libapparmor tests
Log entries for userns add `class`, `requested`, and `denied`, so I cherry-picked the commits that handle that from the message queue MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/858

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/939
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-10-28 10:29:44 +00:00
John Johansen
0d61139e2a Merge libapparmor: allow parsing of logs with 0x1d + uppercase items
audit.log lines on Arch have an additional FSUID="username" OUID="username",
separated from the previous part of the log line with 0x1d.

Extend the log parsing to accept 0x1d as whitespace, and to recognize
(and ignore) FSUID and OUID.

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

Also add one of the log lines from #271 as test_multi test case.

I propose this patch for 3.0..master.

Closes #271
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/940
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-10-28 10:25:23 +00:00
Christian Boltz
fab4b4e762 Merge samba-rpcd-spoolss: allow mkdir /var/cache/samba/printing/
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1993572

I propose this fix for 3.0..master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/937
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-10-27 22:33:56 +00:00
Christian Boltz
e933b08bd9
Add test_multi testcase from #271
This testcase from https://gitlab.com/apparmor/apparmor/-/issues/271 has
a log line with FSUID and OUID, separated by 0x1d.
2022-10-27 21:04:53 +02:00
Christian Boltz
87e4d302cd
libapparmor: allow parsing of logs with 0x1d + uppercase items
audit.log lines on Arch have an additional FSUID="username" OUID="username",
separated from the previous part of the log line with 0x1d.

Extend the log parsing to accept 0x1d as whitespace, and to recognize
(and ignore) FSUID and OUID.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/271
2022-10-27 21:01:37 +02:00
Georgia Garcia
e492eb34b1 libapparmor tests: add userns denied logs
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 18:24:55 +00:00
Steve Beattie
be61c5d22d libapparmor: fix a typo in grammar.y
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/938
Approved-by: Steve Beattie <steve@nxnw.org>
Merged-by: Steve Beattie <steve@nxnw.org>
2022-10-27 18:21:57 +00:00
Georgia Garcia
5cc7a26e78 libapparmor: add support for class in logparsing
We want to use the class field to identify operations such as
posix_mqueue

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 18:16:53 +00:00
Georgia Garcia
a05c9483f3 libapparmor: add support for requested and denied on logparsing
In order to decrease the number of characters in the audit logs
from the kernel, we will drop the "_mask" from the fields
"requested_mask" and "denied_mask".

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 18:16:53 +00:00
Georgia Garcia
19e7016068 Merge add support for user namespace creation
the only supported mode for the moment is `create`, so the following rules have the same effect
```
userns,
userns create,
```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/927
Approved-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 18:16:11 +00:00
Christian Boltz
5f36521e9f
Fix a typo in libapparmor grammar.y 2022-10-27 20:08:07 +02:00
Georgia Garcia
ef54144357 parser tests: add userns simple tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 17:54:42 +00:00
Georgia Garcia
f400b41c4a parser: add support for user namespace creation
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 17:54:42 +00:00
Christian Boltz
6920daea49
samba-rpcd-spoolss: allow mkdir /var/cache/samba/printing/
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1993572
2022-10-27 18:32:46 +02:00
Christian Boltz
18d1b06b0c Merge abstactions/kde: update for kwinrc, kdedefaults/* files
GUI applications such as KDE dragon player, qTox, LibreOffice tries to
access .config/kwinrc, .config/kdedefaults/kwinrc and
.config/kdedefaults/kdeglobals.

Update abstractions/kde to fix denials for applications running under
KDE.

Some examples:
```
type=AVC msg=audit(1666458796.112:5561): apparmor="DENIED" operation="open" profile="libreoffice-soffice" name="/home/vincas/.config/kdedefaults/kdeglobals" pid=43868 comm="soffice.bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666458796.204:5683): apparmor="DENIED" operation="open" profile="libreoffice-soffice" name="/home/vincas/.config/kdedefaults/kwinrc" pid=43868 comm="soffice.bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"

```
```
type=AVC msg=audit(1666462415.255:3640): apparmor="DENIED" operation="open" profile="kde-dragon-player" name="/home/vincas/.config/kdedefaults/kdeglobals" pid=8344 comm="dragon" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666462415.343:3641): apparmor="DENIED" operation="open" profile="kde-dragon-player" name="/home/vincas/.config/kdedefaults/kwinrc" pid=8344 comm="dragon" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
```

```
type=AVC msg=audit(1666459466.968:5852): apparmor="DENIED" operation="open" profile="qtox" name="/home/vincas/.config/kdedefaults/kdeglobals" pid=44561 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666459467.076:6057): apparmor="DENIED" operation="open" profile="qtox" name="/home/vincas/.config/kdedefaults/kwinrc" pid=44561 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666459467.076:6058): apparmor="DENIED" operation="open" profile="qtox" name="/home/vincas/.config/kwinrc" pid=44561 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"

```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/936
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-10-22 19:28:25 +00:00
Vincas Dargis
d9dc0b61e3 abstactions/kde: update for kwinrc, kdedefaults/* files
GUI applications such as KDE dragon player, qTox, LibreOffice tries to
access .config/kwinrc, .config/kdedefaults/kwinrc and
.config/kdedefaults/kdeglobals.

Update abstractions/kde to fix denials for applications running under
KDE.
2022-10-22 21:58:17 +03:00
Alistair Young
5232eaa2d5 Adds /mnt/wsl/resolv.conf to nameservices. 2022-10-21 16:33:46 +00:00
Christian Boltz
fed907431e
syslog-ng: allow reading *.journal in flatter directory structure
On openSUSE Leap 15.4 (and probably also 15.3), the journal lives in
/var/log/journal/*.journal - without an additional subdirectory level.
2022-10-09 21:02:17 +02:00
Christian Boltz
05d7bdd655 Merge parser: fix DISTRO variable in Makefile
A single '$()' results in variable expansion, which makes
"$(rpm --eval ..)" always an empty string.

Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/928
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-10-07 19:44:55 +00:00
Spyros Seimenis
75a6679be5 tests/regression: Add simple e2e test
This adds a single e2e test to check that raw_data of a loaded
policy matches the generated policy (cached).

Signed-off-by: Spyros Seimenis <spyros.seimenis@canonical.com>
2022-10-05 20:39:37 +03:00
Alexey Kodanev
1df547ee8f parser: fix DISTRO variable in Makefile
A single '$()' results in variable expansion, which makes
"$(rpm --eval ..)" always an empty string.

Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
2022-09-30 14:22:27 +03:00
John Johansen
e1cc90f3a2 Merge profiles/apparmor.d: Update samba profile
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1990692
Signed-off-by: Spyros Seimenis <spyros.seimenis@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/926
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-09-30 09:59:14 +00:00
Spyros Seimenis
96aff5a5c5 profiles/apparmor.d: Update samba profile
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1990692
Signed-off-by: Spyros Seimenis <spyros.seimenis@canonical.com>
2022-09-29 16:02:20 +03:00