Inhaltsverzeichnis
You are ready to build Novell AppArmor
profiles after you select the programs to profile. To do so, it is important
to understand the components and syntax of profiles. AppArmor profiles contain
several building blocks that help build simple and reusable profile code:
#include
files, abstractions, program chunks, and
capability entries. #include
statements are used to pull
in parts of other AppArmor profiles to simplify the structure of new profiles.
Abstractions are #include
statements grouped by common
application tasks. Program chunks are chunks of profiles that are specific to
program suites. Capability entries are profile entries for any of the
POSIX.1e Linux capabilities.
For help determining the programs to profile, refer to Abschnitt 1.2, „Determining Programs to Immunize“. To start building AppArmor profiles with YaST, proceed to Kapitel 3, Building and Managing Profiles with YaST. To build profiles using the AppArmor command line interface, proceed to Kapitel 4, Building Profiles from the Command Line.
Novell AppArmor profile components are called Novell AppArmor rules. Currently there are two main types of Novell AppArmor rules, path entries and capability entries. Path entries specify what the process can access in the file system and capability entries provide a more fine-grained control over what a confined process is allowed to do through other system calls that require privileges. Includes are a type of meta rule or directives that pull in path and capability entries from other files.
The easiest way of explaining what a profile consists of and how to create one is to show the details of a sample profile, in this case for a hypothetical application called /usr/bin/foo:
#include <tunables/global># a comment naming the application to confine /usr/bin/foo
{
#include <abstractions/base>
capability setgid
, network inet tcp
, /bin/mount ux, /dev/{,u}
random r, /etc/ld.so.cache r, /etc/foo.conf r, /etc/foo/* r, /lib/ld-*.so* mr, /lib/lib*.so* mr, /proc/[0-9]** r, /usr/lib/** mr, /tmp/
r, /tmp/foo.pid wr, /tmp/foo.* lrw, /@{HOME}
/.foo_file rw, /@{HOME}/.foo_lock kw, # a comment about foo's subprofile, bar. ^bar
{ /lib/ld-*.so* mr, /usr/bin/bar px, /var/spool/* rwl, } }
![]() | This loads a file containing variable definitions. |
![]() | The absolute path to the program that is confined. |
![]() | The curly braces ( |
![]() | This directive pulls in components of AppArmor profiles to simplify profiles. |
![]() | Capability entry statements enable each of the 29 POSIX.1e draft capabilities. |
![]() | A directive determining the kind of network access allowed to the application. For details, refer to Abschnitt 2.1.1, „Network Access Control“. |
![]() | The curly braces ( |
![]() | A path entry specifying what areas of the file system the program
can access. The first part of a path entry specifies the absolute path of
a file (including regular expression globbing) and the second part
indicates permissible access modes ( |
![]() | This variable expands to a value that can be changed without changing the entire profile. |
![]() | This section references a subprofile of the application, also known as a „hat“. For more details on AppArmor's ChangeHat feature, refer to Kapitel 5, Profiling Your Web Applications Using ChangeHat. |
![]() | Using Variables in Profiles |
---|---|
With the current AppArmor tools, variables as presented in the above example can only be used when manually editing and maintaining a profile. A typical example when variables come in handy are network scenarios
in which user home directories are not mounted in the standard location
|
When a profile is created for a program, the program can access only the files, modes, and POSIX capabilities specified in the profile. These restrictions are in addition to the native Linux access controls.
Example: .
To gain the capability CAP_CHOWN
, the program
must have both access to CAP_CHOWN
under
conventional Linux access controls (typically, be a root
-owned
process) and have the capability chown in its profile. Similarly, to be
able to write to the file /foo/bar
the program must
have both the correct user ID and mode bits set in the files attributes
(see the chmod
and chown
man pages) and have /foo/bar w
in its profile.
Attempts to violate Novell AppArmor rules are recorded in
/var/log/audit/audit.log
if the audit
package is installed or otherwise in
/var/log/messages
. In many cases, Novell AppArmor rules prevent
an attack from working because necessary files are not accessible and, in
all cases, Novell AppArmor confinement restricts the damage that the attacker can do
to the set of files permitted by Novell AppArmor.
AppArmor allows mediation of network access based on the address type and family. The following illustrates the network access rule syntax:
network [[<domain>][<type
>][<protocol
>]]
The AppArmor tools support only family and type specification. The AppArmor module
emits only network
in „access denied“
messages. And only these are output by the profile generation tools, both
YaST and command line.
domain
type
The following examples illustrate possible network-related rules to be used in AppArmor profiles. Note that the syntax of the two last ones is not currently supported by the AppArmor tools.
network, network inet
, network inet6
, network inet stream
, network inet tcp
, network tcp
,
AppArmor explicitly distinguishes directory path names from file path names.
Use a trailing /
for any directory path that needs to
be explicitly distinguished:
/some/random/example/* r
Allow read access to files in the
/some/random/example
directory.
/some/random/example/ r
Allow read access to the directory only.
/some/**/ r
Give read access to any directories below
/some
.
/some/random/example/** r
Give read access to files and directories under
/some/random/example
.
/some/random/example/**[^/] r
Give read access to files under
/some/random/example
. Explicitly exclude
directories ([^/]
).
Globbing (or regular expression matching) is when you modify the directory path using wild cards to include a group of files or subdirectories. File resources can be specified with a globbing syntax similar to that used by popular shells, such as csh, Bash, and zsh.
File permission access modes consist of combinations of the following eleven modes:
|
Read mode |
|
Write mode (mutually exclusive to |
|
Append mode (mutually exclusive to |
|
File locking mode |
|
Discrete profile execute mode |
|
Discrete profile execute mode—clean exec |
|
Unconstrained execute mode |
|
Unconstrained execute mode—clean exec |
|
Inherit execute mode |
|
Allow |
|
Link mode |
Allows the program to have read access to the resource. Read access is required for shell scripts and other interpreted content and determines if an executing process can core dump or be attached to with ptrace(2) (ptrace(2) is used by utilities like strace(1), ltrace(1), and gdb(1)).
Allows the program to have write access to the resource. Files must have this permission if they are to be unlinked (removed).
Allows a program to write to the end of a file. In contrast to the
w
mode, the append mode does not include the ability
to overwrite data, to rename, or to remove a file. The append permission
is typically used with applications who need to be able to write to log
files, but which should not be able to manipulate any existing data in
the log files. As the append permission is just a subset of the
permissions associated with the write mode, the w
and a
permission flags cannot be used together and
are mutually exclusive.
The application can take file locks. Former versions of AppArmor allowed files to be locked if an application had access to them. By using a separate file locking mode, AppArmor makes sure locking is restricted only to those files which need file locking and tightens security as locking can be used in several attack scenarios.
This mode requires that a discrete security profile is defined for a resource executed at an AppArmor domain transition. If there is no profile defined, the access is denied.
![]() | Using the Discrete Profile Execute Mode |
---|---|
|
Incompatible with Ux
, ux
,
Px
, and ix
.
Px
allows the named program to run in
px
mode, but AppArmor invokes the Linux kernel's
unsafe_exec routines to scrub the environment,
similar to setuid programs. See ld.so(8) for some
information about setuid and setgid environment scrubbing.
Incompatible with Ux
, ux
,
px
, and ix
.
Allows the program to execute the resource without any AppArmor profile applied to the executed resource. Requires listing execute mode as well.
This mode is useful when a confined program needs to be able to perform
a privileged operation, such as rebooting the machine. By placing the
privileged section in another executable and granting unconstrained
execution rights, it is possible to bypass the mandatory constraints
imposed on all confined processes. For more information about what is
constrained, see the apparmor(7)
man page.
![]() | Using Unconstrained Execute Mode (ux) |
---|---|
Use |
This mode is incompatible with Ux
,
px
, Px
, and
ix
.
Ux
allows the named program to run in
ux
mode, but AppArmor invokes the Linux kernel's
unsafe_exec routines to scrub the environment,
similar to setuid programs. See ld.so(8) for some
information about setuid and setgid environment scrubbing.
![]() | Using Unconstrained Execute Mode (Ux) |
---|---|
Use |
Incompatible with ux
, px
,
Px
, and ix
.
ix
prevents the normal AppArmor domain transition
on execve(2) when the profiled program executes the
named program. Instead, the executed resource inherits the current
profile.
This mode is useful when a confined program needs to call another
confined program without gaining the permissions of the target's
profile or losing the permissions of the current profile. There is no
version to scrub the environment because ix
executions do not change privileges.
Incompatible with Ux
, ux
,
Px
, and px
. Implies
m
.
This mode allows a file to be mapped into memory using
mmap(2)'s PROT_EXEC
flag. This flag
marks the pages executable. It is used on some architectures to provide
nonexecutable data pages, which can complicate exploit attempts. AppArmor
uses this mode to limit which files a well-behaved program (or all
programs on architectures that enforce nonexecutable memory access
controls) may use as libraries, to limit the effect of invalid
-L
flags given to ld(1) and
LD_PRELOAD
, LD_LIBRARY_PATH
, given to
ld.so(8).
The link mode mediates access to hard links. When a link is created, the target file must have the same access permissions as the link created (with the exception that the destination does not need link access).
When choosing one of the Ux or Px file permission access modes, take into account that the following environment variables are removed from the environment before the child process inherits it. As a consequence, applications or processes relying on any of these variables do not work anymore if the profile applied to them carries Ux or Px flags:
GCONV_PATH
GETCONF_DIR
HOSTALIASES
LD_AUDIT
LD_DEBUG
LD_DEBUG_OUTPUT
LD_DYNAMIC_WEAK
LD_LIBRARY_PATH
LD_ORIGIN_PATH
LD_PRELOAD
LD_PROFILE
LD_SHOW_AUXV
LD_USE_LOAD_BIAS
LOCALDOMAIN
LOCPATH
MALLOC_TRACE
NLSPATH
RESOLV_HOST_CONF
RES_OPTIONS
TMPDIR
TZDIR