Browse code

Do not return labels when in privileged mode Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby authored on 2014/04/29 17:08:19
Showing 2 changed files
... ...
@@ -330,8 +330,8 @@ func populateCommand(c *Container, env []string) {
330 330
 		en      *execdriver.Network
331 331
 		context = make(map[string][]string)
332 332
 	)
333
-	context["process_label"] = []string{c.ProcessLabel}
334
-	context["mount_label"] = []string{c.MountLabel}
333
+	context["process_label"] = []string{c.GetProcessLabel()}
334
+	context["mount_label"] = []string{c.GetMountLabel()}
335 335
 
336 336
 	en = &execdriver.Network{
337 337
 		Mtu:       c.daemon.config.Mtu,
... ...
@@ -392,7 +392,6 @@ func (container *Container) Start() (err error) {
392 392
 	if err := container.setupContainerDns(); err != nil {
393 393
 		return err
394 394
 	}
395
-
396 395
 	if err := container.Mount(); err != nil {
397 396
 		return err
398 397
 	}
... ...
@@ -1192,3 +1191,19 @@ func (container *Container) allocatePort(eng *engine.Engine, port nat.Port, bind
1192 1192
 	bindings[port] = binding
1193 1193
 	return nil
1194 1194
 }
1195
+
1196
+func (container *Container) GetProcessLabel() string {
1197
+	// even if we have a process label return "" if we are running
1198
+	// in privileged mode
1199
+	if container.hostConfig.Privileged {
1200
+		return ""
1201
+	}
1202
+	return container.ProcessLabel
1203
+}
1204
+
1205
+func (container *Container) GetMountLabel() string {
1206
+	if container.hostConfig.Privileged {
1207
+		return ""
1208
+	}
1209
+	return container.MountLabel
1210
+}
... ...
@@ -538,10 +538,9 @@ func (daemon *Daemon) newContainer(name string, config *runconfig.Config, img *i
538 538
 	}
539 539
 	container.root = daemon.containerRoot(container.ID)
540 540
 
541
-	if container.MountLabel, container.ProcessLabel, err = label.GenLabels(""); err != nil {
541
+	if container.ProcessLabel, container.MountLabel, err = label.GenLabels(""); err != nil {
542 542
 		return nil, err
543 543
 	}
544
-
545 544
 	return container, nil
546 545
 }
547 546
 
... ...
@@ -848,7 +847,7 @@ func (daemon *Daemon) Close() error {
848 848
 }
849 849
 
850 850
 func (daemon *Daemon) Mount(container *Container) error {
851
-	dir, err := daemon.driver.Get(container.ID, container.MountLabel)
851
+	dir, err := daemon.driver.Get(container.ID, container.GetMountLabel())
852 852
 	if err != nil {
853 853
 		return fmt.Errorf("Error getting container %s from driver %s: %s", container.ID, daemon.driver, err)
854 854
 	}