Commit graph

5242 commits

Author SHA1 Message Date
Christian Boltz
8661676eb4 Merge branch 'cboltz-utils-include-if-exists' into 'master'
Add support for 'include if exists' to the tools

See merge request apparmor/apparmor!499

Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-05-03 19:59:11 +00:00
Christian Boltz
a4864146e2 Merge branch 'cboltz-vim-if-exists' into 'master'
apparmor.vim: support 'include if exists'

See merge request apparmor/apparmor!500

Acked-by: John Johansen <john.johansen@canonical.com> for 2.12..master
2020-05-03 19:27:57 +00:00
Steve Beattie
9b250ef63d test profiles: fix typo in descriptions
Merge branch 'cboltz-parser-tst-typo' into 'master'

See merge request apparmor/apparmor!498
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-03 19:17:08 +00:00
Christian Boltz
c2ac1b5669 Merge branch 'cboltz-superfluous-cast' into 'master'
Remove superfluous self-cast in Invalid*Test

See merge request apparmor/apparmor!495

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-03 12:32:19 +00:00
Christian Boltz
efa7c6d6b6
apparmor.vim: support 'include if exists' 2020-05-03 14:27:59 +02:00
Christian Boltz
6643d0b07a
Add a 'include if exists' rule to cleanprof testcases
... to ensure it is kept.
2020-05-03 13:58:37 +02:00
Christian Boltz
295bb6469a
Enable usage of IncludeRule in the tools
For now, only 'include if exists' rules will be handled by IncludeRule.
Using it also for 'include' rules needs some more code changes so that
included files still get checked etc.

Also remove some testcases from test-parser-simple-tests.py unknown_line
which no longer fail.
2020-05-03 13:55:03 +02:00
Christian Boltz
4df5ac780d
Add IncludeRule and IncludeRuleset including tests
These classes are meant to handle 'include' and 'include if exists'
rules.

Due to restrictions in re_match_include_parse(), some cases in
is_covered_localvars() and is_equal_localvars() can't be reached in the
unittests.

Also, IncludeRule isn't used in aa-logprof (yet?), which means
logprof_header_localvars() result format isn't decided yet, and
therefore not tested.

This means test coverage for the new classes isn't 100% this time ;-)
2020-05-03 13:41:19 +02:00
Christian Boltz
0948df3de0
Fix typo in description of several test profiles
Several bare_include_tests and include_tests test profiles had "existss"
instead of "exists" in their description
2020-05-03 12:28:57 +02:00
John Johansen
dca5b452a5 LSM stacking: add missing permissions for using new kernel interfaces
LSM stacking adds the new /proc/<pid>/attr/apparmor directory
dedicated to apparmor so that it won't collide with other LSMs.

The library has already been switched to using this interface by
default, but the parser need to add permissions to access this
location when hats and/or change_profile rules are defined.

Also make sure to update the apache abstraction to support the new
interface as well.

Signed-off-by: John Johansen <john.johansen@canonical.com
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-05-03 01:00:18 -07:00
Christian Boltz
7b009a909e
Remove superfluous self-cast in Invalid*Test 2020-05-02 22:13:34 +02:00
Christian Boltz
6b9b928f9d
Add tests for re_match_include_parse()
Also extend tests for re_match_include() to make sure it doesn't match
"include if exists" rules.
2020-05-02 19:44:36 +02:00
Christian Boltz
d2dbf41137
add basic support for parsing "include if exists" rules
- extend RE_INCLUDE to also match "include if exists"
- rename re_match_include() to re_match_include_parse() and extend it to
  also support "include if exists" rules. The return value also includes
  "ismagic" now to avoid another future change, but that's not used yet.
- add re_match_include() which is now a wrapper around
  re_match_include_parse() and behaves exactly as the old
  re_match_include()
2020-05-02 19:44:06 +02:00
Christian Boltz
6557e06019 Merge branch 'parser-fix-deprecation-warnings' into 'master'
parser/caching test: fix deprecation warnings

See merge request apparmor/apparmor!492

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-04-30 19:46:45 +00:00
Steve Beattie
e3e25fe86e
parser/caching test: fix deprecation warnings
Newer python.unittest prefers assertNotEqual() over assertNotEquals():

  caching.py:143: DeprecationWarning: Please use assertNotEqual instead.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-30 11:26:36 -07:00
John Johansen
69a0c80a40 aa-status: reindent from spaces to tabs
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
de8f1ba17d aa-status: add support for kill and unconfined profile modes
AppArmor 3 exposes kernel support for the kill and unconfined profile
modes. Make sure aa-status has basic support for these modes.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
e3185cadf3 aa-status: add output for for stacked processes in mixed mode
Processes that are confined by multiple profiles in a stack can have
more than one profile mode applied. Allow aa-status to report
processes that are in a mixed profile confinement mode.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
68811fa42b aa-status: switch aa-status to use libapparmor proc accessor and splitcon
Switch aa-status over to using the libapparmor proc accessor. This
will ensure that aa-status works correctly under LSM stacking kernels,
and if other new interfaces are added in the future.

Also at the same time switch over the splitting of context's to
the library provided aa_splitcon() fn.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
8015535882 binutils: make aa-enabled LSM stacking aware
Make aa-enabled able to distinguish being enabled and enabled without
access to the shared LSM iterfaces.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-29 15:30:54 -07:00
John Johansen
f23125c265 libapparmor: make libapparmor LSM stacking aware
With LSM stacking apparmor may be available even if it is not
enabled. If apparmor is available but not enabled it does not own
the /proc/<pid>/attr/* interface and should not use it as they
will not provide apparmor context.

Note: this also applies to the SO_PEERSEC interface, currently we
only fail is apparmor does not own the interface. Once the new interface
command is finalized supprt to use that will be added.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 15:12:27 -07:00
John Johansen
fb219b5ba1 libapparmor: add support for the new dedicated apparmor interface
LSM stacking makes the old /proc/<pid>/attr/* interfaces potentially
be shared such that the values returned might be for a different LSM
than apparmor.

Use the new apparmor dedicated interface at /proc/<pid>/attr/apparmor/*
if it is present.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 15:12:08 -07:00
Christian Boltz
4281b58c89 Merge branch 'privacy' into 'master'
Privacy statement

See merge request apparmor/apparmor!441

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.11..master
2020-04-26 11:43:14 +00:00
John Johansen
f550c21545 Merge let logprof only propose abstractions without '# LOGPROF-SUGGEST: no'
This implements one part of https://gitlab.com/apparmor/apparmor/issues/15

(the --all-abstractions parameter is still missing, and the not-to-be-proposed abstractions obviously need the comment added)

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/254
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-26 10:44:49 +00:00
John Johansen
955439cbb3 libapparmor: force library configuration to search for python3
libapparmor and the pyton tools now require python3 but on systems
where python2 is the default the build will fail unless the PYTHON=
env var is set to the systems python3.

Instead just force autoconf to search for python3 as the python
version to use.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-26 03:05:48 -07:00
John Johansen
4e242fed7a Merge CI: Drop specifying python and pyflakes version
Since https://gitlab.com/apparmor/apparmor/-/merge_requests/482 python 3.x will be used by default (as the only python version), which makes it superfluous to explicitely specify it.

Note: requires fix: https://gitlab.com/apparmor/apparmor/-/merge_requests/486

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/483
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-26 10:04:55 +00:00
John Johansen
9ba2334423 Merge Fixings for crosscompilation
This series adds a couple of patches to make the software more crosscompilation friendly. They are based on the work I'm doing to fix the package on buildroot

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/485
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-26 09:45:04 +00:00
Angelo Compagnucci
6d682cf138 parser: binutils: fix compilation with libintl
When libintl is available on the system, we need to link against the
libintl library too.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
2020-04-25 17:31:49 +02:00
Angelo Compagnucci
ed4e0a2551 parser: fix parallel install order
In order to have all the prerequisite folders before actually installing
os dependent configuration files, we need to guarantee the correct
install sequence.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
2020-04-24 17:35:38 +02:00
John Johansen
d2464d6dcb Merge branch 'aa-status-in-c' into 'master'
Port aa-status from python to C

See merge request apparmor/apparmor!473
2020-04-24 05:43:48 +00:00
Alex Murray
8f9046b1b1 Merge Port aa-status from python to C
This allows aa-status to be used without a python runtime to support things like https://bugs.launchpad.net/bugs/1865519

Fixes: https://bugs.launchpad.net/bugs/1865519
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/473
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-24 05:43:47 +00:00
John Johansen
e9c2a6087d Merge README: require python 3.3 for utils
... and drop the long-deprecated python 2.7 option, which no longer works.

This is a follow-up of https://gitlab.com/apparmor/apparmor/-/merge_requests/481 which did this change on the code side.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/482
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-20 22:19:33 +00:00
Christian Boltz
2c5d3cb381
CI: Drop specifying python and pyflakes version
Since https://gitlab.com/apparmor/apparmor/-/merge_requests/482
python 3.x will be used by default (as the only python version),
which makes it superfluous to explicitely specify it.
2020-04-20 13:28:09 +02:00
Christian Boltz
baab417059
README: require python 3.3 for utils
... and drop the long-deprecated python 2.7 option, which no longer
works.

This is a follow-up of
https://gitlab.com/apparmor/apparmor/-/merge_requests/481 which did this
change on the code side.
2020-04-20 13:10:43 +02:00
Christian Boltz
b6cbe57bd9 Merge branch 'python3' into 'master'
Switch python utils to only use Python3

See merge request apparmor/apparmor!481

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-04-20 11:04:36 +00:00
John Johansen
ff7d1a4eb7 library: swig: require python 3 when building the swig interface
If Swig builds the library against python 2 and the utils/tests
run using python3, parts of the library are in accesible with
failures like

Traceback (most recent call last):
  File "test-pivot_root_parse.py", line 12, in <module>
    import apparmor.aa as aa
  File "/home/jj/apparmor/apparmor-jjohansen.git/utils/apparmor/aa.py", line 28, in <module>
    import apparmor.logparser
  File "/home/jj/apparmor/apparmor-jjohansen.git/utils/apparmor/logparser.py", line 19, in <module>
    import LibAppArmor
ImportError: No module named LibAppArmor

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-20 02:09:22 -07:00
John Johansen
9657d9b7e8 utils: default make check to pyflakes3
$ make check

will fail unless PYFLAKES=pyflakes3 is passed as an environment
variable. Fix it so make check will work by default.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-20 01:18:40 -07:00
John Johansen
af69088546 utils: only use python3 during testing
The apparmor python tools are written assuming python3. But the tests
are still using python2. This can result in failures of the test suite
on some systems, depending on how libapparmor is built.

Eg. on Ubuntu 18.04

apparmor.git/utils$ PYTHON=/usr/bin/python3 make check PYFLAKES=/usr/bin/pyflakes3
LANG=C podchecker -warning -warning *.pod
aa-audit.pod pod syntax OK.
aa-autodep.pod pod syntax OK.
aa-cleanprof.pod pod syntax OK.
aa-complain.pod pod syntax OK.
aa-decode.pod pod syntax OK.
aa-disable.pod pod syntax OK.
aa-easyprof.pod pod syntax OK.
aa-enforce.pod pod syntax OK.
aa-genprof.pod pod syntax OK.
aa-logprof.pod pod syntax OK.
aa-mergeprof.pod pod syntax OK.
aa-notify.pod pod syntax OK.
aa-remove-unknown.pod pod syntax OK.
aa-sandbox.pod pod syntax OK.
aa-status.pod pod syntax OK.
aa-unconfined.pod pod syntax OK.
logprof.conf.pod pod syntax OK.
aa-notify syntax OK
Checking aa-easyprof
Checking aa-genprof
Checking aa-logprof
Checking aa-cleanprof
Checking aa-mergeprof
Checking aa-autodep
Checking aa-audit
Checking aa-complain
Checking aa-enforce
Checking aa-disable
Checking aa-status
Checking aa-unconfined
Checking apparmor
Checking test/common_test.py
Checking test/minitools_test.py
Checking test/test-aa-decode.py
Checking test/test-aa-easyprof.py
Checking test/test-aa.py
Checking test/test-aamode.py
Checking test/test-aare.py
Checking test/test-baserule.py
Checking test/test-capability.py
Checking test/test-change_profile.py
Checking test/test-common.py
Checking test/test-config.py
Checking test/test-dbus.py
Checking test/test-example.py
Checking test/test-file.py
Checking test/test-libapparmor-test_multi.py
Checking test/test-logparser.py
Checking test/test-mount_parse.py
Checking test/test-network.py
Checking test/test-parser-simple-tests.py
Checking test/test-pivot_root_parse.py
Checking test/test-profile-list.py
Checking test/test-profile-storage.py
Checking test/test-ptrace.py
Checking test/test-regex_matches.py
Checking test/test-rlimit.py
Checking test/test-severity.py
Checking test/test-signal.py
Checking test/test-translations.py
Checking test/test-unix_parse.py
make[1]: Entering directory '/home/jj/apparmor/apparmor-jjohansen.git/utils/test'

=== test-example.py ===
.......
----------------------------------------------------------------------
Ran 7 tests in 0.000s

OK
.......
----------------------------------------------------------------------
Ran 7 tests in 0.000s

OK

=== test-pivot_root_parse.py ===
Traceback (most recent call last):
  File "test-pivot_root_parse.py", line 12, in <module>
    import apparmor.aa as aa
  File "/home/jj/apparmor/apparmor-jjohansen.git/utils/apparmor/aa.py", line 28, in <module>
    import apparmor.logparser
  File "/home/jj/apparmor/apparmor-jjohansen.git/utils/apparmor/logparser.py", line 19, in <module>
    import LibAppArmor
ImportError: No module named LibAppArmor
Makefile:81: recipe for target 'check' failed
make[1]: *** [check] Error 1
make[1]: Leaving directory '/home/jj/apparmor/apparmor-jjohansen.git/utils/test'
Makefile:95: recipe for target 'check' failed
make: *** [check] Error 2

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-20 01:18:12 -07:00
John Johansen
bfde89a62a infrastructure: Add privacy statement to the README
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-19 15:57:12 -07:00
Jamie Strandboge
5583569a29 allow accessing the libnss-systemd VarLink sockets and DBus APIs
https://systemd.io/USER_GROUP_API/ describes the libnss-systemd VarLink
socket APIs:

"
When a client wants to look up a user or group record, it contacts all
sockets bound in this directory in parallel, and enqueues the same query
to each. The first positive reply is then returned to the application,
or if all fail the last seen error is returned instead. (Alternatively
a special Varlink service is available, io.systemd.Multiplexer which
acts as frontend and will do the parallel queries on behalf of the
client, drastically simplifying client development.)
"

This updates the nameservice abstraction to allow read/write on
well-known systemd VarLink named sockets.

In addition, allow lookups for systemd-exec's DynamicUsers via D-Bus

References:
- https://systemd.io/USER_GROUP_API/
- https://systemd.io/USER_RECORD/
- https://www.freedesktop.org/software/systemd/man/nss-systemd.html
- https://www.freedesktop.org/software/systemd/man/systemd.exec.html
- https://launchpad.net/bugs/1796911
- https://launchpad.net/bugs/1869024

Modified by John Johansen by:
- moving rules nss-systemd include
- replacing /proc/ with @{proc}/
- moving and merging commit 16f9f688 rules into nss-systemd include

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/480
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/474
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-16 10:21:04 -07:00
John Johansen
57c3d8e125 Merge test that '\*' from audit.log gets correctly escaped
convert_expression_to_aare() is expected to convert it to AARE `\\\*`

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/479
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-14 07:25:36 +00:00
John Johansen
333eb86734 Merge Get rid of is_covered_aare_compat()
This function was introduced as a temporary (ahem...) solution in 95404bb2f3 but was never really correct. It checked against other_value.regex (as a string!) and, while this was somewhat generous in the results, could have unintended side effects.

Better error out on the safe side and add/keep a few superfluous rules than having a wrong match in is_covered() and miss to add/keep a rule that would be needed.

The perfect solution would be to really compare one AARE against the other as the parser does. I'm not too keen to implement this in python, and will wait until someone provides this function (which the parser already has) via libapparmor ;-)

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/478
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-14 07:24:02 +00:00
John Johansen
2ebf742d31 Merge drop unused cmd_pipe() from easyprof.py
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/477
Aked-by: John Johansen <john.johansen@canonical.com>
2020-04-14 07:20:58 +00:00
John Johansen
ef0c9160ce Merge branch ProfileStorage __setitem__(): restrict overwriting most keys
Only bool and str keys may be overwritten.

Other key types (list, dict, \*Ruleset) can have their content modified (not **setitem**()s job), but replacing the whole collection should never happen.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/476
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-14 07:19:07 +00:00
Christian Boltz
ddd9bd57e4
ProfileStorage __setitem__(): restrict overwriting most keys
Only bool and str keys may be overwritten.

Other key types (list, dict, *Ruleset) can have their content modified
(not __setitem__()s job), but replacing the whole collection should
never happen.
2020-04-13 19:55:54 +02:00
Christian Boltz
c9c4f4ce9c
test that '\*' from audit.log gets correctly escaped
convert_expression_to_aare() is expected to convert it to AARE '\\\*'
2020-04-13 19:46:05 +02:00
Christian Boltz
ef0d675824
Get rid of is_covered_aare_compat()
This function was introduced as a temporary (ahem...) solution in
95404bb2f3 but was never really correct.
It checked against other_value.regex (as a string!) and, while this was
somewhat generous in the results, could have unintended side effects.

Better error out on the safe side and add/keep a few superfluous rules
than having a wrong match in is_covered() and miss to add/keep a rule
that would be needed.

The perfect solution would be to really compare one AARE against the
other as the parser does. I'm not too keen to implement this in python,
and will wait until someone provides this function (which the parser
already has) via libapparmor ;-)
2020-04-13 15:13:12 +02:00
Christian Boltz
30fa90a4ce
drop unused cmd_pipe() from easyprof.py 2020-04-13 14:08:54 +02:00
Christian Boltz
acafe9de82 Merge branch 'profile-usr.sbin.dnsmasq' into 'master'
usr.sbin.dnsmasq: update to support dnsmasq 2.81

See merge request apparmor/apparmor!475

Acked-by: Christian Boltz for 2.11..master
2020-04-12 09:45:12 +00:00
nl6720
88c142c687
usr.sbin.dnsmasq: allow reading @{PROC}/@{pid}/fd/ as is needed by dnsmasq 2.81
See http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=commitdiff;h=48755ebf093543113de96747a7f5f78e0640b333 .

Signed-off-by: nl6720 <nl6720@gmail.com>
2020-04-12 12:15:05 +03:00