Commit graph

5288 commits

Author SHA1 Message Date
Steve Beattie
05747a9e1d
binutils: actually use listed compiler warning flags
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:38 -07:00
Steve Beattie
5fc2cb5524
bintutils: delete the tools on make clean
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:37 -07:00
Steve Beattie
3d0d0c69bc
aa_status: separate out version info
Separate out the aa-status json version info out from being a magic
element embedded in a string in the middle of the json emitter, and move
it to an early location, along with a comment to edit it whenthe format
changes.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:37 -07:00
John Johansen
2acb93c21a
aa-status: add json pretty printing using cJSON
This restores aa-status ability to pretty print json by using
DaveGamble's cJSON: https://github.com/DaveGamble/cJSON

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/493
2020-05-07 01:12:28 -07:00
Christian Boltz
986b4f2b72 Merge branch 'cboltz-fix-genprof-json' into 'master'
Fix showing the local inactive profile in json mode

See merge request apparmor/apparmor!514

Acked-by: John Johansen <john.johansen@canonical.com> for 2.11..master
2020-05-06 22:43:35 +00:00
Christian Boltz
7b8f7d645e Merge branch 'cboltz-utils-cleanup' into 'master'
cleanup get_profile()

See merge request apparmor/apparmor!513

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-06 22:42:48 +00:00
Christian Boltz
68a258b006
Fix showing the local inactive profile in json mode
When aa-genprof proposes a local inactive profile, it had a hardcoded
call to 'less' to display that profile.

Unsurprisingly, this doesn't work in JSON mode and breaks YaST (luckily
it's only a case of "the button doesn't work").

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1171315
2020-05-06 23:20:07 +02:00
Christian Boltz
bb3803b931
Split off UI_ShowFile() from UI_Changes
UI_ShowFile() is more generic and can be used to display various (text)
files, not only diffs.
2020-05-06 23:16:47 +02:00
Christian Boltz
4906bbf965
get_profile(): get rid of profile_type
It's always set to 'INACTIVE_LOCAL' - no need to set and later check it.

Also add a TODO note ;-)
2020-05-06 22:53:57 +02:00
Christian Boltz
f96304fe33
get_profile(): get rid of profile_data variable
... which also makes the code easier to understand
2020-05-06 22:53:22 +02:00
Christian Boltz
476848da46
get_profile: convert profile_hash from hasher() to dict 2020-05-06 22:53:22 +02:00
Christian Boltz
47620e10cb
Rewrite get_profile() to exit early if no extra profile exists 2020-05-06 22:53:22 +02:00
Christian Boltz
2d2fc41cc1
inline get_inactive_profile() into get_profile()
... which is the only user of get_inactive_profile()
2020-05-06 22:53:22 +02:00
Steve Beattie
e6cf0d44d1 utils + parser: minor test cleanups
Fix a typo, some shellcheck warnings, and move one test script from using bash to dash.

See merge request apparmor/apparmor!512

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <opensuse@cboltz.de>
https://gitlab.com/apparmor/apparmor/-/merge_requests/512
2020-05-06 20:35:28 +00:00
Christian Boltz
16c14737e4 Merge branch 'cboltz-fix-genprof' into 'master'
Fix aa-genprof/aa-autodep crash

See merge request apparmor/apparmor!511

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-06 11:31:14 +00:00
Christian Boltz
c7949ba6c4
Read all profiles on aa-genprof startup instead of later
... which can mean "too late" in some special cases (if a profile
already exists in /etc/apparmor.d/$non_default_filename).

However, the main reason is that without this change
- the new profile will be added to (otherwise empty) active_profiles
- the first do_logprof_pass() will read all profiles, including the new
  one, and add them to active_profiles - which unsurprisingly results in
  an error like `ERROR: Profile /usr/sbin/vsftpd exists in
  /etc/apparmor.d/usr.sbin.vsftpd and /etc/apparmor.d/usr.sbin.vsftpd`

To fix this,
- change do_logprof_pass to never call read_profiles() (and get rid of
  the 'passno' parameter)
- adjust its callers (aa-logprof and aa-genprof) to call read_profiles()
  themself
- move printing the 'Updating AppArmor profiles in $directory.' message
  to read_profiles(), but only display it if requested (to keep the
  current UI behaviour)
2020-05-05 23:56:55 +02:00
Christian Boltz
db9f8d38b0
Fix aa-genprof/aa-autodep crash
Since 4b7108f1e5, aa-genprof and
aa-autodep crashed with

    apparmor.common.AppArmorBug: /etc/apparmor.d/usr.sbin.vsftpd not listed in ProfileList files

because the profile was not added to active_profiles.

Add the profile to active_profiles to fix this regression, and to have
all the needed data in active_profiles.
2020-05-05 22:24:08 +02:00
Christian Boltz
3d99683105 Merge branch 'cboltz-drop-repo-code' into 'master'
Drop profile repo code from utils

See merge request apparmor/apparmor!510

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 20:07:14 +00:00
Steve Beattie
65f9d0e2ee
parser: use /bin/sh for minimize test
There are no bashisms in the minimize.sh test script, so convert to
using to /bin/sh

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://gitlab.com/apparmor/apparmor/issues/18
2020-05-05 12:14:04 -07:00
Steve Beattie
a5c0ef282d
parser: shellcheck fixups on test scripts
Make the equality and minimize test scripts more shellcheck compliant.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 12:09:15 -07:00
Steve Beattie
253073b798
utils test: fix typo in simple_tests output
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 11:54:49 -07:00
Christian Boltz
256f55925c
Drop profile repo code from utils
The profile repo is dead since years and most likely won't come back, so
there's no point in keeping and maintaining the code for uploading and
downloading profiles.
2020-05-05 13:09:16 +02:00
Steve Beattie
08c6c6eecf parser error tests: add filename profile deprecation checks
This add a couple of tests for
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/506

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-05-05 02:16:23 -07:00
John Johansen
91deb0cf13 parser: Display a deprecated warning when using filenames as a profile name
The use of filenames for a profile name has been deprecated in
AppArmor 3.0 so output a warning when ever a profile with a filename
based name is encountered.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/506
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-05-05 02:16:23 -07:00
Steve Beattie
b2c706516f
parser tests: add include in preamble tests
The parser tests were missing include tests for include entries in the
preamble section of a profile. This commit adds both #include and
include variants, as well as include if exists variants.

Also added is an exception list for the utils tests -- though it should
be noted that the utils silently drop the "#include if exists" format if
it's in the preamble without raising an exception.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/509
2020-05-05 00:30:18 -07:00
John Johansen
5d52ab0783 Merge Handle preamble "include if exists" rules in ProfileList
Add support for handling `include if exists` rules in profile preambles in the `ProfileList` class.

Besides that, do some groundwork for future changes - see the individual commits for details and spoilers ;-)

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/507
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-05 07:18:09 +00:00
John Johansen
65f1d33a88 aa-status: bump the json version that aa-status outputs
aa-status output has changed slightly to account for the newer profile
modes. This means the json version needs to be bumped so consumers
can detect the change.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/508
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 00:14:36 -07:00
John Johansen
c386d93581 docs: update documentation to point bug reporting to gitlab
Move suggested bug reporting from launchpad to gitlab

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 00:10:53 -07:00
John Johansen
7ca90ab637 Docs: man apparmor.d: Document the profile header
Documentation of the profile header: name, attachments and flags
is missing. Add basic documentation describing the header and
it components.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/505
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-04 18:59:42 -07:00
Christian Boltz
4b7108f1e5
Store and write 'include if exists' rules in the preamble
... using the new storage in ProfileList.

Also add a test rule to cleanprof.{in,out} to ensure the rule is kept.
2020-05-04 22:14:52 +02:00
Christian Boltz
07b52134f4
Extend ProfileList to store and write include rules
- add_inc_ie() stores include and include if exists rules
- get_clean() and get_raw() return the profile preamble (currently only
  the include rules)

Also add tests for the new functions.
2020-05-04 22:14:44 +02:00
Christian Boltz
1569136180
Add get_clean_unsorted() to BaseRuleset
This is similar to get_clean(), but keeps the original rule order
instead of sorting them.

This is useful for include rules in the preamble, where the order might
be relevant - for example if the first include defines a variable that
is then used or extended in the second include file.
2020-05-04 21:59:02 +02:00
Christian Boltz
10fbdb28d3
ProfileList: keep track of profiles in each file
(not used yet, but will be useful later to replace
aa.filelist[$file]['profiles'] ;-)
2020-05-04 21:59:02 +02:00
Christian Boltz
c670d294eb
Rename TestAdd and its functions to TestAdd_profile
This is a follow-up of 5983598ef5
2020-05-04 21:59:02 +02:00
Steve Beattie
64be247aae utils: ProfileList: rename add() to add_profile()
Merge branch 'cboltz-profile-list-rename-add' into 'master'

See merge request apparmor/apparmor!502
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-04 19:47:17 +00:00
Steve Beattie
e416f51c26 regression tests: add permissions for stacking LSM environments
With the addition of commits to make libapparmor LSM stacking aware, several tests were failing due to:

- aa_getpeercon() having an added aa_enabled() check
- aa_getprocattr() looking in /proc/pid/attr/apparmor/current first

Fix the specific failing testcases with additional permissions, and grant default profiles and hat generated by mkprofile.pl write access to /proc/*/attr/apparmor/current.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/504
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-04 18:56:27 +00:00
Steve Beattie
2444060617
regression tests: make stackprofile stacking LSM aware
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-03 20:13:58 -07:00
Steve Beattie
6e66065877
regression tests: add stacked attr/current access by default
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-03 20:13:54 -07:00
Steve Beattie
fb773fec36
socketpair regression test: add aa_getpeercon() enabled perm
Because of the need to be stacking LSM aware, aa_getpeercon() calls
aa_enable to ensure that apparmor is enabled. Without the permission,
aa_getpeercon() fails, causing test failures.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-03 20:11:52 -07:00
John Johansen
278bd918f9 regression tests: Make the xattr_profile.sh depend on outofband transitions
While xattr attachments exist without outofband transitions, they are
broken when values contain the null character. The addition of
outofband transitions fixes this problem.

While we could make the test requirement for outofband transitions
specific to a few tests, since the parser currently requires outofband
transitions to generate xattr attachment conditionals, for a first
pass just make the whole test suite require them.

Revisit this when/if the parser will allow xattr attachments without
outofband transitions.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-05-03 20:06:55 -07:00
Christian Boltz
dc2b971a7f Merge branch 'cboltz-better-failure-description' into 'master'
Better descriptions why some example profiles fail with the tools

See merge request apparmor/apparmor!501

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-03 21:37:31 +00:00
Christian Boltz
5983598ef5
ProfileList: rename add() to add_profile()
This makes the syntax more clear, and is a preparation to allow adding
some more things (like global includes and variable definitions)
2020-05-03 22:37:20 +02:00
Christian Boltz
e8561236c1 Merge branch 'cboltz-local-if-exists' into 'master'
switch local includes to "include if exists"

See merge request apparmor/apparmor!489

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-03 20:11:49 +00:00
Christian Boltz
6c4054fa91
Better descriptions why some example profiles fail with the tools 2020-05-03 22:07:25 +02:00
Christian Boltz
bb2409f935
adjust check for local/ includes to "include if exists" 2020-05-03 22:01:16 +02:00
Christian Boltz
110d6d214c
switch local includes to "include if exists" 2020-05-03 22:01:13 +02:00
Christian Boltz
8661676eb4 Merge branch 'cboltz-utils-include-if-exists' into 'master'
Add support for 'include if exists' to the tools

See merge request apparmor/apparmor!499

Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-05-03 19:59:11 +00:00
Christian Boltz
a4864146e2 Merge branch 'cboltz-vim-if-exists' into 'master'
apparmor.vim: support 'include if exists'

See merge request apparmor/apparmor!500

Acked-by: John Johansen <john.johansen@canonical.com> for 2.12..master
2020-05-03 19:27:57 +00:00
Steve Beattie
9b250ef63d test profiles: fix typo in descriptions
Merge branch 'cboltz-parser-tst-typo' into 'master'

See merge request apparmor/apparmor!498
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-03 19:17:08 +00:00
Christian Boltz
c2ac1b5669 Merge branch 'cboltz-superfluous-cast' into 'master'
Remove superfluous self-cast in Invalid*Test

See merge request apparmor/apparmor!495

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-03 12:32:19 +00:00