Commit graph

48 commits

Author SHA1 Message Date
Zygmunt Krynicki
cc04181578 Allow running tests with spread
Spread is a full-system, or integration test suite runner initially developed
to test snapd. Over time it has spread to other projects where it provides a
structured way to organize, run and debug complex full-system interactions.
Spread is documented on https://github.com/canonical/spread and is used in
production since late 2016.

Spread has a notion of backends which are responsible for allocating and
discarding test machines. For the purpose of running AppArmor regression tests,
I've combined spread with my own tool, image garden. The tool provides
off-the-shelf images, constructed on-the-fly from freely available images, and
makes them easily available to spread.

The reason for doing it this way is so that using non-free cloud systems is not
required and anyone can repeat the test process locally, on their own computer.
Vanilla spread is somewhat limited to x86-64 systems but the way I've used it
here makes it equally possible to test x86_64 *and* aarch64 systems. I've done
most of the development on an ARM single-board-computer running on my desk.

Spread requires a top-level spread.yaml file and a collection of task.yaml
files that describe individual tasks (for us, those are just tests). Tasks have
no implied dependency except that to reach a given task, spread will run all
the _prepare_ statements leading to that task, starting from the project, test
suite and then task. With proper care one can then run a specific individual
test with a one-line command, for example:

```
spread -v garden:ubuntu-cloud-24.04:tests/regression/apparmor:at_secure
```

This will prepare a fresh ubuntu-cloud-24.04 system (matching the CPU
architecture of the host), copy the project tree into the test machine, install
all the build dependencies, build all the parts of apparmor and then run one
specific variant of the regression test, namely the at_secure program.
Importantly the same test can also run on, say debian-cloud-13 (Debian Trixie),
but also, if you have a Google cloud account, on Google Compute Engine or in
one of the other backends either built into spread or available as a fork of
spread or as a helper for ad-hoc backend. Spread can also create more than one
worker per system and distribute the tests to all of the available instances.
In no way are we locking ourselves out of the ability to run our test suite on
our target of choice.

Spread has other useful switches, such as:
- `-reuse` for keeping machines around until discarded with -discard
- `-resend` for re-sending updated copy of the project (useful for -reuse)
- `-debug` for starting an interactive shell on any failure
- `-shell` for starting an interactive shell instead of the `execute` phase

This first patch contains just the spread elements, assuming that both spread
and image-garden are externally installed. A GitLab continuous integration
installing everything required and running a subset of tests will follow
shortly.

I've expanded the initial selection of systems to allow running all the tests
on several versions of Ubuntu, Debian and openSUSE, mainly as a sanity check
but also to showcase how practical spread is at covering real-world systems.

A number of systems and tests are currently failing:

- garden:debian-cloud-12:tests/regression/apparmor:attach_disconnected
- garden:debian-cloud-12:tests/regression/apparmor:deleted
- garden:debian-cloud-12:tests/regression/apparmor:unix_fd_server
- garden:debian-cloud-12:tests/regression/apparmor:unix_socket_pathname
- garden:debian-cloud-13:tests/regression/apparmor:attach_disconnected
- garden:debian-cloud-13:tests/regression/apparmor:deleted
- garden:debian-cloud-13:tests/regression/apparmor:unix_fd_server
- garden:debian-cloud-13:tests/regression/apparmor:unix_socket_pathname
- garden:opensuse-cloud-15.6:tests/regression/apparmor:attach_disconnected
- garden:opensuse-cloud-15.6:tests/regression/apparmor:deleted
- garden:opensuse-cloud-15.6:tests/regression/apparmor:e2e
- garden:opensuse-cloud-15.6:tests/regression/apparmor:unix_fd_server
- garden:opensuse-cloud-15.6:tests/regression/apparmor:unix_socket_pathname
- garden:opensuse-cloud-15.6:tests/regression/apparmor:xattrs_profile
- garden:opensuse-cloud-tumbleweed:tests/regression/apparmor:attach_disconnected
- garden:opensuse-cloud-tumbleweed:tests/regression/apparmor:deleted
- garden:opensuse-cloud-tumbleweed:tests/regression/apparmor:unix_fd_server
- garden:opensuse-cloud-tumbleweed:tests/regression/apparmor:unix_socket_pathname
- garden:ubuntu-cloud-22.04:tests/regression/apparmor:attach_disconnected

In addition, only on openSUSE, I've skipped the entire test suite of the utils
directory, as it requires python3 ttk themes, which I cannot find in packaged
form.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2024-12-05 02:17:07 +01:00
Ryan Lee
cb110eaf98 Write basic file complain-mode regression tests
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2024-11-12 12:08:22 -08:00
Christian Boltz
2ea82b866d
.gitignore: add mod_apparmor and pam_apparmor files
... that are generated during `make`
2024-10-11 22:07:54 +02:00
Ryan Lee
2d7440350f Basic test that uses aa_log_record struct fields via old, C++-incompatible names
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2024-10-03 12:46:00 -07:00
Ryan Lee
645b1406d1 Basic test that invokes aalogparse functions from C++ code
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2024-10-03 12:45:55 -07:00
Ryan Lee
66e1439293 Add an aalogparse reentrancy test for simultaneous log parsing from different threads
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2024-09-10 11:33:24 -07:00
Alex Murray
2b1ddef16e
Revert "utils/emacs: add apparmor-mode.el"
This reverts commit 65b0f83aea.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2024-08-26 13:54:28 +09:30
Georgia Garcia
15ee7ac92c parser: refactor conditional logic into its own class
Remove conditional logic from the parser and move it to its own class,
that way any improvements or conditional features will make cleaner
changes.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-14 17:22:48 -03:00
Alex Murray
65b0f83aea
utils/emacs: add apparmor-mode.el
Imported from https://github.com/alexmurray/apparmor-mode with just a minimal
change to update the URL field to point to the upstream apparmor repo.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2024-08-06 13:36:32 +09:30
Georgia Garcia
aee0492491 parser: add error=EXX flag support
Add a flag that allows setting the error code AppArmor will send when
an operation is denied. This should not be used normally.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-04-15 16:32:16 -03:00
Georgia Garcia
35a6b7a8f2 tests: rename net_finegrained to net_inet
net_inet makes more sense since other finegrained network types can be
added in the future.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-27 17:19:57 -03:00
Georgia Garcia
dd0d145a19 tests: add fine grained network regression tests 2024-02-29 17:09:19 -03:00
Georgia Garcia
f889f9f434 tests: add move_mount regression tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-01-04 18:18:58 -03:00
John Johansen
197d00d21a parser: add support for a generic all rule type
Extend the policy syntax to have a rule that allows specifying all
permissions for all rule types.

  allow all,

This is useful for making blacklist based policy, but can also be
useful when combined with other rule prefixes, eg. to add audit
to all rules.

  audit access all,

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-09-07 01:30:15 -07:00
John Johansen
fef3eb3693 Merge add userspace support for io_uring mediation
```
io_uring rules have the following format:

io_uring [<access_mode>] [<label>],
access_mode := 'sqpoll'|'override_creds'
label := 'label' '=' <target label>
```

You can use the following kernel tree with the io_uring mediation patch to test this feature https://gitlab.com/georgiag/apparmor-kernel/-/commits/io_uring

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/993
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-29 21:38:02 +00:00
John Johansen
d788af0891 Merge aa-load
aa-load is a tool that loads cached (compiled) policies into
the kernel. It can receive as argument a file, a cache directory
containing the hash subtree, and a directory containing cached
files directly underneath - no hash.

This tool can be used in the as a guide for other init
systems to load the cached policies directly.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/770
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-29 21:24:25 +00:00
Georgia Garcia
feb5069f67 tests: add io_uring regression tests
Note that the tests add the dependency of liburing.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-05-03 16:04:29 +02:00
Georgia Garcia
e5e920d178 parser: add parser support for io_uring mediation
io_uring rules have the following format:

io_uring [<access_mode>] [<label>],
access_mode := 'sqpoll'|'override_creds'
label := 'label' '=' <target label>

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-05-03 16:03:52 +02:00
John Johansen
b5f558962f Merge ipc message queue rule support
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/858
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-12-05 03:04:48 +00:00
Georgia Garcia
3d422215ba tests: add sysv message queue regression tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-22 19:31:15 +00:00
Georgia Garcia
cd85ca9777 tests: add posix message queue regression tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-11-22 19:31:15 +00:00
Georgia Garcia
d98c5c4cf9 parser: add parser support for message queue mediation
Message queue rules take the following format:

	mqueue [<access_mode>] [<type>] [<label>] [<mqueue name>],
	access_mode := 'r'|'w'|'rw'|'read'|'write'|
		       'create'|'open'|'delete'|
		       'getattr'|'setattr'
	type := 'type' '=' ('posix'|'sysv')
	label := 'label' '=' <target label>

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-11-22 19:31:15 +00:00
Georgia Garcia
c6f1981cd8 tests: expand userns tests to use setns
Setns is used to associate to an existing user namespace, so the
kernel security hook for user namespace creation is not called.
The restriction for setns is that it should have the capability
sys_admin.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-22 14:45:54 +00:00
Georgia Garcia
0727da47b3 tests: add userns regression tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-04 08:29:45 +00:00
Georgia Garcia
f400b41c4a parser: add support for user namespace creation
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 17:54:42 +00:00
Georgia Garcia
cb4a397b1e tests: add attach_disconnected tests
This test uses unix_fd_server to open a file and pass
its file descriptor to the attach_disconnected tests, which
then mounts, pivots root and then tries to open the file.

Since the server execs the client, this commit also inverts the order
of the parameters to allow the server to forward the client's args
along with the unix_socket path.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/810
Acked-by: John Johansen <john.johansen@canonical.com>
2022-01-27 10:36:14 -03:00
Georgia Garcia
b07a532a6f unix_fd_common tests: refactor out unix_fd_client code into common
The code from unix_fd_client can be used by other clients which
will receive the fd of a file using SCM rights.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/810
Acked-by: John Johansen <john.johansen@canonical.com>
2022-01-27 10:35:29 -03:00
John Johansen
6154925c62 Merge tests: add built test files to gitignore
The following files generated during the build were not ignored by git: aa_policy_cache at_secure dbus_common.o dbus_eavesdrop dbus_message dbus_service dbus_unrequested_reply fd_inheritance fd_inheritor introspect pivot_root query_label socketpair syscall_ioperm syscall_iopl transition unix_socket unix_socket_client unix_socket_common.o uservars.inc xattrs_profile

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/826
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2022-01-27 08:19:27 +00:00
John Johansen
1ca30e35b0 libapparmor: Fix ruby 3.1 build for libapparmor
The Hack used to build the libapparmor swig interface for ruby fails
with ruby 3.1.  Instead of trying to do black magic in ruby to rename
the generated Makefile to Makefile.new, just save off the Makefile
and restore after ruby's setup has been called.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/206
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2022-01-26 23:12:27 -08:00
Georgia Garcia
c0ee4a9a8a tests: add built test files to gitignore
The following files generated during the build were not ignored by git:
  aa_policy_cache
  at_secure
  dbus_common.o
  dbus_eavesdrop
  dbus_message
  dbus_service
  dbus_unrequested_reply
  fd_inheritance
  fd_inheritor
  introspect
  pivot_root
  query_label
  socketpair
  syscall_ioperm
  syscall_iopl
  transition
  unix_socket
  unix_socket_client
  unix_socket_common.o
  uservars.inc
  xattrs_profile

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-01-26 11:00:41 -03:00
Georgia Garcia
21e5a721ab replace deprecated distutils with setuptools
Adds python3 setuptools as a build dependency for libapparmor

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/202
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/813
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-11-11 20:23:35 -03:00
Jon Tourville
90620cb64f Generate af_names.h similar to cap_names.h 2021-10-18 15:55:57 -05:00
Georgia Garcia
b2a1544d94 binutils: add aa-load
aa-load is a tool that loads cached (compiled) policies into
the kernel. It can receive as argument a file, a cache directory
containing the hash subtree, and a directory containing cached
files directly underneath - no hash.

This tool can be used in the as a guide for other init
systems to load the cached policies directly.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2021-07-26 20:52:34 -03:00
Christian Boltz
5c0609453c
.gitignore: Add aa-features-abi and utils coverage files 2021-04-25 20:10:48 +02:00
John Johansen
270fb0a2b2 parser: Move to a pre-generated cap_names.h
The auto-generated cap_names.h has problems when the parser if the
parser is built against a kernel with a smaller capability list than
the kernel policy is being compiled for.

Moving to a pre-generated list lets us support all capabilities even
when we build against older kernels. However we don't want to only use
the pre-generated list as that would make it too easy to miss when a
new capability has been added.

Keep auto generating the caps list and compare it to the pre-generated
caps list so we can detect when new capabilities are added, and fail
the build so that the pre-generated list can be updated. We screen the
diff for only additions so that the parser can continue to build on
older kernels that don't have the full capability list without errors.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
Christian Boltz
a68fe50fda
add parser/default_features.o to .gitignore 2020-05-31 01:27:00 +02:00
Christian Boltz
c9ce3d3ab4
add binutils/aa-status compiled files to .gitignore 2020-05-09 13:29:24 +02:00
Christian Boltz
7ed1a16af1
Add several libapparmor/swig/ruby files to gitignore
These files get created by swig, and deleted with make clean
2019-04-21 21:56:46 +02:00
Christian Boltz
aeee9a1aab
.gitignore profiles/apparmor.d/local/* except README
The old patter *.* doesn't match lsb_release and nvidia_modprobe, and
the only file we ship in local is a README. This patch adjusts the
pattern to ignore everything except README.
2018-10-11 12:59:16 +02:00
Christian Boltz
63d17ecf16
add utils/test/common_test.pyc to gitignore
(cache file that gets created when running the tests with python2)
2018-06-19 15:27:16 +02:00
Christian Boltz
db92d96e68
add libapparmor/src/PMurHash.{o,lo} to gitignore 2018-05-09 23:03:03 +02:00
Tyler Hicks
426990cfaf .gitignore: Add files to ignore in utils/vim/
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2017-12-18 15:50:59 +00:00
Tyler Hicks
e325e74b0f .gitignore: Add files to ignore from libapparmor test runs
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2017-12-18 15:48:59 +00:00
Tyler Hicks
ba0cdbc013 .gitignore: Add files to ignore in binutils/
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2017-12-18 15:45:48 +00:00
Christian Boltz
23220af3b9
.gitignore: add several parser/**.o and utils/**.pyc files
Also ignore parser/libapparmor_re/libapparmor_re.a and the utils
coverage report.
2017-12-17 16:55:10 +01:00
Christian Boltz
d7ffc37011
.gitignore: add several libapparmor *.o files 2017-11-28 22:49:53 +01:00
Tyler Hicks
29c5c6b621 gitignore: Add cscope files to ignored list
Ignoring cscope.* files allows users of cscope to not be bothered by
`git status` reporting that an unknown file is in the source tree.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2017-11-02 16:40:09 +00:00
Steve Beattie
29b20fd688
git conversion: move .bzrignore to .gitignore
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2017-10-27 22:46:03 -07:00
Renamed from .bzrignore (Browse further)