Commit graph

1562 commits

Author SHA1 Message Date
Christian Boltz
6c4054fa91
Better descriptions why some example profiles fail with the tools 2020-05-03 22:07:25 +02:00
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
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
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
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
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
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
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
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
0f891ba30e
Delete (possibly broken) apparmor.vim on failure
If create-apparmor.vim.py fails, an empty apparmor.vim gets created. The
next "make" run will assume that apparmor.vim was already created (the
file exists and has a new-enough timestamp) and will therefore skip the
create-apparmor.vim.py run, keeping the broken apparmor.vim forever.

Adjust the Makefile to delete apparmor.vim if the script fails. This
ensures that make tries again in the next run.
2020-04-05 14:31:33 +02:00
Christian Boltz
9e7c4f88f9
create-apparmor.vim.py: split stdout and stderr
This will prevent that stderr output ends up in apparmor.vim

References:
- https://gitlab.com/apparmor/apparmor/issues/75
- https://bugs.archlinux.org/task/65450
- https://bugs.launchpad.net/apparmor/+bug/1187437
2020-04-05 14:26:15 +02:00
Christian Boltz
60b005788e
fix capabilities in apparmor.vim
https://gitlab.com/apparmor/apparmor/-/merge_requests/461 /
e92da079ca changed creating the
capabilities to use a script.

A side effect is that the list is now separated by \n instead of
spaces. Adjust create-apparmor.vim.py to the new output.
2020-03-29 00:07:11 +01:00
allgdante
e92da079ca Generate CAPABILITIES in a script due to make 4.3
This way we could generate the capabilities in a way that works with
every version of make.
Changes to list_capabilities are intended to exactly replicate the old
behavior.
2020-03-23 15:09:15 +00:00
Launchpad Translations on behalf of apparmor-dev
f6c4461a2c
Launchpad automatic translations update. 2020-03-07 16:10:25 -08:00
Launchpad Translations on behalf of apparmor-dev
58769a4765
Launchpad automatic translations update. 2020-03-07 16:10:18 -08:00
Launchpad Translations on behalf of apparmor-dev
ba232c0e9c
Launchpad automatic translations update. 2020-02-24 09:59:44 -08:00
Launchpad Translations on behalf of apparmor-dev
300e3488ee
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-24 09:59:37 -08:00
Launchpad Translations on behalf of apparmor-dev
ad524d7a85
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:18 -08:00
Launchpad Translations on behalf of apparmor-dev
77dbb4e1a7
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:18 -08:00
Launchpad Translations on behalf of apparmor-dev
938d908462
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:17 -08:00
Launchpad Translations on behalf of apparmor-dev
4d758cc2ab
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:17 -08:00
Launchpad Translations on behalf of apparmor-dev
2aa6f56e4a
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:17 -08:00
Launchpad Translations on behalf of apparmor-dev
78a66a6676
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:16 -08:00
Launchpad Translations on behalf of apparmor-dev
fbf91cfde3
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:16 -08:00
Launchpad Translations on behalf of apparmor-dev
d0708bc782
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:15 -08:00
Launchpad Translations on behalf of apparmor-dev
27fa9a2eaa
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:14 -08:00
Launchpad Translations on behalf of apparmor-dev
0adbd59dbf
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:14 -08:00
Launchpad Translations on behalf of apparmor-dev
47bae2b6e1
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:13 -08:00
Launchpad Translations on behalf of apparmor-dev
8b09271128
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:13 -08:00
Launchpad Translations on behalf of apparmor-dev
010e4fa5fe
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:12 -08:00
Launchpad Translations on behalf of apparmor-dev
9eb195d565
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:12 -08:00
Launchpad Translations on behalf of apparmor-dev
dc7c20ce6d
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:12 -08:00
Christian Boltz
ee8dcde452
let logprof only propose abstractions without '# LOGPROF-SUGGEST: no'
This implements one part of
https://gitlab.com/apparmor/apparmor/issues/15
2020-02-11 21:33:49 +01:00
John Johansen
2416faac54 parser: support matching xattr keys but not values
Support profiles that choose to match the presence of an extended
attribute without validating its value. This lets AppArmor target xattrs
with binary data, such as security.ima and security.evm values. For
example, it's now possible to write a profile such as:

        profile signed_binaries /** xattrs=(security.ima) {
                # ...
        }

Both presence and value matches can be used in the same profile. To
match a signed xattr, target both the xattr and the security.ima value:

        profile python_script /** xattrs=(
                security.evm
                security.apparmor="python"
        ) {
                # ...
        }

Updated to work using out of band matching instead of separate data
array.

Signed-off-by: Eric Chiang <ericchiang@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
Christian Boltz
001ea9e3af
Drop 'localinclude' in parse_profile_data() and ProfileStorage
'localinclude' is/was meant to have 'local/*' includes separate, but
it's write-only and never used, which makes it useless.

Additionally, it causes a crash in the aa-* tools which gets fixed by
removing all the 'localinclude'-related code (what a big word for two
lines ;-)

References: https://bugs.launchpad.net/apparmor/+bug/1848227
2019-10-16 21:30:43 +02:00
Christian Boltz
b76567ce10 Merge branch 'cboltz-status-parenthesis' into 'master'
aa-status: handle profile names containing '('

Closes #51

See merge request apparmor/apparmor!415

Acked-by: John Johansen <john.johansen@canonical.com> for 2.10..master
2019-09-23 18:55:22 +00:00
Paulo Gomes
2d19d4d159
Fix capability mispelling. 2019-09-17 10:38:09 +01:00
Christian Boltz
41d26b0197
aa-status: handle profile names containing '('
aa-status crashed if a profile name contains an opening parenthesis
because the regex enforces (simplified) '^[^(]* \(.*\)' when reading
/sys/kernel/security/apparmor/profiles

This obviously doesn't match if a profile name contains '(' which is
rare and strange, but still allowed, and the match result "None" then
crashes aa-status.

Adjust the regex to allow all chars instead of all except '(' to handle
these corner cases.

Note that '(enforce)' and '(complain)' still get read correctly because
the regex ends with '\((\w+)\)$' and therefore enforces matching
"something inside parenthesis at the end of the line".

This bug exists since aa-status was rewritten into python, and even
existed in the perl version before. However, in the perl version, the
regex matching was protected with an if so profile names with '(' were
skipped and hidden from the aa-status output.

Fixes: https://gitlab.com/apparmor/apparmor/issues/51
2019-08-16 22:10:36 +02:00
Christian Boltz
e246568819
fix whitespace and indentation in several files 2019-08-12 23:58:04 +02:00