Commit graph

1384 commits

Author SHA1 Message Date
Christian Boltz
ec741424f8
split get_profile_filename into .._from_profile_name and .._from_attachment
Split get_profile_filename() into
- get_profile_filename_from_profile_name() (parameter: a profile name)
- get_profile_filename_from_attachment() (parameter: an attachment)

Currently both functions call get_profile_filename_orig() (formerly
get_profile_filename()) so the behaviour doesn't change yet.

The most important part of this commit is changing all
get_profile_filename() calls to use one of the new functions to make
clear if they specify a profile or an attachment/executable as
parameter.

As promised, the is_attachment parameter starts to get used in this
patch ;-)

Note: The get_new parameter (which I'll explain in the patch actually
using it) is set to True in all calls to the new functions.
The long term plan is to get rid of it in most cases (hence defaulting
to False), but that will need more testing.
2018-10-23 00:28:37 +02:00
Christian Boltz
bc783372b8
Add is_attachment parameter to write_profile
The minitools call write_profile(), write_profile_feedback_ui() and
serialize_profile() with the _attachment_ as parameter.

However, aa-logprof etc. call them with the _profile name_ as parameter.

This patch adds an is_attachment parameter to write_profile() and
write_profile_feedback_ui(). It also passes it through to
serialize_profile() via the options parameter.

If is_attachment is True, the parameter will be handled as attachment,
otherwise it is expected to be a profile name.

tools.py gets changed to set is_attachment to True when calling the
functions listed above to make clear that the parameter is an attachment.

Note: This patch only adds the is_attachment parameter/option, but
doesn't change any behaviour. That will happen in the next patch.
2018-10-23 00:18:04 +02:00
nl6720
2209e09aef aa-notify man page: update user's configuration file path
Signed-off-by: nl6720 <nl6720@gmail.com>
2018-10-15 16:44:00 +03:00
Christian Boltz
5c54f66279
Add most abi/bad_*.sd tests to "exception not raised" list
Interestingly, abi/bad_6.sd is detected as invalid, and therefore not
added to the list.
2018-10-13 20:23:57 +02:00
Christian Boltz
bc492533cc
Fix aa-mergeprof crash caused by accidentially initialzed hat
Hasher causes some fun in aa-mergeprof: If the profile in
/etc/apparmor.d/ has a hat or subprofile that doesn't exist in the
to-be-merged profile, aa-mergeprof crashes. This is caused by reading
self.other.aa[program][hat]['include'] which accidently "creates" that
profile inside the aa hasher as empty hasher (instead of ProfileStorage).

Later, the code loops over self.other.aa[profile].keys(), expects
everything to be ProfileStorage, and explodes [1] when for example
trying to run .delete_duplicates on the hasher (which obviously doesn't
provide this method).

This patch adds checks to all self.other.aa accesses in
CleanProf.remove_duplicate_rules() to avoid accidently creating new keys
in the hasher.

Interestingly this bug survived unnoticed for years (at least since
2.11).

[1] last lines of the backtrace:
  File ".../utils/apparmor/cleanprofile.py", line 42, in compare_profiles
    deleted += self.remove_duplicate_rules(profile)
  File ".../utils/apparmor/cleanprofile.py", line 65, in remove_duplicate_rules
    deleted += apparmor.delete_duplicates(self.other.aa[program][hat], inc)
  File ".../utils/apparmor/aa.py", line 1680, in delete_duplicates
    deleted += profile[rule_type].delete_duplicates(include[incname][incname][rule_type])
AttributeError: 'collections.defaultdict' object has no attribute 'delete_duplicates'
2018-10-11 19:49:26 +02:00
nl6720
1fb9acc59e aa-notify: Read user's configuration file from XDG_CONFIG_HOME
Legacy path ~/.apparmor/notify.conf is preferred if it exists, otherwise
$XDG_CONFIG_HOME/apparmor/notify.conf, with fallback to
~/.config/apparmor/notify.conf, is used.

Signed-off-by: nl6720 <nl6720@gmail.com>
2018-10-03 12:38:28 +03:00
John Johansen
22fca3c217 Merge branch 'cboltz-log-to-profile-empty' into 'master'
test-libapparmor-test_multi.py: test for known-empty log

Add a check to logfile_to_profile() that checks the parsed log against a
list of input logs (log_to_profile_known_empty_log) that produce an
empty output.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/214

Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-03 06:47:21 +00:00
Christian Boltz
cf33ec99fc
test-libapparmor-test_multi.py: test for known-empty log
Add a check to logfile_to_profile() that checks the parsed log against a
list of input logs (log_to_profile_known_empty_log) that produce an
empty output.
2018-10-01 20:55:03 +02:00
Christian Boltz
072d3e0451
Add basic support for abi rules to the tools
Add basic "understand and keep" support for abi rules, where
"understand" means to not error out when seeing an abi rule, and "keep"
simply means to keep the original abi rule when serializing a profile.

On the long term, abi rules should be parsed (similar to include rules),
but for now, this patch is the smallest possible changeset and easy to
backport.

Note that the only added test is via cleanprof_test.* which is used by
minitools_test.py - and does _not_ run if you do a 'make check'.
Oh, and of course the simple_tests/abi/ files also get parsed by
test-parser-simple-tests.py.

Also note that serialize_profile_from_old_profile() (which no longer
exists in master, "only" in <= 2.13) would in theory also need support
for abi rules. In practise, making this another case of
"serialize_profile_from_old_profile() has known issues" is probably
fine, but we should at least test that "(V)iew changes" doesn't break if
an abi rule is present.
2018-09-26 22:09:17 +02:00
Emerson Bernier
00871696f1 add zsh to logprof.conf 2018-09-24 16:51:11 +00:00
Christian Boltz
db096135eb
add python3.7 to logprof.conf 2018-09-15 00:32:48 +02:00
Tyler Hicks
2f0a773506 utils: Point to the correct Profiles wiki page
The URL redirect ends up at a page in the new wiki that doesn't exist.
We have to link directly to the gitlab URL here since the current URL
redirect doesn't let us use a wiki.apparmor.net URL and still reach the
expected Profiles page.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 16:46:10 +00:00
Tyler Hicks
eb8975e0cc all: Use HTTPS links for apparmor.net
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 16:41:32 +00:00
Christian Boltz
51482c33f5
remove unused exception binding in sandbox.py
pyflakes 2.0 is more strict and found that 'e' is never used.

References: https://build.opensuse.org/request/show/629206 (comment
section)
2018-08-22 21:23:25 +02:00
John Johansen
86053c9e38 Merge branch 'cboltz-genprof-readonly-ratelimit' into 'master'
aa-genprof: don't crash if setting printk_ratelimit fails

See merge request apparmor/apparmor!157

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 10:02:25 +00:00
John Johansen
c66a1a972c Merge branch 'cboltz-fix-complain-named-profiles' into 'master'
set_profile_flags(): allow named profiles without attachment

See merge request apparmor/apparmor!142

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 10:00:49 +00:00
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
961e69afe5
aa-genprof: don't crash if setting printk_ratelimit fails
When running aa-genprof in a lxd instance, printk_ratelimit is readonly
and writing to it fails. Instead of crashing with a backtrace, only
print a warning.

References: https://bugs.launchpad.net/apparmor/+bug/1785391
2018-08-05 14:46:13 +02: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
0dca959c6b
set_profile_flags(): allow named profiles without attachment
Named profiles can come without an attachment path specified, for
example
    profile foo {...}

This patch fixes set_profile_flags() to actually allow that instead of
erroring out.

References:
- https://bugzilla.opensuse.org/show_bug.cgi?id=1096269 comment #3 and #4
- https://bugs.launchpad.net/apparmor/+bug/1775591
2018-07-10 01:00:00 +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