Commit graph

3556 commits

Author SHA1 Message Date
John Johansen
69868cda18 add man page for aa_query_label
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2015-06-04 02:59:32 -07:00
Steve Beattie
23a2d8b68c This patch fixes several formatting issues with the apparmor.d man page:
- missing formatting code prefixes, usually I for BNFish arguments
 - added blank lines before preformatted sections as the html formatter
   wasn't treating them as seperate from the preceding text (also, they
   generated podchecker warnings)
 - fixed a grammar issue
 - fixed link description text block that was mistakenly indented and
   thus treated as preformatted text
 - moved the "Qualifier Blocks" subsection out of the =over/=back as
   all the pod tools did not like this and it caused podchecker to exit
   with an error, breaking builds that ran make check on the parser
   tree.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-06-02 16:05:37 -07:00
John Johansen
d7436a872c Rename requires_features and have_features
Rename require_features to require_kernel_features and
       have_features to kernel_features

to indicate they are tests for kernel features, as now there are tests
for parser features and in the future there might be library features
as well.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2015-06-02 01:00:29 -07:00
John Johansen
119c751951 The regression tests have issue on backport kernels when the userspace
has not been updated. The issue is that the regression tests detect the
kernel features set and generate policy that the parser may not be able
to compile.

Augment the regressions tests with a couple simple functions to test what
is supported by the parser, and update the test conditionals to use them.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-06-02 01:00:29 -07:00
John Johansen
2d31e2c113 add ability to parser dmesg output as a log file
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-06-02 01:00:29 -07:00
John Johansen
7cc75c44fa Add log parser test for change_profile
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2015-06-02 01:00:29 -07:00
John Johansen
4afcf91162 Add documentation of qualifier blocks to apparmor.d man page
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2015-06-02 01:00:29 -07:00
John Johansen
04dfc5d975 Add missing I<ALIAS RULE> to B<COMMA RULES> pattern
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2015-06-02 01:00:29 -07:00
John Johansen
d506ecfd4d apparmor.d.pod: refactor profile file, profile, subprofile, hat patterns
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2015-06-02 01:00:29 -07:00
John Johansen
8ffec9357d apparmor.d.pod: create RULES grouping and cleanup profile PROFILE rule
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2015-06-02 01:00:29 -07:00
Tyler Hicks
631804e8a7 parser: Document the --features-file option in apparmor_parser(8)
This option was previously only documented in the --help output.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-06-01 11:29:37 -05:00
Launchpad Translations on behalf of apparmor-dev
9f670bed0e Launchpad automatic translations update.
Bug: https://launchpad.net/bugs/1466812
2015-06-01 05:08:17 +00:00
Christian Boltz
01a43e5f1b Convert test-capability.py to AATest
I decided to use a "small" solution for now, which basically means
s/unittest.TestCase/AATest/, cleanup of some setUp() and renaming the
remaining setUp() functions to AASetup().

This doesn't mean an instant win (like in test-severity.py), but allows
to add tests with a tests[] array.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 23:43:27 +02:00
Christian Boltz
5eb796044b Change test-severity.py to use 'unknown' as default rank, and fix the bugs it found
To be able to distinguish between severity 10 and unknown severity,
change AASetup to specify 'unknown' as default rank, and change the
expected result to 'unknown' where it's expected.

Also change the "expected rank %d" to "%s" because it can be a string
now, and add a test that contains directories with different severity
in one variable.

After these changes, handle_variable_rank() errors out with
    TypeError: unorderable types: str() > int()
so fix it by
- initializing rank with the default rank (instead of none)
- explicitely check that rank and rank_new are != the default rank before
  doing a comparison

A side effect is another bugfix - '@{HOME}/sys/@{PROC}/overcommit_memory'
is severity 4, not 10 or unknown (confirmed by reading severity.db).


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 23:39:14 +02:00
Christian Boltz
2f6059767e Convert test-severity.py to use the AATest class
This simplifies test-severity.py a lot:
- lots of test functions are replaced with tests[] arrays
- tempdir handling and cleanup is now done automagically

Even if test-severity.py shrunk by 65 lines, all tests are still there.

There's even an addition - SeverityTestCap now additionally verifies the
result of rank_capability().


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 23:31:56 +02:00
Christian Boltz
cf4eb0182c severity.py: change rank_capability() to not expect the CAP_ prefix
Change rank_capability() so that it doesn't expect the CAP_ prefix.
This makes usage easier because callers can simply hand over the
capability name.

Also change rank() to call rank_capability() without the CAP_ prefix.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 23:29:52 +02:00
Christian Boltz
99b2f67d3c severity.py: rename handle_capability() to rank_capability()
It's only used inside severity.py until now, but I plan to change that
and want a better function name ;-)


Acked-by: Steve Beattie <steve@nxnw.org>.
2015-05-29 23:10:11 +02:00
Christian Boltz
0fd30653fd Use generic names in aa-mergeprof
Replace rule-specific names with generic names:
- s/'capability'/ruletype/
- s/cap_obj/rule_obj/
- s/'network'/ruletype/
- s/net_obj/rule_obj/

Also set ruletype at the beginning of each block.

The long-term goal is to have
    for ruletype in ['capability', 'network', ...]:
with common code to handle all rule types, and having common names makes
it easier to compare the blocks.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 23:03:51 +02:00
Christian Boltz
0461c60a6e cleanup superfluous variable assignments in aa-mergeprof
aa-mergeprof has some sections where it first resets the 'deleted'
variable, and then overwrites it again a line or two later.
This patch removes the superfluous variable resets.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 13:01:37 +02:00
Christian Boltz
8d348b328b let parse_profile_data() check for in-file duplicate profiles
Add a check to parse_profile_data() to detect if a file contains two
profiles with the same name.

Note: Two profiles with the same name, but in different files, won't be
detected by this check.

Also add basic tests to ensure that a valid profile gets parsed, and two
profiles with the same name inside the same file raise an exception.

(Sidenote: these simple tests improve aa.py coverage from 9% to 12%,
which also confirms the function is too long ;-)


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 13:00:32 +02:00
Christian Boltz
5fa5125fd4 Add tempdir and tempfile handling to AATest
Add writeTmpfile() to AATest to write a file into the tmpdir. If no
tmpdir exists yet, automatically create one.

createTmpdir() is a separate function so that it's possible to manually
create the tmpdir (for example, if a test needs an empty tmpdir).

Also add a tearDown() function to delete the tmpdir again. This function
calls self.AATeardown() to avoid the need for super() in child classes.

Finally, simplify AaTestWithTempdir in test-aa.py to use createTmpdir()
and add an example for AATeardown() to test-example.py.



Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 12:55:38 +02:00
Christian Boltz
78505f3057 drop unused match_net_include() and match_net_includes() from aa.py
aa-mergeprof no longer calls match_net_includes(), which means the
function can be dropped.

After that, match_net_include() is also unused, so also drop it.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 01:41:35 +02:00
Christian Boltz
c795a1f228 Update aa-mergeprof to use the NetworkRule(set) class layout
aa-mergeprof still used the old aa[profile][hat][allow]['netdomain']
which no longer gets populated. This resulted in not asking for merging
any network rules.

This patch changes ask_the_question() to the NetworkRule(set) layout.
Besides that,
- don't ask for network rules that are already covered.
  Using is_known_rule() also fixes
  https://bugs.launchpad.net/apparmor/+bug/1382241
- include the audit keyword in the "Network Family" headline
  (I'd prefer to just use the get_clean() rule, but that's another topic)
- hide "(A)llow" when merging a deny rule
- as a side effect of using NetworkRule, fix crashes for 'network,' and
  'network foo,' rules

To avoid having to repeat the list of available "buttons" and the logic
to update that list, add a available_buttons() function that returns the
list of available buttons depending on rule_obj.deny and rule_obj.audit
to aa.py, and import it into mergeprof.

I tested all changes manually.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 01:12:38 +02:00
Christian Boltz
7728556972 Update aa-mergeprof to use the CapabilityRule(set) class layout
aa-mergeprof still used the old aa[profile][hat][allow]['capability']
which no longer gets populated - which resulted in not asking for
merging any capabilities.

Actually (and funnily),
-                if other.aa[profile][hat].get(allow, False):
-                    continue
resulted in never merging capability rules even before the change to
CapabilityRule(set) - this was meant as optimization, but a "not" was
missing in the condition ;-) so it always skipped capability rules.

The patch changes ask_the_question to the CapabilityRule(set) layout.
Besides that,
- include the audit and deny keywords in the "Capability" headline
  (I'd prefer to just use the get_clean() rule, but that's another topic)
- hide "(A)llow" when merging a deny rule
- don't ask for capabilities that are already covered

Also delete match_cap_includes() from aa.py, which is no longer used.


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

Bug: https://launchpad.net/bugs/1382241
2015-05-29 00:17:02 +02:00
Christian Boltz
534715c2e2 Drop old RE_PROFILE_CHANGE_PROFILE regex from regex.py
Also rename RE_PROFILE_CHANGE_PROFILE_2 to RE_PROFILE_CHANGE_PROFILE
and update apparmor/rule/change_profile.py to use the changed name.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-28 22:26:34 +02:00
Christian Boltz
98383c0816 Change aa.py to use ChangeProfileRule and ChangeProfileRuleset
Change aa.py to use ChangeProfileRule and ChangeProfileRuleset instead
of a sub-hasher to store and write change_profile rules. In detail:
- drop all the change_profile rule parsing from parse_profile_data() and
  serialize_profile_from_old_profile() - instead, just call
  ChangeProfileRule.parse()
- change write_change_profile to use ChangeProfileRuleset
- add removal of superfluous/duplicate change_profile rules (the old
  code didn't do this)

Note that this patch is much smaller than the NetworkRule and
CapabilityRule patches because aa-logprof doesn't ask for adding
change_profile rules - adding that is something for a later patch.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-28 22:25:30 +02:00
Christian Boltz
70f9334cd9 Add tests for ChangeProfileRule and ChangeProfileRuleset
As usual, those classes have 100% test coverage.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-28 22:23:32 +02:00
Christian Boltz
59d4011033 Add ChangeProfileRule and ChangeProfileRuleset classes
Add utils/apparmor/rule/change_profile.py with the ChangeProfileRule and
ChangeProfileRuleset classes. These classes are meant to handle
change_profile rules.

In comparison to the current code in aa.py, ChangeProfileRule has some
added features:
- support for audit and allow/deny keywords (for which John promised a
  parser patch really soon)
- support for change_profile rules with an exec condition


Also add the improved regex RE_PROFILE_CHANGE_PROFILE_2 to regex.py.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-28 22:22:56 +02:00
Christian Boltz
f26b035e90 Let set_profile_flags() change the flags for all hats
It did this in the old 2.8 code, but didn't in 2.9.x (first there was a
broken hat regex, then I commented out the hat handling to avoid
breakage caused by the broken regex).

This patch makes sure the hat flags get set when setting the flags for
the main profile.

Also change RE_PROFILE_HAT_DEF to use more named matches
(leadingwhitespace and hat_keyword). Luckily all code that uses the
regex uses named matches already, which means adding another (...) pair
doesn't hurt.

Finally adjust the tests:
- change _test_set_flags to accept another optional parameter
  expected_more_rules (used to specify the expected hat definition)
- add tests for hats (with '^foobar' and 'hat foobar' syntax)
- add tests for child profiles, one of them commented out (see below)


Remaining known issues (also added as TODO notes):

- The hat and child profile flags are *overwritten* with the flags used
  for the main profile. (That's well-known behaviour from 2.8 :-/ but we
  have more flags now, which makes this more annoying.)
  The correct behaviour would be to add or remove the specified flag,
  while keeping other flags unchanged.

- Child profiles are not handled/changed if you specify the 'program'
  parameter. This means:
  - 'aa-complain smbldap-useradd' or 'aa-complain /usr/sbin/smbldap-useradd'
    _will not_ change the flags for the nscd child profile
  - 'aa-complain /etc/apparmor.d/usr.sbin.smbldap-useradd' _will_ change
    the flags for the nscd child profile (and any other profile and
    child profile in that file)


Even with those remaining issues (which need bigger changes in
set_profile_flags() and maybe also in the whole flags handling), the
patch improves things and fixes the regression from the 2.8 code.



Acked-by: Steve Beattie <steve@nxnw.org> for trunk and 2.9
2015-05-28 22:14:37 +02:00
Tyler Hicks
5349536ff8 tests: Add query_label.sh tests for file queries
A number of simple query tests based on read and write perms of files
and directories.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2015-05-28 14:48:53 -05:00
Tyler Hicks
afde1cc53a tests: Adjust query_label.sh to query a different profile
The test program was querying its own profile. Adjust the profile
generation so that a separate profile is generated and have query_label
query the separate profile.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2015-05-28 14:48:50 -05:00
Tyler Hicks
a566935d64 tests: Make query_label accept file queries
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2015-05-28 14:48:46 -05:00
Launchpad Translations on behalf of apparmor-dev
6bcf697731 Launchpad automatic translations update. 2015-05-25 05:09:25 +00:00
Launchpad Translations on behalf of apparmor-dev
ab671b30be Launchpad automatic translations update. 2015-05-21 05:07:49 +00:00
Tyler Hicks
20c2c4c171 libapparmor: Fix pod2man warning in aa_splitcon(3)
*** WARNING: 2 unescaped <> in paragraph at line 43 in file aa_splitcon.pod

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2015-05-19 21:46:23 -05:00
Tyler Hicks
c6e395c08f libapparmor: Strip a trailing newline character in aa_splitcon(3)
Adjust the internal splitcon() function to strip a single trailing
newline character when the bool strip_newline argument is true.

aa_getprocattr_raw(2) needs to set strip_newline to true since the
kernel appends a newline character to the end of the AppArmor contexts
read from /proc/>PID>/attr/current.

aa_splitcon(3) also sets strip_newline to true since it is unknown
whether the context is originated from a location that appends a newline
or not.

aa_getpeercon_raw(2) does not set strip_newline to true since it is
unexpected for the kernel to append a newline to the the buffer returned
from getsockopt(2).

This patch also creates tests specifically for splitcon() and updates
the aa_splitcon(3) man page.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-05-19 21:31:53 -05:00
Tyler Hicks
8fffe4c721 libapparmor: Add unit tests for aa_splitcon()
Test confinement context splitting, using aa_splitcon(3), with and
without a valid mode pointer.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-05-19 21:30:39 -05:00
Tyler Hicks
014093dedc libapparmor: Add aa_splitcon() public function
Create a new libapparmor public function that allows external code to
split an AppArmor confinement context.

This is immediately useful for code that retrieves a D-Bus peer's
AppArmor confinement context using the
org.freedesktop.DBus.GetConnectionCredentials bus method.

https://launchpad.net/bugs/1430532

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-05-19 21:28:47 -05:00
Tyler Hicks
4879b46b13 libapparmor: Detect errors when splitting confinement contexts
The parse_confinement_mode() function returned NULL when a confinement
mode was not present (unconfined) and when it could not properly parse
the confinement context. The two situations should be differentiated
since the latter should be treated as an error.

This patch reworks parse_confinement_mode() to split a confinement
context and, optionally, assign the mode string. If a parsing error is
encountered, NULL is returned to indicate error.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-05-19 21:20:51 -05:00
Tyler Hicks
f6df1c7516 libapparmor: Clean up confinement context's unconfined check
Use the passed in confinement context string size to improve the
comparison by only doing the string comparison if the size matches and
removing the possibility of reading past the end of the buffer.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-05-19 21:20:37 -05:00
Tyler Hicks
6d8827594a libapparmor: Don't count NUL terminator byte
When passing the size of the confinement context to
parse_confinement_mode(), don't include the NUL terminator byte in the
size.

It is confusing to count the NUL terminator as part of the string's
length. This change makes it so that, after a few additional changes,
parse_confinement_mode() can be exposed as part of libapparmor's public
API.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-05-19 21:20:21 -05:00
Tyler Hicks
81f932531c tests: Verify aa_getpeercon() return value
This patch modifies the socketpair.c test to verify the return value of
aa_getpeercon() based upon the expected label and expected mode lengths.

The test had to be changed slightly so that the returned mode, from
aa_getpeercon(), was preserved. It was being overwritten with the
special NO_MODE value.

This change helps to make sure that future changes to the code behind
aa_getpeercon() does not unintentionally change the function's return
value.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-19 21:19:56 -05:00
Christian Boltz
9b5ff659b0 Update Samba profiles for Samba 4.2
Samba 4.2 needs some more permissions for nmbd and winbindd.

To avoid overcomplicated profiles, change abstractions/samba to allow
/var/lib/samba/** rwk, (instead of **.tdb rwk) - this change already
fixes the nmbd profile.

winbindd additionally needs some more write permissions in /etc/samba/
(and also in /var/lib/samba/, which is covered by the abstractions/samba
change and also results in some profile cleanup)


References: https://bugzilla.opensuse.org/show_bug.cgi?id=921098 and
            https://bugzilla.opensuse.org/show_bug.cgi?id=923201


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-05-19 01:25:26 +02:00
Christian Boltz
c2973f0b7b Add the attach_disconnected flag to the ntpd profile
I noticed "disconnected path" (run/nscd/*) events for ntpd while
updating to the latest openSUSE Tumbleweed.


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.9.
2015-05-19 01:20:49 +02:00
Christian Boltz
bb56f039a8 Fix raising AppArmorException in aa-mergeprof
aa-mergeprof failed to fail ;-) when it should raise an AppArmorException.
Instead, it failed with

    AttributeError: 'module' object has no attribute 'AppArmorException'

I confirmed this bug in trunk and 2.9.


Acked-by: Steve Beattie <steve@nxnw.org> for trunk and 2.9.
2015-05-18 01:35:51 +02:00
Steve Beattie
c477af77b4 Periodic sync up with apparmor trunk branch. 2015-05-16 10:11:36 -07:00
Steve Beattie
bd3d21e0bc Merge from launchpad translations project. Changes include:
- added and updated Portuguese translations
- added Hungarian, Russian, Polish strings
2015-05-16 10:05:48 -07:00
Christian Boltz
407280c7f5 Delete apparmor/rule/ python cache files in "make clean"
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-05-11 21:57:55 +02:00
Christian Boltz
481de7e655 move quote_if_needed() to apparmor.rule
quote_if_needed() will be used by the upcoming ChangeProfileRule class,
which means it must be moved out of aa.py to avoid an import loop.
rule/__init__.py looks like a better place.

Also re-import quote_if_needed() into aa.py because it's still needed
there by various functions.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-05-09 13:20:57 +02:00
Christian Boltz
7167632350 Split off RE_PROFILE_NAME and RE_PROFILE_PATH from RE_PROFILE_START
(might get re-used later ;-)

Also add two tests for profile names not starting with / - the quoted
version wasn't catched as invalid before, so this change is actually
also a bugfix.


Acked-by: Steve Beattie <steve@nxnw.org> for trunk and 2.9.
2015-05-09 01:09:08 +02:00