exec_linux.go 1.4 KB

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