How to configure AppArmor profile for Apache2 on Ubuntu 14.04 LTS?

Jaime Bonilla
Jaime Bonilla used Ask the Experts™
on
I am trying to configure an ubuntu (14.04 LTS) linux server with apparmor to protect the Apache2 web server, but I can't find any best practice or how-to guides for this specific purpose, only some basic guides for apparmor with the default profiles which do not include apache2 configuration. The ubuntu web server is running Apache2, Drupal 7, and MySQL. Is there a basic template for the AppArmor-Apache2 config that I should be implementing for basic security or is this something that has to be specific to the site?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

Here's a template for apache2 that might help you out to start with.

It may be more or less restrictive for what you're running on your website (for example, I don't use MySQL), so you'll need to run it for a while in complain mode until you don't see any more "audit" warnings in /var/log/messages.

You will also need to add read permission for your website's document root.

/usr/sbin/apache2 flags=(complain) {
#include <abstractions/base>

capability kill,
capability net_bind_service,
capability setuid,
capability setgid,
network inet,
network inet6,

/dev/tty rw,
/etc/apache2/** r,
/etc/gai.conf r,
/etc/group r,
/etc/host* r,
/etc/mime.types r,
/etc/nsswitch.conf r,
/etc/passwd r,
/etc/php5/apache2/php.ini r,
/etc/php5/conf.d/ r,
/etc/php5/conf.d/*.ini r,
/etc/protocols r,
/etc/resolv.conf r,
/etc/services r,
/proc/[0-9]*/mounts r,
/proc/filesystems r,
/usr/bin/env rix,
/usr/bin/host rix,
/usr/lib/apache2/modules/** mr,
/usr/lib/php5/[0-9]*/*.so rix,
/usr/sbin/apache2 r,
/usr/share/apache2/icons/* r,
/usr/share/file/magic.mime r,
/usr/share/zoneinfo/ r,
/var/log/apache2/** rw,
/var/run/apache2.pid w,
/tmp/ rw,
/tmp/php* rw,
}

Open in new window

Cheers
Jaime BonillaSystems Admininistrator

Author

Commented:
Thank you for the response DFKE, that gives me an idea of a basic/starting template.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial