exec_linux.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package daemon // import "github.com/docker/docker/daemon"
  2. import (
  3. "context"
  4. "github.com/docker/docker/container"
  5. "github.com/docker/docker/daemon/exec"
  6. "github.com/docker/docker/oci/caps"
  7. "github.com/opencontainers/runc/libcontainer/apparmor"
  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. 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. if p.Capabilities == nil {
  24. p.Capabilities = &specs.LinuxCapabilities{}
  25. }
  26. p.Capabilities.Bounding = caps.GetAllCapabilities()
  27. p.Capabilities.Permitted = p.Capabilities.Bounding
  28. p.Capabilities.Inheritable = p.Capabilities.Bounding
  29. p.Capabilities.Effective = p.Capabilities.Bounding
  30. }
  31. if apparmor.IsEnabled() {
  32. var appArmorProfile string
  33. if c.AppArmorProfile != "" {
  34. appArmorProfile = c.AppArmorProfile
  35. } else if c.HostConfig.Privileged {
  36. // `docker exec --privileged` does not currently disable AppArmor
  37. // profiles. Privileged configuration of the container is inherited
  38. appArmorProfile = unconfinedAppArmorProfile
  39. } else {
  40. appArmorProfile = defaultApparmorProfile
  41. }
  42. if appArmorProfile == defaultApparmorProfile {
  43. // Unattended upgrades and other fun services can unload AppArmor
  44. // profiles inadvertently. Since we cannot store our profile in
  45. // /etc/apparmor.d, nor can we practically add other ways of
  46. // telling the system to keep our profile loaded, in order to make
  47. // sure that we keep the default profile enabled we dynamically
  48. // reload it if necessary.
  49. if err := ensureDefaultAppArmorProfile(); err != nil {
  50. return err
  51. }
  52. }
  53. p.ApparmorProfile = appArmorProfile
  54. }
  55. s := &specs.Spec{Process: p}
  56. return WithRlimits(daemon, c)(context.Background(), nil, nil, s)
  57. }