Commit graph

6830 commits

Author SHA1 Message Date
John Johansen
353ba896d4 Prepare for AppArmor 4.0 beta2 release
- update version file

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-03-06 17:06:45 -08:00
John Johansen
c13007f7fc Merge libapparmor: check if AX_CHECK_COMPILE_FLAG is available
The error message when autoconf-archive is not installed is not very
intuitive:

```
./configure: line 14422: EXTRA_WARNINGS: command not found
./configure: line 14423: syntax error near unexpected token `-flto-partition=none,'
./configure: line 14423: `AX_CHECK_COMPILE_FLAG(-flto-partition=none, , , -Werror)'
```

So, check if AX_CHECK_COMPILE_FLAG is defined and if not, complain
that autoconf-archive is missing.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1174
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-03-06 21:21:54 +00:00
John Johansen
88a420853e Merge parser: fix policy generation for non-af_inet rules
The layout for AF_INET and AF_INET6 rules were being applied to all
families, which causes failures in their mediation.

Fixes: ddefe11a ("parser: add fine grained conditionals to network rule")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1175
Merged-by: John Johansen <john@jjmx.net>
2024-03-06 21:19:21 +00:00
Georgia Garcia
2db41acd1b parser: fix generic perms in network rules
The permission for network rules when the inet mediation was not
available, or for when the family was not af_inet or af_inet6 was
being generated as one that would allow anything. Make them specific
using perms.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-06 10:33:54 -03:00
Georgia Garcia
a10d9044b8 parser: fix policy generation for non-af_inet rules
The layout for AF_INET and AF_INET6 rules were being applied to all
families, which causes failures in their mediation.

Fixes: ddefe11a ("parser: add fine grained conditionals to network rule")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-06 10:07:17 -03:00
Christian Boltz
b53441a689 Merge Update ancient paths in apparmor and apparmor.d manpage
- replace example calls of /etc/init.d/apparmor with apparmor.service
- drop /etc/init.d/apparmor in filelist
- replace /var/lib/apparmor/ with /var/cache/apparmor/

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1171
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-06 12:24:13 +00:00
Christian Boltz
7452f34279
Update ancient paths in apparmor and apparmor.d manpage
- replace example calls of /etc/init.d/apparmor with apparmor.service
- drop /etc/init.d/apparmor in filelist
- replace /var/lib/apparmor/ with /var/cache/apparmor/
2024-03-05 22:59:18 +01:00
Georgia Garcia
aedb8a5b00 libapparmor: check if AX_CHECK_COMPILE_FLAG is available
The error message when autoconf-archive is not installed is not very
intuitive:

./configure: line 14422: EXTRA_WARNINGS: command not found
./configure: line 14423: syntax error near unexpected token `-flto-partition=none,'
./configure: line 14423: `AX_CHECK_COMPILE_FLAG(-flto-partition=none, , , -Werror)'

So, check if AX_CHECK_COMPILE_FLAG is defined and if not, complain
that autoconf-archive is missing.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 10:27:34 -03:00
Christian Boltz
6695944c2c Merge utils: fix coding style in mount
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1173
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-04 13:05:41 +00:00
Georgia Garcia
01090dcf1b utils: fix coding style in mount
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 09:24:58 -03:00
Georgia Garcia
3ea2bfec56 Merge Small fixes in MountRule
- Removed unnecessary variable source_is_path in mount rules
- Changed a string to a r-string to avoid an 'invalid escape sequence \s' warning

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1172
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:53:51 +00:00
Georgia Garcia
3d1a867c0a Merge Update mailinglist and homepage in changehat READMEs
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1170
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:53:10 +00:00
Georgia Garcia
dfb02cbd93 Merge MountRule: check for unknown fstype and options keywords, and fix issues uncovered by that
* **MountRule: sync flags_keywords with parser code**

    ... based on /mount.cc mnt_opts_table

    Several keywords and aliases were missing in flags_keywords:
    - B
    - M
    - make-private
    - make-rprivate
    - make-rshared
    - make-rslave
    - make-runbindable
    - make-shared
    - make-slave
    - make-unbindable
    - r
    - R
    - read-only
    - w

    Also sort the keywords in the same order as in mount.cc.

    Note: AARE handling is still a TODO.

    After that, update the list of known parsing failures:
    - several valid profiles are now correctly parsed
    - some `"make-*" mount opt and an invalid src` bad profiles are no
      longer detected as being invalid

* **test-mount.py: fix MountRule instance creation**

    If fstype or options is a str, it has to be exactly one keyword, because
    \__init__() / check_and_split_list() won't parse a str.

    Our "normal" code already honors this, and only hands over fstype and
    options as sets or a single-keyword str.

    However, a few tests (wrongly) handed over a str that would need further
    parsing. Adjust the tests to no longer do this.

* **MountRule: check for unknown fstype and options**

    ... now that the previous commits fixed issues that ended up as unknown
    keywords.

    Also add mount/ok_12.sd as known-failing test. It uses fstype=AARE which
    MountRule doesn't support (yet?).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1169
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:52:53 +00:00
Georgia Garcia
90f056c1c6 Merge Several MountRule fixes and improvements
* Fix writing 'mount {options,fstype} in ...' rules

We need spaces around the 'in' keyword.

Also add some tests for this.

* Make error check more readable

* MountRule: make get_clean() more readable

... by getting rid of two mostly-identical, big return statements.

Also add tests for bare umound and remount rules to ensure full test
coverage.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1168
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:52:33 +00:00
Maxime Bélair
0daf3e8c9b Changing string to r-string to avoid warning 2024-03-04 09:02:24 +01:00
Maxime Bélair
a86c1bd45a Remove unnecessary variable source_is_path in mount rules 2024-03-04 09:00:58 +01:00
Christian Boltz
8f4073ecd9
MountRule: check for unknown fstype and options
... now that the previous commits fixed issues that ended up as unknown
keywords.

Also add mount/ok_12.sd as known-failing test. It uses fstype=AARE which
MountRule doesn't support (yet?).
2024-03-03 21:30:49 +01:00
Christian Boltz
440be71c12
Update mailinglist and homepage in changehat READMEs 2024-03-03 18:12:06 +01:00
Christian Boltz
8d21f01924
test-mount.py: fix MountRule instance creation
If fstype or options is a str, it has to be exactly one keyword, because
__init__() / check_and_split_list() won't parse a str.

Our "normal" code already honors this, and only hands over fstype and
options as sets or a single-keyword str.

However, a few tests (wrongly) handed over a str that would need further
parsing. Adjust the tests to no longer do this.
2024-03-03 15:52:14 +01:00
Christian Boltz
4e546291a5
MountRule: sync flags_keywords with parser code
... based on /mount.cc mnt_opts_table

Several keywords and aliases were missing in flags_keywords:
- B
- M
- make-private
- make-rprivate
- make-rshared
- make-rslave
- make-runbindable
- make-shared
- make-slave
- make-unbindable
- r
- R
- read-only
- w

Also sort the keywords in the same order as in mount.cc.

Note: AARE handling is still a TODO.

After that, update the list of known parsing failures:
- several valid profiles are now correctly parsed
- some `"make-*" mount opt and an invalid src` bad profiles are no
  longer detected as being invalid
2024-03-03 15:37:59 +01:00
Christian Boltz
8c026077d6
MountRule: make get_clean() more readable
... by getting rid of two mostly-identical, big return statements.

Also add tests for bare umound and remount rules to ensure full test
coverage.
2024-03-03 13:09:43 +01:00
Christian Boltz
5e4c4a0cb3
Make error check more readable 2024-03-03 12:53:49 +01:00
Christian Boltz
9c27a7c435
Fix writing 'mount {options,fstype} in ...' rules
We need spaces around the 'in' keyword.

Also add some tests for this.
2024-03-03 12:49:57 +01:00
Christian Boltz
a367c07437 Merge Add useful error message in test-mount.py
If /proc/filesystems contains a filesystem that is not listed in
MountRule valid_fs, print a useful error message that says what exactly
is going on, instead of only saying "False is not True".

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1166
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-01 21:30:33 +00:00
Christian Boltz
2200013088 Merge Cleanup old handling of mount rules
Now that we have MountRule and MountRuleset, drop the old "just store
the whole rule" code for mount rules.

Also drop some old tests that used that "store the whole mount rule"
code, and adjust the regex_matches tests to import the regex directly
from apparmor.regex.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1165
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-01 21:29:48 +00:00
Christian Boltz
d5afc33c40 Merge MountRule: Fix typo in 'btrfs', and add '9p' filesystem
The `9p` filesystem is available during the build in build.opensuse.org.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1164
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-01 21:27:44 +00:00
Christian Boltz
517e7c96c8
MountRule: add '9p' filesystem
This filesystem is available during the build in build.opensuse.org
2024-03-01 21:36:26 +01:00
Christian Boltz
a7cd59819e
Add useful error message in test-mount.py
If /proc/filesystems contains a filesystem that is not listed in
MountRule valid_fs, print a useful error message that says what exactly
is going on, instead of only saying "False is not True".
2024-03-01 20:34:11 +01:00
Christian Boltz
e7f5ee3271
MountRule: Fix typo in 'btrfs' 2024-03-01 19:49:21 +01:00
Christian Boltz
da75b1c8d8
Cleanup old handling of mount rules
Now that we have MountRule and MountRuleset, drop the old "just store
the whole rule" code for mount rules.

Also drop some old tests that used that "store the whole mount rule"
code, and adjust the regex_matches tests to import the regex directly
from apparmor.regex.
2024-03-01 19:46:02 +01:00
Georgia Garcia
b264bb62c9 Prepare for AppArmor 4.0 beta1 release
- update version file
- update library version

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 19:24:53 -03:00
John Johansen
35287c8e1c Merge add fine grained network mediation support
Similar to https://gitlab.com/apparmor/apparmor/-/merge_requests/1095, but this time simplified.
This version removes support for ip and port ranges and subnets. This can be added later.

It also contains an updated version of the network layout required by the kernel side of AppArmor.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1160
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-29 21:58:24 +00:00
Georgia Garcia
119e3f38f9 parser: maintain compatibility for fine grained inet network mediation
A simple rule without conditionals need to be generated for when the
kernel does not support fine grained inet network mediation.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 18:27:20 -03:00
Georgia Garcia
dd0d145a19 tests: add fine grained network regression tests 2024-02-29 17:09:19 -03:00
Georgia Garcia
f6ad1cbe1e tests: add multi string support in requires_parser_support
By not having quotes in $@, the string splits by the whitespace.
That prevents us from checking if the parser supports rules
that have spaces in them.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 16:25:59 -03:00
Georgia Garcia
8a5e7227db parser: add parser tests for specified perms
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 16:25:59 -03:00
Georgia Garcia
79ee3eb180 parser: add parser tests for local conditional 2024-02-29 16:25:59 -03:00
Georgia Garcia
052dd987b3 parser: add network conditional parser tests 2024-02-29 16:25:59 -03:00
Georgia Garcia
7e25be7b0b parser: change network conditionals to allow unquoted ids
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 16:25:59 -03:00
Georgia Garcia
ddefe11a40 parser: add fine grained conditionals to network rule
Options available are ip= and port= inside the peer group or outside,
representing local addresses and ports:

network peer=(ip=127.0.0.1 port=8080),
network ip=::1 port=8080 peer=(ip=::2 port=8081),

The 'ip' option supports both IPv4 and IPv6. Examples would be
ip=192.168.0.4, or ip=::578d

The 'port' option accepts a 16-bit unsigned integer. An example would
be port=1234

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 16:25:59 -03:00
John Johansen
b83cf90b82 Merge Fix some DENIES for smbd when honouring pam restrictions
with smbd.conf param 'obey pam restrictions = yes'

on tumbleweed we get some new DENIES (which can prevent login)

e.g.

type=AVC msg=audit(1709113104.674:533): apparmor="DENIED" operation="exec" class="file" profile="smbd" name="/usr/sbin/unix_chkpwd" pid=3509 comm="smbd[127.0.0.1]" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:345): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/usr/etc/security/limits.d/" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:346): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/proc/3746/loginuid" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:347): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/usr/etc/environment" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

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

Signed-off-by: Noel Power <noel.power@suse.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1159
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-29 18:00:40 +00:00
John Johansen
e3cb9e1669 Merge Adding userspace support for mount rules in aa-genprof/aa-logprof
Adding userspace support for mount rules in aa-genprof/aa-logprof

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1153
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-29 17:59:51 +00:00
Maxime Bélair
924b335dfc Adding userspace support for mount rules in aa-genprof/aa-logprof 2024-02-29 17:59:50 +00:00
John Johansen
a2da64304f Merge profiles: add nautilus unconfined profile
Nautilus uses user namespaces to load thumbnails, hence it needs an
unconfined profile when user namespaces are restricted from unconfined
like other applications in MR #1123

Although nautilus has extensions that would allow opening a terminal
from the nautilus interface, they do not inherit nautilus' AppArmor
label, therefore the use of unconfined does not allow arbitrary use of
unprivileged user namespaces using the nautilus label.

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify them instead
of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

Fixes: https://bugs.launchpad.net/bugs/2047256
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1161
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-29 12:02:44 +00:00
Georgia Garcia
bb53886211 profiles: add nautilus unconfined profile
Nautilus uses user namespaces to load thumbnails, hence it needs an
unconfined profile when user namespaces are restricted from unconfined
like other applications in MR #1123

Although nautilus has extensions that would allow opening a terminal
from the nautilus interface, they do not inherit nautilus' AppArmor
label, therefore the use of unconfined does not allow arbitrary use of
unprivileged user namespaces using the nautilus label.

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify them instead
of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

Fixes: https://bugs.launchpad.net/bugs/2047256
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 08:21:25 -03:00
Georgia Garcia
746f76d3e1 parser: add ability to specify permission in network rules
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-28 21:42:18 -03:00
Georgia Garcia
35f25a251b parser: fix coverity issues found in snapshot 70858
This commit add fixes for issues found in coverity's snapshot 70858.
  - CID 323127:  Performance inefficiencies  (COPY_INSTEAD_OF_MOVE)
  - CID 323125:  Uninitialized members  (UNINIT_CTOR)

I'm also removing Novell, Inc. from the copyright notice added by a
copy-paste error, and an unused variable left over from debugging.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-28 10:24:08 -03:00
Noel Power
c09f58a364 Fix some DENIES for smbd when honouring pam restrictions
with smbd.conf param 'obey pam restrictions = yes'

on tumbleweed we get some new DENIES (which can prevent login)

e.g.

type=AVC msg=audit(1709113104.674:533): apparmor="DENIED" operation="exec" class="file" profile="smbd" name="/usr/sbin/unix_chkpwd" pid=3509 comm="smbd[127.0.0.1]" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:345): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/usr/etc/security/limits.d/" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:346): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/proc/3746/loginuid" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:347): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/usr/etc/environment" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

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

Signed-off-by: Noel Power <noel.power@suse.com>
2024-02-28 09:59:55 +00:00
Christian Boltz
909e330fd0 Merge aa-notify: precompile filter regexes
Precompile each filter regex with re.compile so they don't need to be
recompiled for each log message when using re.match directly.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1158
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-02-26 17:15:26 +00:00
Georgia Garcia
88907253e4 aa-notify: precompile filter regexes
Precompile each filter regex with re.compile so they don't need to be
recompiled for each log message when using re.match directly.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-26 10:24:46 -03:00