Skip to content

Conversation

@ewindisch
Copy link
Contributor

The automatic installation of AppArmor policies prevents the
management of custom, site-specific apparmor policies for the
default container profile. Furthermore, this change will allow
a future policy for the engine itself to be written without demanding
the engine be able to arbitrarily create and manage AppArmor policies.

This change also introduces tests for the AppArmor policy and
removes a couple ineffective rules.

Signed-off-by: Eric Windisch [email protected]

@ewindisch ewindisch force-pushed the apparmor-policy branch 3 times, most recently from 0992a8a to 97c4f9d Compare May 12, 2015 04:08
ewindisch added a commit to ewindisch/docker that referenced this pull request May 12, 2015
Wraps the engine itself with an AppArmor policy.

This restricts what may be done via a reexec,
or through applications we call out to, such as 'xz'.

Significantly, this policy restricts the policies
to which a container may be spawned into. By default,
users will be able to transition to an unconfined
policy or any policy prefaced with 'docker-'.

Local operators may add new local policies prefaced
with 'docker-' without needing to modify this policy.
Operators choosing to disable privileged containers
will need to modify this policy to remove access
to change_policy to unconfined.

Builds on top of PR moby#13144.

Signed-off-by: Eric Windisch <[email protected]>
@jessfraz
Copy link
Contributor

This will need to be added to the new debs, I can send u a PR or we can update after merge

@crosbymichael
Copy link
Contributor

@tianon

this change is fine with me

@jessfraz
Copy link
Contributor

is there 2 prs open for this?

EDIT nm i get it

@jessfraz
Copy link
Contributor

LGTM

hack/make/ubuntu Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Suggests" would be the appropriate dependency here, not "Recommends"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, checking back with the debian policy manual, I really prefer this is a Recommends. It's not simply suggested to use an LSM with Docker. Recommends is also what we use for the debian packages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually have documentation that explains how to use an LSM effectively in combination with Docker? Without telling users how to actually use this in the real world, we're just blindly setting it and hoping it helps (and with our default profile, making sure it helps for our own desired "use cases" that we think the majority of people use Docker for/in).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tianon I agree better documentation should be written, but AppArmor simply works out of the box. I haven't seen an Ubuntu machine where Docker and AppArmor weren't just working straight of the box. While documentation would be nice, it isn't necessary for this to be effective for users. It's a good, working default.

It can be argued that breaking out of a container is not something that users should care about, but to the degree that users do care about this, using an LSM is essential. With all kernels to date, it is trivial to break out of a container where an LSM is not used. Using an LSM cannot eliminate that threat, especially against kernel RCEs, but does makes it much more difficult to execute a local privilege escalation.

That said, I believe the policy could be locked down further, both by default, and by local preference. I have been developing better policies in order to improve the default, which I intend to introduce in a separate PR. The work I've done on building a hardened policy would be good material for documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tianon you make the recommendation on #13156 that a Debian user using the "ubuntu" FPM packages might get AppArmor installed when they don't want it. I suppose that's true. However, they should want AppArmor or SELinux and I think recommending them is reasonable. If the argument is that the user might prefer SELinux and this package is not flexible enough... perhaps we should have an lxc-docker-lsm package that specifies the recommendation with provided-by lxc-docker-lsm-apparmor lxc-docker-lsm-selinux? Then, installs could happen with no LSM (it's still optional), or could satisfy the apt recommendation by either LSM module.

This seems complicated, but seems to be within the model of Debian packaging semantics.

Copy link
Member

@tianon tianon Jun 1, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tianon
Copy link
Member

tianon commented May 19, 2015

This also needs to happen in hack/make/build-deb via dh-apparmor, which needs to be added to the list of packages in contrib/builder/deb/generate.sh and then the appropriate bits added in hack/make/.build-deb (http://manpages.debian.org/dh_apparmor).

@tianon
Copy link
Member

tianon commented May 19, 2015

Also, this could be considered a regression, since this is happening the way it is today specifically so that people on systems that use AppArmor can install using the static binary without adding any extra files, so this change needs to be considered carefully.

I'm personally +1 on the change, but it is a departure from our traditional stance of "only need this one binary".

hack/make/ubuntu Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the extra space here intentional or accidental? (/etc/apparmor.d/ docker)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The space is intentional.

The 'aa-status --enabled' is entirely reasonable. Libcontainer was using the check for the binary, which is a terrible way to check, but I was keeping for a minimal change.

@ewindisch
Copy link
Contributor Author

I'm going to update this with suggestions from Tianon.

@tianon FWIW, the SELinux policy isn't included either. One big advantage of having this in packaging is that it becomes possible for users/deployers to roll out a customized default policy. That said, the potential for a dynamic per-container policy (a la process labels) could change how we look at this...

Finally, if we don't want to (immediately) move the policy into packaging then perhaps we merge this into libcontainer? docker-archive/libcontainer#579

@tianon
Copy link
Member

tianon commented May 19, 2015 via email

ewindisch added a commit to ewindisch/docker that referenced this pull request May 28, 2015
Wraps the engine itself with an AppArmor policy.

This restricts what may be done via a reexec,
or through applications we call out to, such as 'xz'.

Significantly, this policy restricts the policies
to which a container may be spawned into. By default,
users will be able to transition to an unconfined
policy or any policy prefaced with 'docker-'.

Local operators may add new local policies prefaced
with 'docker-' without needing to modify this policy.
Operators choosing to disable privileged containers
will need to modify this policy to remove access
to change_policy to unconfined.

Builds on top of PR moby#13144.

Signed-off-by: Eric Windisch <[email protected]>
@ewindisch ewindisch force-pushed the apparmor-policy branch 2 times, most recently from 6dae1f6 to 52715f8 Compare May 29, 2015 14:59
@ewindisch
Copy link
Contributor Author

Now with tests! (and rebased)

ewindisch added a commit to ewindisch/docker that referenced this pull request May 29, 2015
Wraps the engine itself with an AppArmor policy.

This restricts what may be done via a reexec,
or through applications we call out to, such as 'xz'.

Significantly, this policy restricts the policies
to which a container may be spawned into. By default,
users will be able to transition to an unconfined
policy or any policy prefaced with 'docker-'.

Local operators may add new local policies prefaced
with 'docker-' without needing to modify this policy.
Operators choosing to disable privileged containers
will need to modify this policy to remove access
to change_policy to unconfined.

Builds on top of PR moby#13144.

Signed-off-by: Eric Windisch <[email protected]>
@ewindisch ewindisch force-pushed the apparmor-policy branch 2 times, most recently from a803f41 to a649a65 Compare June 2, 2015 15:28
@ewindisch
Copy link
Contributor Author

Made this less controversial / safer to merge:

  • Keeps it as a 'suggests' on Debian (although I'd like to change this later...)
  • Does not change the AppArmor policy from what is currently in libcontainer

I'll submit subsequent PRs to tighten the policy and add further tests.

@tianon
Copy link
Member

tianon commented Jun 2, 2015

LGTM (although eyebrow raise at 8 commits 😄)

@ewindisch
Copy link
Contributor Author

@tianon I could squash if it's worthwhile. shrug

@thaJeztah
Copy link
Member

Well, we tell every other contributor to squash, so...

image

The automatic installation of AppArmor policies prevents the
management of custom, site-specific apparmor policies for the
default container profile. Furthermore, this change will allow
a future policy for the engine itself to be written without demanding
the engine be able to arbitrarily create and manage AppArmor policies.

- Add deb package suggests for apparmor.
- Ubuntu postinst use aa-status & fix policy path
- Add the policies to the debian packages.
- Add apparmor tests for writing proc files
Additional restrictions against modifying files in proc
are enforced by AppArmor. Ensure that AppArmor is preventing
access to these files, not simply Docker's configuration of proc.
- Remove /proc/k?mem from AA policy
The path to mem and kmem are in /dev, not /proc
and cannot be restricted successfully through AppArmor.
The device cgroup will need to be sufficient here.
- Load contrib/apparmor during integration tests
Note that this is somewhat dirty because we
cannot restore the host to its original configuration.
However, it should be noted that prior to this patch
series, the Docker daemon itself was loading apparmor
policy from within the tests, so this is no dirtier or
uglier than the status-quo.

Signed-off-by: Eric Windisch <[email protected]>
@ewindisch
Copy link
Contributor Author

squashed

@thaJeztah
Copy link
Member

💓 thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfrazelle you were planning to take over adding the dh-apparmor bits to actually plumb this into the maintscripts automatically post-merge, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tianon are you just asking use of dh_apparmor here?

Copy link
Member

@tianon tianon Jun 15, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tianon
Copy link
Member

tianon commented Jun 8, 2015

LGTM -- @jfrazelle you decide who's going to add the rest of the build-deb bits 😉 (I'm happy to do it or to defer to you)

@ewindisch
Copy link
Contributor Author

@jfrazelle @tianon happy to look into it myself, not sure what other build-deb bits you're looking for...

@calavera
Copy link
Contributor

it needs a rebase 😔

@crosbymichael
Copy link
Contributor

@ewindisch ping!

reopen when you have this rebased and ready to be looked at again.

thanks

@ewindisch
Copy link
Contributor Author

@crosbymichael rebase and fixes for @unclejack applied.

@thaJeztah
Copy link
Member

@ewindisch oh! Looks like you'll have to create a new pull-request, because GitHub doesn't update PRs if they are closed (and I can no longer re-open because of that) :'(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants