Commit graph

1043 commits

Author SHA1 Message Date
Christian Boltz
5431db744f [11/38] FileRule: Handle duplicated exec permissions
The parser accepts duplicated execute permissions as long as they don't
conflict. For example,
	/bin/foo pxpxpxpx,
is a valid rule.

This patch changes FileRule to also accept those duplicated permissions,
even if it's unlikely to hit them outside of the parser tests ;-)

Also add some tests to make sure the parsing works as expected.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 19:52:12 +02:00
Christian Boltz
68ccc4eea5 [10/38] RE_PATH: allow to match '/'
RE_PATH expected (simplified) '/.+', however this excludes a plain '/'
that can appear in path rules.

This patch changes the regex so that it also matches '/'.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:51:36 +02:00
Christian Boltz
b84877b900 [09/38] Drop contains() in aamode.py
After dropping the dead code in handle_children(), there's only one use
of contains() left in log_str_to_mode().

This patch changes log_str_to_mode to use mode_contains() and drops the
now unused contains() function.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:50:57 +02:00
Christian Boltz
b8171d547e [08/38] Drop dead code in aa.py handle_children()
The 'exec' handling in handle_children starts with

     if do_execute:
         if profile_known_exec(...)
            continue

which means if profile_known_exec() returns True, the rest of the loop
will be skipped. profile_known_exec() will return True if it finds an
exec rule in the profile or an include (independent of the exec type,
and (thanks to rematchfrag()) even if the path is globbed.

Later in the loop, there are checks for various exec modes - but those
checks can only be reached without an existing x rule, so they'll never
be hit.

This patch removes the dead code in the handle_children() / 'exec' / 'no
existing x rule found' section.

I confirmed that this code is really dead by
a) reading the code and, after being confused
b) two manual aa-logprof runs with coverage enabled - in one of them, I
   added some ix, Px and Cx rules, and in the second one, no more exec
   rules were needed/asked.

After dropping the dead code, combinedmode and combinedaudit are no
longer used, so we can also drop the code that sets those variables.


Sidenote: this patch drops 2% of the lines in aa.py ;-)



Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:49:50 +02:00
Christian Boltz
c8e98de53a [07/38] Add tests for FileRule
As usual, we have 100% test coverage - at least until patch 22, which
introduces one 'partial' ;-)


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:49:00 +02:00
Christian Boltz
05e57e3932 [06/38] Add FileRule and FileRuleset
These classes handle file rules, including file rules with leading
perms, and are meant to replace lots of file rule code in aa.py and
aa-mergeprof.

Note: get_glob() and logprof_header_localvars() don't even look
finalized and will be changed in a later patch. (Some other things will
also be changed or added with later patches - but you probably won't
notice them while reviewing this patch.)


Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Kshitij Gupta <kgupta8592@gmail.com> (with some suggestions for a follow-up patch)



v1.1: remove 'and not deny' from a condition in split_perms() to get
more helpful error messages for rules like "deny /foo pix,"

Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 19:47:52 +02:00
Christian Boltz
8a875d84d2 [05/38] Make sanity check in _is_covered_list() optional
_is_covered_list() has a sanity check that raises an exception if both
other_value and other_all evaluate to False. This breaks when using
_is_covered_list() for FileRule.perms which can be empty if exec_perms
are specified.

This patch adds an optional parameter that allows to skip the sanity
check.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:47:19 +02:00
Christian Boltz
9eb7ce5992 [04/38] Add detailed regex for file rules
For now, use an additional regex RE_PROFILE_FILE_ENTRY to avoid
breakage of the existing code by the added match groups.

The regex includes support for file rules with leading and trailing
permissions as well as bare file rules.

Note: even with the restriction to the permission letters we actually
use, it's in theory still possible that a future additional rule type or
permission letter might lead to additional matches for other rule types.
Therefore the parsing code should check for all other rule types before
matching for file rules.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:46:37 +02:00
Christian Boltz
1302c5cf96 [03/38] check_and_split_list(): allow 'lst' parameter to be a set
list, tuple, set - does python offer even more array types? ;-)


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2016-10-01 19:46:15 +02:00
Christian Boltz
f1ecae9d4e [02/38] check_and_split_list: optionally allow empty list
File permissions can be an empty list (if only exec permissions are
specified). This patch adds the optional allow_empty_list parameter so
that the function can handle this case.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:45:51 +02:00
Christian Boltz
46350f7e27 [01/38] Pass 'strict' flag from is_equal to is_equal_localvars
File rules contain some optional details (like leading permissions and
the file keyword) which should be ignored in non-strict mode.

This patch passes through the 'strict' parameter to is_equal_localvars
and adds it as function parameter in all existing rule classes.
It also adjusts test-baserule.py to test with the additional parameter.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:45:16 +02:00
Steve Beattie
4492e7cb2d utils/test/test-aa.py: skip tests that break with python2.7
For reasons that aren't entirely clear, the action to set
apparmor.aa.cfg['settings']['ldd'] to './fake_ldd' does not actually
work on python2.7, get_reqs() tries to use /usr/bin/ldd anyway (printing
out the contents of apparmor.aa.cfg['settings']['ldd'] after the set
operation shows it to still contain '/usr/bin/ldd' o.O). Therefore, skip
these two tests when running under python2.7.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>

Bug: https://launchpad.net/bugs/1522938
2016-09-21 11:52:42 -07:00
Christian Boltz
b6734696ea Allow 'kcm' in network rules
This is probably
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/Documentation/networking/kcm.txt


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10.

Bug: https://launchpad.net/bugs/1513880
2016-09-12 23:34:11 +02:00
Christian Boltz
e2039f021e Fix aa-logprof "add hat" endless loop
This turned out to be a simple case of misinterpreting the promptUser()
result - it returns the answer and the selected option, and
"surprisingly" something like
    ('CMD_ADDHAT', 0)
never matched
    'CMD_ADDHAT'
;-)

I also noticed that the new hat doesn't get initialized as
profile_storage(), and that the changed profile doesn't get marked as
changed. This is also fixed by this patch.


References: https://bugs.launchpad.net/apparmor/+bug/1538306



Acked-by: Steve Beattie <steve@nxnw.org> for trunk, 2.10 and 2.9
2016-08-15 22:02:55 +02:00
Christian Boltz
c8bc128039 type_is_str(): make pyflakes3 happy
pyflakes3 doesn't check sys.version and therefore complains about
'unicode' being undefined.

This patch defines unicode as alias of str to make pyflakes3 happy, and
as a side effect, simplifies type_is_str().


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10.
2016-08-12 12:02:20 +02:00
Christian Boltz
9a76e33e9b delete_duplicates(): don't modify self.rules while looping over it
By calling self.delete() inside the delete_duplicates() loop, the
self.rules list was modified. This resulted in some rules not being
checked and therefore (some, not all) superfluous rules not being
removed.

This patch switches to a temporary variable to loop over, and rebuilds
self.rules with the rules that are not superfluous.

This also fixes some strange issues already marked with a "Huh?" comment
in the tests.


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10.

Note that in 2.10 cleanprof_test.* doesn't contain a ptrace rule,
therefore the cleanprof_test.out change doesn't make sense for 2.10.
2016-08-08 23:14:33 +02:00
Christian Boltz
00026d74ca logparser: store network-related params if an event looks like network
Network events can come with an operation= that looks like a file event.
Nevertheless, if the event has a typical network parameter (like
net_protocol) set, make sure to store the network-related flags in ev.

This fixes the test failure introduced in my last commit.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com> for trunk, 2.10 and 2.9
2016-07-31 17:13:57 +02:00
Christian Boltz
89c9a8cdc5 logparser.py: ignore network events with 'send receive'
We already ignore network events that look like file events (based on
the operation keyword) if they have a request_mask of 'send' or
'receive' to avoid aa-logprof crashes because of "unknown" permissions.
It turned out that both can happen at once, so we should also ignore
this case.

Also add the now-ignored log event as test_multi testcase.


References: https://bugs.launchpad.net/apparmor/+bug/1577051 #13


Acked-by: Tyler Hicks <tyhicks@canonical.com> for trunk, 2.10 and 2.9.
2016-07-30 00:41:43 +02:00
Tyler Hicks
cbaa772320 utils: Handle the safe/unsafe change_profile exec modes
https://launchpad.net/bugs/1584069

This patch adds support for the safe and unsafe exec modes for
change_profile rules. The logic is pretty simple at this point because
the kernel's default for exec modes changed in newer versions.
Therefore, this patch simply retains any specified exec mode in parsed
rules. If an exec mode is not specified in a rule, there is no attempt
to force the usage of "safe" because older kernels do not support it.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2016-07-20 17:24:11 -05:00
Christian Boltz
939587178b Drop unused escape() function from aa.py
Besides being unused, this function contains a broken regex.


References: https://bugs.launchpad.net/bugs/1593324


Acked-by: Steve Beattie <steve@nxnw.org>
2016-06-17 13:26:40 +02:00
Kshitij Gupta
242bbfbbeb Re-order imports in aa-mergeprof and rule/capability.py
Acked-by: Christian Boltz <apparmor@cboltz.de>
2016-06-10 01:18:32 +05:30
Christian Boltz
9ab68b9225 Add a note about still enforcing deny rules to aa-complain manpage
This behaviour makes sense (for example to force the confined program to
use a fallback path), but is probably surprising for users, so we should
document it.

References: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=826218#37


Acked-by: John Johansen <john.johansen@canonical.com> for trunk, 2.10 and 2.9
2016-06-05 23:43:29 +02:00
Christian Boltz
db093de5ff honor 'chown' file events in logparser.py
Also add a testcase to libapparmor's log collection


Acked-by: Kshitij Gupta <kgupta8592@gmail.com> for trunk, 2.10 and 2.9
2016-06-05 20:06:43 +02:00
Christian Boltz
fd17ff0daa aa-genprof: ask about profiles in extra dir (again)
Thanks to reading the wrong directory in read_inactive_profiles()
(profile_dir instead of extra_profile_dir), aa-genprof never asked about
using a profile from the extra_profile_dir.

Sounds like an easy fix, right? ;-)

After fixing this (last chunk), several other errors popped up, one
after the other:
- get_profile() missed a required parameter in a serialize_profile() call
- when saving the profile, it was written to extra_profile_dir, not to
  profile_dir where it (as a now-active profile) should be. This is
  fixed by removing the filename from existing_profiles{} so that it can
  pick up the default name.
- CMD_FINISHED (when asking if the extra profile should be used or a new
  one) behaved exactly like CMD_CREATE_PROFILE, but this is surprising
  for the user. Remove it to avoid confusion.
- displaying the extra profile was only implemented in YaST mode
- get_pager() returned None, not an actual pager. Since we have 'less'
  hardcoded at several places, also return it in get_pager()

Finally, also remove CMD_FINISHED from the get_profile() test in
test-translations.py.


(test-translations.py is only in trunk, therefore this part of the patch
is obviously trunk-only.)




Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk
Acked-by: John Johansen <john.johansen@canonical.com> for trunk + a 50% ACK for 2.10 and 2.9
Acked-by: Kshitij Gupta <kgupta8592@gmail.com> for trunk, 2.10 and 2.9
2016-06-01 21:04:13 +02:00
Christian Boltz
016668437d Update change_profile highlighting in apparmor.vim
This patch includes several changes and fixes in change_profile highlighting:
- allow audit and deny keywords
- allow bare change_profile rules
- allow change_profile rules without '-> ...' part
- allow usage of the new 'safe' and 'unsafe' keywords
- ensure the exec condition starts with / or @


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-27 20:05:21 +02:00
Steve Beattie
4d5a4675d8 translations: fix up msgfmt warnings
This commit touches up the .po files that generate warnings
when msgfmt processes them to create .mo files, at least with gettext
0.19.7-2ubuntu3 in Ubuntu 16.04 LTS. Example warning types cleaned up
include:

  ce.po:7: warning: header field 'Last-Translator' still has the initial default value
  ce.po:7: warning: header field 'Language' missing in header
  de.po:6: warning: header field 'Language-Team' still has the initial default value

This commit also fixes up po files where the Report-Msgid-Bugs-To:
field had not been updated, setting it with the email address
'AppArmor list <apparmor@lists.ubuntu.com>'

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2016-05-24 13:08:06 -07:00
Steve Beattie
ad65a4467e merge translations update from launchpad 2016-05-23 15:30:36 -07:00
Christian Boltz
e4cbcb4c85 Ignore file events with a request mask of 'send' or 'receive'
Those events are actually network events, so ideally we should map them
as such. Unfortunately this requires bigger changes, so here is a hotfix
that ignores those events and thus avoids crashing aa-logprof.

References: https://bugs.launchpad.net/apparmor/+bug/1577051
            https://bugs.launchpad.net/apparmor/+bug/1582374


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk, 2.10 and 2.9
2016-05-23 23:31:43 +02:00
Christian Boltz
80bfb955ac [9/9] Add support for dbus events to aa-logprof
In detail, this means:
- handle ptrace events in logparser.py
- "translate" those events in aa.py - from log (logparser.py readlog())
  to prelog (handle_children()) to log_dict (collapse_log()))
- finally ask the user about the ptrace in ask_the_questions()
  (no code change needed there)

Note that these changes are not covered by tests, however they worked in
a manual test with the log examples in the libapparmor testsuite.
Unfortunately there's no example log for eavesdrop, so it might be a
good idea to a) add such a log line and b) test with it

Acked-by: Seth Arnold <seth.arnold@canonical.com>


Note: as discussed on #apparmor, I changed the mapping of peer_profile so
that it ends up in peer=(label=...) instead of the wrong peer=(name=...).
2016-05-23 23:24:30 +02:00
Christian Boltz
c91fd7688a [8/9] Add support for handling dbus rules everywhere
"Everywhere" means aa-mergeprof and aa-cleanprof. In theory also
aa-logprof, but that needs some code that parses dbus log events ;-)

Also add some dbus rules to the aa-cleanprof test profiles to ensure
superfluous dbus rules get deleted.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-23 23:21:13 +02:00
Christian Boltz
c32e4d8b84 [7/9] Remove the DBUS_Rule class
DBUS_Rule (in rules.py) was added in r2424 as a "this is how it should
look like" proof of concept, but was never used.

We have a "real" class for dbus rules now, so we can drop the proof of
concept class.


Also remove a commented, old version of RE_DBUS_ENTRY from aa.py


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-23 23:19:59 +02:00
Christian Boltz
a293f066b5 [6/9] Use DbusRule and DbusRuleset
Change aa.py to use DbusRule and DbusRuleset in profile_storage,
parse_profile_data() and write_dbus. This also means we can drop the
now unused parse_dbus_rule() and write_dbus_rules() functions.

Raw_DBUS_Rule in rules.py is now also unused and can be dropped.


Also shorten the list of known-failing tests in
test-parser-simple-tests.py. Even if the list of removals doesn't look
too long, the generated_dbus/* removals mean 1989 tests now cause the
expected failures.

OTOH, I had to add 4 tests to the known-failing list:
- 3 tests with a "wrong" order of the conditionals which the parser
  accepts (which is slightly surprising, because usually we enforce the
  order of rule parts)
- one test fails because the path in the path= conditional doesn't start
  with / or a variable. Instead, it starts with an alternation, which
  wouldn't be allowed in file rules.

Those 4 failures need more investigation, but shouldn't block this
patchset.


Finally, adjust test-regex_matches.py to import RE_PROFILE_DBUS from
apparmor.regex instead of apparmor.aa.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-23 23:17:37 +02:00
Christian Boltz
e924168708 [5/9] Add tests for DbusRule and DbusRuleset
The tests include the two tests from test-dbus_parse.py, therefore
delete this file.

As usual, we have 100% coverage :-)

Also addd an explicit str() conversion to common_test.py to avoid
    TypeError: not all arguments converted during string formatting


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-23 23:15:19 +02:00
Christian Boltz
3ebc9d9bb3 [4/9] Add support for dbus events in parse_event()
Add the dbus-specific details to the event data returned by parse_event().


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-23 23:14:09 +02:00
Christian Boltz
3e1ef00d47 [3/9] Add DbusRule and DbusRuleset classes
Those classes will be used to parse and handle dbus rules.
They understand the syntax of dbus rules.

Note that get_clean() doesn't output superfluos things, so
  dbus ( send ),
will become
  dbus send,


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-23 23:13:19 +02:00
Christian Boltz
18b5894888 [2/9] Add strip_parenthesis() to regex.py
Some dbus rule conditionals come with optional parenthesis. Instead of
making the regex even more complicated, use a small function to strip
those parenthesis.

Also add some tests for strip_parenthesis() to test-regex.py.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2016-05-23 23:12:07 +02:00
Christian Boltz
2e2aa861d2 [1/9] add a named match group to RE_PROFILE_DBUS
As a preparation for the DbusRule class, add a <details> match group
to RE_PROFILE_DBUS.

Also adjust test-regex_matches.py for the added group.

Note: RE_PROFILE_DBUS is only used in aa.py, and only matches[0..2]
are used. 0 and 1 are audit and allow/deny and 2 is and stays the whole
rule (except audit and allow/deny). Therefore no aa.py changes are
needed.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-23 23:10:48 +02:00
Christian Boltz
472d534a0d test-translations.py: add two button sets used in aa-mergeprof
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-14 13:25:15 +02:00
Christian Boltz
f6d2ef85f5 load variables in ask_the_questions()
Variables can be used in several rule types (from the existing *Rule
classes: change_profile, dbus, ptrace, signal). It seems nobody uses
variables with those rules, otherwise we'd have received a bugreport ;-)

I noticed this while working on FileRule, where usage of variables is
more common. The file code in bzr (not using a *Rule class) already
loads the variables, so old versions don't need changes for file rule
handling.

However, 2.10 already has ChangeProfileRule and therefore also needs
this fix.


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10.
2016-05-10 14:32:46 +02:00
Christian Boltz
b7449494de Run utils tests with C locale
While running test-translations.py with the fixed german translations,
I noticed that I still get errors about hotkey conflicts

It turned out that test-translations.py reads the system-wide
apparmor-utils.mo in addition to the in-tree translations.
(I have the 2.11 beta1 translations installed, which contain hotkey
conflicts for the german translations).

This is surprising because test-translations.py explicitely sets the
locale path. Interestingly, this happens only 4 times (checked with a
temp profile with audit for those files) while test-translations.py has
9 tests).

(Any idea if this behaviour is normal or a bug?)


This patch adds LC_ALL=C to the make check and make coverage commandline
so that the system-wide translations don't get used.

I checked with a modified de.po that in-tree hotkey conflicts still get
detected.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-10 14:31:25 +02:00
Launchpad Translations on behalf of apparmor-dev
584f63d56b Launchpad automatic translations update. 2016-05-07 04:31:30 +00:00
Christian Boltz
a1e4212d12 Add a test to check for hotkey conflicts
This test builds and installs the apparmor-utils translations into a
tempdir, and then checks if there's any hotkey conflict in one of the
languages. This is based on a manually maintained list of "buttons" that
are displayed at the same time.

To make things a bit easier to test, add CMD_CANCEL to ui.py CMDS[].
Also replace hardcoded usage of '(Y)es', '(N)o' and '(C)ancel' with
CMDS['CMD_YES'], CMDS['CMD_NO'] and CMDS['CMD_CANCEL'].



Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-05-06 22:19:34 +02:00
Launchpad Translations on behalf of apparmor-dev
99d189d8e2 Launchpad automatic translations update. 2016-04-22 05:13:38 +00:00
Launchpad Translations on behalf of apparmor-dev
9d839b2512 Launchpad automatic translations update. 2016-04-04 05:14:55 +00:00
Launchpad Translations on behalf of apparmor-dev
d0871bf2a8 Launchpad automatic translations update. 2016-03-30 05:13:33 +00:00
Christian Boltz
733d5faa78 Don't store exec modes in transtions[]
exec choices are stored in transitions[], but that's never used
(and I don't see a need for it), therefore stop storing it.


Note: hat choices (CMD_ADDHAT, CMD_USEDEFAULT and CMD_DENY) get still
stored in transitions[], and that information is used if the same hat
name appears again.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-03-29 12:58:15 +02:00
Max Timchenko
cefadd8da1 Add a JSON output option to aa-status
Automated infrastructure management tools, such as Chef, Puppet, and so
on, could use a way to check AppArmor status that is both high-level
(meaning it does not rely on kernel interfaces in /proc) and machine-
readable (meaning it does not require the complexity of parsing output 
of tools originally intended for human consumption).

Adding a JSON variant of the standard aa-status output achieves both.
2016-03-24 10:59:45 -04:00
Launchpad Translations on behalf of apparmor-dev
1cbdd17c11 Launchpad automatic translations update. 2016-03-20 05:16:46 +00:00
Steve Beattie
95321544b1 Merge utils/ DE translations from Launchpad. 2016-03-19 04:06:57 -07:00
Launchpad Translations on behalf of apparmor-dev
a5b8ebebb4 Launchpad automatic translations update. 2016-03-19 05:19:32 +00:00