Commit graph

1166 commits

Author SHA1 Message Date
John Johansen
9dab5f07f4 Merge branch 'cboltz-change-flags' into 'master'
prevent that aa-complain etc. overwrites flags in child profiles if they differ from the main profile

See merge request apparmor/apparmor!150

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 09:59:39 +00:00
John Johansen
e4e73e3dc0 Merge branch 'cboltz-notify-pkg' into 'master'
make message about notify-send package cross-distro compatible

See merge request apparmor/apparmor!144

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 09:24:58 +00:00
Christian Boltz
b00aab0843
let change_profile_flags() change flags in child profiles
... instead of overwriting them with the flags of the main profile.

This fixes a longstanding issue with aa-complain, aa-enforce and
aa-audit which broke the flags of child profiles and hats if they
differed from the main profile.

It also fixes several issues documented in the tests (which obviously
need adjustment to match the fixed behaviour).

Also change the "no profile found" cases to AppArmorException - errors
in a profile are not worth triggering AppArmorBug ;-)
2018-07-25 23:22:33 +02:00
Christian Boltz
d26ffbdd29
change_profile_flags: raise AppArmorBug on empty new flag 2018-07-25 23:21:28 +02:00
Christian Boltz
c016fc6656
merge set_profile_flags() into change_profile_flags()
(and adjust a few comments in profile_storage.py)
2018-07-25 22:25:38 +02:00
Christian Boltz
abd124c00d
rewrite set_profile_flags() tests to use change_profile_flags()
All callers call change_profile_flags(), so it makes sense to test this
function instead of set_profile_flags().

Besides that, set_profile_flags() will be merged into
change_profile_flags() in the next commit ;-)

Note that this commit adds some '# XXX' notes to the tests. These will
be addressed in later commits.
2018-07-25 22:20:48 +02:00
Christian Boltz
4a021ec203
change_profile_flags: use ', ' as flags delimiter
This looks better than a comma without whitespace.

Also adjust minitools_test.py to follow this change.
2018-07-25 21:33:22 +02:00
Christian Boltz
e80caa130a
extend add_or_remove_flag() to handle str for old flags
If the old flags are given as str (or None), call split_flags() to
convert them to a list.

This allows to simplify change_profile_flags() which now doesn't need to
call split_flags() on its own.

Also add some tests with a str for the old flags
2018-07-25 20:59:34 +02:00
Christian Boltz
604004c2b6
split off add_or_remove_flag() from change_profile_flags()
Also add some tests for add_or_remove_flag()
2018-07-25 20:44:39 +02:00
Christian Boltz
ce7ea062c5
move splitting flags into profile_storage split_flags() function
... and change change_profile_flags() to use it instead of doing it
itsself

Also add some tests for split_flags()
2018-07-25 20:36:45 +02:00
Christian Boltz
9d78694b00
activate_repo_profiles(): use change_profile_flags
... instead of set_profile_flags() to keep possibly existing flags like
attach_disconnected.

Note that this function is unused (meant to be used with the
no-longer-existing profile repo), therefore nobody noticed that
set_profile_flags() was called with the wrong number of parameters ;-)
2018-07-25 17:41:42 +02:00
Christian Boltz
44ee1d5090
make message about notify-send package cross-distro compatible
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1100779
2018-07-12 22:00:41 +02:00
Christian Boltz
73b33bdf36
Fix unsetting filename in get_profile()
When creating a new profile with aa-genprof, get_profile() searches for
an inactive ("extra") profile and, if it finds one, removes the filename
from that profile so that it gets stored in /etc/apparmor.d/ later.

However, it used .pop() to remove the filename, which explodes since
ProfileStorage is a class now.

This patch fixes this (tested manually).
2018-07-03 18:34:23 +02:00
Christian Boltz
b613860f14
serialize_profile: simplify setting of include_flags
Note that NO_FLAGS was an inverse option, therefore
- NO_FLAGS was changed to FLAGS (also in sync_profile() which is the
  only caller that sets FLAGS)
- the default for include_flags (if FLAGS is not set) is True
2018-06-25 22:55:26 +02:00
Christian Boltz
9865e112f7
serialize_profile(): simplify setting include_metadata 2018-06-25 22:47:30 +02:00
Christian Boltz
5ef95fff4f
serialize_profile(): add type check for options
This makes the "if options:" check superfluous, therefore remove it and
change the whitespace of the following lines
2018-06-25 22:43:39 +02:00
Christian Boltz
7e42135010
fix serialize_profile() calls to always use a dict for options 2018-06-25 21:42:29 +02:00
Christian Boltz
db7983aee5
simplify setting serialize_options 2018-06-25 21:39:47 +02:00
Christian Boltz
b7a4f37cbb Merge branch 'cboltz-nested-child-error' into 'master'
parse_profile_start(): Error out on nested child profiles

See merge request apparmor/apparmor!136

Acked-by: John Johansen <john.johansen@canonical.com> for 2.10..master
2018-06-21 10:20:03 +00:00
Christian Boltz
82eb749b6f Merge branch 'cboltz-view-changes' into 'master'
use serialize_profile() for the new profile in (V)iew Changes

See merge request apparmor/apparmor!131

Acked-by: John Johansen <john.johansen@canonical.com>
2018-06-21 10:19:12 +00:00
Christian Boltz
6c8fff099f Merge branch 'cboltz-simplify-write-vars' into 'master'
simplify write_list_vars()

See merge request apparmor/apparmor!130

Acked-by: John Johansen <john.johansen@canonical.com>
2018-06-20 15:52:02 +00:00
Christian Boltz
8462c39b14
parse_profile_start(): Error out on nested child profiles
The tools can't handle nested child profiles yet. Instead of failing
in funny[tm] ways (parse_profile_start() only returned the first two
segments of the profile name) better error out with a clear message.
2018-06-20 14:43:48 +02:00
Christian Boltz
2312873406
add some tests for BaseRule/BaseRuleset
These tests verify that
- _is_equal_aare() really raises an exception when it sees an invalid
  combination of other_value and other_all
- BaseRuleset.__repr__() works as expected

As a side effect, this commit pushes the test coverage of
apparmor/rule/__init__.py to 100% ;-)
2018-06-09 20:53:53 +02:00
Christian Boltz
82fc0b8239
delete now unused serialize_parse_profile_start()
(another function that was only used by
serialize_profile_from_old_profile())

Also delete the tests we had for that function.
2018-06-09 15:27:26 +02:00
Christian Boltz
0eb12a8cbd
delete serialize_profile_from_old_profile()
... which is unused since the last commit.

Also delete several functions that were only used by this function:
- write_change_profile()
- write_rlimits()
- write_capabilities()
- write_netdomain()
- write_dbus()
- write_signal()
- write_ptrace()
- write_file()

Finally, no longer import some functions from profile_storage:
- write_links
- write_mount
- write_pivot_root
- write_unix

BTW: Deleting these 460 lines improves test coverage of aa.py from
38% to 44%, and total test coverage from 63% to 66% :-)
2018-06-09 15:13:50 +02:00
Christian Boltz
469eb444de
use serialize_profile() for the new profile in (V)iew Changes
... instead of serialize_profile_from_old_profile()

This will give a realistic preview of the changes (serialize_profile()
is also used when actually writing the profile) and replaces the
known-buggy serialize_profile_from_old_profile() with known-working
code.

It also fixes the issue reported in
    https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1528139
which means we no longer need the workaround of catching AttributeError
(verified in manual before/after test)

References:
- https://bugs.launchpad.net/apparmor/+bug/1394788
- https://bugs.launchpad.net/bugs/1528139
- https://bugs.launchpad.net/apparmor/+bug/1404893
2018-06-09 15:10:07 +02:00
Christian Boltz
af9490556d
get rid of superfluous variables in write_list_vars()
- rename prof_data parameter to ref
- drop empty allow, prefix and tail, and their usage in the format
  string
- inline sep into the format string
- replace usage of fn with the actual function name (var_transform)
2018-05-31 22:09:26 +02:00
Christian Boltz
5ae94391c5
inline set_ref_allow() into write_list_vars()
set_ref_allow() is only used by write_list_vars(). Inline it (actually
only the used, boring if branch) to simplify the code.
2018-05-31 22:00:50 +02:00
Christian Boltz
06eb65eb50
inline write_pair() into write_list_vars()
write_pair() is only used by write_list_vars(), so there's no need to
keep it as a separate function
2018-05-31 22:00:50 +02:00
Christian Boltz
c2a420d32b
let var_transform() sort variable content
This is needed to get a reproducible output.

Also adjust the tests in test-profile-storage.py and add some example
variable to cleanprof.in and cleanprof.out
2018-05-31 22:00:36 +02:00
John Johansen
c9d341782e Merge branch 'cboltz-move-write-methods' into 'master'
Cboltz move write methods

See merge request apparmor/apparmor!122
2018-05-25 12:38:12 +00:00
John Johansen
097ff0fa6b Merge branch 'cboltz-drop-safety-nets' into 'master'
Drop some safety nets in aa.py

See merge request apparmor/apparmor!113
2018-05-25 12:34:28 +00:00
Christian Boltz
79d9ee5c3b
test-libapparmor-test_multi: initialize parent profiles
If a log line contains a denial for a child profile, log_dict will
(obviously) only contain the child profile. However, serialize_profile()
expects that the parent profile is also initialized as ProfileStorage.

This patch makes sure the parent profile gets initialized.

It also removes 26 of the 37 reasons in the TODO note in aa.py :-)
2018-05-10 12:44:04 +02:00
Christian Boltz
fbfeed0b65
Add get_rules_clean to ProfileStorage, and change write_rules to use it
ProfileStorage.get_rules_clean() returns all rules in a profile
(withouth the profile header or the closing '}')

Also change aa.py write_rules() to use get_rules_clean()
2018-05-09 22:36:38 +02:00
Christian Boltz
66620f3e19
move several write_* functions to apparmor.profile_storage
ProfileStorage() stores the content of a profile, so it makes sense to
also have the functions to write those rules (including helper functions
used by these functions) in the same file.

Note that I only moved the functions for rule types that are not handled
by *Ruleset classes.

The functions for writing rules stored in a *Ruleset class will
hopefully be superfluous sooner or later (probably later because
serialize_parse_profile_start() depends on them, and rewriting it won't
be easy)

Also move the test for var_transform() to test-profile-storage.py.
2018-05-09 22:23:34 +02:00
Christian Boltz
c47ed1d2e5
add more rule types to test/cleanprof.* profile 2018-05-09 22:04:04 +02:00
Steve Beattie
6a2b90ba56
utils: rewrite write_alias()
Merge remote-tracking branch 'cboltz/cboltz-rewrite-write_alias' from
Christian Boltz

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/120/
2018-05-08 08:26:20 -07:00
Steve Beattie
0b259753b8
utils: fix writing alias rules
Merge remote-tracking branch 'cboltz/cboltz-fix-write-alias' from
Christian Boltz.

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/119
2018-05-08 07:46:20 -07:00
Steve Beattie
c639836d1a
utils: test-libapparmor-test_multi.py: allow to parse a specific logfile
Merge branch cboltz-test-libapparmor-allow-single from Christian Boltz

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/118
2018-05-06 23:55:27 -07:00
Steve Beattie
3f92d285f9
utils: fix writing "link subset" rules
Merge branch 'cboltz-utils-fix-link-subset' from Christian Boltz

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/117
2018-05-06 22:26:23 -07:00
Steve Beattie
434c3f2264
utils: parse_profile_data(): error out on alias inside profile
Merge branch 'cboltz-strict-parse-alias' frim Christian Boltz
 
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/116
2018-05-06 22:10:53 -07:00
Christian Boltz
3ee6058050
rewrite write_alias()
Instead of calling write_pair() (which is quite complex because it needs
to handle multiple rule types), write the alias rules directly in
write_alias().

This comes with minor code duplication, but makes the code much more
readable (3 instead of 7 %s)
2018-05-06 20:07:28 +02:00
Christian Boltz
ae4ab62855
Fix writing alias rules
write_pair() ignored the 'tail' parameter, which resulted in writing
invalid alias rules (without the trailing comma).

Also add an alias to test/cleanprof.* to ensure it doesn't break again.
2018-05-06 19:38:38 +02:00
Christian Boltz
0bc6078cfd
test-libapparmor-test_multi.py: allow to parse a specific logfile
test-libapparmor-test_multi.py converts the libapparmor test_multi log
examples to profiles.

This patch allows to call test-libapparmor-test-multi.py with a logfile
(containing a single log line) as parameter. It will then print the
resulting profile.

Example:

  # python3 test-libapparmor-test_multi.py /path/to/libraries/libapparmor/testsuite/test_multi/testcase_dbus_01.in
  /tmp/apparmor-2.8.0/tests/regression/apparmor/dbus_service {
    dbus send bus=session path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello peer=(label=unconfined),

  }
2018-05-06 17:59:18 +02:00
Christian Boltz
514535608f
Fix writing "link subset" rules
Writing a "link subset" rule missed a space, which resulted in something
like
  link subset/foo -> /bar,

Also add a test rule to tests/cleanprof.* to ensure this doesn't break
again.
2018-05-06 14:56:45 +02:00
Christian Boltz
f910cb5559
parse_profile_data(): error out on alias inside profile
Defining an alias is only allowed outside of a profile.

Also add a parser test with an alias inside a profile.
2018-05-06 14:27:32 +02:00
Christian Boltz
2b7920ffec
simplify write_piece
write_piece() has some funny code that converts the result of
write_header() and write_rules() (which is a list) to... a list.

Needless to say that this is superfluous ;-)
2018-05-05 21:22:10 +02:00
Christian Boltz
62e429bc4b
Drop some safety nets in aa.py
match_includes() and is_known_rule() have safety nets to avoid troube if
include[incname][incname] is not a valid ProfileStorage object.
However, this situation shouldn't happen in practise anymore, so let's
drop these now superfluous safety nets.

I use this patch locally since months without problems.
2018-05-05 20:58:34 +02:00
Christian Boltz
5b9497a8c6
is_skippable_dir(): add 'cache.d' to exclude list
This excludes the /etc/apparmor.d/cache.d/ directory from aa-logprof
parsing because parsing the binary cache, well, takes a while :-/

Reported on the opensuse-factory mailinglist by Frank Krüger and
confirmed by others.
2018-04-30 00:57:52 +02:00
John Johansen
aa7dc70de3 translations: sync from launchpad translations
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-04-15 06:54:44 -07:00