Commit graph

28 commits

Author SHA1 Message Date
Georgia Garcia
5cc7a26e78 libapparmor: add support for class in logparsing
We want to use the class field to identify operations such as
posix_mqueue

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 18:16:53 +00:00
Mark Grassi
accc2debe9 Rename BaseRule's parse() method to create_instance() 2022-09-10 19:54:35 -04:00
Mark Grassi
c57138f255 Order imports and module-level dunder name assignments. 2022-08-21 11:15:07 -04:00
Mark Grassi
96f7121944 Fix most PEP 8 whitespace, indentation, and major line length violations. 2022-08-21 11:15:07 -04:00
Mark Grassi
7581c9e113 Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
Christian Boltz
a07515bdd4
Run severity tests with official severity.db
... instead of the slightly outdated copy in test/
2021-04-14 21:37:53 +02:00
Christian Boltz
4c77f7193b
Use parse() instead of _parse() in LogprofHeaderTest
The *LogprofHeaderTest accidently used the private _parse() insteaf of
the official parse().
2021-03-07 18:28:27 +01:00
Steve Beattie
461d9c2294
treewide: spelling/typo fixes in comments and docs
With the exception of the documentation fixes, these should all be
invisible to users.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/687
2020-12-01 12:47:11 -08:00
Christian Boltz
7b009a909e
Remove superfluous self-cast in Invalid*Test 2020-05-02 22:13:34 +02:00
Christian Boltz
45a3d8920a
Drop unused 'pid' parameter from ReadLog.__init__()
... and self.pid which is also unused.

This simple change also means to adjust all the code that uses ReadLog.
We get rid of log_pid in aa.py, and have to change lots of test-*
2019-05-09 17:15:35 +02:00
Christian Boltz
aa1e315e77
Add tests for link rules to test-file.py 2019-04-22 23:39:47 +02:00
Christian Boltz
45922c6d21
make utils tests less verbose
Given the big number of tests, printing a dot for each test (instead of
multiple lines) is enough ;-)
2018-04-08 20:18:30 +02:00
Christian Boltz
a0d4e246ab
FileRule: detect that 'a' is covered by 'w'
References: https://bugs.launchpad.net/apparmor/+bug/1385474
2017-12-03 17:51:04 +01:00
Christian Boltz
1857f07d08
test-file.py: Document that w doesn't cover a yet
This is the code "translation" of
https://bugs.launchpad.net/apparmor/+bug/1385474
2017-12-03 17:34:04 +01:00
Christian Boltz
ae692bfb3b Drop 'log' parameter from ReadLog
This parameter is always [], so we can simplify the ReadLog __init__()
parameters.

Note that some tests handed over '' instead of []. This was a bug, but
didn't matter because those tests only use a small portion of ReadLog.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2017-08-28 23:15:51 +02:00
Christian Boltz
e9b7c3ff60 logparser.py parse_event(): always store family, protocol and sock_type
Storing these event details depending on the operation type only makes
things more difficult because it's hard to differenciate between file
and network events.

Note that this happens at the first log parsing stage (libapparmor log
event -> temporary python array) and therefore doesn't add a serious
memory footprint. The event tree will still only contain the elements
relevant for the actual event type.

This change means that lots of testcases now get 3 more fields (all
None) when testing parse_event(), so update all affected testcases.
(test-network doesn't need a change for probably obvious reasons.)

Also rename a misnamed test in test-change_profile.


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10.
2016-11-19 10:55:03 +01:00
Christian Boltz
65844a5e1f complete test coverage for FileRule
Add a testcase with exec-only permissions (which get ignored by
get_perms_for_path()) to increase FileRule test coverage to 100%.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-10 22:08:15 +02:00
Christian Boltz
1c4a885e27 Switch utils to python3
As discussed a while ago, switch the utils (including their tests) to
use python3 by default. While on it, drop usage of "env" to always get
the system python3 instead of a random one that happens to live
somewhere in $PATH.

In practise, this patch doesn't change much - AFAIK openSUSE, Debian and
Ubuntu already patch aa-* to use python3.

Also add a note to README to officially deprecate Python 2.x.
(I won't break Python 2.x support intentionally - unless some future
change gives me a very good reason to finally drop Python 2.x support.)



Acked-by: Seth Arnold <seth.arnold@canonical.com>
(since 2016-08-23, but the commit had to wait for the FileRule series
 because it touches test-file.py)
2016-10-01 20:57:09 +02:00
Christian Boltz
9a6c3430d0 [33/38] Add cleanup flag to *Ruleset.add()
Adding a rule to *Ruleset means it simply gets added. This also means
that then-superfluous rules will be kept.

This patch adds an optional cleanup flag to add(). If set, rules covered
by the new rule will be deleted. The difference to delete_duplicates()
is that cleanup only deletes rules that are covered by the new rule, but
keeps other, unrelated superfluous rules.

Also return the number of deleted rules to give the UI a chance to
report this number.

Finally, adjust the existing tests for FileRuleset to ensure default
mode (without cleanup) doesn't delete any rules, and add a test using
the cleanup flag.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:13:06 +02:00
Christian Boltz
d1347051f4 [31/38] FileRule: add get_exec_rules_for_path() and get_exec_conflict_rules()
get_exec_rules_for_path() returns a FileRuleset with all rules matching
the given path.

get_exec_conflict_rules() returns a FileRuleset with all exec rules that
conflict with the given oldrule. This will be used by aa-mergeprof to
ask the user which rule he wants to keep.

Also add tests for both functions.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:12:01 +02:00
Christian Boltz
06d880d1ff [27/38] Implement FileRule logprof_header()
Merge the existing and requested permissions into a nice set of headers
that can be displayed by aa-logprof. This will look like:

	Path:      /foo
	Old Mode:  r + owner w
	New Mode:  rw

Also split off a _join_given_perms() function off _joint_perms() so that
we can use the permission string merging for things not stored in self.*.

Finally add some tests for logprof_header().



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:06:38 +02:00
Christian Boltz
435281f018 [22/38] Add get_perms_for_path() and get_rules_for_path() to FileRuleset
- get_rules_for_path() returns all rules matching the given path
  (both exact matches and AARE matches)
- get_perms_for_path() returns the merged permissions for the given
  path and a list of paths used in the matching rules

Also add tests for these two functions.



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:03:07 +02:00
Christian Boltz
8dc09bd643 [21/38] Add severity support to FileRule
Also add a rank_path() function to severity.py and change rank() to call
rank_path() for paths.
Long-term goal: get rid of the type "guessing" in rank()

Finally add some tests, mostly based on test-severity.py SeverityTest


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:02:34 +02:00
Christian Boltz
0fe9ed8960 [19/38] Add support for editing paths to FileRule
This means adding
- self.can_edit - True if editing via '(N)ew' should be possible (will
  be False for bare file rules)
- edit_header() - returns the prompt text and the current path
- validate_edit() - checks if the new path matches the original one
- store_edit() - changes the path to the new one (even if it doesn't
  match the old one)

self.can_edit and the 3 functions are also added to BaseRule:
- can_edit is False by default
- the functions raise a NotImplementedError


Also add tests for the added code.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:00:32 +02:00
Christian Boltz
f0ddee648d [17/38] Implement globbing in FileRule
Add the glob() and glob_ext() functions to FileRule, and set
self.can_glob and self.can_glob_ext. Also add some tests (just enough to
make sure the FileRule integration works - the globbing is handled
inside AARE,and the AARE tests contain more testcases).

Note that the implementation differs from the original plan (which was
to have globbing in *Ruleset). Therefore add can_glob and can_glob_ext
to BaseRule (both default to False), and add a comment to BaseRuleset
that globbing needs to be removed from all *Ruleset classes.


Acked-by: Steve Beattie <steve@nxnw.org>


As discussed, I added a pointer to the test-aare.py globbing tests in
test-file.py.
2016-10-01 19:57:30 +02:00
Christian Boltz
c1fc2c9011 [13/38] Add ANY_EXEC to FileRule
aa-logprof needs to check if an exec rule for a given path exists.

This patch adds a __FileAnyExec class to FileRule, as well as ANY_EXEC
(which should be used externally, similar to ALL), and adjusts several
checks to allow it as a special execute mode.

This will allow to use is_covered() (or aa.py is_known_rule()) to find
out if execute is permitted, which replaces aa.py profile_known_exec()
in one of the following patches.

As usual, also add some tests.



Acked-by: Steve Beattie <steve@nxnw.org>


Note: as discussed, I adjusted the comment for 'pass' around line 240.
2016-10-01 19:53:38 +02:00
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
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