-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathapparmor_profiles_man.xml
More file actions
2028 lines (1993 loc) · 76.1 KB
/
apparmor_profiles_man.xml
File metadata and controls
2028 lines (1993 loc) · 76.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0"?>
<!DOCTYPE chapter [
<!ENTITY % entities SYSTEM "generic-entities.ent">
%entities;
]>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:its="http://www.w3.org/2005/11/its" version="5.0" role="General" xml:id="cha-apparmor-commandline">
<title>Building profiles from the command line</title>
<info>
<meta name="description" its:translate="yes">Manage system security with AppArmor by configuring and monitoring its profiles using command-line tools</meta>
<dm:docmanager xmlns:dm="urn:x-suse:ns:docmanager">
<dm:bugtracker>
</dm:bugtracker>
<dm:translation>yes</dm:translation>
</dm:docmanager>
<revhistory xml:id="rh-cha-apparmor-commandline">
<revision>
<date>2026-04-07</date>
<revdescription>
<para/>
</revdescription>
</revision>
</revhistory>
</info>
<para>
&aareg; provides the user the ability to use a command line interface
rather than a graphical interface to manage and configure the system
security. Track the status of &aa; and create, delete or modify
&aa; profiles using the &aa; command line tools.
</para>
<tip>
<title>Background information</title>
<para>
Before starting to manage your profiles using the &aa; command line
tools, check out the general introduction to &aa; given in
<xref linkend="cha-apparmor-concept"/> and
<xref linkend="cha-apparmor-profiles"/>.
</para>
</tip>
<sect1 xml:id="sec-apparmor-commandline-status">
<title>Checking the &aa; status</title>
<para>
&aa; can be in any one of three states:
</para>
<variablelist>
<varlistentry>
<term>Unloaded</term>
<listitem>
<para>
&aa; is not activated in the kernel.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Running</term>
<listitem>
<para>
&aa; is activated in the kernel and is enforcing &aa; program
policies.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Stopped</term>
<listitem>
<para>
&aa; is activated in the kernel, but no policies are enforced.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
Detect the state of &aa; by inspecting
<filename>/sys/kernel/security/apparmor/profiles</filename>. If
<command>cat /sys/kernel/security/apparmor/profiles</command> reports a
list of profiles, &aa; is running. If it is empty and returns nothing,
&aa; is stopped. If the file does not exist, &aa; is unloaded.
</para>
<para>
Manage &aa; with <command>systemctl</command>. It lets you perform the
following operations:
</para>
<variablelist>
<varlistentry>
<term><command>sudo systemctl start apparmor</command>
</term>
<listitem>
<para>
Behavior depends on the state of &aa;. If it is not activated,
<option>start</option> activates and starts it, putting it in the
running state. If it is stopped, <option>start</option> causes the
re-scan of &aa; profiles found in
<filename>/etc/apparmor.d</filename> and puts &aa; in the running
state. If &aa; is already running, <option>start</option> reports a
warning and takes no action.
</para>
<note>
<title>Already running processes</title>
<para>
Already running processes need to be restarted to apply the &aa;
profiles on them.
</para>
</note>
</listitem>
</varlistentry>
<varlistentry>
<term><command>sudo systemctl stop apparmor</command>
</term>
<listitem>
<para>
Stops &aa; if it is running by removing all profiles from kernel
memory, effectively disabling all access controls, and putting &aa;
into the stopped state. If the &aa; is already stopped,
<option>stop</option> tries to unload the profiles again, but nothing
happens.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>sudo systemctl reload apparmor</command>
</term>
<listitem>
<para>
Causes the &aa; module to re-scan the profiles in
<filename>/etc/apparmor.d</filename> without unconfining running
<remark>sknorr, 2014-08-26: "unconfining?" Sounds terrible. Would
"freeing" be an option?
tbazant, 2014-09-08: No, it's a used term, related to 'unconfined' state
</remark>
processes. Freshly created profiles are enforced and recently deleted
ones are removed from the <filename>/etc/apparmor.d</filename>
directory.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect1>
<sect1 xml:id="sec-apparmor-commandline-build">
<title>Building &aa; profiles</title>
<para>
The &aa; module profile definitions are stored in the
<filename>/etc/apparmor.d</filename> directory as plain text files. For a
detailed description of the syntax of these files, refer to
<xref linkend="cha-apparmor-profiles"/>.
</para>
<para>
All files in the <filename>/etc/apparmor.d</filename> directory are
interpreted as profiles and are loaded as such. Renaming files in that
directory is not an effective way of preventing profiles from being
loaded. You must remove profiles from this directory to prevent them from
being read and evaluated effectively, or call
<command>aa-disable</command> on the profile, which creates a
symbolic link in <filename>/etc/apparmor.d/disabled/</filename>.
</para>
<para>
You can use a text editor, such as <command>vi</command>, to access and
make changes to these profiles. The following sections contain detailed
steps for building profiles:
</para>
<variablelist>
<varlistentry>
<term>Adding or creating &aa; profiles</term>
<listitem>
<para>
Refer to <xref linkend="sec-apparmor-commandline-add"/>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Editing &aa; profiles</term>
<listitem>
<para>
Refer to <xref linkend="sec-apparmor-commandline-edit"/>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Deleting &aa; profiles</term>
<listitem>
<para>
Refer to
<xref linkend="sec-apparmor-commandline-del"/>
</para>
</listitem>
</varlistentry>
</variablelist>
<!-- Code 10 doesn't have apparmor.vim. Maybe next release ...
<para>
Use vim to view and edit your profile by typing <command>vim</command> in a
terminal window. To enable syntax highlighting when you edit an &aa;
profile in
vim, use the commands <command>:syntax on</command> then <command>:set
syntax=apparmor</command>. For more information about vim and syntax
coloring, refer to <xref
linkend="sec-apparmor-commandline-profiling-summary-vim"/>.
</para>
-->
</sect1>
<sect1 xml:id="sec-apparmor-commandline-add">
<title>Adding or creating an &aa; profile</title>
<para>
To add or create an &aa; profile for an application, you can use a
systemic or stand-alone profiling method, depending on your needs. Learn
more about these two approaches in
<xref linkend="sec-apparmor-commandline-profiling"/>.
</para>
</sect1>
<sect1 xml:id="sec-apparmor-commandline-edit">
<title>Editing an &aa; profile</title>
<para>
The following steps describe the procedure for editing an &aa;
profile:
</para>
<procedure>
<step>
<para>
If you are not currently logged in as &rootuser;, enter
<command>su</command> in a terminal window.
</para>
</step>
<step>
<para>
Enter the &rootuser; password when prompted.
</para>
</step>
<step>
<para>
Go to the profile directory with <command>cd
/etc/apparmor.d/</command>.
</para>
</step>
<step>
<para>
Enter <command>ls</command> to view all profiles currently installed.
</para>
</step>
<step>
<para>
Open the profile to edit in a text editor, such as vim.
</para>
</step>
<step>
<para>
Make the necessary changes, then save the profile.
</para>
</step>
<step>
<para>
Restart &aa; by entering <command>systemctl reload
apparmor</command> in a terminal window.
</para>
</step>
</procedure>
</sect1>
<sect1 xml:id="sec-apparmor-commandline-unload">
<title>Unloading unknown &aa; profiles</title>
<warning>
<title>Danger of unloading wanted profiles</title>
<para>
<command>aa-remove-unknown</command> unloads all profiles that
are not stored in <filename>/etc/apparmor.d</filename>, for example
automatically generated LXD profiles. This may compromise the
security of the system. Use the <option>-n</option> parameter to
list all profiles that are unloaded.
</para>
</warning>
<para>
To unload all &aa; profiles that are no longer in
<filename>/etc/apparmor.d/</filename>, run:
</para>
<screen>&prompt.sudo;<command>aa-remove-unknown</command></screen>
<para>
You can print a list of profiles that are removed:
</para>
<screen>&prompt.sudo;<command>aa-remove-unknown -n</command></screen>
</sect1>
<sect1 xml:id="sec-apparmor-commandline-del">
<title>Deleting an &aa; profile</title>
<para>
The following steps describe the procedure for deleting an &aa;
profile.
</para>
<procedure>
<step>
<para>
Remove the &aa; definition from the kernel:
</para>
<screen>&prompt.sudo;<command>apparmor_parser -R /etc/apparmor.d/<replaceable>PROFILE</replaceable></command></screen>
</step>
<step>
<para>
Remove the definition file:
</para>
<screen>&prompt.sudo;<command>rm /etc/apparmor.d/<replaceable>PROFILE</replaceable></command>
&prompt.sudo;<command>rm /var/lib/apparmor/cache/<replaceable>PROFILE</replaceable></command></screen>
</step>
</procedure>
</sect1>
<sect1 xml:id="sec-apparmor-commandline-profiling">
<title>Two methods of profiling</title>
<para>
Given the syntax for &aa; profiles in
<xref linkend="cha-apparmor-profiles"/>, you
could create profiles without using the tools. However, the effort
involved would be substantial. To avoid such a situation, use the &aa;
tools to automate the creation and refinement of profiles.
</para>
<para>
There are two ways to approach &aa; profile creation. Tools are
available for both methods.
</para>
<variablelist>
<varlistentry>
<term>Stand-alone profiling</term>
<listitem>
<para>
A method suitable for profiling small applications that have a finite
runtime, such as user client applications like mail clients. For more
information, refer to
<xref linkend="sec-apparmor-commandline-profiling-stand-alone"/>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Systemic profiling</term>
<listitem>
<para>
A method suitable for profiling many programs at once
and for profiling applications that may run for days, weeks or
continuously across reboots, such as network server applications like
Web servers and mail servers. For more information, refer to
<xref linkend="sec-apparmor-commandline-profiling-systemic"/>.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
Automated profile development becomes more manageable with the &aa;
tools:
</para>
<procedure>
<step>
<para>
Decide which profiling method suits your needs.
</para>
</step>
<step>
<para>
Perform a static analysis. Run either <command>aa-genprof</command> or
<command>aa-autodep</command>, depending on the profiling method
chosen.
</para>
</step>
<step>
<para>
Enable dynamic learning. Activate learning mode for all profiled
programs.
</para>
</step>
</procedure>
<sect2 xml:id="sec-apparmor-commandline-profiling-stand-alone">
<title>Stand-alone profiling</title>
<para>
Stand-alone profile generation and improvement is managed by a program
called <command>aa-genprof</command>. This method is easy because
<command>aa-genprof</command> takes care of everything, but is limited
because it requires <command>aa-genprof</command> to run for the entire
duration of the test run of your program (you cannot reboot the machine
while you are still developing your profile).
</para>
<para>
To use <command>aa-genprof</command> for the stand-alone method of
profiling, refer to
<xref linkend="sec-apparmor-commandline-profiling-summary-genprof"/>.
</para>
</sect2>
<sect2 xml:id="sec-apparmor-commandline-profiling-systemic">
<title>Systemic profiling</title>
<para>
This method is called <emphasis>systemic profiling</emphasis> because it
updates all the profiles on the system at once, rather than focusing
on the one or few targeted by <command>aa-genprof</command> or
stand-alone profiling. With systemic profiling, profile construction and
improvement are less automated, but more flexible. This method
is suitable for profiling long-running applications whose behavior
continues after rebooting, or many programs at once.
</para>
<para>
Build an &aa; profile for a group of applications as follows:
</para>
<procedure>
<step>
<para>
Create profiles for the individual programs that make up your
application.
</para>
<para>
Although this approach is systemic, &aa; only monitors those
programs with profiles and their children. To get &aa; to consider
a program, you must at least have <command>aa-autodep</command> create
an approximate profile for it. To create this approximate profile,
refer to
<xref linkend="sec-apparmor-commandline-profiling-summary-autodep"/>.
</para>
</step>
<step>
<para>
Put relevant profiles into learning or complain mode.
</para>
<para>
Activate learning or complain mode for all profiled programs by
entering
</para>
<screen>&prompt.sudo;aa-complain /etc/apparmor.d/*</screen>
<para>
in a terminal window while logged in as &rootuser;. This
functionality is also available through the &yast; Profile Mode
module, described in
<xref linkend="sec-apparmor-yast-manage-profmodes"/>.
</para>
<para>
When in learning mode, access requests are not blocked, even if the
profile dictates that they should be. This enables you to run through
several tests (as shown in
<xref linkend="st-apparmor-commandline-profiling-systemic-exec"/>) and
learn the access needs of the program so it runs properly. With this
information, you can decide how secure to make the profile.
</para>
<para>
Refer to
<xref linkend="sec-apparmor-commandline-profiling-summary-complain"/>
for more detailed instructions for using learning or complain mode.
</para>
</step>
<step xml:id="st-apparmor-commandline-profiling-systemic-exec">
<para>
Exercise your application.
</para>
<para>
Run your application and exercise its functionality. How much to
exercise the program is up to you, but you need the program to access
each file representing its access needs. Because the execution is not
being supervised by <command>aa-genprof</command>, this step can go on
for days or weeks and can span complete system reboots.
</para>
</step>
<step xml:id="st-apparmor-commandline-profiling-systemic-log">
<para>
Analyze the log.
</para>
<para>
In systemic profiling, run <command>aa-logprof</command> directly
instead of letting <command>aa-genprof</command> run it (as in
stand-alone profiling). The general form of
<command>aa-logprof</command> is:
</para>
<screen>&prompt.sudo;aa-logprof [ -d <replaceable>/path/to/profiles</replaceable> ] [ -f <replaceable>/path/to/logfile</replaceable> ]</screen>
<para>
Refer to
<xref linkend="sec-apparmor-commandline-profiling-summary-logprof"/>
for more information about using <command>aa-logprof</command>.
</para>
</step>
<step>
<para>
Repeat
<xref linkend="st-apparmor-commandline-profiling-systemic-exec"/> and
<xref linkend="st-apparmor-commandline-profiling-systemic-log"/>.
</para>
<para>
This generates optimal profiles. An iterative approach captures
smaller data sets that can be trained and reloaded into the policy
engine. Subsequent iterations generate fewer messages and run faster.
</para>
</step>
<step>
<para>
Edit the profiles.
</para>
<para>
You should review the profiles that have been generated. You
can open and edit the profiles in
<filename>/etc/apparmor.d/</filename> using a text editor.
</para>
</step>
<step>
<para>
Return to enforce mode.
</para>
<para>
This is when the system goes back to enforcing the rules of the
profiles, not only logging information. This can be done manually by
removing the <literal>flags=(complain)</literal> text from the
<!-- could also be a symbolic link in /etc/apparmor.d/force-complain/ -->
profiles or automatically by using the <command>aa-enforce</command>
command, which works identically to the <command>aa-complain</command>
command, except it sets the profiles to enforce mode. This
functionality is also available through the &yast; Profile Mode
module, described in
<xref linkend="sec-apparmor-yast-manage-profmodes"/>.
</para>
<para>
To ensure that all profiles are taken out of complain mode and put
into enforce mode, enter <command>aa-enforce
/etc/apparmor.d/*</command>.
</para>
</step>
<step>
<para>
Re-scan all profiles.
</para>
<para>
To have &aa; re-scan all the profiles and change the enforcement
mode in the kernel, enter <command>systemctl reload
apparmor</command>.
</para>
</step>
</procedure>
</sect2>
<sect2 xml:id="sec-apparmor-commandline-profiling-summary">
<title>Summary of profiling tools</title>
<para>
All of the &aa; profiling utilities are provided by the
<systemitem>apparmor-utils</systemitem> RPM package and are stored in
<filename>/usr/sbin</filename>. Each tool has a different purpose.
</para>
<sect3 xml:id="sec-apparmor-commandline-profiling-summary-autodep">
<title>aa-autodep—creating approximate profiles</title>
<para>
This creates an approximate profile for the program or application
selected. You can generate approximate profiles for binary executables
and interpreted script programs. The resulting profile is called
<quote>approximate</quote> because it does not necessarily contain all
of the profile entries that the program needs to be properly confined
by &aa;. The minimum <command>aa-autodep</command> approximate
profile has, at minimum, a base include directive, which contains basic
profile entries needed by most programs. For certain types of programs,
<command>aa-autodep</command> generates a more expanded profile. The
profile is generated by recursively calling <command>ldd(1)</command>
on the executables listed on the command line.
</para>
<para>
To generate an approximate profile, use the
<command>aa-autodep</command> program. The program argument can be
either the simple name of the program, which
<command>aa-autodep</command> finds by searching your shell's path
variable, or it can be a fully qualified path. The program itself can
be of any type (ELF binary, shell script, Perl script, etc.).
<command>aa-autodep</command> generates an approximate profile to
improve through the dynamic profiling that follows.
</para>
<para>
The resulting approximate profile is written to the
<filename>/etc/apparmor.d</filename> directory using the &aa;
profile naming convention of naming the profile after the absolute path
of the program, replacing the forward slash (<literal>/</literal>)
characters in the path with period (<literal>.</literal>) characters.
The general syntax of <command>aa-autodep</command> is to enter the
following in a terminal window:
</para>
<screen>&prompt.sudo;aa-autodep [ -d <replaceable>/PATH/TO/PROFILES</replaceable> ] [<replaceable>PROGRAM1</replaceable> <replaceable>PROGRAM2</replaceable>...]</screen>
<para>
If you do not enter the program name or names, you are prompted for
them. <replaceable>/path/to/profiles</replaceable> overrides the
default location of <filename>/etc/apparmor.d</filename>, should you
keep profiles in a location other than the default.
</para>
<para>
To begin profiling, you must create profiles for each main executable
service that is part of your application (anything that might start
without being a child of another program that already has a profile).
Finding all such programs depends on the application in question. Here
are several strategies for finding such programs:
</para>
<variablelist>
<varlistentry>
<term>Directories</term>
<listitem>
<para>
If all the programs to profile are in one directory and there are no
other programs in that directory, the simple command
<command>aa-autodep</command>
<replaceable>/path/to/your/programs/*</replaceable> creates basic
profiles for all programs in that directory.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>pstree -p</term>
<listitem>
<para>
You can run your application and use the standard Linux
<command>pstree</command> command to find all processes running.
Then manually hunt down the location of these programs and run the
<command>aa-autodep</command> for each one. If the programs are in
your path, <command>aa-autodep</command> finds them for you. If they
are not in your path, the standard Linux command
<command>find</command> might be helpful in finding your programs.
Execute <command>find / -name '</command>
<replaceable>MY_APPLICATION</replaceable>' -print to determine an
application's path (<replaceable>MY_APPLICATION</replaceable> being
an example application). You may use wild cards if appropriate.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect3>
<sect3 xml:id="sec-apparmor-commandline-profiling-summary-complain">
<title>aa-complain—entering complain or learning mode</title>
<para>
The complain or learning mode tool (<command>aa-complain</command>)
detects violations of &aa; profile rules, such as the profiled
program accessing files not permitted by the profile. The violations
are permitted, but also logged. To improve the profile, turn complain
mode on, run the program through a suite of tests to generate log
events that characterize the program's access needs, then postprocess
the log with the &aa; tools to transform log events into improved
profiles.
</para>
<para>
Manually activating complain mode (using the command line) adds a flag
to the top of the profile so that <literal>/bin/foo</literal> becomes
<literal>/bin/foo flags=(complain)</literal>. To use complain mode,
<!-- or create a symbolic link in force-complain -->
open a terminal window and enter one of the following lines as
&rootuser;:
</para>
<itemizedlist mark="bullet" spacing="normal">
<listitem>
<para>
If the example program (<replaceable>PROGRAM1</replaceable>) is in
your path, use:
</para>
<screen>&prompt.sudo;aa-complain [<replaceable>PROGRAM1</replaceable> <replaceable>PROGRAM2</replaceable> ...]</screen>
</listitem>
<listitem>
<para>
If the program is not in your path, specify the entire path as
follows:
</para>
<screen>&prompt.sudo;aa-complain /sbin/<replaceable>PROGRAM1</replaceable></screen>
</listitem>
<listitem>
<para>
If the profiles are not in <filename>/etc/apparmor.d</filename>, use
the following to override the default location:
</para>
<screen>&prompt.sudo;aa-complain <replaceable>/path/to/profiles/</replaceable><replaceable>PROGRAM1</replaceable></screen>
</listitem>
<listitem>
<para>
Specify the profile for <replaceable>/sbin/program1</replaceable> as
follows:
</para>
<screen>&prompt.sudo;aa-complain /etc/apparmor.d/sbin.<replaceable>PROGRAM1</replaceable></screen>
</listitem>
</itemizedlist>
<para>
Each of the above commands activates the complain mode for the profiles
or programs listed. If the program name does not include its entire
path, <command>aa-complain</command> searches <envar>$PATH</envar> for
the program. For example, <command>aa-complain /usr/sbin/*</command>
finds profiles associated with all the programs in
<filename>/usr/sbin</filename> and puts them into complain mode.
<command>aa-complain /etc/apparmor.d/*</command> puts all the
profiles in <filename>/etc/apparmor.d</filename> into complain mode.
</para>
<tip>
<title>Toggling profile mode with &yast;</title>
<para>
&yast; offers a graphical front-end for toggling complain and
enforce mode. See <xref linkend="sec-apparmor-yast-manage-profmodes"/>
for information.
</para>
</tip>
</sect3>
<sect3 xml:id="sec-apparmor-commandline-profiling-summary-decode">
<title>aa-decode—decoding hex-encoded strings in &aa; log files</title>
<para>
<command>aa-decode</command> decodes hex-encoded strings in the
&aa; log output. It can also process the audit log on standard
input, convert any hex-encoded &aa; log entries, and display them on
standard output.
</para>
</sect3>
<sect3 xml:id="sec-apparmor-commandline-profiling-summary-disable">
<title>aa-disable—disabling an &aa; security profile</title>
<para>
Use <command>aa-disable</command> to disable the enforcement mode for
one or more &aa; profiles. This command unloads the profile from
the kernel and prevents the profile from being loaded on &aa;
start-up. Use <command>aa-enforce</command> or
<command>aa-complain</command> utilities to change this behavior.
</para>
</sect3>
<sect3 xml:id="sec-apparmor-commandline-profiling-summary-easyprof">
<title>aa-easyprof—easy profile generation</title>
<para>
<command>aa-easyprof</command> provides an easy-to-use interface for
&aa; profile generation. <command>aa-easyprof</command> supports the
use of templates and profile groups to quickly profile an application.
While <command>aa-easyprof</command> can help with profile generation,
its utility is dependent on the quality of the templates, profile
groups and abstractions used. Also, this tool may create a profile that
is less restricted than when creating a profile manually or with
<command>aa-genprof</command> and <command>aa-logprof</command>.
</para>
<para>
For more information, see the man page of
<command>aa-easyprof</command> (8).
</para>
</sect3>
<sect3 xml:id="sec-apparmor-commandline-profiling-summary-enforce">
<title>aa-enforce—entering enforce mode</title>
<para>
The enforce mode detects violations of &aa; profile rules, such as
the profiled program accessing files not permitted by the profile. The
violations are logged and not permitted. The default is for enforce
mode to be enabled. To log the violations only, but still permit them,
use complain mode.
</para>
<para>
Manually activating enforce mode (using the command line) removes the
complain flag from the top of the profile so that <literal>/bin/foo
flags=(complain)</literal> becomes <literal>/bin/foo</literal>. To use
enforce mode, open a terminal window and enter one of the following
lines.
</para>
<itemizedlist mark="bullet" spacing="normal">
<listitem>
<para>
If the example program (<replaceable>PROGRAM1</replaceable>) is in
your path, use:
</para>
<screen>&prompt.sudo;aa-enforce [<replaceable>PROGRAM1</replaceable> <replaceable>PROGRAM2</replaceable> ...]</screen>
</listitem>
<listitem>
<para>
If the program is not in your path, specify the entire path, as
follows:
</para>
<screen>&prompt.sudo;aa-enforce /sbin/<replaceable>PROGRAM1</replaceable></screen>
</listitem>
<listitem>
<para>
If the profiles are not in
<replaceable>/etc/apparmor.d</replaceable>, use the following to
override the default location:
</para>
<screen>&prompt.sudo;aa-enforce -d <replaceable>/path/to/profiles/ program1</replaceable></screen>
</listitem>
<listitem>
<para>
Specify the profile for <replaceable>/sbin/program1</replaceable> as
follows:
</para>
<screen>&prompt.sudo;aa-enforce /etc/apparmor.d/sbin.<replaceable>PROGRAM1</replaceable></screen>
</listitem>
</itemizedlist>
<para>
Each of the above commands activates the enforce mode for the profiles
and programs listed.
</para>
<para>
If you do not enter the program or profile names, you are prompted to
enter one. <replaceable>/path/to/profiles</replaceable> overrides the
default location of <filename>/etc/apparmor.d</filename>.
</para>
<para>
The argument can be either a list of programs or a list of profiles. If
the program name does not include its entire path,
<command>aa-enforce</command> searches <envar>$PATH</envar> for the
program.
</para>
<tip>
<title>Toggling profile mode with &yast;</title>
<para>
&yast; offers a graphical front-end for toggling complain and
enforce mode. See <xref linkend="sec-apparmor-yast-manage-profmodes"/>
for information.
</para>
</tip>
</sect3>
<sect3 xml:id="sec-apparmor-commandline-profiling-summary-exec">
<title>aa-exec—confining a program with the specified profile</title>
<para>
Use <command>aa-exec</command> to launch a program confined by a
specified profile and/or profile namespace. If both a profile and
namespace are specified, the program is confined by the profile in
the new namespace. If only a profile namespace is specified, the
profile name of the current confinement is used. If neither a
profile nor namespace is specified, the command runs using the
standard profile attachment—as if you did not use the
<command>aa-exec</command> command.
</para>
<para>
For more information on the command's options, see its manual page
<command>man 8 aa-exec</command>.
</para>
</sect3>
<sect3 xml:id="sec-apparmor-commandline-profiling-summary-genprof">
<title>aa-genprof—generating profiles</title>
<para>
<command>aa-genprof</command> is &aa;'s profile generating utility.
It runs <command>aa-autodep</command> on the specified program,
creating an approximate profile (if a profile does not already exist
for it), sets it to complain mode, reloads it into &aa;, marks the
log, and prompts the user to execute the program and exercise its
functionality. Its syntax is as follows:
</para>
<screen>&prompt.sudo;aa-genprof [ -d <replaceable>/path/to/profiles</replaceable> ] <replaceable>PROGRAM</replaceable></screen>
<para>
To create a profile for the Apache Web server program httpd2-prefork,
do the following as &rootuser;:
</para>
<procedure>
<step>
<para>
Enter <command>systemctl stop apache2</command>.
</para>
</step>
<step>
<para>
Next, enter <command>aa-genprof httpd2-prefork</command>.
</para>
<para>
Now <command>aa-genprof</command> does the following:
</para>
<orderedlist spacing="normal">
<listitem>
<para>
Resolves the full path of httpd2-prefork using your shell's path
variables. You can also specify a full path. On &productname;,
the default full path is
<phrase><filename>/usr/sbin/httpd2-prefork</filename></phrase>.
</para>
</listitem>
<listitem>
<para>
Checks to see if there is an existing profile for httpd2-prefork.
If there is one, it updates it. If not, it creates one using the
<command>aa-autodep</command> as described in
<xref linkend="sec-apparmor-commandline-profiling-summary"/>.
</para>
</listitem>
<listitem>
<para>
Puts the profile for this program into learning or complain mode so
that profile violations are logged, but are permitted to proceed. A
log event looks like this (see
<filename>/var/log/audit/audit.log</filename>):
</para>
<screen>type=APPARMOR_ALLOWED msg=audit(1189682639.184:20816): \
apparmor="DENIED" operation="file_mmap" parent=2692 \
profile="/usr/sbin/httpd2-prefork//HANDLING_UNTRUSTED_INPUT" \
name="/var/log/apache2/access_log-20140116" pid=28730 comm="httpd2-prefork" \
requested_mask="::r" denied_mask="::r" fsuid=30 ouid=0</screen>
<para>
If you are not running the audit daemon, the &aa; events are
logged directly to &systemd; journal (see
<xref linkend="cha-journalctl"/>):
</para>
<screen>Sep 13 13:20:30 K23 kernel: audit(1189682430.672:20810): \
apparmor="DENIED" operation="file_mmap" parent=2692 \
profile="/usr/sbin/httpd2-prefork//HANDLING_UNTRUSTED_INPUT" \
name="/var/log/apache2/access_log-20140116" pid=28730 comm="httpd2-prefork" \
requested_mask="::r" denied_mask="::r" fsuid=30 ouid=0</screen>
<para>
They also can be viewed using the <command>dmesg</command> command:
</para>
<screen>audit(1189682430.672:20810): apparmor="DENIED" \
operation="file_mmap" parent=2692 \
profile="/usr/sbin/httpd2-prefork//HANDLING_UNTRUSTED_INPUT" \
name="/var/log/apache2/access_log-20140116" pid=28730 comm="httpd2-prefork" \
requested_mask="::r" denied_mask="::r" fsuid=30 ouid=0</screen>
</listitem>
<listitem>
<para>
Marks the log with a beginning marker of log events to consider.
For example:
</para>
<screen>
Sep 13 17:48:52 figwit root: GenProf: e2ff78636296f16d0b5301209a04430d</screen>
</listitem>
</orderedlist>
</step>
<step>
<para>
When prompted by the tool, run the application to profile in another
terminal window and perform as many of the application functions as
possible. Thus, the learning mode can log the files and directories
to which the program requires access to function properly.
For example, in a new terminal window, enter <command>systemctl start
apache2</command>.
</para>
</step>
<step>
<para>
Select from the following options that are available in the
<command>aa-genprof</command> terminal window after you have executed
the program function:
</para>
<itemizedlist mark="bullet" spacing="normal">
<listitem>
<para>
<keycap>S</keycap> runs <command>aa-genprof</command> on the system
log from where it was marked when <command>aa-genprof</command> was
started and reloads the profile. If system events exist in the log,
&aa; parses the learning mode log files. This generates a series
of questions that you must answer to guide
<command>aa-genprof</command> in generating the security profile.
</para>
</listitem>
<listitem>
<para>
<keycap>F</keycap> exits the tool.
</para>
</listitem>
</itemizedlist>
<note>
<para>
If requests to add hats appear, proceed to
<xref linkend="cha-apparmor-hat"/>.
</para>
</note>
</step>
<step>
<para>
Answer two types of questions:
</para>
<itemizedlist mark="bullet" spacing="normal">
<listitem>
<para>
A resource is requested by a profiled program that is not in the
profile (see
<xref linkend="ex-apparmor-commandline-profiling-summary-genprof-learn"/>).
</para>
</listitem>
<listitem>
<para>
A program is executed by the profiled program and the security
domain transition has not been defined (see
<xref linkend="ex-apparmor-commandline-profiling-summary-genprof-perms"/>).
</para>
</listitem>
</itemizedlist>
<para>
Each of these categories results in a series of questions that you
must answer to add the resource or program to the profile.
<xref linkend="ex-apparmor-commandline-profiling-summary-genprof-learn"/>
and
<xref linkend="ex-apparmor-commandline-profiling-summary-genprof-perms"/>
provide examples of each one. Subsequent steps describe your options
in answering these questions.
</para>
<itemizedlist mark="bullet" spacing="normal">
<listitem>
<para>
Dealing with execute accesses is complex. You must decide how to
proceed with this entry regarding which execute permission type to
grant to this entry:
</para>
<example xml:id="ex-apparmor-commandline-profiling-summary-genprof-learn">
<title>Learning mode exception: controlling access to specific resources</title>
<screen>Reading log entries from /var/log/audit/audit.log.
Updating AppArmor profiles in /etc/apparmor.d.
Profile: /usr/sbin/cupsd
Program: cupsd
Execute: /usr/lib/cups/daemon/cups-lpd
Severity: unknown
(I)nherit / (P)rofile / (C)hild / (N)ame / (U)nconfined / (X)ix / (D)eny / Abo(r)t / (F)inish</screen>
</example>
<variablelist>
<varlistentry>
<term>Inherit (ix)</term>
<listitem>
<para>
The child inherits the parent's profile, running with the same