Commit graph

1250 commits

Author SHA1 Message Date
Otto Kekäläinen
81d514d89a aa-notify: Always use aa.CONFDIR, don't assume "/etc/apparmor"
Also fix cosmetic comment.
2019-05-03 17:53:24 +03:00
Christian Boltz
7282fbd8bf Merge branch 'cboltz-drop-set-process' into 'master'
Drop broken set_process() and the profile_changes array

See merge request apparmor/apparmor!376

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-05-01 16:44:48 +00:00
Christian Boltz
14a3ca0439
Drop no longer used set_allow_str()
The old link rule implementation (which was replaced some commits ago)
was the last user of this function.
2019-04-30 00:59:09 +02:00
Christian Boltz
7099459f2c
drop profile_changes array
... which is unused after dropping set_process()
2019-04-30 00:02:05 +02:00
Christian Boltz
b07459c854
Drop broken set_process()
This function was meant to set a process running under a null-* profile
to its "real" profile after deciding about the exec mode/target.
However, this is not supported in the kernel.

"Luckily" the function was also broken and exited early, which
successfully prevented erroring out.

All that means set_process() is useless and we can drop it.
2019-04-29 23:35:52 +02:00
Christian Boltz
382eb7a629 Merge branch 'cboltz-link' into 'master'
Move handling of 'link' rules to FileRule

See merge request apparmor/apparmor!371

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-29 19:09:32 +00:00
Christian Boltz
f473e692c7 Merge branch 'cboltz-mergeprof-import' into 'master'
drop superfluous import apparmor.aamode from aa-mergeprof

See merge request apparmor/apparmor!373

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-29 18:58:07 +00:00
Christian Boltz
53a2eb56b4
handle_children: raise exception on unknown event type
(shouldn't happen, but a check never hurts)
2019-04-28 17:57:37 +02:00
Christian Boltz
f5add27aaa
rename 'netdomain' log events to 'network' to match rule name 2019-04-28 16:27:48 +02:00
Christian Boltz
b86fed1a57
drop commented out code from logparser.py 2019-04-28 14:37:43 +02:00
Christian Boltz
bed9ce35a1
inline parse_log_record() into parse_event_for_tree() and read_log() 2019-04-28 12:04:43 +02:00
Christian Boltz
1ce93a4c2d
inline add_event_to_tree() into read_log() 2019-04-28 11:57:29 +02:00
Christian Boltz
3dd6fdad79
drop superfluous import apparmor.aamode from aa-mergeprof 2019-04-23 21:53:52 +02:00
Christian Boltz
99b476510f
Remove 'owner link' tests from list of known-broken tests
... because they work now :-)
2019-04-23 00:22:25 +02:00
Christian Boltz
6bcfbb7a18
Remove old code for link rules 2019-04-23 00:22:25 +02:00
Christian Boltz
09a761ed80
Update and extend cleanprof tests for link rules 2019-04-22 23:41:08 +02:00
Christian Boltz
aa1e315e77
Add tests for link rules to test-file.py 2019-04-22 23:39:47 +02:00
Christian Boltz
f176baf904
Add support for link rules to FileRule 2019-04-22 23:39:47 +02:00
Christian Boltz
a477a06847
Extend RE_PROFILE_FILE_ENTRY to cover link rules 2019-04-22 23:39:47 +02:00
Christian Boltz
ee2185f4b6 Merge branch 'cboltz-link-owner' into 'master'
Add testcases for 'owner link' rules

See merge request apparmor/apparmor!369

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-22 17:59:06 +00:00
Christian Boltz
7d95e2658e Merge branch 'cboltz-typo' into 'master'
Fix typo in set_json_mode() comment

See merge request apparmor/apparmor!364

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-22 17:58:15 +00:00
Christian Boltz
0facb1598c
Add testcases for 'owner link' rules
.. and document that the tools don't support them yet
2019-04-22 13:36:33 +02:00
Christian Boltz
1d19bb7110
parse_profile_start: test with un-named profile
Also update the comment in _parse to match the updated return values.
2019-04-22 12:38:38 +02:00
Otto Kekäläinen
d4cab56ac7 aa-notify: Use fixed output width in tests so results always look same 2019-04-21 18:37:10 +03:00
Otto Kekäläinen
d5990da72a aa-notify: Use AATest class in tests since possible now with Python 2019-04-21 18:37:10 +03:00
Otto Kekäläinen
a74d7cf51c Re-implement aa-notify in Python (Closes: #16)
- Code layout based on aa-genprof example
- Extend Python dependencies to cover new need by aa-notify
- Update documentation after aa-notify is no longer in Perl
2019-04-21 18:37:10 +03:00
Otto Kekäläinen
3a1eec49d4 Add tests for shared aa library functions used in command line scripts 2019-04-21 18:37:10 +03:00
Otto Kekäläinen
3c7e1668bd aa.py: Indicate permission error if log file is found but cannot be opened 2019-04-21 18:35:33 +03:00
Otto Kekäläinen
455c441357 aa.py: Ensure there is always a fallback falue for the logfile location
Related to #22.

Fixes error message:

  Traceback (most recent call last):
    File "./aa-notify", line 523, in <module>
      main()
    File "./aa-notify", line 399, in main
      aa.set_logfile(args.file)
    File "/home/otto/koodia/apparmor/utils/apparmor/aa.py", line 1762,
    in set_logfile
      print(conf.find_first_file(cfg['settings']['logfiles']))
    File "/usr/lib/python3.6/configparser.py", line 1233, in __getitem__
      raise KeyError(key)
  KeyError: 'logfiles'
2019-04-20 23:34:04 +03:00
Christian Boltz
7153eb09d9
Fix typo in set_json_mode() comment 2019-04-19 22:25:30 +02:00
Otto Kekäläinen
fdd13db13b Add tests for shared aa library functions used in command line scripts 2019-04-19 17:29:26 +03:00
Christian Boltz
9feebc4363
Add some tests for complex profile names
Add some tests with the complex profile name (including alternations and
wildcards) to ensure we don't break such cases in the future.

These tests are based on the log from the (invalid) bugreport
https://gitlab.com/apparmor/apparmor/issues/26
2019-03-31 17:34:55 +02:00
John Johansen
52b3fc220e Adjust tests to match base abstraction update.
Since !345 the set of permissions that are granted (get_file_perms_2)
or suggested (propose_file_rules) has changed. These new sets are
expected due to the changes brought by this MR, so let's adjust
the test suite accordingly.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/358
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-29 07:56:23 +00:00
intrigeri
0170e98f9c Adjust tests to match base abstraction update.
Since !345 the set of permissions that are granted (get_file_perms_2)
or suggested (propose_file_rules) has changed. These new sets are
expected due to the changes brought by this MR, so let's adjust
the test suite accordingly.
2019-03-24 14:45:03 +00:00
John Johansen
cfe20d2b63 Add support for profiles with xattrs matching
Add userland support for matching based on extended file attributes. This
leverages DFA based matching already in the kernel:

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8e51f908
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=73f488cd

Matching is exposed via flags on the profile:

    /usr/bin/* xattrs=(user.foo=bar user.bar=foo) {
        # ...
    }

xattr values are appended to the existing xmatch via a null transition.

    $ echo '/usr/bin/* xattrs=(user.foo=foo user.bar=bar) {}' | \
        ./parser/apparmor_parser -QT -D expr-tree
    DFA: Expression Tree
    /usr/bin/[^\0000/]([^\0000/])*(\0000bar)?(\0000foo)?< 0x1>
    DFA: Expression Tree
    (\a|(\n|(\0002|\t)))< 0x4>

Tested manually on a 4.19 kernel via QEMU+KVM.

TODO:

  * ~~Add regression tests~~ (EDIT: done)
  * ~~EDIT: add support in the tools~~ (EDIT: done)

Questions for reviewers:

  * ~~parser/libapparmor: regex construction probably needs cleaning up~~ (EDIT: done)
  * ~~parser/parser_regex.c: confused what xmatch length is for~~ (EDIT: done)

/cc @mjg59

PR: https://gitlab.com/apparmor/apparmor/merge_requests/270
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-21 08:12:07 +00:00
Christian Boltz
49849ed7a3
update network keyword list in utils and add test
The tools also have a list of network keywords, update it:
- add xdp and qipcrtr
- move ib and mpls to match the kernel order

Also add a test to ensure that (at least) the keywords provided by the
running kernel are listed in network_domain_keywords.
2019-03-16 12:52:37 +01:00
Eric Chiang
a42fd8c6f4 parser: add support for matching based on extended file attributes
Add userland support for matching based on extended file attributes.
This leverages DFA based matching already in the kernel:

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8e51f908
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=73f488cd

Matching is exposed via flags on the profile:

  /usr/bin/* xattrs=(user.foo=bar user.bar=**) {
      # ...
  }

Profiles list the set of extended attributes that a file MUST have, and
a regex to match the value of that extended attributes. Additional
extended attributes on the file don't effect the match.

Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-03-14 10:47:54 -07:00
Christian Boltz
62abfe38e8
Replace deprecated assertEquals with assertEqual
assertEquals is deprecated since Python 2.7 and 3.2.
2019-02-26 21:27:00 +01:00
Christian Boltz
f729391deb Merge branch 'cboltz-test-setup_aa' into 'master'
add an example for setup_aa() to test-example.py

See merge request apparmor/apparmor!330

Acked-by: Steve Beattie <steve@nxnw.org>
2019-02-13 22:42:19 +00:00
Steve Beattie
45c26214cc
utils: fixup test-aa.py tests that fail due to usr-merge
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-02-12 23:17:59 -08:00
Christian Boltz
d6bc00b35b
add an example for setup_aa() to test-example.py
(commented out, but having it documented is helpful nevertheless)
2019-02-10 23:24:29 +01:00
Otto Kekäläinen
aaf7d0a27a Skip aa-notify tests if their requirements for running are missing
When run locally on a development machine or in production, the full test
is likely to run. However inside a CI system container 'last' might fail
to show last login or there might not be access to kern.log and the test
will automatically skip those without failing the whole test suite.
2019-02-09 13:50:02 +02:00
Otto Kekäläinen
f05a464369 Add tests for aa-notify
This will help ensure the future rewrite of aa-notify from Perl to Python
is less likely to introduce regressions. Tests run the command line utility
via a subprocess so it does not matter that the tests are in Python but
the aa-notify utility is in Perl (for now).
2019-02-09 13:12:01 +02:00
Otto Kekäläinen
c04a0cadef Extend common DebugLogger with option to log to stderr
This makes it possible for e.g. command line tools to have the --debug
option and when invoked print the existing debug messages directly to
stderr so the user running the command can see them.
2019-02-07 01:05:32 +02:00
Otto Kekäläinen
707ef17923 Rewrite aa-decode to use inline Python instead of to-be-deprecated Perl 2019-02-05 00:20:47 +02:00
Otto Kekäläinen
a3ae271d1e Bugfix aa-decode test: Get stderr correctly, don't ignore stderr contents
Defining 'stderr = subprocess.STDOUT' as a default value for function
did not work and the 'stderr' was always empty, thus also 'outerr' was
always empty and not standard error contents was ever considered in any
way.

Best in fact was to remove excess function arguments as they were not even
used and replace it with a simpler and less error prone structure.

Even after reading 'stderr' correctly it did not help much as all tests
used 'assertIn' which ignored excess output. Better replace the normal
output with the error output if there ever was something, since stderr
is most likely a serious thing and tests should stop on it.
2019-02-05 00:15:13 +02:00
Otto Kekäläinen
eb378f46d5 Clean up and document AppArmor UI module
- Add documentation stub for what the UI module is and how JSON works
- Make indentation consistent
- Use pythonic 'if' clauses
- Add two spaces after function definitions (Python style)
2019-02-04 20:14:58 +02:00
John Johansen
803cb5558f drop failing corner-case check in logparser.py
aa-logprof errors out if it hits a log event for a non-existing profile
while a profile file with the default filename for that non-existing
profile exists. This can for example happen after adding a profile name
to a profile if audit.log still contains events for the attachment-based
profile name.

Since we ignore log events for non-existing profiles in general, drop
the code for the special case "but a file matching the default filename
for that non-existing profile exists" and also silently ignore events
for this very special non-existing profile.

Also drop the now unused function get_profile_filename()

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1120472

PR: https://gitlab.com/apparmor/apparmor/merge_requests/296
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 10:26:05 +00:00
Eric Chiang
cb8c3377ba *: ensure make apparmor_parser is cached
This change updates parser/Makefile to respect target dependencies and
not rebuild apparmor_parser if nothing's changed. The goal is to allow
cross-compiled tests #17 to run on a target system without the tests
attempting to rebuild the parser.

Two changes were made:

* Generate af_names.h in a script so the script timestamp is compared.
* Use FORCE instead of PHONY for libapparmor_re/libapparmor_re.a

Changes to list_af_names are intended to exactly replicate the old
behavior.

Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-01-22 15:30:51 -08:00
Christian Boltz
ed692337a5
Drop get_profile_filename() from logparser.py
This function is unused since the last commit.
2019-01-02 20:42:57 +01:00