Skip to content

Commit b661ad7

Browse files
authored
Merge pull request #1504 from lorenz/ignore-image-defined-volumes
Add option for ignoring volumes defined in images
2 parents 26dc5b9 + 5a1d49b commit b661ad7

5 files changed

Lines changed: 19 additions & 3 deletions

File tree

docs/config.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ version = 2
4545
# It generates a self-sign certificate unless the following x509_key_pair_streaming are both set.
4646
enable_tls_streaming = false
4747

48+
# ignore_image_defined_volumes ignores volumes defined by the image. Useful for better resource
49+
# isolation, security and early detection of issues in the mount configuration when using
50+
# ReadOnlyRootFilesystem since containers won't silently mount a temporary volume.
51+
ignore_image_defined_volumes = false
52+
4853
# 'plugins."io.containerd.grpc.v1.cri".x509_key_pair_streaming' contains a x509 valid key pair to stream with tls.
4954
[plugins."io.containerd.grpc.v1.cri".x509_key_pair_streaming]
5055
# tls_cert_file is the filepath to the certificate paired with the "tls_key_file"

pkg/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ type PluginConfig struct {
236236
// container requests with huge page limits if the cgroup controller for hugepages is not present.
237237
// This helps with supporting Kubernetes <=1.18 out of the box. (default is `true`)
238238
TolerateMissingHugePagesCgroupController bool `toml:"tolerate_missing_hugepages_controller" json:"tolerateMissingHugePagesCgroupController"`
239+
// IgnoreImageDefinedVolumes ignores volumes defined by the image. Useful for better resource
240+
// isolation, security and early detection of issues in the mount configuration when using
241+
// ReadOnlyRootFilesystem since containers won't silently mount a temporary volume.
242+
IgnoreImageDefinedVolumes bool `toml:"ignore_image_defined_volumes" json:"ignoreImageDefinedVolumes"`
239243
}
240244

241245
// X509KeyPairStreaming contains the x509 configuration for streaming

pkg/config/config_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ func DefaultConfig() PluginConfig {
6666
MaxConcurrentDownloads: 3,
6767
DisableProcMount: false,
6868
TolerateMissingHugePagesCgroupController: true,
69+
IgnoreImageDefinedVolumes: false,
6970
}
7071
}

pkg/config/config_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ func DefaultConfig() PluginConfig {
6464
},
6565
},
6666
},
67-
MaxConcurrentDownloads: 3,
67+
MaxConcurrentDownloads: 3,
68+
IgnoreImageDefinedVolumes: false,
6869
// TODO(windows): Add platform specific config, so that most common defaults can be shared.
6970
}
7071
}

pkg/server/container_create.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,13 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
137137
}
138138
}()
139139

140-
// Create container volumes mounts.
141-
volumeMounts := c.volumeMounts(containerRootDir, config.GetMounts(), &image.ImageSpec.Config)
140+
var volumeMounts []*runtime.Mount
141+
if !c.config.IgnoreImageDefinedVolumes {
142+
// Create container image volumes mounts.
143+
volumeMounts = c.volumeMounts(containerRootDir, config.GetMounts(), &image.ImageSpec.Config)
144+
} else if len(image.ImageSpec.Config.Volumes) != 0 {
145+
log.G(ctx).Debugf("Ignoring volumes defined in image %v because IgnoreImageDefinedVolumes is set", image.ID)
146+
}
142147

143148
// Generate container mounts.
144149
mounts := c.containerMounts(sandboxID, config)

0 commit comments

Comments
 (0)