2021-08-23 09:14:53 -04:00
|
|
|
//go:build !windows
|
|
|
|
// +build !windows
|
2016-12-19 07:22:45 -05:00
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-12-19 07:22:45 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/container"
|
2018-01-11 14:53:06 -05:00
|
|
|
"github.com/docker/docker/errdefs"
|
2016-12-19 07:22:45 -05:00
|
|
|
)
|
|
|
|
|
2019-08-09 06:33:15 -04:00
|
|
|
func (daemon *Daemon) saveAppArmorConfig(container *container.Container) error {
|
2019-11-27 09:43:53 -05:00
|
|
|
container.AppArmorProfile = "" // we don't care about the previous value.
|
2016-12-19 07:22:45 -05:00
|
|
|
|
daemon: load and cache sysInfo on initialization
The `daemon.RawSysInfo()` function can be a heavy operation, as it collects
information about all cgroups on the host, networking, AppArmor, Seccomp, etc.
While looking at our code, I noticed that various parts in the code call this
function, potentially even _multiple times_ per container, for example, it is
called from:
- `verifyPlatformContainerSettings()`
- `oci.WithCgroups()` if the daemon has `cpu-rt-period` or `cpu-rt-runtime` configured
- in `ContainerDecoder.DecodeConfig()`, which is called on boith `container create` and `container commit`
Given that this information is not expected to change during the daemon's
lifecycle, and various information coming from this (such as seccomp and
apparmor status) was already cached, we may as well load it once, and cache
the results in the daemon instance.
This patch updates `daemon.RawSysInfo()` to use a `sync.Once()` so that
it's only executed once for the daemon's lifecycle.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-01-07 06:54:47 -05:00
|
|
|
if !daemon.RawSysInfo().AppArmor {
|
2016-12-19 07:22:45 -05:00
|
|
|
return nil // if apparmor is disabled there is nothing to do here.
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := parseSecurityOpt(container, container.HostConfig); err != nil {
|
2017-11-28 23:09:37 -05:00
|
|
|
return errdefs.InvalidParameter(err)
|
2016-12-19 07:22:45 -05:00
|
|
|
}
|
|
|
|
|
daemon: load and cache sysInfo on initialization
The `daemon.RawSysInfo()` function can be a heavy operation, as it collects
information about all cgroups on the host, networking, AppArmor, Seccomp, etc.
While looking at our code, I noticed that various parts in the code call this
function, potentially even _multiple times_ per container, for example, it is
called from:
- `verifyPlatformContainerSettings()`
- `oci.WithCgroups()` if the daemon has `cpu-rt-period` or `cpu-rt-runtime` configured
- in `ContainerDecoder.DecodeConfig()`, which is called on boith `container create` and `container commit`
Given that this information is not expected to change during the daemon's
lifecycle, and various information coming from this (such as seccomp and
apparmor status) was already cached, we may as well load it once, and cache
the results in the daemon instance.
This patch updates `daemon.RawSysInfo()` to use a `sync.Once()` so that
it's only executed once for the daemon's lifecycle.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-01-07 06:54:47 -05:00
|
|
|
if container.HostConfig.Privileged {
|
2019-10-12 18:04:44 -04:00
|
|
|
container.AppArmorProfile = unconfinedAppArmorProfile
|
daemon: load and cache sysInfo on initialization
The `daemon.RawSysInfo()` function can be a heavy operation, as it collects
information about all cgroups on the host, networking, AppArmor, Seccomp, etc.
While looking at our code, I noticed that various parts in the code call this
function, potentially even _multiple times_ per container, for example, it is
called from:
- `verifyPlatformContainerSettings()`
- `oci.WithCgroups()` if the daemon has `cpu-rt-period` or `cpu-rt-runtime` configured
- in `ContainerDecoder.DecodeConfig()`, which is called on boith `container create` and `container commit`
Given that this information is not expected to change during the daemon's
lifecycle, and various information coming from this (such as seccomp and
apparmor status) was already cached, we may as well load it once, and cache
the results in the daemon instance.
This patch updates `daemon.RawSysInfo()` to use a `sync.Once()` so that
it's only executed once for the daemon's lifecycle.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-01-07 06:54:47 -05:00
|
|
|
} else if container.AppArmorProfile == "" {
|
|
|
|
container.AppArmorProfile = defaultAppArmorProfile
|
2016-12-19 07:22:45 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|