<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.itcollege.ee/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mteivens</id>
	<title>ICO wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.itcollege.ee/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mteivens"/>
	<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php/Special:Contributions/Mteivens"/>
	<updated>2026-05-10T02:12:45Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120540</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120540"/>
		<updated>2017-04-28T19:37:49Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
=== Example log record in complain mode ===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
Apr 27 17:35:30 test kernel: [11443.630597] audit: type=1400 audit(1493303730.576:1168): apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;open&amp;quot; profile=&amp;quot;/usr/sbin/proftpd&amp;quot; name=&amp;quot;/etc/protocols&amp;quot; pid=21403 comm=&amp;quot;proftpd&amp;quot; requested_mask=&amp;quot;r&amp;quot; denied_mask=&amp;quot;r&amp;quot; fsuid=0 ouid=0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;open&amp;quot; //allows action&lt;br /&gt;
&lt;br /&gt;
profile=&amp;quot;/usr/sbin/proftpd&amp;quot; //program which is allowed to open&lt;br /&gt;
&lt;br /&gt;
name=&amp;quot;/etc/protocols&amp;quot; // file which will be opened &lt;br /&gt;
&lt;br /&gt;
pid=21403 //process id&lt;br /&gt;
&lt;br /&gt;
comm=&amp;quot;proftpd&amp;quot; // actual command&lt;br /&gt;
&lt;br /&gt;
requested_mask=&amp;quot;r&amp;quot; // requested action read&lt;br /&gt;
&lt;br /&gt;
denied_mask=&amp;quot;r&amp;quot; // action to be denied&lt;br /&gt;
&lt;br /&gt;
fsuid=0 ouid=0 //  file system id and object owner uid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sample profile explained ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {               // profile &lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;  // includes basic base rules&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,      // can override Discretionary access control&lt;br /&gt;
  network inet stream,          // can create ipv4 socket&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,                 //&lt;br /&gt;
  /etc/nginx/conf.d/ r,         //&lt;br /&gt;
  /etc/nginx/mime.types r,      //&lt;br /&gt;
  /etc/nginx/nginx.conf r,      //   file read allowed&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,  //&lt;br /&gt;
  /etc/nsswitch.conf r,         //&lt;br /&gt;
  /etc/passwd r,                //&lt;br /&gt;
  /etc/ssl/openssl.cnf r,       //&lt;br /&gt;
  /usr/sbin/nginx mr,           //   allows reading and writing files in memory &lt;br /&gt;
  /var/log/nginx/error.log w,   //   write to file allowed&lt;br /&gt;
  /var/www/html/** r,           //   read allowed recursively inside directory&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Practical example by hardening server ==&lt;br /&gt;
&lt;br /&gt;
Lets assume that you want to set up Ubuntu LTS server and quickly harden it with AppArmor. The server will run Virtualmin as a server control panel.&lt;br /&gt;
First you install Virtualmin by running these commands. Saddly they do not provide checksumms.&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://software.virtualmin.com/gpl/scripts/install.sh&lt;br /&gt;
bash install.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install additional profiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt install apparmor-profiles&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By checking &amp;lt;code&amp;gt;aa-status&amp;lt;/code&amp;gt; you can see that there are bunch of profiles already in enforce and complain mode.&lt;br /&gt;
&lt;br /&gt;
[[File:Aa-status.png|80px]]&lt;br /&gt;
&lt;br /&gt;
Next, to actually enable  profiling on new process, you need to install AppArmor tools &amp;lt;code&amp;gt;apt-get install apparmor-utils&amp;lt;/code&amp;gt;&lt;br /&gt;
Then put proftpd process in complaint mode&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are running more than one program in complain mode, then by default kernel might limit messages logged, and this might not let you build complete profile. To temporarily circumvent this, execute this command &amp;lt;code&amp;gt;sysctl -w kernel.printk_ratelimit=0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we check which services are running and listening to network sockets, but does not have profiles defined yet by running &amp;lt;code&amp;gt;aa-unconfined&amp;lt;/code&amp;gt;&lt;br /&gt;
In output you can see that there are some unconfined programs running. We skip perl because that is too generic, also SSH for now, and enable profiling for ProFTPD and some Dovecot subprocesses (we need to use full path for master process, because it is not in out $PATH).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-autodep /usr/lib/postfix/sbin/master&lt;br /&gt;
aa-autodep dovecot&lt;br /&gt;
&lt;br /&gt;
Then run them in complain mode&lt;br /&gt;
&lt;br /&gt;
aa-complain dovecot&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
aa-complain /usr/lib/postfix/sbin/master&lt;br /&gt;
&lt;br /&gt;
Restart services&lt;br /&gt;
&lt;br /&gt;
systemctl restart postfix&lt;br /&gt;
systemctl restart dovecot&lt;br /&gt;
systemctl restart proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that just proceed to do normal things, browse and send emails, create new folders in IMAP account, upload and download files thru ProFTPD. After you think you have done everything you wanted to allow, run &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and generate profiles. &lt;br /&gt;
Lets mass enable generated profiles in enforce mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.dovecot.*&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.postfix*&lt;br /&gt;
aa-enforce proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reminder that enabling profiles in enforced mode might render your system unstable. You need to have a clear plan, what your system is going to do. How many users will be there, what will they want to do, etc.&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;.&lt;br /&gt;
They are installed in same default directory /etc/apparmor.d as the rest of profiles.&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120539</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120539"/>
		<updated>2017-04-28T19:05:07Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Example log record in complain mode */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
=== Example log record in complain mode ===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
Apr 27 17:35:30 test kernel: [11443.630597] audit: type=1400 audit(1493303730.576:1168): apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;open&amp;quot; profile=&amp;quot;/usr/sbin/proftpd&amp;quot; name=&amp;quot;/etc/protocols&amp;quot; pid=21403 comm=&amp;quot;proftpd&amp;quot; requested_mask=&amp;quot;r&amp;quot; denied_mask=&amp;quot;r&amp;quot; fsuid=0 ouid=0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;open&amp;quot; //allows action&lt;br /&gt;
&lt;br /&gt;
profile=&amp;quot;/usr/sbin/proftpd&amp;quot; //program which is allowed to open&lt;br /&gt;
&lt;br /&gt;
name=&amp;quot;/etc/protocols&amp;quot; // file which will be opened &lt;br /&gt;
&lt;br /&gt;
pid=21403 //process id&lt;br /&gt;
&lt;br /&gt;
comm=&amp;quot;proftpd&amp;quot; // actual command&lt;br /&gt;
&lt;br /&gt;
requested_mask=&amp;quot;r&amp;quot; // requested action read&lt;br /&gt;
&lt;br /&gt;
denied_mask=&amp;quot;r&amp;quot; // action to be denied&lt;br /&gt;
&lt;br /&gt;
fsuid=0 ouid=0 //  file system id and object owner uid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Practical example by hardening server ==&lt;br /&gt;
&lt;br /&gt;
Lets assume that you want to set up Ubuntu LTS server and quickly harden it with AppArmor. The server will run Virtualmin as a server control panel.&lt;br /&gt;
First you install Virtualmin by running these commands. Saddly they do not provide checksumms.&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://software.virtualmin.com/gpl/scripts/install.sh&lt;br /&gt;
bash install.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install additional profiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt install apparmor-profiles&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By checking &amp;lt;code&amp;gt;aa-status&amp;lt;/code&amp;gt; you can see that there are bunch of profiles already in enforce and complain mode.&lt;br /&gt;
&lt;br /&gt;
[[File:Aa-status.png|80px]]&lt;br /&gt;
&lt;br /&gt;
Next, to actually enable  profiling on new process, you need to install AppArmor tools &amp;lt;code&amp;gt;apt-get install apparmor-utils&amp;lt;/code&amp;gt;&lt;br /&gt;
Then put proftpd process in complaint mode&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are running more than one program in complain mode, then by default kernel might limit messages logged, and this might not let you build complete profile. To temporarily circumvent this, execute this command &amp;lt;code&amp;gt;sysctl -w kernel.printk_ratelimit=0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we check which services are running and listening to network sockets, but does not have profiles defined yet by running &amp;lt;code&amp;gt;aa-unconfined&amp;lt;/code&amp;gt;&lt;br /&gt;
In output you can see that there are some unconfined programs running. We skip perl because that is too generic, also SSH for now, and enable profiling for ProFTPD and some Dovecot subprocesses (we need to use full path for master process, because it is not in out $PATH).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-autodep /usr/lib/postfix/sbin/master&lt;br /&gt;
aa-autodep dovecot&lt;br /&gt;
&lt;br /&gt;
Then run them in complain mode&lt;br /&gt;
&lt;br /&gt;
aa-complain dovecot&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
aa-complain /usr/lib/postfix/sbin/master&lt;br /&gt;
&lt;br /&gt;
Restart services&lt;br /&gt;
&lt;br /&gt;
systemctl restart postfix&lt;br /&gt;
systemctl restart dovecot&lt;br /&gt;
systemctl restart proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that just proceed to do normal things, browse and send emails, create new folders in IMAP account, upload and download files thru ProFTPD. After you think you have done everything you wanted to allow, run &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and generate profiles. &lt;br /&gt;
Lets mass enable generated profiles in enforce mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.dovecot.*&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.postfix*&lt;br /&gt;
aa-enforce proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reminder that enabling profiles in enforced mode might render your system unstable. You need to have a clear plan, what your system is going to do. How many users will be there, what will they want to do, etc.&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;.&lt;br /&gt;
They are installed in same default directory /etc/apparmor.d as the rest of profiles.&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120538</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120538"/>
		<updated>2017-04-28T18:05:49Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Example log record in complain mode */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
=== Example log record in complain mode ===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
Apr 27 17:42:19 test kernel: [11852.194015] audit: type=1400 audit(1493304139.134:32425): apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;sendmsg&amp;quot; info=&amp;quot;Failed name lookup - disconnected path&amp;quot; error=-13 profile=&amp;quot;/usr/lib/dovecot/log&amp;quot; name=&amp;quot;run/systemd/journal/dev-log&amp;quot; pid=21375 comm=&amp;quot;log&amp;quot; requested_mask=&amp;quot;w&amp;quot; denied_mask=&amp;quot;w&amp;quot; fsuid=0 ouid=0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
Apr 27 17:35:30 test kernel: [11443.630597] audit: type=1400 audit(1493303730.576:1168): apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;open&amp;quot; profile=&amp;quot;/usr/sbin/proftpd&amp;quot; name=&amp;quot;/etc/protocols&amp;quot; pid=21403 comm=&amp;quot;proftpd&amp;quot; requested_mask=&amp;quot;r&amp;quot; denied_mask=&amp;quot;r&amp;quot; fsuid=0 ouid=0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Practical example by hardening server ==&lt;br /&gt;
&lt;br /&gt;
Lets assume that you want to set up Ubuntu LTS server and quickly harden it with AppArmor. The server will run Virtualmin as a server control panel.&lt;br /&gt;
First you install Virtualmin by running these commands. Saddly they do not provide checksumms.&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://software.virtualmin.com/gpl/scripts/install.sh&lt;br /&gt;
bash install.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install additional profiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt install apparmor-profiles&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By checking &amp;lt;code&amp;gt;aa-status&amp;lt;/code&amp;gt; you can see that there are bunch of profiles already in enforce and complain mode.&lt;br /&gt;
&lt;br /&gt;
[[File:Aa-status.png|80px]]&lt;br /&gt;
&lt;br /&gt;
Next, to actually enable  profiling on new process, you need to install AppArmor tools &amp;lt;code&amp;gt;apt-get install apparmor-utils&amp;lt;/code&amp;gt;&lt;br /&gt;
Then put proftpd process in complaint mode&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are running more than one program in complain mode, then by default kernel might limit messages logged, and this might not let you build complete profile. To temporarily circumvent this, execute this command &amp;lt;code&amp;gt;sysctl -w kernel.printk_ratelimit=0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we check which services are running and listening to network sockets, but does not have profiles defined yet by running &amp;lt;code&amp;gt;aa-unconfined&amp;lt;/code&amp;gt;&lt;br /&gt;
In output you can see that there are some unconfined programs running. We skip perl because that is too generic, also SSH for now, and enable profiling for ProFTPD and some Dovecot subprocesses (we need to use full path for master process, because it is not in out $PATH).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-autodep /usr/lib/postfix/sbin/master&lt;br /&gt;
aa-autodep dovecot&lt;br /&gt;
&lt;br /&gt;
Then run them in complain mode&lt;br /&gt;
&lt;br /&gt;
aa-complain dovecot&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
aa-complain /usr/lib/postfix/sbin/master&lt;br /&gt;
&lt;br /&gt;
Restart services&lt;br /&gt;
&lt;br /&gt;
systemctl restart postfix&lt;br /&gt;
systemctl restart dovecot&lt;br /&gt;
systemctl restart proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that just proceed to do normal things, browse and send emails, create new folders in IMAP account, upload and download files thru ProFTPD. After you think you have done everything you wanted to allow, run &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and generate profiles. &lt;br /&gt;
Lets mass enable generated profiles in enforce mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.dovecot.*&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.postfix*&lt;br /&gt;
aa-enforce proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reminder that enabling profiles in enforced mode might render your system unstable. You need to have a clear plan, what your system is going to do. How many users will be there, what will they want to do, etc.&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;.&lt;br /&gt;
They are installed in same default directory /etc/apparmor.d as the rest of profiles.&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120526</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120526"/>
		<updated>2017-04-27T15:23:29Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
=== Example log record in complain mode ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Apr 27 17:42:19 test kernel: [11852.194015] audit: type=1400 audit(1493304139.134:32425): apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;sendmsg&amp;quot; info=&amp;quot;Failed name lookup - disconnected path&amp;quot; error=-13 profile=&amp;quot;/usr/lib/dovecot/log&amp;quot; name=&amp;quot;run/systemd/journal/dev-log&amp;quot; pid=21375 comm=&amp;quot;log&amp;quot; requested_mask=&amp;quot;w&amp;quot; denied_mask=&amp;quot;w&amp;quot; fsuid=0 ouid=0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Apr 27 17:35:30 test kernel: [11443.630597] audit: type=1400 audit(1493303730.576:1168): apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;open&amp;quot; profile=&amp;quot;/usr/sbin/proftpd&amp;quot; name=&amp;quot;/etc/protocols&amp;quot; pid=21403 comm=&amp;quot;proftpd&amp;quot; requested_mask=&amp;quot;r&amp;quot; denied_mask=&amp;quot;r&amp;quot; fsuid=0 ouid=0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Practical example by hardening server ==&lt;br /&gt;
&lt;br /&gt;
Lets assume that you want to set up Ubuntu LTS server and quickly harden it with AppArmor. The server will run Virtualmin as a server control panel.&lt;br /&gt;
First you install Virtualmin by running these commands. Saddly they do not provide checksumms.&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://software.virtualmin.com/gpl/scripts/install.sh&lt;br /&gt;
bash install.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install additional profiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt install apparmor-profiles&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By checking &amp;lt;code&amp;gt;aa-status&amp;lt;/code&amp;gt; you can see that there are bunch of profiles already in enforce and complain mode.&lt;br /&gt;
&lt;br /&gt;
[[File:Aa-status.png|80px]]&lt;br /&gt;
&lt;br /&gt;
Next, to actually enable  profiling on new process, you need to install AppArmor tools &amp;lt;code&amp;gt;apt-get install apparmor-utils&amp;lt;/code&amp;gt;&lt;br /&gt;
Then put proftpd process in complaint mode&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are running more than one program in complain mode, then by default kernel might limit messages logged, and this might not let you build complete profile. To temporarily circumvent this, execute this command &amp;lt;code&amp;gt;sysctl -w kernel.printk_ratelimit=0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we check which services are running and listening to network sockets, but does not have profiles defined yet by running &amp;lt;code&amp;gt;aa-unconfined&amp;lt;/code&amp;gt;&lt;br /&gt;
In output you can see that there are some unconfined programs running. We skip perl because that is too generic, also SSH for now, and enable profiling for ProFTPD and some Dovecot subprocesses (we need to use full path for master process, because it is not in out $PATH).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-autodep /usr/lib/postfix/sbin/master&lt;br /&gt;
aa-autodep dovecot&lt;br /&gt;
&lt;br /&gt;
Then run them in complain mode&lt;br /&gt;
&lt;br /&gt;
aa-complain dovecot&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
aa-complain /usr/lib/postfix/sbin/master&lt;br /&gt;
&lt;br /&gt;
Restart services&lt;br /&gt;
&lt;br /&gt;
systemctl restart postfix&lt;br /&gt;
systemctl restart dovecot&lt;br /&gt;
systemctl restart proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that just proceed to do normal things, browse and send emails, create new folders in IMAP account, upload and download files thru ProFTPD. After you think you have done everything you wanted to allow, run &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and generate profiles. &lt;br /&gt;
Lets mass enable generated profiles in enforce mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.dovecot.*&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.postfix*&lt;br /&gt;
aa-enforce proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reminder that enabling profiles in enforced mode might render your system unstable. You need to have a clear plan, what your system is going to do. How many users will be there, what will they want to do, etc.&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;.&lt;br /&gt;
They are installed in same default directory /etc/apparmor.d as the rest of profiles.&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120525</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120525"/>
		<updated>2017-04-27T14:48:57Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
=== Example log record in complain mode ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Apr 27 17:42:19 test kernel: [11852.194015] audit: type=1400 audit(1493304139.134:32425): apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;sendmsg&amp;quot; info=&amp;quot;Failed name lookup - disconnected path&amp;quot; error=-13 profile=&amp;quot;/usr/lib/dovecot/log&amp;quot; name=&amp;quot;run/systemd/journal/dev-log&amp;quot; pid=21375 comm=&amp;quot;log&amp;quot; requested_mask=&amp;quot;w&amp;quot; denied_mask=&amp;quot;w&amp;quot; fsuid=0 ouid=0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Apr 27 17:35:30 test kernel: [11443.630597] audit: type=1400 audit(1493303730.576:1168): apparmor=&amp;quot;ALLOWED&amp;quot; operation=&amp;quot;open&amp;quot; profile=&amp;quot;/usr/sbin/proftpd&amp;quot; name=&amp;quot;/etc/protocols&amp;quot; pid=21403 comm=&amp;quot;proftpd&amp;quot; requested_mask=&amp;quot;r&amp;quot; denied_mask=&amp;quot;r&amp;quot; fsuid=0 ouid=0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Practical example by hardening server ==&lt;br /&gt;
&lt;br /&gt;
Lets assume that you want to set up Ubuntu LTS server and quickly harden it with AppArmor. The server will run Virtualmin as a server control panel.&lt;br /&gt;
First you install Virtualmin by running these commands. Saddly they do not provide checksumms.&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://software.virtualmin.com/gpl/scripts/install.sh&lt;br /&gt;
bash install.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install additional profiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt install apparmor-profiles&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By checking &amp;lt;code&amp;gt;aa-status&amp;lt;/code&amp;gt; you can see that there are bunch of profiles already in enforce and complain mode.&lt;br /&gt;
&lt;br /&gt;
[[File:Aa-status.png|80px]]&lt;br /&gt;
&lt;br /&gt;
Next, to actually enable  profiling on new process, you need to install AppArmor tools &amp;lt;code&amp;gt;apt-get install apparmor-utils&amp;lt;/code&amp;gt;&lt;br /&gt;
Then put proftpd process in complaint mode&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are running more than one program in complain mode, then by default kernel might limit messages logged, and this might not let you build complete profile. To temporarily circumvent this, execute this command &amp;lt;code&amp;gt;sysctl -w kernel.printk_ratelimit=0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we check which services are running and listening to network sockets, but does not have profiles defined yet by running &amp;lt;code&amp;gt;aa-unconfined&amp;lt;/code&amp;gt;&lt;br /&gt;
In output you can see that there are some unconfined programs running. We skip perl because that is too generic, also SSH for now, and enable profiling for ProFTPD and some Dovecot subprocesses (we need to use full path for master process, because it is not in out $PATH).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-autodep /usr/lib/postfix/sbin/master&lt;br /&gt;
aa-autodep dovecot&lt;br /&gt;
&lt;br /&gt;
Then run them in complain mode&lt;br /&gt;
&lt;br /&gt;
aa-complain dovecot&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
aa-complain /usr/lib/postfix/sbin/master&lt;br /&gt;
&lt;br /&gt;
Restart services&lt;br /&gt;
&lt;br /&gt;
systemctl restart postfix&lt;br /&gt;
systemctl restart dovecot&lt;br /&gt;
systemctl restart proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that just proceed to do normal things, browse and send emails, create new folders in IMAP account, upload and download files thru ProFTPD. After you think you have done everything you wanted to allow, run &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and generate profiles. &lt;br /&gt;
Lets mass enable generated profiles in enforce mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.dovecot.*&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.postfix*&lt;br /&gt;
aa-enforce proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reminder that enabling profiles in enforced mode might render your system unstable. You need to have a clear plan, what your system is going to do. How many users will be there, what will they want to do, etc.&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;.&lt;br /&gt;
They are installed in same default directory /etc/apparmor.d as the rest of profiles.&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120524</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120524"/>
		<updated>2017-04-27T14:46:22Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Practical example by hardening server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Practical example by hardening server ==&lt;br /&gt;
&lt;br /&gt;
Lets assume that you want to set up Ubuntu LTS server and quickly harden it with AppArmor. The server will run Virtualmin as a server control panel.&lt;br /&gt;
First you install Virtualmin by running these commands. Saddly they do not provide checksumms.&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://software.virtualmin.com/gpl/scripts/install.sh&lt;br /&gt;
bash install.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install additional profiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt install apparmor-profiles&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By checking &amp;lt;code&amp;gt;aa-status&amp;lt;/code&amp;gt; you can see that there are bunch of profiles already in enforce and complain mode.&lt;br /&gt;
&lt;br /&gt;
[[File:Aa-status.png|80px]]&lt;br /&gt;
&lt;br /&gt;
Next, to actually enable  profiling on new process, you need to install AppArmor tools &amp;lt;code&amp;gt;apt-get install apparmor-utils&amp;lt;/code&amp;gt;&lt;br /&gt;
Then put proftpd process in complaint mode&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are running more than one program in complain mode, then by default kernel might limit messages logged, and this might not let you build complete profile. To temporarily circumvent this, execute this command &amp;lt;code&amp;gt;sysctl -w kernel.printk_ratelimit=0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we check which services are running and listening to network sockets, but does not have profiles defined yet by running &amp;lt;code&amp;gt;aa-unconfined&amp;lt;/code&amp;gt;&lt;br /&gt;
In output you can see that there are some unconfined programs running. We skip perl because that is too generic, also SSH for now, and enable profiling for ProFTPD and some Dovecot subprocesses (we need to use full path for master process, because it is not in out $PATH).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-autodep proftpd&lt;br /&gt;
aa-autodep /usr/lib/postfix/sbin/master&lt;br /&gt;
aa-autodep dovecot&lt;br /&gt;
&lt;br /&gt;
Then run them in complain mode&lt;br /&gt;
&lt;br /&gt;
aa-complain dovecot&lt;br /&gt;
aa-complain proftpd&lt;br /&gt;
aa-complain /usr/lib/postfix/sbin/master&lt;br /&gt;
&lt;br /&gt;
Restart services&lt;br /&gt;
&lt;br /&gt;
systemctl restart postfix&lt;br /&gt;
systemctl restart dovecot&lt;br /&gt;
systemctl restart proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that just proceed to do normal things, browse and send emails, create new folders in IMAP account, upload and download files thru ProFTPD. After you think you have done everything you wanted to allow, run &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and generate profiles. &lt;br /&gt;
Lets mass enable generated profiles in enforce mode&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.dovecot.*&lt;br /&gt;
aa-enforce /etc/apparmor.d/usr.lib.postfix*&lt;br /&gt;
aa-enforce proftpd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reminder that enabling profiles in enforced mode might render your system unstable. You need to have a clear plan, what your system is going to do. How many users will be there, what will they want to do, etc.&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;.&lt;br /&gt;
They are installed in same default directory /etc/apparmor.d as the rest of profiles.&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120503</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120503"/>
		<updated>2017-04-27T12:09:06Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Practical example by hardening server ==&lt;br /&gt;
&lt;br /&gt;
Lets assume that you want to set up Ubuntu LTS server and quickly harden it with AppArmor. The server will run Virtualmin as a server control panel.&lt;br /&gt;
First you install Virtualmin by running these commands. Saddly they do not provide checksumms.&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://software.virtualmin.com/gpl/scripts/install.sh&lt;br /&gt;
bash install.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install additional profiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt install apparmor-profiles&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By checking &amp;lt;code&amp;gt;aa-status&amp;lt;/code&amp;gt; you can see that there are bunch of profiles already in enforce and complain mode.&lt;br /&gt;
&lt;br /&gt;
[[File:Aa-status.png|80px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;.&lt;br /&gt;
They are installed in same default directory /etc/apparmor.d as the rest of profiles.&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120502</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120502"/>
		<updated>2017-04-27T12:04:36Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Practical example by hardening server ==&lt;br /&gt;
&lt;br /&gt;
Lets assume that you want to set up Ubuntu LTS server and quickly harden it with AppArmor. The server will run Virtualmin as a server control panel.&lt;br /&gt;
First you install Virtualmin by running these commands. Saddly they do not provide checksumms.&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://software.virtualmin.com/gpl/scripts/install.sh&lt;br /&gt;
bash install.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install additional profiles&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt install apparmor-profiles&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By checking &amp;lt;code&amp;gt;aa-status&amp;lt;/code&amp;gt; you can see that there are bunch of profiles already in enforce and complain mode.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;.&lt;br /&gt;
They are installed in same default directory /etc/apparmor.d as the rest of profiles.&lt;br /&gt;
[[File:Aa-status.png|right|thumb|Logo]]&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Aa-status.png&amp;diff=120501</id>
		<title>File:Aa-status.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Aa-status.png&amp;diff=120501"/>
		<updated>2017-04-27T12:03:50Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120499</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120499"/>
		<updated>2017-04-27T11:10:32Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Getting additional rules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;.&lt;br /&gt;
They are installed in same default directory /etc/apparmor.d as the rest of profiles.&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120498</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120498"/>
		<updated>2017-04-27T11:08:05Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Permission flags */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
These are permission flags which are used in policy files. With them you can specify which things are allowed and which are denied.&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120497</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120497"/>
		<updated>2017-04-27T10:44:58Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Creating new profiles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if you want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by running &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120496</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120496"/>
		<updated>2017-04-27T10:43:24Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Reload singe profile */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Replace (reload) singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120495</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120495"/>
		<updated>2017-04-27T10:40:47Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120493</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120493"/>
		<updated>2017-04-27T09:48:29Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Enabling disabled profile */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120492</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120492"/>
		<updated>2017-04-27T09:42:39Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Reload singe profile */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   apparmor_parser -r /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120491</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120491"/>
		<updated>2017-04-27T09:42:23Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Load profile */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  apparmor_parser -a /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120470</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120470"/>
		<updated>2017-04-26T19:10:31Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Systematic profiling ===&lt;br /&gt;
&lt;br /&gt;
Lets try and do systematic profiling on vsftpd and nginx. After installing them, this command needs to be run in order to create profile skeleton for both programms &amp;lt;code&amp;gt;aa-autodep vsftpd nginx&amp;lt;/code&amp;gt;. After that run this command to puth both profiles in complain mode &amp;lt;code&amp;gt;aa-complain vsftpd nginx&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then restart both services &amp;lt;code&amp;gt;systemctl restart vsftpd ; systemctl restart nginx&amp;lt;/code&amp;gt;&lt;br /&gt;
and do some basic tasks. Open html page in web browser, create and open some subdirectories. Upload and delete files with ftp client. After you think you have done everything you require from both services, run this command &amp;lt;code&amp;gt;aa-logprof&amp;lt;/code&amp;gt; and approve rules. You may need to run it a few times untill you tweak rules just right. Below are the basic rules which allows ftp juser to upload files in his home directory and in /var/www/html/, and ngix to serve them properly over http.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:50:54 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/postfix-common&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability net_bind_service,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
&lt;br /&gt;
  network inet6 stream,&lt;br /&gt;
  network netlink raw,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/login.defs r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/pam.d/* r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/securetty r,&lt;br /&gt;
  /etc/shadow r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.conf r,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/** rw,&lt;br /&gt;
  /usr/sbin/vsftpd mr,&lt;br /&gt;
  /var/ r,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  /var/www/ rw,&lt;br /&gt;
  /var/www/html/** rw,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 21:46:31 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/nginx {&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability dac_override,&lt;br /&gt;
&lt;br /&gt;
  network inet stream,&lt;br /&gt;
&lt;br /&gt;
  /etc/group r,&lt;br /&gt;
  /etc/nginx/conf.d/ r,&lt;br /&gt;
  /etc/nginx/mime.types r,&lt;br /&gt;
  /etc/nginx/nginx.conf r,&lt;br /&gt;
  /etc/nginx/sites-enabled/ r,&lt;br /&gt;
  /etc/nsswitch.conf r,&lt;br /&gt;
  /etc/passwd r,&lt;br /&gt;
  /etc/ssl/openssl.cnf r,&lt;br /&gt;
  /usr/sbin/nginx mr,&lt;br /&gt;
  /var/log/nginx/error.log w,&lt;br /&gt;
  /var/www/html/** r,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting additional rules ==&lt;br /&gt;
You can download precreated AppArmor rules for most popular services by installing additional package&lt;br /&gt;
&amp;lt;code&amp;gt;apt install apparmor-profiles&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional resources ==&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference More about various policy flags]&lt;br /&gt;
* [http://wiki.apparmor.net/index.php/Documentation General documentation]&lt;br /&gt;
* [https://www.novell.com/documentation/apparmor/apparmor201_sp10_admin/data/bx5bmky.html Building Profiles from the Command Line]&lt;br /&gt;
* [https://help.ubuntu.com/community/AppArmor AppArmor Ubuntu wiki]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120468</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120468"/>
		<updated>2017-04-26T17:47:07Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Run profile in enforce mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Permission flags ==&lt;br /&gt;
&lt;br /&gt;
* r    - read&lt;br /&gt;
* w    - write -- conflicts with append&lt;br /&gt;
* a    - append -- conflicts with write&lt;br /&gt;
* ux   - unconfined execute&lt;br /&gt;
* Ux   - unconfined execute -- scrub the environment&lt;br /&gt;
* px   - discrete profile execute&lt;br /&gt;
* Px   - discrete profile execute -- scrub the environment&lt;br /&gt;
* cx   - transition to subprofile on execute&lt;br /&gt;
* Cx   - transition to subprofile on execute -- scrub the environment&lt;br /&gt;
* ix   - inherit execute&lt;br /&gt;
* m    - allow PROT_EXEC with mmap(2) calls&lt;br /&gt;
* l    - link&lt;br /&gt;
* k    - lock&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;is  very narrow and ftp will not work properly if your system have more than one user. First profile that was made for vsftpd looked like this&lt;br /&gt;
&amp;lt;pre&amp;gt;  # Last Modified: Wed Apr 26 00:39:00 2017&lt;br /&gt;
  #include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/lxc/container-base&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /home/*/ rw,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you test it out, you will notice, that you can still access pretty much everything even when this profile does not specify it. It is because the line &amp;lt;code&amp;gt;#include &amp;lt;abstractions/lxc/container-base&amp;gt;&amp;lt;/code&amp;gt; gives wide access. So instead i changed permissions to be more narrow, and now profile looked like this. User will be able to write in his home directory and in /tmp. He will not see contents in /home.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Last Modified: Wed Apr 26 20:39:27 2017&lt;br /&gt;
#include &amp;lt;tunables/global&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/usr/sbin/vsftpd {&lt;br /&gt;
  #include &amp;lt;abstractions/authentication&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/base&amp;gt;&lt;br /&gt;
  #include &amp;lt;abstractions/nameservice&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  capability audit_write,&lt;br /&gt;
  capability setgid,&lt;br /&gt;
  capability setuid,&lt;br /&gt;
  capability sys_admin,&lt;br /&gt;
  capability sys_chroot,&lt;br /&gt;
&lt;br /&gt;
  / r,&lt;br /&gt;
  /dev/urandom r,&lt;br /&gt;
  /etc/fstab r,&lt;br /&gt;
  /etc/ftpusers r,&lt;br /&gt;
  /etc/hosts.allow r,&lt;br /&gt;
  /etc/hosts.deny r,&lt;br /&gt;
  /etc/mtab r,&lt;br /&gt;
  /etc/shells r,&lt;br /&gt;
  /etc/vsftpd.* r,&lt;br /&gt;
  /etc/vsftpd/* r,&lt;br /&gt;
  /tmp/ r,&lt;br /&gt;
  /tmp/* w,&lt;br /&gt;
  /usr/sbin/vsftpd mrix,&lt;br /&gt;
  /var/log/vsftpd.log w,&lt;br /&gt;
  @{HOME}/ r,&lt;br /&gt;
  @{HOME}/* w,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120466</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120466"/>
		<updated>2017-04-26T15:27:00Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Run profile in comlpain mode */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in complain mode ===&lt;br /&gt;
  aa-complain /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;could look very narrow and ftp will not work properly if your system have more than one user. You can push &#039;&#039;&#039;E&#039;&#039;&#039; for &#039;&#039;Glob with (E)xtension&#039;&#039; and it will offer you wider rule that will allow writing in /home not /home/user1/ directory only.&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120465</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120465"/>
		<updated>2017-04-26T15:26:21Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Check status */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status&lt;br /&gt;
or&lt;br /&gt;
  aa-status&lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in comlpain mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;could look very narrow and ftp will not work properly if your system have more than one user. You can push &#039;&#039;&#039;E&#039;&#039;&#039; for &#039;&#039;Glob with (E)xtension&#039;&#039; and it will offer you wider rule that will allow writing in /home not /home/user1/ directory only.&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120464</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120464"/>
		<updated>2017-04-26T15:22:09Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Creating new profiles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status &lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in comlpain mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. First one is called &#039;&#039;Stand-Alone profiling&#039;&#039; and second one is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;could look very narrow and ftp will not work properly if your system have more than one user. You can push &#039;&#039;&#039;E&#039;&#039;&#039; for &#039;&#039;Glob with (E)xtension&#039;&#039; and it will offer you wider rule that will allow writing in /home not /home/user1/ directory only.&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120454</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120454"/>
		<updated>2017-04-25T20:19:03Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Stand=alone profiling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status &lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in comlpain mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. One is called &#039;&#039;Stand-Alone profiling&#039;&#039; and other is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand-alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, lets try and profile Vsftpd. After installing it, this command needs to be run first &amp;lt;code&amp;gt;aa-genprof /usr/sbin/vsftpd&amp;lt;/code&amp;gt;. It will stay in monitoring mode. Then in other terminal window restart or start Vsftpd daemon by running &amp;lt;code&amp;gt;systemctl restart vsftpd&amp;lt;/code&amp;gt;. After that just proceed with casual tasks. Connect with local user to FTP, upload, download, create and delete files and directories. Also create file in /tmp. After doing this, switch to first terminal window and push &#039;&#039;&#039;S&#039;&#039;&#039; for &#039;&#039;(S)can system log for AppArmor events&#039;&#039;. Aa-genprof will then asks a couple of questions about actions what vsftpd did and you can either approve or disable them, alone with some more options. For example this rule &amp;lt;code&amp;gt;/home/user1/* r&amp;lt;/code&amp;gt;could look very narrow and ftp will not work properly if your system have more than one user. You can push &#039;&#039;&#039;E&#039;&#039;&#039; for &#039;&#039;Glob with (E)xtension&#039;&#039; and it will offer you wider rule that will allow writing in /home not /home/user1/ directory only.&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120453</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120453"/>
		<updated>2017-04-25T18:50:46Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Creating new profiles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status &lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in comlpain mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
There are two ways of profiling. One is called &#039;&#039;Stand-Alone profiling&#039;&#039; and other is &#039;&#039;Systematic profiling&#039;&#039;. &lt;br /&gt;
* Stand-alone is more fit if oyu want to create profile for one application, however setbacks are, that you need to keep running the profiling process whole time, while you are creating profile.&lt;br /&gt;
* Systematic profiling is meant for multiple processes, and you can restart server and programs while still profiling.&lt;br /&gt;
&lt;br /&gt;
=== Stand=alone profiling ===&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;.&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120449</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120449"/>
		<updated>2017-04-25T17:41:01Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Whats is AppArmor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
[[File:Apparmor_logo.png|right|thumb|Logo]]&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status &lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in comlpain mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Apparmor_logo.png&amp;diff=120448</id>
		<title>File:Apparmor logo.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Apparmor_logo.png&amp;diff=120448"/>
		<updated>2017-04-25T17:36:43Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120447</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120447"/>
		<updated>2017-04-25T17:32:12Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== AppArmor and its ussage ===&lt;br /&gt;
== Whats is AppArmor ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[https://wiki.ubuntu.com/AppArmor AppArmor]&#039;&#039;&#039; is a Linux kernel security module that allows the system administrator to restrict programs&#039; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths. AppArmor supplements the traditional Unix discretionary access control(DAC) model by providing (mandatory access control) (MAC). It was included in the mainline Linux kernel since version 2.6.36 and its development has been supported by [https://www.canonical.com/ Canonical] since 2009.&lt;br /&gt;
It is available by default on Ubuntu and Suse distributions. AppArmor relies on paths instead of inodes, which are used by another similar security mechanism [https://en.wikipedia.org/wiki/Security-Enhanced_Linux SELinux].&lt;br /&gt;
Apparmor uses rules, which are combined into profiles for every process you want to restrict by it. These profiles can be run in &amp;quot;enforce&amp;quot; or &amp;quot;complain&amp;quot; modes. To generate profile you can run it with AppArmor in profile mode. While enforced profile will disallow any restricted activity, profile ran in complain mode will still allow program to do what was intended, but log this violation in logfile.&lt;br /&gt;
&lt;br /&gt;
== AppArmor features ==&lt;br /&gt;
&lt;br /&gt;
AppArmor can restrict following things&lt;br /&gt;
&lt;br /&gt;
* file access (read, write, link, lock)&lt;br /&gt;
* library loading&lt;br /&gt;
* execution of applications&lt;br /&gt;
* coarse-grained network (protocol, type, domain)&lt;br /&gt;
* capabilities&lt;br /&gt;
* coarse owner checks (task must have the same euid/fsuid as the object being checked) starting with Ubuntu 9.10&lt;br /&gt;
* mount starting with Ubuntu 12.04 LTS&lt;br /&gt;
* unix(7) named sockets starting with Ubuntu 13.10&lt;br /&gt;
* DBus API (path, interface, method) starting with Ubuntu 13.10&lt;br /&gt;
* signal(7) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* ptrace(2) starting with Ubuntu 14.04 LTS&lt;br /&gt;
* unix(7) abstract and anonymous sockets starting with Ubuntu 14.10&lt;br /&gt;
&lt;br /&gt;
== AppArmor commands ==&lt;br /&gt;
=== Check status ===&lt;br /&gt;
  apparmor_status &lt;br /&gt;
&lt;br /&gt;
=== Load profile ===&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Reload singe profile ===&lt;br /&gt;
   cat /etc/apparmor.d/profile.name | apparmor_parser -r&lt;br /&gt;
&lt;br /&gt;
=== Reload all profiles ===&lt;br /&gt;
  systemctl reload apparmor&lt;br /&gt;
&lt;br /&gt;
=== Disable profile ===&lt;br /&gt;
   ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/&lt;br /&gt;
   apparmor_parser -R /etc/apparmor.d/profile.name&lt;br /&gt;
&lt;br /&gt;
=== Enabling disabled profile ===&lt;br /&gt;
  rm /etc/apparmor.d/disable/profile.name&lt;br /&gt;
  cat /etc/apparmor.d/profile.name | apparmor_parser -a&lt;br /&gt;
&lt;br /&gt;
=== Run profile in comlpain mode ===&lt;br /&gt;
  aa-enforce /path/to/program&lt;br /&gt;
&lt;br /&gt;
=== Disabling AppArmor ===&lt;br /&gt;
Open &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; file and change or add this line &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;apparmor=0&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
Then run &amp;lt;code&amp;gt;update-grub2&amp;lt;/code&amp;gt; and restart your PC.&lt;br /&gt;
&lt;br /&gt;
== Creating new profiles ==&lt;br /&gt;
First you probably need to install additional package by runing &amp;lt;code&amp;gt;apt install apparmor-utils&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Apparmor_status.png&amp;diff=120446</id>
		<title>File:Apparmor status.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Apparmor_status.png&amp;diff=120446"/>
		<updated>2017-04-25T16:18:08Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=OSadmin_wiki_article&amp;diff=120445</id>
		<title>OSadmin wiki article</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=OSadmin_wiki_article&amp;diff=120445"/>
		<updated>2017-04-25T15:52:39Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Intro=&lt;br /&gt;
*Choose a topic from personal experience related with the subject or from topics found on the wiki page&lt;br /&gt;
*[[#Chosen_topics|Write the topic here]].&lt;br /&gt;
*Lecturer will confirm the topic&lt;br /&gt;
*Write your article in wiki environment &lt;br /&gt;
*Inform the [[Operating_systems#Lecturer|lecturer]] when the article is finished&lt;br /&gt;
*Receive feedback for corrections&lt;br /&gt;
&lt;br /&gt;
=Requirements for the wiki article=&lt;br /&gt;
Author: name, group and date when the article is written&lt;br /&gt;
&lt;br /&gt;
==Introduction ==&lt;br /&gt;
Covers points what will be discussed in the article, what are the requirements for the article reader; what are the operating system’s requirements. &lt;br /&gt;
&lt;br /&gt;
==Contents==&lt;br /&gt;
All commands should be easily separable from the overall text. &lt;br /&gt;
Users should be able to copy the commands directly (additional info like prompt and user distinction symbols should be left out from the command description area)&lt;br /&gt;
The text should determine what user permissions are needed to perform these tasks. &lt;br /&gt;
The reader of your article is your fellow students, so try to avoid irrelevant information and stay on topic (don’t explain the meaning of IP address or how to install Ubuntu, when your topic is actually about htop)&lt;br /&gt;
All the content should be referenced. &lt;br /&gt;
Do not use slang and try to be grammatically correct.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt; &lt;br /&gt;
Bear in mind that this is an open environment, so everything you write in your wiki article, will be public. &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Referencing==&lt;br /&gt;
Best practises of wiki referencing should be used. &lt;br /&gt;
Terms are but between square brackets to reference other articles in the system.&lt;br /&gt;
All drawing and images have to be referenced below the picture and in the text. (for example “System architecture can be viewed on image x, y and z.”)&lt;br /&gt;
Author’s own ideas have to be clearly presentable. Everything used from the sources have to be referenced. &lt;br /&gt;
&lt;br /&gt;
==Fellow student review==&lt;br /&gt;
Please find a fellow student who will review your article and give a feedback on the discussion tab of the article using [http://enos.itcollege.ee/~edmund/materials/viki-artikkel/Assessment-model-for-the-wiki-article.html the following assessment model].&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Besides a short overview, what was discussed in this article, it should also include the author&#039;s own opinion about the topic. &lt;br /&gt;
&lt;br /&gt;
==Category==&lt;br /&gt;
Add the following category to the end of the article (last row):&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Chosen topics=&lt;br /&gt;
Please write here your topic and name, group:&lt;br /&gt;
* &#039;&#039;&#039;Fedora OS&#039;&#039;&#039;; Anamul Hoque Shihab; CSE-11&lt;br /&gt;
* &#039;&#039;&#039;Basic Automation with Python&#039;&#039;&#039;; Ardi Vaba; CSE-11&lt;br /&gt;
* &#039;&#039;&#039;SSH Encryption&#039;&#039;&#039;; Frank Korving; CSE-11&lt;br /&gt;
* &#039;&#039;&#039;Translation of OSadmin wiki help page to English [[https://wiki.itcollege.ee/index.php/Osadmin_spikker]]&#039;&#039;&#039;; Peep Kuulme; CSE-11&lt;br /&gt;
* [https://wiki.itcollege.ee/index.php/Cross-Site_Scripting_(XSS)_attacks &#039;&#039;&#039;Cross-Site Scripting&#039;&#039;&#039;]; Masaki Ihara; CSE-11&lt;br /&gt;
*[https://wiki.itcollege.ee/index.php/Auditd &#039;&#039;&#039;Auditd - Linux system monitoring with audit daemon&#039;&#039;&#039;], Nika Ptskialadze, CSE-11&lt;br /&gt;
* &#039;&#039;&#039;GNU Privacy Guard (GnuPG)&#039;&#039;&#039;; Patricia Bruno Barbosa; CSE-11&lt;br /&gt;
* &#039;&#039;&#039;BackBox OS&#039;&#039;&#039;; Ats Tootsi; CSE-11&lt;br /&gt;
*[https://wiki.itcollege.ee/index.php/Apparmor_and_its_usage &#039;&#039;&#039;Apparmor and its usage&#039;&#039;&#039;], Mikus, CSE-11&lt;br /&gt;
*&#039;&#039;&#039;&#039;Arch Linux&#039;&#039;&#039;&#039;;Farhan Nayeem Islam;CSE-C11&lt;br /&gt;
* &#039;&#039;&#039;&#039;VPN basics&#039;&#039;&#039;&#039;, Christian Cataldo, CSE-C11; [https://wiki.itcollege.ee/index.php/VPN_(English_version)]&lt;br /&gt;
* &#039;&#039;Translation of DDoS Wiki page[[https://wiki.itcollege.ee/index.php/DDoS_Eng]]&#039;&#039;&#039;; Andris Männik; CSE-11&lt;br /&gt;
*&#039;&#039;&#039;Translation of Ps Wiki page[[https://wiki.itcollege.ee/index.php/Ps]]&#039;&#039;&#039;&#039;&#039;; Christopher Carr; CSE-11&lt;br /&gt;
*&#039;&#039;&#039;Translation of Bash_Shell wiki page[[https://wiki.itcollege.ee/index.php/BASH_shell]]&#039;&#039;&#039;; Steven Rugam; CSE-11&lt;br /&gt;
*&#039;&#039;&#039;Pass: The Standard Unix Password Manager&#039;&#039;&#039;; Oliver Rahula; CSE-11&lt;br /&gt;
==Ideas==&lt;br /&gt;
* UNIX CLI password manager https://www.passwordstore.org and its GUI http://qtpass.org/&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
* [https://wiki.itcollege.ee/index.php/Osadmin_referaadi_teemad counterpart article in Estonian]&lt;br /&gt;
* http://manpage.io&lt;br /&gt;
* https://linuxjourney.com/&lt;br /&gt;
* [https://linux.die.net/man/ Linux man-pages]&lt;br /&gt;
* [https://linux.die.net Linux docs]&lt;br /&gt;
* http://www.tecmint.com/60-commands-of-linux-a-guide-from-newbies-to-system-administrator/&lt;br /&gt;
* http://www.tecmint.com/useful-linux-commands-for-system-administrators/&lt;br /&gt;
* http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html&lt;br /&gt;
* http://www.thegeekstuff.com/2010/12/50-unix-linux-sysadmin-tutorials&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Creating_malware_lab&amp;diff=120444</id>
		<title>Creating malware lab</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Creating_malware_lab&amp;diff=120444"/>
		<updated>2017-04-25T15:51:59Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: Mteivens moved page Creating malware lab to Apparmor and its usage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Apparmor and its usage]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120443</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=120443"/>
		<updated>2017-04-25T15:51:59Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: Mteivens moved page Creating malware lab to Apparmor and its usage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;batman beginz&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120027</id>
		<title>Investigating nfc cards</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120027"/>
		<updated>2017-04-11T21:05:08Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==== Investigating Mifare NFC cards with PN532 module and C.H.I.P ====&lt;br /&gt;
In this brief document i will attempt to explain how to setup your chip and pn532 NFC reader to poke around with NFc cars.&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
&lt;br /&gt;
After flashing[https://flash.getchip.com/] your chip, first thing yo need to do is install &#039;&#039;libnfc&#039;&#039; by running command &lt;br /&gt;
 apt-get install libnfc-bin&lt;br /&gt;
&lt;br /&gt;
And add your NFC device&lt;br /&gt;
 mkdir -p /etc/nfc/devices.d/&lt;br /&gt;
 echo -e &amp;quot;name = \&amp;quot;PN532 board via UART\&amp;quot; \nconnstring = pn532_uart:/dev/ttyS0&amp;quot; &amp;gt; /etc/nfc/devices.d/pn532_uart.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you actually need to connect reader to chip. Check attached picture to see where to connect each pin.&lt;br /&gt;
&lt;br /&gt;
[[File:Pn532_pinout.png|200px]]&lt;br /&gt;
&lt;br /&gt;
If you did everything right, you should be able to detect the device by running &lt;br /&gt;
 nfc-scan-device&lt;br /&gt;
[[File:Nfc-scan-device.png]]&lt;br /&gt;
&lt;br /&gt;
=== Identifying cards ===&lt;br /&gt;
Using this command you can check if reader detects NFC card successfully &lt;br /&gt;
 nfc-list&lt;br /&gt;
&lt;br /&gt;
You can identify cards by returned ATQA/SENS_RES, SAK/SEL_RES and ATS[http://nfc-tools.org/index.php?title=ISO14443A] bytes manually by useing command&lt;br /&gt;
 nfc-list&lt;br /&gt;
or you can use this utility[http://nfc-tools.org/index.php?title=Lsnfc] to make it easier. Below you can see responses from ISIC card (non bank issued one).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery&amp;gt;&lt;br /&gt;
File:Lsnfc.png|lsnfc output&lt;br /&gt;
Nfc-list.png|nfc-list output&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic working principles of Mifare Classic card ===&lt;br /&gt;
Both, ISIC and Estonian transportation cards are working on Mifare Classic chip. Bank cards use another chip which is able to emulate Mifare Classic. SEB uses Mifare Plus and Swedbank uses JCOP as far as i know. &lt;br /&gt;
&lt;br /&gt;
Mifare classic`s memory is organized in 16 sectors of 4 blocks. One block contains 16 bytes.&lt;br /&gt;
&lt;br /&gt;
[[File:Mifare_classic_memory_layout.png|200px]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Mifare_classic_memory_layout.png&amp;diff=120026</id>
		<title>File:Mifare classic memory layout.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Mifare_classic_memory_layout.png&amp;diff=120026"/>
		<updated>2017-04-11T19:23:57Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120025</id>
		<title>Investigating nfc cards</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120025"/>
		<updated>2017-04-11T18:54:55Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==== Investigating Mifare NFC cards with PN532 module and C.H.I.P ====&lt;br /&gt;
In this brief document i will attempt to explain how to setup your chip and pn532 NFC reader to poke around with NFc cars.&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
&lt;br /&gt;
After flashing[https://flash.getchip.com/] your chip, first thing yo need to do is install &#039;&#039;libnfc&#039;&#039; by running command &lt;br /&gt;
 apt-get install libnfc-bin&lt;br /&gt;
&lt;br /&gt;
And add your NFC device&lt;br /&gt;
 mkdir -p /etc/nfc/devices.d/&lt;br /&gt;
 echo -e &amp;quot;name = \&amp;quot;PN532 board via UART\&amp;quot; \nconnstring = pn532_uart:/dev/ttyS0&amp;quot; &amp;gt; /etc/nfc/devices.d/pn532_uart.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you actually need to connect reader to chip. Check attached picture to see where to connect each pin.&lt;br /&gt;
&lt;br /&gt;
[[File:Pn532_pinout.png|200px]]&lt;br /&gt;
&lt;br /&gt;
If you did everything right, you should be able to detect the device by running &lt;br /&gt;
 nfc-scan-device&lt;br /&gt;
[[File:Nfc-scan-device.png]]&lt;br /&gt;
&lt;br /&gt;
=== Identifying cards ===&lt;br /&gt;
Using this command you can check if reader detects NFC card successfully &lt;br /&gt;
 nfc-list&lt;br /&gt;
&lt;br /&gt;
You can identify cards by returned ATQA/SENS_RES, SAK/SEL_RES and ATS[http://nfc-tools.org/index.php?title=ISO14443A] bytes manually by useing command&lt;br /&gt;
 nfc-list&lt;br /&gt;
or you can use this utility[http://nfc-tools.org/index.php?title=Lsnfc] to make it easier. Below you can see responses from ISIC card (non bank issued one).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery&amp;gt;&lt;br /&gt;
File:Lsnfc.png|lsnfc output&lt;br /&gt;
Nfc-list.png|nfc-list output&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120024</id>
		<title>Investigating nfc cards</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120024"/>
		<updated>2017-04-11T15:36:45Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Identifying cards */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==== Investigating Mifare NFC cards with PN532 module and C.H.I.P ====&lt;br /&gt;
In this brief document i will attempt to explain how to setup your chip and pn532 NFC reader to poke around with NFc cars.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
After flashing[https://flash.getchip.com/] your chip, first thing yo need to do is install &#039;&#039;libnfc&#039;&#039; by running command &lt;br /&gt;
 apt-get install libnfc-bin&lt;br /&gt;
&lt;br /&gt;
And add your NFC device&lt;br /&gt;
 mkdir -p /etc/nfc/devices.d/&lt;br /&gt;
 echo -e &amp;quot;name = \&amp;quot;PN532 board via UART\&amp;quot; \nconnstring = pn532_uart:/dev/ttyS0&amp;quot; &amp;gt; /etc/nfc/devices.d/pn532_uart.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you actually need to connect reader to chip. Check attached picture to see where to connect each pin.&lt;br /&gt;
&lt;br /&gt;
[[File:Pn532_pinout.png|200px]]&lt;br /&gt;
&lt;br /&gt;
If you did everything right, you should be able to detect the device by running &lt;br /&gt;
 nfc-scan-device&lt;br /&gt;
[[File:Nfc-scan-device.png]]&lt;br /&gt;
&lt;br /&gt;
== Identifying cards ==&lt;br /&gt;
Using this command you can check if reader detects NFC card successfully &lt;br /&gt;
 nfc-list&lt;br /&gt;
&lt;br /&gt;
You can identify cards by returned ATQA/SENS_RES, SAK/SEL_RES and ATS[http://nfc-tools.org/index.php?title=ISO14443A] bytes manually by useing command&lt;br /&gt;
 nfc-list&lt;br /&gt;
or you can use this utility[http://nfc-tools.org/index.php?title=Lsnfc] to make it easier. Below you can see responses from ISIC card (non bank issued one).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery&amp;gt;&lt;br /&gt;
File:Lsnfc.png|lsnfc output&lt;br /&gt;
Nfc-list.png|nfc-list output&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120023</id>
		<title>Investigating nfc cards</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120023"/>
		<updated>2017-04-11T15:34:17Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==== Investigating Mifare NFC cards with PN532 module and C.H.I.P ====&lt;br /&gt;
In this brief document i will attempt to explain how to setup your chip and pn532 NFC reader to poke around with NFc cars.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
After flashing[https://flash.getchip.com/] your chip, first thing yo need to do is install &#039;&#039;libnfc&#039;&#039; by running command &lt;br /&gt;
 apt-get install libnfc-bin&lt;br /&gt;
&lt;br /&gt;
And add your NFC device&lt;br /&gt;
 mkdir -p /etc/nfc/devices.d/&lt;br /&gt;
 echo -e &amp;quot;name = \&amp;quot;PN532 board via UART\&amp;quot; \nconnstring = pn532_uart:/dev/ttyS0&amp;quot; &amp;gt; /etc/nfc/devices.d/pn532_uart.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you actually need to connect reader to chip. Check attached picture to see where to connect each pin.&lt;br /&gt;
&lt;br /&gt;
[[File:Pn532_pinout.png|200px]]&lt;br /&gt;
&lt;br /&gt;
If you did everything right, you should be able to detect the device by running &lt;br /&gt;
 nfc-scan-device&lt;br /&gt;
[[File:Nfc-scan-device.png]]&lt;br /&gt;
&lt;br /&gt;
== Identifying cards ==&lt;br /&gt;
Using this command you can check if reader detects NFC card successfully &lt;br /&gt;
 nfc-list&lt;br /&gt;
&lt;br /&gt;
You can identify cards by returned ATQA/SENS_RES, SAK/SEL_RES and ATS[http://nfc-tools.org/index.php?title=ISO14443A] bytes or you can use this utility[http://nfc-tools.org/index.php?title=Lsnfc] to make it easier. Below you can see responses from ISIC card (non bank issued one).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery&amp;gt;&lt;br /&gt;
File:Lsnfc.png|lsnfc output&lt;br /&gt;
Nfc-list.png|nfc-list output&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nfc-list.png&amp;diff=120022</id>
		<title>File:Nfc-list.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nfc-list.png&amp;diff=120022"/>
		<updated>2017-04-11T15:32:43Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Lsnfc.png&amp;diff=120021</id>
		<title>File:Lsnfc.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Lsnfc.png&amp;diff=120021"/>
		<updated>2017-04-11T15:32:06Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120020</id>
		<title>Investigating nfc cards</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Investigating_nfc_cards&amp;diff=120020"/>
		<updated>2017-04-11T13:08:19Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: Created page with &amp;quot;==== Investigating Mifare NFC cards with PN532 module and C.H.I.P ==== In this brief document i will attempt to explain how to setup your chip and pn532 NFC reader to poke aro...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==== Investigating Mifare NFC cards with PN532 module and C.H.I.P ====&lt;br /&gt;
In this brief document i will attempt to explain how to setup your chip and pn532 NFC reader to poke around with NFc cars.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
After flashing[https://flash.getchip.com/] your chip, first thing yo need to do is install &#039;&#039;libnfc&#039;&#039; by running command &lt;br /&gt;
 apt-get install libnfc-bin&lt;br /&gt;
&lt;br /&gt;
And add your NFC device&lt;br /&gt;
 mkdir -p /etc/nfc/devices.d/&lt;br /&gt;
 echo -e &amp;quot;name = \&amp;quot;PN532 board via UART\&amp;quot; \nconnstring = pn532_uart:/dev/ttyS0&amp;quot; &amp;gt; /etc/nfc/devices.d/pn532_uart.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you actually need to connect reader to chip. Check attached picture to see where to connect each pin.&lt;br /&gt;
&lt;br /&gt;
[[File:Pn532_pinout.png|200px]]&lt;br /&gt;
&lt;br /&gt;
If you did everything right, you should be able to detect the device by running &lt;br /&gt;
 nfc-scan-device&lt;br /&gt;
[[File:Nfc-scan-device.png]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nfc-scan-device.png&amp;diff=120019</id>
		<title>File:Nfc-scan-device.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nfc-scan-device.png&amp;diff=120019"/>
		<updated>2017-04-11T13:03:44Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Pn532_pinout.png&amp;diff=120018</id>
		<title>File:Pn532 pinout.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Pn532_pinout.png&amp;diff=120018"/>
		<updated>2017-04-11T12:57:21Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=OSadmin_wiki_article&amp;diff=119992</id>
		<title>OSadmin wiki article</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=OSadmin_wiki_article&amp;diff=119992"/>
		<updated>2017-04-09T18:48:04Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Chosen topics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Intro=&lt;br /&gt;
*Choose a topic from personal experience related with the subject or from topics found on the wiki page&lt;br /&gt;
*[[#Chosen_topics|Write the topic here]].&lt;br /&gt;
*Lecturer will confirm the topic&lt;br /&gt;
*Write your article in wiki environment &lt;br /&gt;
*Inform the [[Operating_systems#Lecturer|lecturer]] when the article is finished&lt;br /&gt;
*Receive feedback for corrections&lt;br /&gt;
&lt;br /&gt;
=Requirements for the wiki article=&lt;br /&gt;
Author: name, group and date when the article is written&lt;br /&gt;
&lt;br /&gt;
==Introduction ==&lt;br /&gt;
Covers points what will be discussed in the article, what are the requirements for the article reader; what are the operating system’s requirements. &lt;br /&gt;
&lt;br /&gt;
==Contents==&lt;br /&gt;
All commands should be easily separable from the overall text. &lt;br /&gt;
Users should be able to copy the commands directly (additional info like prompt and user distinction symbols should be left out from the command description area)&lt;br /&gt;
The text should determine what user permissions are needed to perform these tasks. &lt;br /&gt;
The reader of your article is your fellow students, so try to avoid irrelevant information and stay on topic (don’t explain the meaning of IP address or how to install Ubuntu, when your topic is actually about htop)&lt;br /&gt;
All the content should be referenced. &lt;br /&gt;
Do not use slang and try to be grammatically correct.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt; &lt;br /&gt;
Bear in mind that this is an open environment, so everything you write in your wiki article, will be public. &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Referencing==&lt;br /&gt;
Best practises of wiki referencing should be used. &lt;br /&gt;
Terms are but between square brackets to reference other articles in the system.&lt;br /&gt;
All drawing and images have to be referenced below the picture and in the text. (for example “System architecture can be viewed on image x, y and z.”)&lt;br /&gt;
Author’s own ideas have to be clearly presentable. Everything used from the sources have to be referenced. &lt;br /&gt;
&lt;br /&gt;
==Fellow student review==&lt;br /&gt;
Please find a fellow student who will review your article and give a feedback on the discussion tab of the article using [http://enos.itcollege.ee/~edmund/materials/viki-artikkel/Assessment-model-for-the-wiki-article.html the following assessment model].&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Besides a short overview, what was discussed in this article, it should also include the author&#039;s own opinion about the topic. &lt;br /&gt;
&lt;br /&gt;
==Category==&lt;br /&gt;
Add the following category to the end of the article (last row):&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Chosen topics=&lt;br /&gt;
Please write here your topic and name, group:&lt;br /&gt;
* &#039;&#039;&#039;Basic Automation with Python&#039;&#039;&#039;; Ardi Vaba; CSE-11&lt;br /&gt;
* &#039;&#039;&#039;SSH Encryption&#039;&#039;&#039;; Frank Korving; CSE-11&lt;br /&gt;
* &#039;&#039;&#039;Translation of OSadmin wiki help page to English [[https://wiki.itcollege.ee/index.php/Osadmin_spikker]]&#039;&#039;&#039;; Peep Kuulme; CSE-11&lt;br /&gt;
* &#039;&#039;&#039;XSS Attack Vectors&#039;&#039;&#039;; Masaki Ihara; CSE-11&lt;br /&gt;
*[https://wiki.itcollege.ee/index.php/Auditd &#039;&#039;&#039;Auditd - Linux system monitoring with audit daemon&#039;&#039;&#039;], Nika Ptskialadze, CSE-11&lt;br /&gt;
* &#039;&#039;&#039;GNU Privacy Guard (GnuPG)&#039;&#039;&#039;; Patricia Bruno Barbosa; CSE-11&lt;br /&gt;
* &#039;&#039;&#039;BackBox OS&#039;&#039;&#039;; Ats Tootsi; CSE-11&lt;br /&gt;
*[https://wiki.itcollege.ee/index.php/creating_malware_lab &#039;&#039;&#039;How to create your own malware analysis lab&#039;&#039;&#039;], Mikus, CSE-11&lt;br /&gt;
*&#039;&#039;&#039;&#039;Arch Linux&#039;&#039;&#039;&#039;;Farhan Nayeem Islam;CSE-C11&lt;br /&gt;
* &#039;&#039;&#039;VPN basics&#039;&#039;&#039;; Christian Cataldo; CSE-11&lt;br /&gt;
&lt;br /&gt;
==Ideas==&lt;br /&gt;
* UNIX CLI password manager https://www.passwordstore.org and its GUI http://qtpass.org/&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
* [https://wiki.itcollege.ee/index.php/Osadmin_referaadi_teemad counterpart article in Estonian]&lt;br /&gt;
* http://manpage.io&lt;br /&gt;
* https://linuxjourney.com/&lt;br /&gt;
* [https://linux.die.net/man/ Linux man-pages]&lt;br /&gt;
* [https://linux.die.net Linux docs]&lt;br /&gt;
* http://www.tecmint.com/60-commands-of-linux-a-guide-from-newbies-to-system-administrator/&lt;br /&gt;
* http://www.tecmint.com/useful-linux-commands-for-system-administrators/&lt;br /&gt;
* http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html&lt;br /&gt;
* http://www.thegeekstuff.com/2010/12/50-unix-linux-sysadmin-tutorials&lt;br /&gt;
&lt;br /&gt;
[[Category:Operatsioonisüsteemide administreerimine ja sidumine]]&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=119991</id>
		<title>Apparmor and its usage</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Apparmor_and_its_usage&amp;diff=119991"/>
		<updated>2017-04-09T18:47:09Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: Created page with &amp;quot;batman beginz&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;batman beginz&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Claiming_GitHub_Student_Developer_Pack&amp;diff=105182</id>
		<title>Claiming GitHub Student Developer Pack</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Claiming_GitHub_Student_Developer_Pack&amp;diff=105182"/>
		<updated>2016-09-01T21:46:10Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: /* Claiming GitHub Student Developer Pack */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;GitHub`s &#039;&#039;Student developer pack&#039;&#039; gives you free access or discounts to various services like GitHub, Digital ocean, Stripe, Namecheap, AWS, Microsoft Azure and others. &lt;br /&gt;
&lt;br /&gt;
You can check full offer [https://education.github.com/pack here]&lt;br /&gt;
&lt;br /&gt;
In order to claim this pack you have to add your &#039;&#039;itcollege.ee&#039;&#039; email to your profile. To do so you login into your profile, click on user picture in right upper corner and click &#039;&#039;Settings&#039;&#039;. Add your &#039;&#039;itcollege.ee&#039;&#039; address in &#039;&#039;&#039;Email&#039;&#039;&#039; section. &lt;br /&gt;
&lt;br /&gt;
[[File:Devpack_add_email.png|300px|border|Adding itcollege.ee email address]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a few seconds you should receive a verification email to your address. Open it and click on verification link provided in email.&lt;br /&gt;
&lt;br /&gt;
[[File:Devpack_verify_email.png|300px|border|Verifying your email]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you verified your address, [https://education.github.com/pack go here], and click &#039;&#039;Get your pack&#039;&#039;, acknowledge that you are a student by clicking another button and fill out form afterwards. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Devpack_form.png|300px|thumb|left|Form]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As far as i can tell they do not really care about your full name and/or your name at all, but who knows, maybe you trigger additional check if you put something propostrous for your name. After you finished and submitted this form, you get text saying that GitHub will contact you in a few weeks. Maybe its true for others but i got second email almost instantly, which confirmed that i now have access to Student Developer Pack.&lt;br /&gt;
&lt;br /&gt;
Again, [https://education.github.com/pack go here], click &#039;&#039;Get your pack&#039;&#039; and voila, you have claimed teh Student Developer Pack.&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Claiming_GitHub_Student_Developer_Pack&amp;diff=105181</id>
		<title>Claiming GitHub Student Developer Pack</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Claiming_GitHub_Student_Developer_Pack&amp;diff=105181"/>
		<updated>2016-09-01T21:44:57Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: Created page with &amp;quot;=Claiming GitHub Student Developer Pack=  GitHub`s &amp;#039;&amp;#039;Student developer pack&amp;#039;&amp;#039; gives you free access or discounts to various services like GitHub, Digital ocean, Stripe, Namech...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Claiming GitHub Student Developer Pack=&lt;br /&gt;
&lt;br /&gt;
GitHub`s &#039;&#039;Student developer pack&#039;&#039; gives you free access or discounts to various services like GitHub, Digital ocean, Stripe, Namecheap, AWS, Microsoft Azure and others. &lt;br /&gt;
&lt;br /&gt;
You can check full offer [https://education.github.com/pack here]&lt;br /&gt;
&lt;br /&gt;
In order to claim this pack you have to add your &#039;&#039;itcollege.ee&#039;&#039; email to your profile. To do so you login into your profile, click on user picture in right upper corner and click &#039;&#039;Settings&#039;&#039;. Add your &#039;&#039;itcollege.ee&#039;&#039; address in &#039;&#039;&#039;Email&#039;&#039;&#039; section. &lt;br /&gt;
&lt;br /&gt;
[[File:Devpack_add_email.png|300px|border|Adding itcollege.ee email address]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a few seconds you should receive a verification email to your address. Open it and click on verification link provided in email.&lt;br /&gt;
&lt;br /&gt;
[[File:Devpack_verify_email.png|300px|border|Verifying your email]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you verified your address, [https://education.github.com/pack go here], and click &#039;&#039;Get your pack&#039;&#039;, acknowledge that you are a student by clicking another button and fill out form afterwards. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Devpack_form.png|300px|thumb|left|Form]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As far as i can tell they do not really care about your full name and/or your name at all, but who knows, maybe you trigger additional check if you put something propostrous for your name. After you finished and submitted this form, you get text saying that GitHub will contact you in a few weeks. Maybe its true for others but i got second email almost instantly, which confirmed that i now have access to Student Developer Pack.&lt;br /&gt;
&lt;br /&gt;
Again, [https://education.github.com/pack go here], click &#039;&#039;Get your pack&#039;&#039; and voila, you have claimed teh Student Developer Pack.&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Devpack_add_email.png&amp;diff=105180</id>
		<title>File:Devpack add email.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Devpack_add_email.png&amp;diff=105180"/>
		<updated>2016-09-01T21:29:08Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: Mteivens uploaded a new version of File:Devpack add email.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Devpack_verify_email.png&amp;diff=105179</id>
		<title>File:Devpack verify email.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Devpack_verify_email.png&amp;diff=105179"/>
		<updated>2016-09-01T21:12:59Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Devpack_form.png&amp;diff=105178</id>
		<title>File:Devpack form.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Devpack_form.png&amp;diff=105178"/>
		<updated>2016-09-01T21:12:41Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Devpack_add_email.png&amp;diff=105177</id>
		<title>File:Devpack add email.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Devpack_add_email.png&amp;diff=105177"/>
		<updated>2016-09-01T21:12:25Z</updated>

		<summary type="html">&lt;p&gt;Mteivens: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mteivens</name></author>
	</entry>
</feed>