Skip to content

Commit d97a00d

Browse files
committed
Added an apparmorEnabled boolean in the Daemon struct to indicate if AppArmor is enabled or not. It is set in NewDaemon using sysInfo information.
Signed-off-by: Roberto Muñoz Fernández <[email protected]> Added an apparmorEnabled boolean in the Daemon struct to indicate if AppArmor is enabled or not. It is set in NewDaemon using sysInfo information. Signed-off-by: Roberto Muñoz Fernández <[email protected]> gofmt'd Signed-off-by: Roberto Muñoz Fernández <[email protected]> change the function name to something more adequate and changed the behaviour to show empty value on an apparmor disabled system. Signed-off-by: Roberto Muñoz Fernández <[email protected]> go fmt Signed-off-by: Roberto Muñoz Fernández <[email protected]>
1 parent 48dd90d commit d97a00d

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

daemon/container_linux.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//+build !windows
2+
3+
package daemon
4+
5+
import (
6+
"github.com/docker/docker/container"
7+
)
8+
9+
func (daemon *Daemon) saveApparmorConfig(container *container.Container) error {
10+
container.AppArmorProfile = "" //we don't care about the previous value.
11+
12+
if !daemon.apparmorEnabled {
13+
return nil // if apparmor is disabled there is nothing to do here.
14+
}
15+
16+
if err := parseSecurityOpt(container, container.HostConfig); err != nil {
17+
return err
18+
}
19+
20+
if !container.HostConfig.Privileged {
21+
if container.AppArmorProfile == "" {
22+
container.AppArmorProfile = defaultApparmorProfile
23+
}
24+
25+
} else {
26+
container.AppArmorProfile = "unconfined"
27+
}
28+
return nil
29+
}

daemon/container_windows.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//+build windows
2+
3+
package daemon
4+
5+
import (
6+
"github.com/docker/docker/container"
7+
)
8+
9+
func (daemon *Daemon) saveApparmorConfig(container *container.Container) error {
10+
return nil
11+
}

daemon/daemon.go

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type Daemon struct {
9292
discoveryWatcher discoveryReloader
9393
root string
9494
seccompEnabled bool
95+
apparmorEnabled bool
9596
shutdown bool
9697
uidMaps []idtools.IDMap
9798
gidMaps []idtools.IDMap
@@ -683,6 +684,7 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
683684
d.uidMaps = uidMaps
684685
d.gidMaps = gidMaps
685686
d.seccompEnabled = sysInfo.Seccomp
687+
d.apparmorEnabled = sysInfo.AppArmor
686688

687689
d.nameIndex = registrar.NewRegistrar()
688690
d.linkIndex = newLinkIndex()

daemon/start.go

+4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
164164
checkpointDir = container.CheckpointDir()
165165
}
166166

167+
if daemon.saveApparmorConfig(container); err != nil {
168+
return err
169+
}
170+
167171
if err := daemon.containerd.Create(container.ID, checkpoint, checkpointDir, *spec, container.InitializeStdio, createOptions...); err != nil {
168172
errDesc := grpc.ErrorDesc(err)
169173
contains := func(s1, s2 string) bool {

0 commit comments

Comments
 (0)