exec_linux.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package daemon
  2. import (
  3. "github.com/docker/docker/container"
  4. "github.com/docker/docker/daemon/caps"
  5. "github.com/docker/docker/daemon/exec"
  6. "github.com/opencontainers/runc/libcontainer/apparmor"
  7. "github.com/opencontainers/runtime-spec/specs-go"
  8. )
  9. func (daemon *Daemon) execSetPlatformOpt(c *container.Container, ec *exec.Config, p *specs.Process) error {
  10. if len(ec.User) > 0 {
  11. uid, gid, additionalGids, err := getUser(c, ec.User)
  12. if err != nil {
  13. return err
  14. }
  15. p.User = specs.User{
  16. UID: uid,
  17. GID: gid,
  18. AdditionalGids: additionalGids,
  19. }
  20. }
  21. if ec.Privileged {
  22. if p.Capabilities == nil {
  23. p.Capabilities = &specs.LinuxCapabilities{}
  24. }
  25. p.Capabilities.Bounding = caps.GetAllCapabilities()
  26. p.Capabilities.Permitted = p.Capabilities.Bounding
  27. p.Capabilities.Inheritable = p.Capabilities.Bounding
  28. p.Capabilities.Effective = p.Capabilities.Bounding
  29. }
  30. if apparmor.IsEnabled() {
  31. var appArmorProfile string
  32. if c.AppArmorProfile != "" {
  33. appArmorProfile = c.AppArmorProfile
  34. } else if c.HostConfig.Privileged {
  35. appArmorProfile = "unconfined"
  36. } else {
  37. appArmorProfile = "docker-default"
  38. }
  39. if appArmorProfile == "docker-default" {
  40. // Unattended upgrades and other fun services can unload AppArmor
  41. // profiles inadvertently. Since we cannot store our profile in
  42. // /etc/apparmor.d, nor can we practically add other ways of
  43. // telling the system to keep our profile loaded, in order to make
  44. // sure that we keep the default profile enabled we dynamically
  45. // reload it if necessary.
  46. if err := ensureDefaultAppArmorProfile(); err != nil {
  47. return err
  48. }
  49. }
  50. }
  51. daemon.setRlimits(&specs.Spec{Process: p}, c)
  52. return nil
  53. }