v0.2.1
-----BEGIN PGP SIGNATURE-----

iQIcBAABCgAGBQJZOB22AAoJEBjzaFwAIr/zzZkP/RWF1/ylslIYJCPwiNxTnHmE
Q3afFNRw/qjj0OG6KI24kn6BqVKBhLWbF9GGXRo7zhkeQDEcFwu0By6GI9T3zDsR
abZi6LkLx86rgeSEcQIZK2hb9WmsRMHkncfjDVJNG0Kx3Z3EW691Hxc+eNQcnfrz
LxsGcikOZ+x2++Y53kgrkspSqU56RNW/D9r1sm0Fkj8IgeSCsrFas91Z9Z12WkCP
QPWUi8ToGi53Dp5XeoIz2v0iiigza8CgEgEgM+rKctMFqoynOJIa1NHvY7tIDlrb
SaC42rYGZtJVYYAZXG9tuMpHoSeokLrQT/Bp6CVMONjE6mEPDdFFs7UfDF+NNqVW
ZLy1tUAlo9qkjpTtcC/8VPQ/XZu8O4VEdWazkRuPg0olS5eW3ubdi1rUippBqvN8
ixnV9IX8JRUDq7EyJu5ObzA3KMZARqefG3x+Lp/5UQxOyKnlrfkHOFpzcixsB13q
Uk0VAu7mgqQosTedpS4av4Zkyn5t9zX6LeItEKl6GkQfGTFWaTkMDPDUjhC3q9H/
OICfDyIMEFDzoTNA9tr+CUVQZYkAhcM5gfHwFI2hVpwoXgo0/rPoJrp3oVyiXFDm
76WWss0iXKFCiDL9987nMgAA12LArmvIy3DTNBOKIFgyqpoeHDYdQYePtwcnZXP3
udzqFmsKK1iOEwKbn17M
=/xWj
-----END PGP SIGNATURE-----
Bump version to v0.2.1

Signed-off-by: Jess Frazelle <acidburn@google.com>
2 files changed
tree: 85fabd79a66c3833177f9bff18f9faa7d1d421bf
  1. .gitignore
  2. .travis.yml
  3. Dockerfile
  4. LICENSE
  5. Makefile
  6. README.md
  7. VERSION
  8. apparmor/
  9. bane.jpg
  10. docker-nginx-sample
  11. main.go
  12. sample.toml
  13. vendor/
  14. version/
README.md

bane

Travis CI

AppArmor profile generator for docker containers. Basically a better AppArmor profile, than creating one by hand, because who would ever do that.

"Reviewing AppArmor profile pull requests is the bane of my existence"

  • Jess Frazelle

bane

Installation

Binaries

Via Go

$ go get github.com/jessfraz/bane

Usage

$ bane -h
 _
| |__   __ _ _ __   ___
| '_ \ / _` | '_ \ / _ \
| |_) | (_| | | | |  __/
|_.__/ \__,_|_| |_|\___|
 Custom AppArmor profile generator for docker containers
 Version: v0.2.1

  -d    run in debug mode
  -profile-dir string
        directory for saving the profiles (default "/etc/apparmor.d/containers")
  -v    print version and exit (shorthand)
  -version
        print version and exit

Config File

sample.toml is a AppArmor sample config for nginx in a container.

File Globbing

Glob ExampleDescription
/dir/filematch a specific file
/dir/*match any files in a directory (including dot files)
/dir/a*match any file in a directory starting with a
/dir/*.pngmatch any file in a directory ending with .png
/dir/[^.]*match any file in a directory except dot files
/dir/match a directory
/dir/*/match any directory within /dir/
/dir/a*/match any directory within /dir/ starting with a
/dir/*a/match any directory within /dir/ ending with a
/dir/**match any file or directory in or below /dir/
/dir/**/match any directory in or below /dir/
/dir/**[^/]match any file in or below /dir/
/dir{,1,2}/**match any file or directory in or below /dir/, /dir1/, and /dir2/

Installing a Profile

Now that we have our config file from above let's install it. bane will automatically install the profile in a directory /etc/apparmor.d/containers/ and run apparmor_parser.

$ sudo bane sample.toml
# Profile installed successfully you can now run the profile with
# `docker run --security-opt="apparmor:docker-nginx-sample"`

# now let's run nginx
$ docker run -d --security-opt="apparmor:docker-nginx-sample" -p 80:80 nginx

Using custom AppArmor profiles has never been easier!

Now let's try to do malicious activities with the sample profile:

$ docker run --security-opt="apparmor:docker-nginx-sample" -p 80:80 --rm -it nginx bash
root@6da5a2a930b9:~# ping 8.8.8.8
ping: Lacking privilege for raw socket.

root@6da5a2a930b9:/# top
bash: /usr/bin/top: Permission denied

root@6da5a2a930b9:~# touch ~/thing
touch: cannot touch 'thing': Permission denied

root@6da5a2a930b9:/# sh
bash: /bin/sh: Permission denied

root@6da5a2a930b9:/# dash
bash: /bin/dash: Permission denied

Sample dmesg output when using LogOnWritePaths:

[ 1964.142128] type=1400 audit(1444369315.090:38): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="docker-nginx" pid=3945 comm="apparmor_parser"
[ 1966.620327] type=1400 audit(1444369317.570:39): apparmor="AUDIT" operation="open" profile="docker-nginx" name="/1" pid=3985 comm="nginx" requested_mask="c" fsuid=0 ouid=0
[ 1966.624381] type=1400 audit(1444369317.574:40): apparmor="AUDIT" operation="mkdir" profile="docker-nginx" name="/var/cache/nginx/client_temp/" pid=3985 comm="nginx" requested_mask="c" fsuid=0 ouid=0
[ 1966.624446] type=1400 audit(1444369317.574:41): apparmor="AUDIT" operation="chown" profile="docker-nginx" name="/var/cache/nginx/client_temp/" pid=3985 comm="nginx" requested_mask="w" fsuid=0 ouid=0
[ 1966.624463] type=1400 audit(1444369317.574:42): apparmor="AUDIT" operation="mkdir" profile="docker-nginx" name="/var/cache/nginx/proxy_temp/" pid=3985 comm="nginx" requested_mask="c" fsuid=0 ouid=0
[ 1966.624494] type=1400 audit(1444369317.574:43): apparmor="AUDIT" operation="chown" profile="docker-nginx" name="/var/cache/nginx/proxy_temp/" pid=3985 comm="nginx" requested_mask="w" fsuid=0 ouid=0
[ 1966.624507] type=1400 audit(1444369317.574:44): apparmor="AUDIT" operation="mkdir" profile="docker-nginx" name="/var/cache/nginx/fastcgi_temp/" pid=3985 comm="nginx" requested_mask="c" fsuid=0 ouid=0
[ 1966.624534] type=1400 audit(1444369317.574:45): apparmor="AUDIT" operation="chown" profile="docker-nginx" name="/var/cache/nginx/fastcgi_temp/" pid=3985 comm="nginx" requested_mask="w" fsuid=0 ouid=0
[ 1966.624546] type=1400 audit(1444369317.574:46): apparmor="AUDIT" operation="mkdir" profile="docker-nginx" name="/var/cache/nginx/uwsgi_temp/" pid=3985 comm="nginx" requested_mask="c" fsuid=0 ouid=0
[ 1966.624582] type=1400 audit(1444369317.574:47): apparmor="AUDIT" operation="chown" profile="docker-nginx" name="/var/cache/nginx/uwsgi_temp/" pid=3985 comm="nginx" requested_mask="w" fsuid=0 ouid=0

What does the generated profile look like?

For the above sample.toml the generated profile is available as docker-nginx-sample.

Integration with Docker

This was originally a proof of concept for what will hopefully become a native security profile in the Docker engine. For more information on this, see docker/docker#17142.