Skip to content

Commit 0cba774

Browse files
author
John Howard
committed
Address feedback from Tonis
Signed-off-by: John Howard <jhoward@microsoft.com>
1 parent afd305c commit 0cba774

24 files changed

+103
-21
lines changed

builder/dockerfile/builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ func addNodesForLabelOption(dockerfile *parser.Node, labels map[string]string) {
358358
//
359359
// TODO: Remove?
360360
func BuildFromConfig(config *container.Config, changes []string, os string) (*container.Config, error) {
361+
if !system.IsOSSupported(os) {
362+
return nil, errdefs.InvalidParameter(system.ErrNotSupportedOperatingSystem)
363+
}
361364
if len(changes) == 0 {
362365
return config, nil
363366
}

builder/dockerfile/dispatchers.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ func initializeStage(d dispatchRequest, cmd *instructions.Stage) error {
156156
return err
157157
}
158158
state := d.state
159-
state.beginStage(cmd.Name, image)
159+
if err := state.beginStage(cmd.Name, image); err != nil {
160+
return err
161+
}
160162
if len(state.runConfig.OnBuild) > 0 {
161163
triggers := state.runConfig.OnBuild
162164
state.runConfig.OnBuild = nil
@@ -309,7 +311,9 @@ func resolveCmdLine(cmd instructions.ShellDependantCmdLine, runConfig *container
309311
// RUN [ "echo", "hi" ] # echo hi
310312
//
311313
func dispatchRun(d dispatchRequest, c *instructions.RunCommand) error {
312-
314+
if !system.IsOSSupported(d.state.operatingSystem) {
315+
return system.ErrNotSupportedOperatingSystem
316+
}
313317
stateRunConfig := d.state.runConfig
314318
cmdFromArgs := resolveCmdLine(c.ShellDependantCmdLine, stateRunConfig, d.state.operatingSystem)
315319
buildArgs := d.state.buildArgs.FilterAllowed(stateRunConfig.Env)

builder/dockerfile/evaluator.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package dockerfile
2121

2222
import (
2323
"reflect"
24+
"runtime"
2425
"strconv"
2526
"strings"
2627

@@ -211,10 +212,16 @@ func (s *dispatchState) hasFromImage() bool {
211212
return s.imageID != "" || (s.baseImage != nil && s.baseImage.ImageID() == "")
212213
}
213214

214-
func (s *dispatchState) beginStage(stageName string, image builder.Image) {
215+
func (s *dispatchState) beginStage(stageName string, image builder.Image) error {
215216
s.stageName = stageName
216217
s.imageID = image.ImageID()
217218
s.operatingSystem = image.OperatingSystem()
219+
if s.operatingSystem == "" { // In case it isn't set
220+
s.operatingSystem = runtime.GOOS
221+
}
222+
if !system.IsOSSupported(s.operatingSystem) {
223+
return system.ErrNotSupportedOperatingSystem
224+
}
218225

219226
if image.RunConfig() != nil {
220227
// copy avoids referencing the same instance when 2 stages have the same base
@@ -226,6 +233,7 @@ func (s *dispatchState) beginStage(stageName string, image builder.Image) {
226233
s.setDefaultPath()
227234
s.runConfig.OpenStdin = false
228235
s.runConfig.StdinOnce = false
236+
return nil
229237
}
230238

231239
// Add the default PATH to runConfig.ENV if one exists for the operating system and there

daemon/build.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/docker/docker/pkg/containerfs"
1313
"github.com/docker/docker/pkg/idtools"
1414
"github.com/docker/docker/pkg/stringid"
15+
"github.com/docker/docker/pkg/system"
1516
"github.com/docker/docker/registry"
1617
"github.com/pkg/errors"
1718
"github.com/sirupsen/logrus"
@@ -70,7 +71,7 @@ func (rl *releaseableLayer) Commit() (builder.ReleaseableLayer, error) {
7071
if err != nil {
7172
return nil, err
7273
}
73-
// TODO: An optimization woudld be to handle empty layers before returning
74+
// TODO: An optimization would be to handle empty layers before returning
7475
return &releaseableLayer{layerStore: rl.layerStore, roLayer: newLayer}, nil
7576
}
7677

@@ -171,6 +172,9 @@ func (daemon *Daemon) pullForBuilder(ctx context.Context, name string, authConfi
171172
// leaking of layers.
172173
func (daemon *Daemon) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ReleaseableLayer, error) {
173174
if refOrID == "" {
175+
if !system.IsOSSupported(opts.OS) {
176+
return nil, nil, system.ErrNotSupportedOperatingSystem
177+
}
174178
layer, err := newReleasableLayerForImage(nil, daemon.layerStores[opts.OS])
175179
return nil, layer, err
176180
}
@@ -182,6 +186,9 @@ func (daemon *Daemon) GetImageAndReleasableLayer(ctx context.Context, refOrID st
182186
}
183187
// TODO: shouldn't we error out if error is different from "not found" ?
184188
if image != nil {
189+
if !system.IsOSSupported(image.OperatingSystem()) {
190+
return nil, nil, system.ErrNotSupportedOperatingSystem
191+
}
185192
layer, err := newReleasableLayerForImage(image, daemon.layerStores[image.OperatingSystem()])
186193
return image, layer, err
187194
}
@@ -191,6 +198,9 @@ func (daemon *Daemon) GetImageAndReleasableLayer(ctx context.Context, refOrID st
191198
if err != nil {
192199
return nil, nil, err
193200
}
201+
if !system.IsOSSupported(image.OperatingSystem()) {
202+
return nil, nil, system.ErrNotSupportedOperatingSystem
203+
}
194204
layer, err := newReleasableLayerForImage(image, daemon.layerStores[image.OperatingSystem()])
195205
return image, layer, err
196206
}

daemon/commit.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/docker/docker/image"
1818
"github.com/docker/docker/layer"
1919
"github.com/docker/docker/pkg/ioutils"
20+
"github.com/docker/docker/pkg/system"
2021
"github.com/pkg/errors"
2122
)
2223

@@ -149,6 +150,9 @@ func (daemon *Daemon) Commit(name string, c *backend.ContainerCommitConfig) (str
149150
daemon.containerPause(container)
150151
defer daemon.containerUnpause(container)
151152
}
153+
if !system.IsOSSupported(container.OS) {
154+
return "", system.ErrNotSupportedOperatingSystem
155+
}
152156

153157
if c.MergeConfigs && c.Config == nil {
154158
c.Config = container.Config
@@ -251,6 +255,7 @@ func (daemon *Daemon) Commit(name string, c *backend.ContainerCommitConfig) (str
251255
}
252256

253257
func (daemon *Daemon) exportContainerRw(container *container.Container) (arch io.ReadCloser, err error) {
258+
// Note: Indexing by OS is safe as only called from `Commit` which has already performed validation
254259
rwlayer, err := daemon.layerStores[container.OS].GetRWLayer(container.ID)
255260
if err != nil {
256261
return nil, err

daemon/create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ func (daemon *Daemon) setRWLayer(container *container.Container) error {
270270
StorageOpt: container.HostConfig.StorageOpt,
271271
}
272272

273+
// Indexing by OS is safe here as validation of OS has already been performed in create() (the only
274+
// caller), and guaranteed non-nil
273275
rwLayer, err := daemon.layerStores[container.OS].CreateRWLayer(container.ID, layerID, rwLayerOpts)
274276
if err != nil {
275277
return err

daemon/daemon.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ func (daemon *Daemon) restore() error {
155155
logrus.Errorf("Failed to load container %v: %v", id, err)
156156
continue
157157
}
158-
158+
if !system.IsOSSupported(container.OS) {
159+
logrus.Errorf("Failed to load container %v: %s (%q)", id, system.ErrNotSupportedOperatingSystem, container.OS)
160+
continue
161+
}
159162
// Ignore the container if it does not support the current driver being used by the graph
160163
currentDriverForContainerOS := daemon.graphDrivers[container.OS]
161164
if (container.Driver == "" && currentDriverForContainerOS == "aufs") || container.Driver == currentDriverForContainerOS {

daemon/delete.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo
9494
return fmt.Errorf("Could not kill running container %s, cannot remove - %v", container.ID, err)
9595
}
9696
}
97+
if !system.IsOSSupported(container.OS) {
98+
return fmt.Errorf("cannot remove %s: %s ", container.ID, system.ErrNotSupportedOperatingSystem)
99+
}
97100

98101
// stop collection of stats for the container regardless
99102
// if stats are currently getting collected.

daemon/export.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/docker/docker/errdefs"
1010
"github.com/docker/docker/pkg/archive"
1111
"github.com/docker/docker/pkg/ioutils"
12+
"github.com/docker/docker/pkg/system"
1213
)
1314

1415
// ContainerExport writes the contents of the container to the given
@@ -47,6 +48,9 @@ func (daemon *Daemon) ContainerExport(name string, out io.Writer) error {
4748
}
4849

4950
func (daemon *Daemon) containerExport(container *container.Container) (arch io.ReadCloser, err error) {
51+
if !system.IsOSSupported(container.OS) {
52+
return nil, fmt.Errorf("cannot export %s: %s ", container.ID, system.ErrNotSupportedOperatingSystem)
53+
}
5054
rwlayer, err := daemon.layerStores[container.OS].GetRWLayer(container.ID)
5155
if err != nil {
5256
return nil, err

daemon/image_delete.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/docker/docker/errdefs"
1212
"github.com/docker/docker/image"
1313
"github.com/docker/docker/pkg/stringid"
14+
"github.com/docker/docker/pkg/system"
1415
"github.com/pkg/errors"
1516
)
1617

@@ -66,10 +67,13 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I
6667
start := time.Now()
6768
records := []types.ImageDeleteResponseItem{}
6869

69-
imgID, _, err := daemon.GetImageIDAndOS(imageRef)
70+
imgID, operatingSystem, err := daemon.GetImageIDAndOS(imageRef)
7071
if err != nil {
7172
return nil, err
7273
}
74+
if !system.IsOSSupported(operatingSystem) {
75+
return nil, errors.Errorf("unable to delete image: %q", system.ErrNotSupportedOperatingSystem)
76+
}
7377

7478
repoRefs := daemon.referenceStore.References(imgID.Digest())
7579

0 commit comments

Comments
 (0)