Commit graph

6807 commits

Author SHA1 Message Date
John Johansen
1e7f63415a Merge ubuntu-browsers.d/kde: fix plasma-browser-integration
Out of the box the KDE plasma-browser-integration package does not work
after a user installed the corresponding Firefox extension: The browser
can't start the native host binary. The same is probably true for
Chromium.

This was originally reported to KDE at https://bugs.kde.org/show_bug.cgi?id=397399

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1115
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-11-03 02:51:36 +00:00
Christian Boltz
d4dff5ce4e
Allow reading /etc/authselect/nsswitch.conf
On systems with authselect installed, /etc/nsswitch.conf is a symlink to
/etc/authselect/nsswitch.conf.

Fixes: https://gitlab.com/apparmor/apparmor-profiles/-/issues/13
2023-11-01 17:03:06 +01:00
Christian Boltz
86c05357cf
Add test for unknown capability
Even if this is very unlikely to happen (because of the previously added
test, and because CapabilityRule only allows to specify known severity
keywords), ensure proper behaviour if an unknown severity gets rated.
2023-10-29 22:10:07 +01:00
Christian Boltz
f17bd59904
Test severity of all capabilities
... to ensure that they are all listed in severity.db
2023-10-29 22:10:07 +01:00
Christian Boltz
d38c7b22ce
CapabilityRule: simplify and improve __init__()
- convert a string parameter to a list to avoid duplication of the
  validation logic
- add separate check for empty cap_list
- remove check for empty strings - the previous commit already added
  such a check to the for loop. Also, move the comment to that check.
2023-10-29 21:42:57 +01:00
Christian Boltz
942202da17
CapabilityRule: Validate given caps against cap list
... and error out if an unknown capability is given.

This also means recognizing bad capabilities in the parser simple_tests
now works (so remove these from the exception_not_raised list), and that
we can no longer hand over an unknown capability in test-capability.py
to test their severity.
2023-10-29 21:31:43 +01:00
Christian Boltz
5c34655f4a
CapabilityRule: Add list of known capabilities
... and add a test to ensure that the list is/stays complete.
2023-10-29 21:28:13 +01:00
Christian Boltz
57ba373213
test-capability: use valid capability names
... instead of non-existing ones.

This is a search-and-replace commit:

ptrace -> sys_ptrace

chgrp -> fowner (because fowner wasn't used in the test before)
2023-10-29 21:23:00 +01:00
Christian Boltz
5d9d4483fb
Add Documentation=... to apparmor.service
This is taken from Debian's apparmor.service, and is the first (and
easiest) step to get the upstream and Debian file closer.
2023-10-29 10:49:33 +01:00
Malte S. Stretz
8b95030665 ubuntu-browsers.d/kde: fix plasma-browser-integration
Out of the box the KDE plasma-browser-integration package does not work
after a user installed the corresponding Firefox extension: The browser
can't start the native host binary. The same is probably true for
Chromium.

This was originally reported to KDE at https://bugs.kde.org/show_bug.cgi?id=397399
2023-10-18 11:37:18 +02:00
John Johansen
58a89284d5 Merge tools.py: the big cleanup
tools.py contained quite some things that need a big cleanup.

See the individual commits for details and more readable diffs.

Note: This MR "only" does cleanups and some refactoring. It does not change the (user-visible) behaviour of the code.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1114
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-14 00:54:15 +00:00
John Johansen
28f336cb91 Merge abstractions: pipewire rt conf
Pipewire also uses the client-rt.conf file, add this to the audio abstraction.

See pipewire source: https://github.com/PipeWire/pipewire/blob/master/src/daemon/client-rt.conf.in

Hit this during normal usage of Firefox.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1113
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-14 00:05:21 +00:00
Antonius Mulder
61fc6805a9 abstractions: pipewire rt conf
Pipewire also uses the client-rt.conf file, add this to
the audio abstraction.
2023-10-13 13:06:42 -07:00
Christian Boltz
f2f24884c3
get_next_to_profile(): ensure all branches set all variables
This also means we can get rid of most cleanprof-specific conditions
without changing the behaviour (because the other functions don't use
'profile' yet).

Also hand over prof_filename to clean_profile() so that it doesn't need
to find it out itsself.
2023-10-12 13:44:04 +02:00
Christian Boltz
5d8347bc26
clean_profile(): re-order code
Error out early (avoids a tab level), and handle the short branch first
in the if condition.
2023-10-12 13:11:30 +02:00
Christian Boltz
0c595ac801
clean_profile(): rename filename to prof_filename
... for consistency with the variable name in all the other functions.
2023-10-12 13:08:13 +02:00
Christian Boltz
1d5f90efcd
Rename profile variable to prof_filename
... if it contains the profile filename. This avoids confusion with the
"real" 'profile' variable that contains a profile name.
2023-10-12 13:04:29 +02:00
Christian Boltz
4f51c93f9d
get_next_to_profile(): return profile and prof_filename
Before, the 'profile' return value was either a profile name or a
profile filename, depending on the active module (cleanprof vs.
everything else).

Separate the return values so that it's clear what we get.

Notes:
- This commit doesn't change functionality, only the number of return
  values and some variable names.
- There's no guarantee that all return values are set. They can also be
  None. (This might change in the future.)

Also adjust the callers of get_next_to_profile(), and rename 'profile'
to 'prof_filename' in calling functions that actually use the profile
filename.
2023-10-12 12:36:09 +02:00
Christian Boltz
4d1c17b426
Drop enable_profile() and disable_profile()
enable_profile() was unused.

disable_profile() was only used once, inline it into cmd_disable()
2023-10-12 12:36:09 +02:00
Christian Boltz
918a15e244
Merge common parts of mode changes into get_next_for_modechange() 2023-10-12 12:36:09 +02:00
Christian Boltz
fc8c7722a1
tools.py: call apparmor.read_profiles() in __init__()
... instead of calling it in every cmd_* function.
2023-10-12 12:36:05 +02:00
John Johansen
7eff621fc7 Merge parser/rc.apparmor: Handle Incus
Add init function support to skip incus prefixed policy like is done for lxc and lxd
 
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1112
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-12 05:52:40 +00:00
Stéphane Graber
659a187687
parser/rc.apparmor: Handle Incus
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
2023-10-12 00:55:03 -04:00
John Johansen
cee501349e Merge ProfileList: merge self.attachments_AARE into self.attachments['re']
Since the unittests now compare a dict that contains an AARE, this also needs:

AARE: add `__eq__()` to allow checking aare1 == aare2

... and add some tests for it

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1111
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-12 04:44:24 +00:00
Christian Boltz
27de7ea0c2
ProfileList: merge self.attachments_AARE into self.attachments['re'] 2023-10-11 20:39:37 +02:00
Christian Boltz
bfd72c93be
AARE: add __eq__() to allow checking aare1 == aare2
... and add some tests for it
2023-10-11 20:38:38 +02:00
John Johansen
6ac0e0236b Merge Fix aa-cleanprof to work with named profiles
This needed replacement of "program" with "profile" at various places in
tools.py (of course this description is over-simplified).

The changes in get_next_to_profile() (which is used by several aa-*
minitools) are restricted to cleanprof to avoid side effects in the
other aa-* minitools.

However, the other aa-* minitools possibly also suffer from problems
with named profiles, but checking and fixing that is left for another
commit ;-)

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

.

The fix needs an additional function in ProfileList (`profile_from_attachment()`) to get the profile name for a given attachment.

Since this is not very different from filename_from_attachment(), move
most of the code into a thing_from_attachment() function, and make
{profile,filename}_from_attachment wrappers for it.

Also adjust the tests to the changed internal data structure, and add
tests for profile_from_attachment().

I propose this patch for 3.0..master. (3.0 will probably need a slightly different patch - I'll submit a separate MR once this MR is merged.)

Closes #351
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1108
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-10 03:55:12 +00:00
Christian Boltz
151bf26bb9
Fix aa-cleanprof to work with named profiles
This needed replacement of "program" with "profile" at various places in
tools.py (of course this description is over-simplified).

The changes in get_next_to_profile() (which is used by several aa-*
minitools) are restricted to cleanprof to avoid side effects in the
other aa-* minitools.

However, the other aa-* minitools possibly also suffer from problems
with named profiles, but checking and fixing that is left for another
commit ;-)

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/351
2023-10-08 20:01:27 +02:00
Christian Boltz
26903320fd
ProfileList: add profile_from_attachment()
... to get the profile name for a given attachment.

Since this is not very different from filename_from_attachment(), move
most of the code into a thing_from_attachment() function, and make
{profile,filename}_from_attachment wrappers for it.

Also adjust the tests to the changed internal data structure, and add
tests for profile_from_attachment().
2023-10-08 15:25:55 +02:00
John Johansen
884adcc58f repare for AppArmor 4.0 alpha 3 release
- update version file

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-09-18 03:51:29 -07:00
John Johansen
f5be84acdc Merge Utils: add support for the 'all,' rule
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1105
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-09-12 00:39:42 +00:00
John Johansen
5d940b2a47 Merge apparmor.vim: add support for the 'all' rule
... and update the bugreporting info in the header

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1106
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-09-12 00:37:44 +00:00
Christian Boltz
583d116871
apparmor.vim: add support for the 'all' rule
... and update the bugreporting info in the header
2023-09-10 18:38:48 +02:00
Christian Boltz
e361644d5a
Utils: add support for the 'all,' rule 2023-09-10 18:07:41 +02:00
John Johansen
4e758a838d
Merge parser: add support for a generic all rule type
Extend the policy syntax to have a rule that allows specifying all
permissions for all rule types.

  allow all,

This is useful for making blacklist based policy, but can also be
useful when combined with other rule prefixes, eg. to add audit
to all rules.

  audit access all,

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1103
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-09-07 09:09:13 +00:00
John Johansen
197d00d21a parser: add support for a generic all rule type
Extend the policy syntax to have a rule that allows specifying all
permissions for all rule types.

  allow all,

This is useful for making blacklist based policy, but can also be
useful when combined with other rule prefixes, eg. to add audit
to all rules.

  audit access all,

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-09-07 01:30:15 -07:00
John Johansen
a9c5388f69
Merge parser: refactor network rules and prepare for fine grained network rules
This lays the ground work for fine grained network mediation. The switch to using the rules class brings the advantages of shared infrastructure and is needed for tracking all the different combinations possible with finer control.

In addition range generation and support for large numbers (needed for ipv6) are added. This patchset does not make policy visible changes to network rules.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1104
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-09-07 07:22:21 +00:00
Georgia Garcia
75ca0e7919 parser: track leading zeros required for ipv6 range regex generator
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:52 -07:00
Georgia Garcia
fb5f59024c parser: add uppercase hex on regex range generator
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:42 -07:00
Georgia Garcia
a71ac76e6d parser: add regex generator for range
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:29 -07:00
Georgia Garcia
2be9c431ca parser: add opt_cond in preparation to finer grained network mediation
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:15 -07:00
Georgia Garcia
05de4b82e7 parser: implement dedup of network rules
Since network rules don't use the "perms" attribute, it is using the
dedup class in which duplicate rules are removed.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:04 -07:00
Georgia Garcia
820f1fb5f2 parser: refactor network to use rule class as its base.
There is one significant difference in the encoding of the network
rules. Before this change, when the parser was encoding a "network,"
rule, it would generate an entry for every family and every
type/protocol. After this patch the parser should generate an entry
for every family, but the type/protocol is changed to .. in the pcre
syntax. There should be no difference in behavior.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:12:51 -07:00
John Johansen
65905b0c55
Merge aa-status: separate error messages from the regular output
using dfprintf for error messages subjects them to the other
output controls and can cause them to be surpressed when they
shouldn't.

Instead use a dedicated error function and add a quiet flag to
allow silencing errors.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1102
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-09-07 06:01:08 +00:00
John Johansen
1945ecbf19 aa-status: separate error messages from the regular output
using dfprintf for error messages subjects them to the other
output controls and can cause them to be surpressed when they
shouldn't.

Instead use a dedicated error function and add a quiet flag to
allow silencing errors.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-28 15:52:44 -07:00
John Johansen
11976c42e3 Merge binutils/aa_status.c: quiet verbose outputs when --json is specified
By default aa-status outputs with --verbose enabled - if --json is also
specified then aa-status would currently output in its first line "apparmor
module is loaded.":

aa-status --json | head -n1
apparmor module is loaded.

And only after this the actual json output would follow. This then results in
failures to parse this JSON output:

aa-status --json | jq .
parse error: Invalid numeric literal at line 1, column 9

This in turn then breaks tools / tests which expect the output of aa-status
--json to be purely json - e.g:
https://salsa.debian.org/apparmor-team/apparmor-profiles-extra/-/blob/debian/unstable/debian/tests/policy-is-loaded#L12

So ensure dprintf() etc do not output when --json is specified to restrict the
output of aa-status to pure JSON.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1097
Approved-by: Seth Arnold <seth.arnold@gmail.com>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:07:17 +00:00
John Johansen
327588f019 Merge parser: fix coverity scan 553075
coverity is reporting an overrun of the profile_mode_table

217     		if (merge_profile_mode(mode, rhs.mode) == MODE_CONFLICT)
>>>     CID 322989:    (OVERRUN)
>>>     Overrunning array "profile_mode_table" of 6 8-byte elements at element index 6 (byte offset 55) using index "this->mode" (which evaluates to 6).

this is because it is being indexed by the profile_mode enum which can
go up to a 6th entry. The code tests for MODE_CONFLICT before using
the table so it shouldn't trigger a bug today, but play it safe for
the future and also get rid of the coverity scan error by adding a
"conflict" entry to the mode_table.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1098
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:05:45 +00:00
John Johansen
84e22b4cca Merge Docs: apparmor.d.pod document io_uring and userns rules
Documentation for io_uring and userns rules is missing from the
apparmor.d man page. Provide some basic documentation for them.

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

Closes #349
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1099
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:05:20 +00:00
John Johansen
248625ae00 Merge apparmor.d.pod: rename SIGNALS to SIGNAL
SIGNAL makes more sense because it's about a single signal.

Besides that, a9494f5523 introduced a (at
that point broken) usage of SIGNAL which becomes valid with this commit.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1100
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:05:04 +00:00
John Johansen
9ab72ffc7c Merge Install systemd unit on fedora/redhat systems
... instead of trying the old rc.apparmor.redhat initscript, which we no
longer ship since 2019519e34.

Also remove a superfluous level of indirection (rhel4 -> redhat).

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

Closes #350
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1101
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:04:53 +00:00