Generating a profile
aa-genprof and aa-autodep for application developers for administrators
One recorded aa-genprof session that takes a program from no profile to enforce mode. What the tool does before its first question - the starter profile and complain mode and the log mark. The Scan and Finish loop. The exec question and the rule each key writes. Reading the profile the tool wrote. aa-autodep and scripts and the programs the tools refuse to profile.
On the map: tools
▶ Watch this deck — 9 scenes, ~7 min
Worth seeing first
- Why AppArmor — profiles and modes and what a denial is
- Profile mode flags — complain and enforce mode
- File rules — the rules the tool will write for you
Part of journeys
- Write your first profile, step 11 of 12 · previous: Choosing abstractions · next: aa-logprof
01 From no profile to enforce, in one sitting
aa-genprof PROGRAM creates a starter profile in complain mode, then loops: you run the program, (S)can turns the new log records into questions, your answers become rules. (F)inish sets enforce mode. The deck follows one recorded session.
Demo has no profile. You could write one by hand, and the syntax decks show how. Or you can let demo show you what it needs. That's aa-genprof. You give it the program. It writes a tiny profile and switches it to complain mode, where nothing is blocked and everything missing is logged. You run demo and use it. The tool reads the log and asks you one question per thing demo did. Your answers become rules. When you're done, it switches the profile to enforce. This deck follows one real session with demo, key by key, including two places where the tool's suggestion was wrong.
Details and sources
Details
aa-genprof [-d DIR] [-f LOGFILE] [--no-abstraction] [-o OUTDIR] program. Run it as root: it writes into the profile directory, loads profiles and reads the audit log.- The program is
demo(/usr/bin/demo), the map's example: it reads/etc/demo/demo.conf, looks up a user, reads a word list under/usr/share/demo, writes/var/lib/demo/state.dband/var/log/demo.log, makes a temporary file, opens a TCP connection, raises its priority and runs/usr/bin/demo-helper. - The session: one exec question, ten rule questions for
demo, three for the helper's profile, one save prompt, then Finish. - Complain mode: an access the profile does not allow goes through and is logged with
apparmor="ALLOWED". Explicitdenyrules are still enforced in complain mode. aa-logprofasks the same questions without the loop, for every profile at once. See aa-logprof.- Observed on 2026-11-16: the tree's
utils/(aa-genprof, aa-logprof, aa-autodep and their Python package) and the tree'sprofiles/apparmor.dwere run in a disposable Debian forky/sid guest (kernel7.3.4+deb14-cloud-amd64;apparmor_parserand the Python binding of libapparmor 5.0.2 from Debian; auditd), as root. Keys were sent by a script on a terminal; the transcripts arefindings/tools/observed/session1.txtandsession2.txt. The slides quote session 2.
Read more
02 What aa-genprof does first
Before the first question aa-genprof checks the program against logprof.conf, writes a starter profile (abstractions/base and mr on the binary) in complain mode, loads it, sets kernel.printk_ratelimit to 0 and marks the end of the log.
Start it as root with the program's path. Before it asks anything, aa-genprof does four things. It checks that demo isn't on a list of programs that shouldn't get their own profile. It writes a first profile, the same one aa-autodep would write: the base abstraction, plus read and map for the binary itself. It sets that profile to complain mode and loads it. And it turns off the kernel's rate limit for log messages, so no event is dropped, and notes where the log ends right now. Then it waits, with one line to choose from: scan, or finish.
Details and sources
Details
- The program name is looked up in
PATHwhen it has no slash. Errors:Can't find NAME in the system path list...,NAME does not exists, please double-check the path. - A profile is created only when none exists for the program. An existing profile is kept and put into complain mode.
- The starter profile:
flags=(complain),include <abstractions/base>, and/usr/bin/demo mr,;abi <abi/5.0>,andinclude <tunables/global>are added when those files exist in the profile directory. The file is named after the path,/etc/apparmor.d/usr.bin.demo, and the profile has the path as its name, without theprofilekeyword. - The profile text on the slide is put together from the tool's code and from the starter profile observed for a script (scene "aa-autodep, scripts and programs the tools refuse"); the session itself printed only the two message lines.
/proc/sys/kernel/printk_ratelimitis set to 0 so that bursts of records are not dropped, and restored when the tool exits. When that fails:Can't set printk_ratelimit, some events might be lost.- The log mark: with
/var/log/audit/audit.logpresent the tool notes the time of the last audit record; otherwise it writes a lineGenProf: logmark-<time>to the kernel log withloggerand scans from there. - It also prints a paragraph that suggests checking the wiki for an existing profile.
- Error when AppArmor is not running:
It seems AppArmor was not started. Please enable AppArmor and try again. - Observed on 2026-11-16: the tree's
utils/(aa-genprof, aa-logprof, aa-autodep and their Python package) and the tree'sprofiles/apparmor.dwere run in a disposable Debian forky/sid guest (kernel7.3.4+deb14-cloud-amd64;apparmor_parserand the Python binding of libapparmor 5.0.2 from Debian; auditd), as root. Keys were sent by a script on a terminal; the transcripts arefindings/tools/observed/session1.txtandsession2.txt. The slides quote session 2.
for AppArmor developers
Code
- aa-genprof start-up: aa-genprof:77-151; the mark: aa-genprof:160-166.
create_new_profile: aa.py:386-428;autodep: aa.py:484-520;check_qualifiers: aa.py:2501-2511.
03 Run the program, then press S
While the profile is in complain mode the program runs normally and every missing permission is logged as apparmor="ALLOWED". (S)can reads the log from the mark, skips what the profile covers and asks about the rest, exec events first.
Now go to another window and use demo. Really use it: every feature you skip is a rule you won't get. Demo reads its config, looks up a user, writes its state and its log, opens a network connection and starts a helper. In complain mode all of that works, and each thing the profile doesn't allow leaves a log record marked allowed. Back in the first window, press S. The tool reads the log from the point it noted, drops what the profile already covers, and starts asking. Exec questions come first, because the answer decides which profile the helper's own events belong to.
Details and sources
Details
- Records from the session (pid removed):
apparmor="ALLOWED" operation="open" class="file" profile="/usr/bin/demo" name="/etc/demo/demo.conf" comm="demo" requested_mask="r" denied_mask="r" fsuid=0 ouid=0;apparmor="ALLOWED" operation="capable" class="cap" profile="/usr/bin/demo" comm="demo" capability=23 capname="sys_nice";apparmor="ALLOWED" operation="exec" class="file" profile="/usr/bin/demo" name="/usr/bin/demo-helper" comm="demo" requested_mask="x" denied_mask="x" fsuid=0 ouid=0 target="/usr/bin/demo//null-/usr/bin/demo-helper". The slide shortens them. - Sixteen such records came from one run of
demo; several records about one path are merged into one question. - The exec record names a target
/usr/bin/demo//null-/usr/bin/demo-helper: in complain mode the kernel runs a program the profile has no exec rule for under a temporary profile and logs its accesses under that name. The tool assigns those records to a real profile after you answer the exec question. - The order of a scan: exec events, hat requests, then for each profile the other rule classes, complain-mode records before enforce-mode records, then the save prompt.
- Only what ran between the mark and the scan is in the log. Start-up, every option, error paths and shutdown each need to happen at least once.
- A scan with nothing new prints
Complain-mode changes:andEnforce-mode changes:and returns to the prompt. - Observed on 2026-11-16: the tree's
utils/(aa-genprof, aa-logprof, aa-autodep and their Python package) and the tree'sprofiles/apparmor.dwere run in a disposable Debian forky/sid guest (kernel7.3.4+deb14-cloud-amd64;apparmor_parserand the Python binding of libapparmor 5.0.2 from Debian; auditd), as root. Keys were sent by a script on a terminal; the transcripts arefindings/tools/observed/session1.txtandsession2.txt. The slides quote session 2.
Read more
- aa-genprof(8)
- Reading a denial, Profiles for security-sensitive programs (the scene "Finding every operation: the log is not enough")
for AppArmor developers
Code
do_logprof_pass: aa.py:1501-1516; reading from the mark: logparser.py:397-430.
04 First question: the helper
An exec record becomes a choice of exec mode: In(h)erit writes ix, (P)rofile px, (C)hild cx, (N)amed an arrow rule, (U)nconfined ux, (D)eny a deny rule. Answering yes to secure execution capitalises the letter. Choosing a profile that does not exist creates it.
The first question is about the helper demo started. Each key is an exec mode. H, inherit, runs the helper under demo's own profile. P gives it a profile of its own. C makes a child profile inside demo's. The key U runs it unconfined, and the tool warns you twice. We press P. The tool asks whether to enable secure execution, we say yes, and the rule is written with a capital P. Since the helper has no profile yet, the tool creates one on the spot, in complain mode. From here on, the helper's log records turn into questions for that new profile, in this same scan.
Details and sources
Details
Keys of the exec question and what each writes into the profile of the program that ran the exec:
| Key | Rule written | Then |
|---|---|---|
| H, In(h)erit | /usr/bin/demo-helper ix, (with mr) | the helper's records are asked about under the caller's profile |
| P, (P)rofile | /usr/bin/demo-helper px,; Px after yes to secure execution | a profile for the helper is created in complain mode if none exists |
| C, (C)hild | cx or Cx | a child profile is created inside the caller's profile |
| N, (N)amed | asks "Are you specifying a transition to a local profile?" and "Enter profile name to transition to: "; writes px -> NAME or cx -> NAME | |
| U, (U)nconfined | after two warnings ux, or Ux | the helper's records are ignored |
| X, (X) ix On / Off | switches the list to the fallback modes pix, cix | |
| D, (D)eny | deny /usr/bin/demo-helper x, | the helper's records are ignored |
| I, (I)gnore | nothing | asked again at the next scan |
- The secure-execution question in full: "Should AppArmor enable secure-execution mode when switching profiles? Doing so is more secure, but some applications depend on the presence of LD_PRELOAD or LD_LIBRARY_PATH, which would be sanitized by enabling secure-execution mode." Its default is yes. See safe and unsafe exec.
- No key of the exec question is bracketed, so Return selects nothing and the question is shown again.
- Which keys appear depends on
[qualifiers]inlogprof.conf: for shells the list has no (P)rofile, for core utilities such ascatneither (P)rofile nor (U)nconfined. Severity:is a number fromseverity.dbfor the path withx, orunknown.- Session lines after P and Y:
Adding /usr/bin/demo-helper Px, to profile.andWriting updated profile for /usr/bin/demo-helper. - Known discrepancy: a child profile created with (C)hild stays in complain mode after Finish;
aa-logprof --allow-allanswers the secure-execution question with no and writes lowercasepx. - Observed on 2026-11-16: the tree's
utils/(aa-genprof, aa-logprof, aa-autodep and their Python package) and the tree'sprofiles/apparmor.dwere run in a disposable Debian forky/sid guest (kernel7.3.4+deb14-cloud-amd64;apparmor_parserand the Python binding of libapparmor 5.0.2 from Debian; auditd), as root. Keys were sent by a script on a terminal; the transcripts arefindings/tools/observed/session1.txtandsession2.txt. The slides quote session 2.
for AppArmor developers
Code
ask_exec: aa.py:740-1019; the key listbuild_x_functions: aa.py:622-661;[qualifiers]: logprof.conf:42-130.
05 Ten questions about demo
Every rule question lists offers and keys. The bracketed default was (D)eny for every question of the session, so Return writes a deny rule; A allows the selected offer. Offers are sorted by name with the first selected: a digit picks another one.
Then the rules. Each question shows what demo did and offers one or more rules. Watch the brackets. The preselected answer is deny, even here in complain mode, so return writes a deny rule. Press A to allow. For the priority change we do press D: demo doesn't need it. For the temp file, the first offer is the user-tmp abstraction, and that's fine. For the network connection, the first offer is an Apache abstraction, simply because offers are sorted by name. Press 3 to pick the exact rule, then A. We missed that on the second network question, and you'll see it in the result.
Details and sources
Details
- The ten rule questions for
demoin the session, in order:capability sys_nice(answered D:deny capability sys_nice,),/tmp/demo.22t5Sb(A oninclude <abstractions/user-tmp>),/var/log/demo.log(O then A:/var/log/demo.log w,),/var/lib/demo/state.db(A),/usr/share/demo/words-1.txt(G then A:owner /usr/share/demo/* r,),/etc/passwd,/etc/nsswitch.conf,/etc/demo/demo.conf(A each), theconnectevent (3 then A), the socketcreateevent (A on the selected offer, the Apache abstraction). - The default. The code sets the default to Allow for complain-mode records and Deny for enforce-mode records. In the session every question under "Complain-mode changes:" showed
(A)llow / [(D)eny]. Known discrepancy: the comparison that should select Allow never matches. Do not press Return to accept. With anincludeoffer selected, Deny writes nothing: the tool prints "Denying via an include file isn't supported by the AppArmor tools" and asks again. - Offers: abstractions that have a rule covering the record, sorted by name, then the exact rule. For a file there can also be paths of existing rules and ready-made globs. The first offer is selected; a digit or the arrow keys select another.
abstractions/apache2-commonis offered for any inet or inet6 stream socket: it containsnetwork inet stream,. It also allows being traced, signals from Apache's profiles and everything inabstractions/nameservice.- The network question's headers in full:
Accesses: connect,Network Family: inet,Socket Type: stream,Local: ALL,Peer: {'ip': '127.0.0.1', 'port': 9}. The slide shows two of them on one line and wraps the long offer. - The key row is one line in the terminal; file questions add
(G)lob / Glob with (E)xtension / (N)ewand(O)wner permissions off. Each key is explained in aa-logprof. - Observed on 2026-11-16: the tree's
utils/(aa-genprof, aa-logprof, aa-autodep and their Python package) and the tree'sprofiles/apparmor.dwere run in a disposable Debian forky/sid guest (kernel7.3.4+deb14-cloud-amd64;apparmor_parserand the Python binding of libapparmor 5.0.2 from Debian; auditd), as root. Keys were sent by a script on a terminal; the transcripts arefindings/tools/observed/session1.txtandsession2.txt. The slides quote session 2.
Read more
- aa-logprof (the scenes "One question, taken apart" and "Where the suggestions go wrong"), Choosing abstractions, The capability rule, Network rules
for AppArmor developers
Code
ask_rule_questions: aa.py:1128-1292; the default: aa.py:1177-1182; the offers: aa.py:1150-1161.
06 Read what you answered
The saved profile holds exactly what was answered: an unrelated abstraction from one accepted offer, owner on files because the session ran as their owner, and exact paths. The file is written sorted, with the path as the profile name. Review it before relying on it.
S to save, and here's the file the tool wrote, rules sorted. Now read it like a reviewer. The Apache abstraction is in there: one careless A. It brings ptrace and signal rules demo has no use for, so delete that line. Most file rules say owner, because we ran demo as root on root's files, and the log showed the user and the file's owner matched. Run demo as another user and those rules stop matching. And the config directory got one exact path per file. None of this is wrong syntax. It's a first draft, and the tool doesn't judge it for you.
Details and sources
Details
The file as written after the first save (/etc/apparmor.d/usr.bin.demo on an installed system; the slide leaves out the first four lines and the blank lines):
# Last Modified: Mon Nov 16 12:26:18 2026 abi <abi/5.0>,
include <tunables/global>
/usr/bin/demo { include <abstractions/apache2-common> include <abstractions/base> include <abstractions/user-tmp>
deny capability sys_nice,
network (connect) inet stream peer=(ip=127.0.0.1 port=9),
/usr/bin/demo mr, /usr/bin/demo-helper Px, /var/log/demo.log w, owner /etc/demo/demo.conf r, owner /etc/nsswitch.conf r, owner /etc/passwd r, owner /usr/share/demo/* r, owner /var/lib/demo/state.db w,
}
flags=(complain)is gone from this listing because it was taken after Finish; during the session the profile carries it.include <abstractions/apache2-common>came from accepting the selected offer of the socketcreatequestion. It grantsnetwork inet stream,andnetwork inet6 stream,,ptrace (readby)andptrace (tracedby), severalsignalrules andabstractions/nameservice. With it in place the exactnetwork (connect)rule is redundant.owner: the tool adds it when the record'sfsuidequals itsouid. Seen later in the same guest:demorun by an ordinary user under this profile was denied/etc/demo/demo.conf,/usr/share/demo/words-1.txtand/var/lib/demo/state.db(fsuid=1000 ouid=0)./etc/nsswitch.confand/etc/passwdgot their own rules.abstractions/nameservicecovers both, but it was not offered for them. Known discrepancy: the tools do not expand variables such as@{etc_ro}when they test whether an abstraction covers a path.deny capability sys_nice,is enforced silently:demoprintssetpriority: Permission deniedand nothing is logged.- New profile files are created with mode 0600. The profile for the helper was written the same way (
usr.bin.demo-helper). - Observed on 2026-11-16: the tree's
utils/(aa-genprof, aa-logprof, aa-autodep and their Python package) and the tree'sprofiles/apparmor.dwere run in a disposable Debian forky/sid guest (kernel7.3.4+deb14-cloud-amd64;apparmor_parserand the Python binding of libapparmor 5.0.2 from Debian; auditd), as root. Keys were sent by a script on a terminal; the transcripts arefindings/tools/observed/session1.txtandsession2.txt. The slides quote session 2.
Read more
for AppArmor developers
Code
- Writing the file:
serialize_profileandwrite_profile, aa.py:2210-2303; theownerdecision: file.py:477-479; the abstraction: apache2-common:7-24.
07 Finish, and what is still missing
(F)inish sets every profile the session created to enforce mode and reloads it. What was not exercised has no rule: observed, a run with a new option is denied /etc/demo/extra.conf. aa-logprof adds such rules later without starting over.
Run demo again, scan again. When a scan comes back with no questions, press F. The tool sets demo's profile, and the helper's, to enforce mode and reloads them. Now the profile is the limit. Demo run the way you ran it works. But start demo with an option you didn't try, and it's denied its extra config file. That code didn't run while the tool was watching. That's normal, and you don't start over. You run aa-logprof, which reads the same log and asks the same kind of question, for any profile, at any time. It has its own deck.
Details and sources
Details
- On Finish the tool sets each profile it created or put into complain mode back to enforce and reloads it with
apparmor_parser -r. Messages:Setting /usr/bin/demo to enforce mode.,Setting /usr/bin/demo-helper to enforce mode.,Reloaded AppArmor profiles in enforce mode., a paragraph inviting you to contribute the profile,Finished generating profile for /usr/bin/demo. - The kernel's list of profiles afterwards:
/usr/bin/demo (enforce),/usr/bin/demo-helper (enforce), and still/usr/bin/demo//null-/usr/bin/demo-helper (complain), the temporary profile from the first run. It is not used again and disappears when the profile is removed or the system restarts. - Under enforce,
demoas profiled:setpriority: Permission denied(thedeny capability sys_nice,answered with D; the program goes on),demo-helper: done,demo: done. The slide shows the last line only.demo extra:/etc/demo/extra.conf: Permission denied, withapparmor="DENIED" operation="open" class="file" profile="/usr/bin/demo" name="/etc/demo/extra.conf" comm="demo" requested_mask="r" denied_mask="r" fsuid=0 ouid=0. - A careful path to enforce for a service: keep the profile in complain mode for a while in real use (answer Finish, then
aa-complain), runaa-logprofuntil it asks nothing, thenaa-enforce. - Known discrepancy: child profiles created during the session are left in complain mode by Finish.
- Observed on 2026-11-16: the tree's
utils/(aa-genprof, aa-logprof, aa-autodep and their Python package) and the tree'sprofiles/apparmor.dwere run in a disposable Debian forky/sid guest (kernel7.3.4+deb14-cloud-amd64;apparmor_parserand the Python binding of libapparmor 5.0.2 from Debian; auditd), as root. Keys were sent by a script on a terminal; the transcripts arefindings/tools/observed/session1.txtandsession2.txt. The slides quote session 2.
Read more
- aa-logprof, Changing a profile's mode, Profiles for security-sensitive programs (the scene "From complain to enforce, the careful way")
- aa-enforce(8), aa-complain(8)
08 aa-autodep, scripts and programs the tools refuse
aa-autodep PROGRAM writes the starter profile and nothing more. For a script it allows the script with r, the interpreter with ix and adds the interpreter's abstraction. Programs marked in [qualifiers] of logprof.conf are refused. Observed.
Two smaller things. aa-autodep is the first step of aa-genprof on its own: it writes the starter profile in complain mode and stops. For a script, that profile allows reading the script and running its interpreter with ix, and it includes the interpreter's abstraction, as you see here for a shell script. And some programs are refused. The tool's config file lists shells and core utilities, like cat, as programs that shouldn't have their own profile, because confining them changes everything that calls them. Ask aa-genprof to profile cat and it stops with this message. For those, you write the rule in the caller's profile instead.
Details and sources
Details
aa-autodep [--force] [-d DIR] [--no-reload] program...writes the starter profile for each program that has none (--forceoverwrites) and loads it in complain mode.- For a script the first line decides: the interpreter after
#!getsix, the script itselfr. The abstraction isabstractions/bashwhen the interpreter issh,bashordash, andabstractions/perl,abstractions/pythonorabstractions/rubyfor those interpreters; any other interpreter gets none. - The profile written for
/usr/bin/demo-script(#!/bin/sh) in the session, complete:
# Last Modified: Mon Nov 16 12:18:54 2026 abi <abi/5.0>,
include <tunables/global>
/usr/bin/demo-script flags=(complain) { include <abstractions/base> include <abstractions/bash>
/usr/bin/dash ix, /usr/bin/demo-script r,
}
/bin/shwas resolved to/usr/bin/dash: the rule names the file the symlink leads to. See Symlinks.- With
ixthe interpreter runs under the script's profile, so the profile must allow everything the script does through it. - Refusal, in full: "/usr/bin/cat is currently marked as a program that should not have its own profile. Usually, programs are marked this way if creating a profile for them is likely to break the rest of the system. If you know what you're doing and are certain you want to create a profile for this program, edit the corresponding entry in the [qualifiers] section in /etc/apparmor/logprof.conf." Exit status 1. In the session the message was preceded by three lines of a Python stack.
- Marked programs include the shells (
bash,dash,ksh,zsh),mount, utilities such asawk,cat,chmod,cp,grep,ls,sed, and theperlandpythoninterpreters. A profile attached to/usr/bin/catwould apply to every unconfined use ofcat. - If a profile with the same name exists among the inactive profiles (
/usr/share/apparmor/extra-profiles), the tool offers to use it instead of the starter profile. Read from the tool's code, not run. - Observed on 2026-11-16: the tree's
utils/(aa-genprof, aa-logprof, aa-autodep and their Python package) and the tree'sprofiles/apparmor.dwere run in a disposable Debian forky/sid guest (kernel7.3.4+deb14-cloud-amd64;apparmor_parserand the Python binding of libapparmor 5.0.2 from Debian; auditd), as root. Keys were sent by a script on a terminal; the transcripts arefindings/tools/observed/session1.txtandsession2.txt. The slides quote session 2.
for AppArmor developers
Code
- aa-autodep: aa-autodep:24-34; interpreter detection
get_interpreter_and_abstraction: aa.py:347-383;check_qualifiers: aa.py:2501-2511; the list: logprof.conf:42-130.
09 Where to go from here
Next: ut-logprof, prac-general-purpose, prac-abstractions, syn-exec-modes, syn-owner, ut-modes, adm-denials.
That's a profile from nothing to enforce: a starter profile in complain mode, run, scan, answer, and finish. The tool writes down your answers, so the quality of the profile is the quality of the answers. Next, the aa-logprof deck takes one question apart, covers glob and owner, and lists where the suggestions go wrong. The deck on general-purpose apps helps you decide how broad a first profile may be, and the abstractions deck tells you which offers to accept. And the exec modes deck explains the letters behind that first question.
Details and sources
Details
aa-genprof PROGRAM: starter profile in complain mode, then run, (S)can, answer, save, repeat; (F)inish sets enforce mode.- The profile contains what was answered. Review the includes, the
ownerqualifiers and the width of the paths before relying on it.
What each deck answers:
- aa-logprof: the parts of a question, Glob, owner, saving,
logprof.conf, what goes wrong. - Profiles for general-purpose apps: how broad a first profile may be.
- Choosing abstractions: which include offers to accept.
- Exec modes and safe and unsafe exec: the exec question.
- The owner qualifier, Profile modes, Changing a profile's mode.
- Reading a denial, Profiles for security-sensitive programs.
Read more
Basis of the statements on this page: "observed" means the utilities of the AppArmor tree at 836052d21 (6.0.0~alpha2) were run on 2026-11-16 in a disposable Debian forky/sid guest (kernel 7.3.4+deb14-cloud-amd64, apparmor_parser and the libapparmor Python binding 5.0.2 from Debian, auditd), as root, with keys sent by a script; transcripts are in findings/tools/observed/. "Code" means read from the tree and not run.
Command lines
| Command | Does |
|---|---|
aa-genprof [-d DIR] [-f LOGFILE] [-j] [--no-abstraction] [-o OUTDIR] program | starter profile if needed, complain mode, the Scan and Finish loop, enforce mode at the end |
aa-autodep [--force] [-d DIR] [--no-reload] program... | writes the starter profile in complain mode |
| Option | Meaning |
|---|---|
-d DIR | profile directory instead of /etc/apparmor.d |
-f LOGFILE | log file to read |
-j | dialogs as JSON, for front ends |
--no-abstraction | do not offer or add abstractions |
-o OUTDIR | write changed profiles to this directory instead |
What aa-genprof does, in order
| Step | Message or effect | Basis |
|---|---|---|
| find the program | errors Can't find ... in the system path list or ... does not exists, please double-check the path. | code |
check [qualifiers] | "... is currently marked as a program that should not have its own profile." | observed |
| read all profiles | Updating AppArmor profiles in DIR. | observed |
| starter profile if none exists | Writing updated profile for PROGRAM. | observed |
| complain mode and reload | Setting PROGRAM to complain mode. | observed |
kernel.printk_ratelimit = 0 | warning Can't set printk_ratelimit, some events might be lost on failure | code |
| mark the log | time of the last audit record, or a GenProf: logmark-... line | code |
| prompt | [(S)can system log for AppArmor events] / (F)inish | observed |
| Scan | Reading log entries from FILE., exec questions, Complain-mode changes:, Enforce-mode changes:, save prompt | observed |
| Finish | Setting PROGRAM to enforce mode. for each profile of the session, Reloaded AppArmor profiles in enforce mode., Finished generating profile for PROGRAM. | observed |
The starter profile
| Program is | Rules |
|---|---|
| a binary | include <abstractions/base>, PROGRAM mr, |
a script with #! | include <abstractions/base>, the interpreter's abstraction (bash, perl, python, ruby) when known, SCRIPT r,, INTERPRETER ix, |
Always with flags=(complain); abi <abi/5.0>, and include <tunables/global> when those files exist in the profile directory. The profile is named by the program's path and stored as that path with slashes turned into dots.
The exec question
| Key | Rule | Notes |
|---|---|---|
| H | TARGET ix, | |
| P | TARGET px, or Px, | creates a profile for the target if none exists |
| C | TARGET cx, or Cx, | creates a child profile |
| N | px -> NAME or cx -> NAME | asks for the name |
| U | TARGET ux, or Ux, | two confirmations |
| X | toggles pix / cix forms | |
| D | deny TARGET x, | |
| I | nothing | asked again later |
| R, F | abort, finish |
Capital letters result from answering yes to the secure-execution question. The letters offered for a target come from [qualifiers] in logprof.conf.
The session, question by question
| Question | Key | Rule written |
|---|---|---|
Execute /usr/bin/demo-helper | P, Y | /usr/bin/demo-helper Px, and a new profile |
capability sys_nice | D | deny capability sys_nice, |
/tmp/demo.22t5Sb owner rw | A | include <abstractions/user-tmp> |
/var/log/demo.log owner w | O, A | /var/log/demo.log w, |
/var/lib/demo/state.db owner w | A | owner /var/lib/demo/state.db w, |
/usr/share/demo/words-1.txt owner r | G, A | owner /usr/share/demo/* r, |
/etc/passwd, /etc/nsswitch.conf, /etc/demo/demo.conf owner r | A | one owner ... r, rule each |
| network connect inet stream | 3, A | network (connect) inet stream peer=(ip=127.0.0.1 port=9), |
| network create inet stream | A | include <abstractions/apache2-common> (the selected offer) |
helper: /var/lib/demo/helper.out, /etc/demo/helper.conf, /etc/ld.so.cache | A | one owner rule each in the helper's profile |
| Changed Local Profiles | S | both files written and reloaded |
Known discrepancies seen in the session
- The bracketed default of every rule question is Deny, also for complain-mode records.
abstractions/apache2-commonis the first offer for any inet stream socket./etc/ld.so.cacheis proposed althoughabstractions/basecovers it, andabstractions/nameserviceis not offered for/etc/nsswitch.conf: the tools do not expand variables in abstraction rules.- The refusal for a marked program prints lines of a Python stack before its message.
Roads from here
FILE ACCESS
- Exec modes — the modes behind the exec question
- safe and unsafe exec — the secure-execution question
PROFILE HEAD
- Profile mode flags — complain and enforce mode
QUALIFIERS
- The owner qualifier — the owner qualifier the tool adds
IN PRACTICE · general-purpose apps
- Profiles for general-purpose apps — how broad a first profile should be
- Choosing abstractions — which abstraction offers to accept
IN PRACTICE · security-sensitive programs
- Profiles for security-sensitive programs — when a tool-made draft is not enough
RUNNING THE PARSER
- Reading a denial — the log records the tool reads
TOOLS · utils/
- aa-logprof — every part of a question and what goes wrong
- Switching profile modes (no slides yet) — aa-complain and aa-enforce on their own