Commit graph

1384 commits

Author SHA1 Message Date
Christian Boltz
986b4f2b72 Merge branch 'cboltz-fix-genprof-json' into 'master'
Fix showing the local inactive profile in json mode

See merge request apparmor/apparmor!514

Acked-by: John Johansen <john.johansen@canonical.com> for 2.11..master
2020-05-06 22:43:35 +00:00
Christian Boltz
68a258b006
Fix showing the local inactive profile in json mode
When aa-genprof proposes a local inactive profile, it had a hardcoded
call to 'less' to display that profile.

Unsurprisingly, this doesn't work in JSON mode and breaks YaST (luckily
it's only a case of "the button doesn't work").

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1171315
2020-05-06 23:20:07 +02:00
Christian Boltz
bb3803b931
Split off UI_ShowFile() from UI_Changes
UI_ShowFile() is more generic and can be used to display various (text)
files, not only diffs.
2020-05-06 23:16:47 +02:00
Christian Boltz
4906bbf965
get_profile(): get rid of profile_type
It's always set to 'INACTIVE_LOCAL' - no need to set and later check it.

Also add a TODO note ;-)
2020-05-06 22:53:57 +02:00
Christian Boltz
f96304fe33
get_profile(): get rid of profile_data variable
... which also makes the code easier to understand
2020-05-06 22:53:22 +02:00
Christian Boltz
476848da46
get_profile: convert profile_hash from hasher() to dict 2020-05-06 22:53:22 +02:00
Christian Boltz
47620e10cb
Rewrite get_profile() to exit early if no extra profile exists 2020-05-06 22:53:22 +02:00
Christian Boltz
2d2fc41cc1
inline get_inactive_profile() into get_profile()
... which is the only user of get_inactive_profile()
2020-05-06 22:53:22 +02:00
Steve Beattie
e6cf0d44d1 utils + parser: minor test cleanups
Fix a typo, some shellcheck warnings, and move one test script from using bash to dash.

See merge request apparmor/apparmor!512

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <opensuse@cboltz.de>
https://gitlab.com/apparmor/apparmor/-/merge_requests/512
2020-05-06 20:35:28 +00:00
Christian Boltz
c7949ba6c4
Read all profiles on aa-genprof startup instead of later
... which can mean "too late" in some special cases (if a profile
already exists in /etc/apparmor.d/$non_default_filename).

However, the main reason is that without this change
- the new profile will be added to (otherwise empty) active_profiles
- the first do_logprof_pass() will read all profiles, including the new
  one, and add them to active_profiles - which unsurprisingly results in
  an error like `ERROR: Profile /usr/sbin/vsftpd exists in
  /etc/apparmor.d/usr.sbin.vsftpd and /etc/apparmor.d/usr.sbin.vsftpd`

To fix this,
- change do_logprof_pass to never call read_profiles() (and get rid of
  the 'passno' parameter)
- adjust its callers (aa-logprof and aa-genprof) to call read_profiles()
  themself
- move printing the 'Updating AppArmor profiles in $directory.' message
  to read_profiles(), but only display it if requested (to keep the
  current UI behaviour)
2020-05-05 23:56:55 +02:00
Christian Boltz
db9f8d38b0
Fix aa-genprof/aa-autodep crash
Since 4b7108f1e5, aa-genprof and
aa-autodep crashed with

    apparmor.common.AppArmorBug: /etc/apparmor.d/usr.sbin.vsftpd not listed in ProfileList files

because the profile was not added to active_profiles.

Add the profile to active_profiles to fix this regression, and to have
all the needed data in active_profiles.
2020-05-05 22:24:08 +02:00
Steve Beattie
253073b798
utils test: fix typo in simple_tests output
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 11:54:49 -07:00
Christian Boltz
256f55925c
Drop profile repo code from utils
The profile repo is dead since years and most likely won't come back, so
there's no point in keeping and maintaining the code for uploading and
downloading profiles.
2020-05-05 13:09:16 +02:00
John Johansen
5d52ab0783 Merge Handle preamble "include if exists" rules in ProfileList
Add support for handling `include if exists` rules in profile preambles in the `ProfileList` class.

Besides that, do some groundwork for future changes - see the individual commits for details and spoilers ;-)

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/507
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-05 07:18:09 +00:00
John Johansen
c386d93581 docs: update documentation to point bug reporting to gitlab
Move suggested bug reporting from launchpad to gitlab

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 00:10:53 -07:00
Christian Boltz
4b7108f1e5
Store and write 'include if exists' rules in the preamble
... using the new storage in ProfileList.

Also add a test rule to cleanprof.{in,out} to ensure the rule is kept.
2020-05-04 22:14:52 +02:00
Christian Boltz
07b52134f4
Extend ProfileList to store and write include rules
- add_inc_ie() stores include and include if exists rules
- get_clean() and get_raw() return the profile preamble (currently only
  the include rules)

Also add tests for the new functions.
2020-05-04 22:14:44 +02:00
Christian Boltz
1569136180
Add get_clean_unsorted() to BaseRuleset
This is similar to get_clean(), but keeps the original rule order
instead of sorting them.

This is useful for include rules in the preamble, where the order might
be relevant - for example if the first include defines a variable that
is then used or extended in the second include file.
2020-05-04 21:59:02 +02:00
Christian Boltz
10fbdb28d3
ProfileList: keep track of profiles in each file
(not used yet, but will be useful later to replace
aa.filelist[$file]['profiles'] ;-)
2020-05-04 21:59:02 +02:00
Christian Boltz
c670d294eb
Rename TestAdd and its functions to TestAdd_profile
This is a follow-up of 5983598ef5
2020-05-04 21:59:02 +02:00
Steve Beattie
64be247aae utils: ProfileList: rename add() to add_profile()
Merge branch 'cboltz-profile-list-rename-add' into 'master'

See merge request apparmor/apparmor!502
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-04 19:47:17 +00:00
Christian Boltz
5983598ef5
ProfileList: rename add() to add_profile()
This makes the syntax more clear, and is a preparation to allow adding
some more things (like global includes and variable definitions)
2020-05-03 22:37:20 +02:00
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