exec_linux.go 1.9 KB

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