Move security opts to HostConfig
These settings need to be in the HostConfig so that they are not committed to an image and cannot introduce a security issue. We can safely move this field from the Config to the HostConfig without any regressions because these settings are consumed at container created and used to populate fields on the Container struct. Because of this, existing settings will be honored for containers already created on a daemon with custom security settings and prevent values being consumed via an Image. Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Upstream-commit: c9379eb3fbbc484c056f5a5e49d8d0b755a29c45 Component: engine
This commit is contained in:
committed by
unclejack
parent
b4519950ef
commit
b670ee9b69
@ -528,10 +528,10 @@ func (daemon *Daemon) getEntrypointAndArgs(configEntrypoint, configCmd []string)
|
||||
return entrypoint, args
|
||||
}
|
||||
|
||||
func parseSecurityOpt(container *Container, config *runconfig.Config) error {
|
||||
func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error {
|
||||
var (
|
||||
label_opts []string
|
||||
err error
|
||||
labelOpts []string
|
||||
err error
|
||||
)
|
||||
|
||||
for _, opt := range config.SecurityOpt {
|
||||
@ -541,7 +541,7 @@ func parseSecurityOpt(container *Container, config *runconfig.Config) error {
|
||||
}
|
||||
switch con[0] {
|
||||
case "label":
|
||||
label_opts = append(label_opts, con[1])
|
||||
labelOpts = append(labelOpts, con[1])
|
||||
case "apparmor":
|
||||
container.AppArmorProfile = con[1]
|
||||
default:
|
||||
@ -549,7 +549,7 @@ func parseSecurityOpt(container *Container, config *runconfig.Config) error {
|
||||
}
|
||||
}
|
||||
|
||||
container.ProcessLabel, container.MountLabel, err = label.InitLabels(label_opts)
|
||||
container.ProcessLabel, container.MountLabel, err = label.InitLabels(labelOpts)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -583,7 +583,6 @@ func (daemon *Daemon) newContainer(name string, config *runconfig.Config, img *i
|
||||
execCommands: newExecStore(),
|
||||
}
|
||||
container.root = daemon.containerRoot(container.ID)
|
||||
err = parseSecurityOpt(container, config)
|
||||
return container, err
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
|
||||
func TestParseSecurityOpt(t *testing.T) {
|
||||
container := &Container{}
|
||||
config := &runconfig.Config{}
|
||||
config := &runconfig.HostConfig{}
|
||||
|
||||
// test apparmor
|
||||
config.SecurityOpt = []string{"apparmor:test_profile"}
|
||||
|
||||
@ -44,6 +44,9 @@ func (daemon *Daemon) ContainerStart(job *engine.Job) engine.Status {
|
||||
}
|
||||
|
||||
func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.HostConfig) error {
|
||||
if err := parseSecurityOpt(container, hostConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
// Validate the HostConfig binds. Make sure that:
|
||||
// the source exists
|
||||
for _, bind := range hostConfig.Binds {
|
||||
|
||||
@ -32,7 +32,6 @@ type Config struct {
|
||||
Entrypoint []string
|
||||
NetworkDisabled bool
|
||||
OnBuild []string
|
||||
SecurityOpt []string
|
||||
}
|
||||
|
||||
func ContainerConfigFromJob(job *engine.Job) *Config {
|
||||
@ -56,7 +55,6 @@ func ContainerConfigFromJob(job *engine.Job) *Config {
|
||||
}
|
||||
job.GetenvJson("ExposedPorts", &config.ExposedPorts)
|
||||
job.GetenvJson("Volumes", &config.Volumes)
|
||||
config.SecurityOpt = job.GetenvList("SecurityOpt")
|
||||
if PortSpecs := job.GetenvList("PortSpecs"); PortSpecs != nil {
|
||||
config.PortSpecs = PortSpecs
|
||||
}
|
||||
|
||||
@ -56,6 +56,7 @@ type HostConfig struct {
|
||||
CapAdd []string
|
||||
CapDrop []string
|
||||
RestartPolicy RestartPolicy
|
||||
SecurityOpt []string
|
||||
}
|
||||
|
||||
// This is used by the create command when you want to set both the
|
||||
@ -90,6 +91,7 @@ func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
|
||||
job.GetenvJson("PortBindings", &hostConfig.PortBindings)
|
||||
job.GetenvJson("Devices", &hostConfig.Devices)
|
||||
job.GetenvJson("RestartPolicy", &hostConfig.RestartPolicy)
|
||||
hostConfig.SecurityOpt = job.GetenvList("SecurityOpt")
|
||||
if Binds := job.GetenvList("Binds"); Binds != nil {
|
||||
hostConfig.Binds = Binds
|
||||
}
|
||||
|
||||
@ -256,7 +256,6 @@ func Parse(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config,
|
||||
Volumes: flVolumes.GetMap(),
|
||||
Entrypoint: entrypoint,
|
||||
WorkingDir: *flWorkingDir,
|
||||
SecurityOpt: flSecurityOpt.GetAll(),
|
||||
}
|
||||
|
||||
hostConfig := &HostConfig{
|
||||
@ -276,6 +275,7 @@ func Parse(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config,
|
||||
CapAdd: flCapAdd.GetAll(),
|
||||
CapDrop: flCapDrop.GetAll(),
|
||||
RestartPolicy: restartPolicy,
|
||||
SecurityOpt: flSecurityOpt.GetAll(),
|
||||
}
|
||||
|
||||
if sysInfo != nil && flMemory > 0 && !sysInfo.SwapLimit {
|
||||
|
||||
Reference in New Issue
Block a user