2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
import (
|
2019-04-10 14:45:14 -04:00
|
|
|
"context"
|
|
|
|
|
2021-04-08 09:37:13 -04:00
|
|
|
"github.com/containerd/containerd/pkg/apparmor"
|
2016-03-18 14:50:19 -04:00
|
|
|
"github.com/docker/docker/container"
|
|
|
|
"github.com/docker/docker/daemon/exec"
|
2018-12-10 15:40:40 -05:00
|
|
|
"github.com/docker/docker/oci/caps"
|
2019-08-05 10:37:47 -04:00
|
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
2016-03-18 14:50:19 -04:00
|
|
|
)
|
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
func (daemon *Daemon) execSetPlatformOpt(c *container.Container, ec *exec.Config, p *specs.Process) error {
|
2016-03-18 14:50:19 -04:00
|
|
|
if len(ec.User) > 0 {
|
2020-07-29 08:26:05 -04:00
|
|
|
var err error
|
|
|
|
p.User, err = getUser(c, ec.User)
|
2016-03-18 14:50:19 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ec.Privileged {
|
2022-01-31 15:08:01 -05:00
|
|
|
p.Capabilities = &specs.LinuxCapabilities{
|
|
|
|
Bounding: caps.GetAllCapabilities(),
|
|
|
|
Permitted: caps.GetAllCapabilities(),
|
|
|
|
Effective: caps.GetAllCapabilities(),
|
2017-09-22 09:52:41 -04:00
|
|
|
}
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
2021-04-08 09:37:13 -04:00
|
|
|
if apparmor.HostSupports() {
|
2017-03-12 23:57:35 -04:00
|
|
|
var appArmorProfile string
|
|
|
|
if c.AppArmorProfile != "" {
|
|
|
|
appArmorProfile = c.AppArmorProfile
|
|
|
|
} else if c.HostConfig.Privileged {
|
2018-03-02 07:17:56 -05:00
|
|
|
// `docker exec --privileged` does not currently disable AppArmor
|
|
|
|
// profiles. Privileged configuration of the container is inherited
|
2019-10-12 18:04:44 -04:00
|
|
|
appArmorProfile = unconfinedAppArmorProfile
|
2017-03-12 23:57:35 -04:00
|
|
|
} else {
|
2019-08-09 06:33:15 -04:00
|
|
|
appArmorProfile = defaultAppArmorProfile
|
2017-03-12 23:57:35 -04:00
|
|
|
}
|
|
|
|
|
2019-08-09 06:33:15 -04:00
|
|
|
if appArmorProfile == defaultAppArmorProfile {
|
2017-03-12 23:57:35 -04:00
|
|
|
// Unattended upgrades and other fun services can unload AppArmor
|
|
|
|
// profiles inadvertently. Since we cannot store our profile in
|
|
|
|
// /etc/apparmor.d, nor can we practically add other ways of
|
|
|
|
// telling the system to keep our profile loaded, in order to make
|
|
|
|
// sure that we keep the default profile enabled we dynamically
|
|
|
|
// reload it if necessary.
|
|
|
|
if err := ensureDefaultAppArmorProfile(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 07:17:56 -05:00
|
|
|
p.ApparmorProfile = appArmorProfile
|
2017-03-12 23:57:35 -04:00
|
|
|
}
|
2019-04-10 14:45:14 -04:00
|
|
|
s := &specs.Spec{Process: p}
|
|
|
|
return WithRlimits(daemon, c)(context.Background(), nil, nil, s)
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|