### Running spread script Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Example of how to run the spread script for testing. ```bash # or ~/go/bin/spread -v garden:ubuntu-cloud-24.04:tests/regression/apparmor:at_secure ``` ``` -------------------------------- ### Build and install Image Garden from source Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Commands to build and install Image Garden from source, including dependencies. ```bash sudo apt install git golang whois ovmf genisoimage qemu-utils qemu-system go install github.com/snapcore/spread/cmd/spread@latest git clone https://gitlab.com/zygoon/image-garden make -C image-garden sudo make -C image-garden install image-garden make ubuntu-cloud-24.10.x86_64.run ``` -------------------------------- ### Install Image Garden snap Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Command to install the Image Garden snap for testing purposes. ```bash sudo snap install image-garden ``` -------------------------------- ### Snapcraft.yaml configuration for AppArmor Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Example snippet showing how to configure snapcraft.yaml to use a vendored AppArmor tarball. ```yaml apparmor: plugin: autotools build-packages: - autoconf-archive - bison - flex - gettext - g++ - pkg-config - wget source: ./apparmor-5.0.0.tar.gz source-checksum: sha256/0d13f2cfa7da87a2284e45fb23c4820bca4939accf9a77f01fe0bb8cdec7038e ``` -------------------------------- ### Debug test failures with retained files Source: https://gitlab.com/apparmor/apparmor/-/blob/master/tests/regression/apparmor/README.md Example output when running a test harness with the -r option to retain temporary files for inspection. ```text # bash unlink.sh -r Files retained in: /tmp/sdtest.25406-19681 #ls -l /tmp/sdtest.25406-19681 total 3 -rw-r--r-- 1 root root 0 Jul 2 11:51 file -rw-r--r-- 1 root root 25 Jul 2 11:51 output.unlink -rw-r--r-- 1 root root 182 Jul 2 11:51 profile -rw-r--r-- 1 root root 292 Jul 2 11:51 runtest ``` -------------------------------- ### Regression tests - using apparmor userspace installed on host Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Commands to run regression tests with system-installed apparmor userspace. ```bash $ cd tests/regression/apparmor (requires root) $ make -j $(nproc) USE_SYSTEM=1 $ sudo make tests USE_SYSTEM=1 $ sudo bash open.sh -r # runs and saves the last testcase from open.sh ``` -------------------------------- ### Overriding aa-decode for utils tests Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Example of setting an environment variable to override aa-decode for utils tests. ```bash $ APPARMOR_DECODE=/usr/bin/aa-decode make check ``` -------------------------------- ### Build Init Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Steps to build the init component. ```bash $ make -j $(nproc) $ make check $ make install ``` -------------------------------- ### Build Binary Utilities Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Steps to build the binary utilities. ```bash $ cd binutils $ make -j $(nproc) $ make check $ make install ``` -------------------------------- ### Build libapparmor Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Steps to build the libapparmor library. ```bash $ cd ./libraries/libapparmor $ sh ./autogen.sh $ sh ./configure --prefix=/usr --with-perl --with-python # see below $ make -j $(nproc) $ make check $ make install ``` -------------------------------- ### Build Utilities Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Steps to build the utilities, with an optional PYFLAKES argument. ```bash $ cd utils $ make -j $(nproc) $ make check PYFLAKES=/usr/bin/pyflakes3 $ make install ``` -------------------------------- ### Execute tests with verbose output Source: https://gitlab.com/apparmor/apparmor/-/blob/master/tests/regression/apparmor/README.md Run the test suite with the VERBOSE environment variable set to 1 to see individual subtest results. ```bash sudo VERBOSE=1 make tests ``` -------------------------------- ### Debug test failures with shell tracing Source: https://gitlab.com/apparmor/apparmor/-/blob/master/tests/regression/apparmor/README.md Run a test harness with the -x option to enable shell debugging for complex failures. ```bash # bash -x unlink.sh ``` -------------------------------- ### Build Profiles Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Steps to build the profiles, which depends on the parser. ```bash $ cd profiles $ make $ make check # depends on the parser having been built first $ make install ``` -------------------------------- ### Benchmark parser CLI Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Commands to benchmark the parser CLI using hyperfine. ```bash $ cd profiles $ make bench-parser-cli ``` -------------------------------- ### Build Parser Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Steps to build the parser, which depends on libapparmor. ```bash $ cd parser $ make -j $(nproc) # depends on libapparmor having been built first $ make -j $(nproc) tst_binaries # a build step of make check that can be parallelized $ make check $ make install ``` -------------------------------- ### Build snapd snap with vendored AppArmor Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Command to build the snapd snap after integrating a vendored AppArmor version. ```bash $ snapcraft pack ``` -------------------------------- ### Create a new AppArmor test script Source: https://gitlab.com/apparmor/apparmor/-/blob/master/tests/regression/apparmor/README.md Template for a shell script test using the AppArmor test harness. Requires 'prologue.inc' to be sourced after setting the 'bin' variable. ```bash #! /bin/bash pwd=`dirname $0` pwd=`cd $pwd ; pwd` # bin must be set prior to including prologue.inc. This is the only # requirement placed on the shell script author by prologue.inc bin=$pwd # prologue.inc must be included before running any tests . "$bin/prologue.inc" # variable definitions used by this script? file=/bin/true okperm=x badperm=r # PASS TEST # generate a profile allowing x access to /bin/true genprofile $file:$okperm # run this test (exec) passing /bin/true as argv[1] # check it's output, it is expected to pass runchecktest "EXEC with x" pass $file # NOLINK PERMTEST # generate a new profile allowing only r access to /bin/true # apparmor_parser will automatically be invoked in -r mode genprofile $file:$badperm # run this test (exec) passing /bin/true as argv[1] # check it's output, it is expected to FAIL runchecktest "EXEC no x" fail $file # That's it. Exit status $rc is automatically returned by epilogue.inc ``` -------------------------------- ### net_supports.inc - Network Socket Support Probes Source: https://gitlab.com/apparmor/apparmor/-/blob/master/tests/regression/apparmor/README.md This section details various probes for checking network socket rule encoding support in different versions of AppArmor. ```APIDOC ## `net_supports.inc` ### Description Provides functions to probe and check for support of various network socket rule encoding versions and features. ### Functions - `parser_supports_v7_socket_encode`: - Description: Probes parser support for socket-v7 UNIX rule encoding without downgrade/not-enforced warnings. - `parser_supports_ubuntu_socket`: - Description: Compatibility alias for `parser_supports_v7_socket_encode`. - `parser_supports_v8_socket_encode`: - Description: Probes parser support for socket-v8 UNIX rule encoding without downgrade/not-enforced warnings. - `parser_supports_v9_socket_encode`: - Description: Probes parser support for socket-v9 UNIX rule encoding without downgrade/not-enforced warnings. - `parser_supports_upstream_socket`: - Description: Probes parser support for upstream socket rule encoding (v9 preferred, v8 fallback). - `parser_supports_v7_unix_encode`: - Description: Probes parser support for AF_UNIX-v7 rule encoding without downgrade/not-enforced warnings. - `parser_supports_v9_unix_encode`: - Description: Probes parser support for AF_UNIX-v9 rule encoding without downgrade/not-enforced warnings. - `parser_supports_extended_v9_unix`: - Description: Probes parser support for extended v9 AF_UNIX rules that older encodings cannot represent. - `supports_unix_v7`: - Description: Checks kernel and parser support for AF_UNIX-v7 mediation. - `supports_unix_v9`: - Description: Checks kernel and parser support for AF_UNIX-v9 mediation. - `supports_unix_rules`: - Description: Checks whether AF_UNIX mediation is available (v9 or v7). - `supports_socket_v7`: - Description: Checks kernel and parser support for socket mediation v7. - `supports_socket_v8`: - Description: Checks kernel and parser support for socket mediation v8. - `supports_socket_v9`: - Description: Checks kernel and parser support for socket mediation v9. - `supports_socket_mediation`: - Description: Checks whether socket mediation is available (v9/v8/v7). ``` -------------------------------- ### Test Execution Helpers (prologue.inc) Source: https://gitlab.com/apparmor/apparmor/-/blob/master/tests/regression/apparmor/README.md Functions for running tests in foreground or background, checking results, and managing test environments. ```APIDOC ## Test Execution Helpers ### Description Functions provided by prologue.inc to manage test execution, validation, and environment setup. ### Methods - runchecktest [arg1 ... argN]: Run test in foreground and check output. - runchecktest_errno [arg1 ... argN]: Run foreground test and verify specific errno. - runtestfg [arg1 ... argN]: Run test in foreground without immediate check. - checktestfg [post_check_cmd]: Check latest foreground run output. - runtestbg [arg1 ... argN]: Run test in background. - checktestbg [post_check_cmd]: Check latest background run output. - settest [wrapper_template]: Select test executable. - genprofile [opt1 ... optN] [profile_token1 ... profile_tokenN]: Generate and load test profile. - removeprofile [profile_path]: Unload generated profile. ``` -------------------------------- ### Build PAM AppArmor Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Steps to build the PAM AppArmor module, which depends on libapparmor. ```bash $ cd changehat/pam_apparmor $ make -j $(nproc) # depends on libapparmor having been built first $ make install ``` -------------------------------- ### Run Individual AppArmor Test Case Source: https://gitlab.com/apparmor/apparmor/-/blob/master/utils/test/README.md Execute a specific test case from a Python file using the unittest framework. Specify the class name and test method on the command line. ```python python3 ./test-tile.py ClassFoo.test_bar ``` -------------------------------- ### Display test execution status Source: https://gitlab.com/apparmor/apparmor/-/blob/master/tests/regression/apparmor/README.md Default output format displayed by the makefile during test execution. ```text running for each test. ``` -------------------------------- ### Configure.ac snippet for AppArmor5 check Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Autoconf snippet demonstrating how to check for AppArmor5 library availability, particularly for snapd builds. ```autoconf # Check if apparmor userspace library is available. AS_IF([test "x$enable_apparmor" = "xyes"], [ # Expect AppArmor5 when building as a snap under snapcraft AS_IF([test "x$SNAPCRAFT_PROJECT_NAME" = "xsnapd"], [ PKG_CHECK_MODULES([APPARMOR5], [libapparmor = 5.0.0], [ AC_DEFINE([HAVE_APPARMOR], [1], [Build with apparmor5 support])], [ AC_MSG_ERROR([unable to find apparmor5 for snap build of snapd])])], [ PKG_CHECK_MODULES([APPARMOR], [libapparmor], [ AC_DEFINE([HAVE_APPARMOR], [1], [Build with apparmor support])])]) ], [ AC_MSG_WARN([ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X X X Apparmor is disabled, all snaps will run in devmode X X X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX]) ]) ``` -------------------------------- ### Build Apache mod_apparmor Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Steps to build the Apache mod_apparmor module, which depends on libapparmor. ```bash $ cd changehat/mod_apparmor $ make -j $(nproc) # depends on libapparmor having been built first $ make install ``` -------------------------------- ### Libapparmor tests Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Command to run libapparmor tests. ```bash $ cd libraries/libapparmor $ make check ``` -------------------------------- ### Parser tests Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Commands to run parser tests. ```bash $ cd parser/tst $ make $ make tests ``` -------------------------------- ### Utils tests Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Command to run tests for Python utilities. ```bash $ cd utils $ make check ``` -------------------------------- ### Run Spread test suite Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Command to run the Spread test suite with specified artifacts and distribution. ```bash cd $APPARMOR_PATH git clean -xdf ~/go/bin/spread -artifacts ./spread-artifacts -v ubuntu-cloud-24.10 ``` -------------------------------- ### Parser stress tests Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Commands to run parser stress tests. ```bash $ ./stress.sh (see stress.sh -h for options) ``` -------------------------------- ### Profile checks Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Commands to perform basic consistency checks on profiles. ```bash $ cd profiles $ make && make check ``` -------------------------------- ### Regression tests - using apparmor userspace from the tree Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Commands to run regression tests with apparmor userspace from the source tree. ```bash $ cd tests/regression/apparmor (requires root) $ make -j $(nproc) $ sudo make tests $ sudo bash open.sh -r # runs and saves the last testcase from open.sh ``` -------------------------------- ### Set AppArmor Test Environment Variables Source: https://gitlab.com/apparmor/apparmor/-/blob/master/utils/test/README.md Set PYTHONPATH and __AA_CONFDIR environment variables to point to the in-tree AppArmor modules, libapparmor, and its Python wrapper. This is required before running tests. ```bash $ export PYTHONPATH=..:../../libraries/libapparmor/swig/python/build/$(/usr/bin/python3 ../../libraries/libapparmor/swig/python/test/buildpath.py) ``` ```bash $ export __AA_CONFDIR=. ``` -------------------------------- ### DBus Testing Utilities (dbus.inc) Source: https://gitlab.com/apparmor/apparmor/-/blob/master/tests/regression/apparmor/README.md Functions for managing DBus daemons and brokers, and sending signals or methods for testing AppArmor DBus mediation. ```APIDOC ## DBus Testing Utilities ### Description Utilities for setting up temporary DBus environments and performing message-based testing. ### Methods - gendbusprofile [rule1 ... ruleN]: Generate DBus-focused profile. - start_dbus_daemon / kill_dbus_daemon: Manage temporary dbus-daemon. - start_dbus_broker / kill_dbus_broker: Manage temporary DBus broker. - sendsignal: Send standard DBus signal. - sendmethod: Send standard DBus method call. - compare_logs : Compare DBus logs for test validation. ``` -------------------------------- ### Stress Tests Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Commands to run AppArmor stress tests. ```bash $ make all $ ./change_hat $ ./child $ ./kill.sh $ ./open $ ./s.sh Or run all at once: $ ./stress.sh ``` -------------------------------- ### Setting Python Environment Variables for AppArmor Userspace Build Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md This snippet shows the environment variables that may need to be exported before building AppArmor userspace on certain systems. ```bash $ export PYTHONPATH=$(realpath libraries/libapparmor/swig/python) $ export PYTHON=/usr/bin/python3 $ export PYTHON_VERSION=3 $ export PYTHON_VERSIONS=python3 ``` -------------------------------- ### Generate Coverity intermediate directory tarball Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Command to generate a compressed tarball of an intermediate Coverity directory for analysis. ```bash $ make coverity ``` -------------------------------- ### unix_socket.inc - Unix Socket Mediation Tests Source: https://gitlab.com/apparmor/apparmor/-/blob/master/tests/regression/apparmor/README.md This section details the function for running comprehensive checks on Unix socket mediation scenarios. ```APIDOC ## `unix_socket.inc` ### Description Provides a function to execute detailed test cases for Unix socket mediation. ### Function - `do_test`: - Description: Runs socket mediation matrix checks for one address/type scenario. - Parameters: - `addr_type` (string) - Required - The type of address. - `test_prog` (string) - Required - The test program to run. - `l_u_access` (string) - Required - Local Unix access permissions. - `l_b_access` (string) - Required - Local bind access permissions. - `type` (string) - Required - The type of socket. - `addr` (string) - Required - The socket address. - `p_access` (string) - Required - Peer access permissions. - `p_label` (string) - Required - Peer label. - `p_addr` (string) - Required - Peer address. - `bad_type` (string) - Required - An invalid socket type for testing. - `bad_addr` (string) - Required - An invalid socket address for testing. - `bad_p_label` (string) - Required - An invalid peer label for testing. - `bad_p_addr` (string) - Required - An invalid peer address for testing. ``` -------------------------------- ### AppArmor Source Layout Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md The AppArmor project consists of several different parts, each with its own source directory. ```shell binutils/ source for basic utilities written in compiled languages changehat/ source for using changehat with Apache, PAM and Tomcat common/ common makefile rules desktop/ empty documentation/ misc docs (not man pages), logos, ... init/ initscript fns and corresponding documentation kernel-patches/ compatibility patches for various kernel versions - deprecated libraries/ libapparmor source and language bindings parser/ source for parser profiles/ configuration files, reference profiles and abstractions tests/ regression and stress testsuites utils/ high-level utilities for working with AppArmor ``` -------------------------------- ### Generate AppArmor tarball for snapd Source: https://gitlab.com/apparmor/apparmor/-/blob/master/README.md Commands to generate a tarball of the AppArmor userspace for use with snapd. ```bash $ make tarball $ sha256sum apparmor-*.tar.gz ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.