Skip to content

Commit eca8694

Browse files
committed
Allow mounts to be specified in containers.conf
We want to allow HPC Customers and others to specify mounts inside of containers.conf, so that they can have a default list of mounts into all of thier containers. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
1 parent 94b250a commit eca8694

File tree

6 files changed

+43
-9
lines changed

6 files changed

+43
-9
lines changed

docs/containers.conf.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ limit is never exceeded.
229229

230230
Default format tag for container log messages. This is useful for creating a specific tag for container log messages. Container log messages default to using the truncated container ID as a tag.
231231

232+
**mounts**=[]
233+
234+
List of mounts.
235+
Specified as "type=TYPE,source=<directory-on-host>,destination=<directory-in-container>,<options>"
236+
237+
Example: [ "type=bind,source=/var/lib/foobar,destination=/var/lib/foobar,ro", ]
238+
232239
**netns**="private"
233240

234241
Default way to to create a NET namespace for the container.

pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ type ContainersConfig struct {
185185
// Containers logs default to truncated container ID as a tag.
186186
LogTag string `toml:"log_tag,omitempty"`
187187

188+
// Mount to add to all containers
189+
Mounts []string `toml:"mounts,omitempty"`
190+
188191
// NetNS indicates how to create a network namespace for the container
189192
NetNS string `toml:"netns,omitempty"`
190193

pkg/config/config_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ image_copy_tmp_dir="storage"`
249249
"TERM=xterm",
250250
}
251251

252+
mounts := []string{
253+
"type=glob,source=/tmp/test2*,ro=true",
254+
"type=bind,source=/etc/services,destination=/etc/services,ro",
255+
}
256+
252257
volumes := []string{
253258
"$HOME:$HOME",
254259
}
@@ -265,6 +270,7 @@ image_copy_tmp_dir="storage"`
265270
gomega.Expect(err).To(gomega.BeNil())
266271
gomega.Expect(defaultConfig.Engine.CgroupManager).To(gomega.Equal("systemd"))
267272
gomega.Expect(defaultConfig.Containers.Env).To(gomega.BeEquivalentTo(envs))
273+
gomega.Expect(defaultConfig.Containers.Mounts).To(gomega.BeEquivalentTo(mounts))
268274
gomega.Expect(defaultConfig.Containers.PidsLimit).To(gomega.BeEquivalentTo(2048))
269275
gomega.Expect(defaultConfig.Network.CNIPluginDirs).To(gomega.Equal(pluginDirs))
270276
gomega.Expect(defaultConfig.Network.NetavarkPluginDirs).To(gomega.Equal([]string{"/usr/netavark"}))

pkg/config/containers.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ default_sysctls = [
196196
#
197197
#log_tag = ""
198198

199+
# List of mounts. Specified as
200+
# "type=TYPE,source=<directory-on-host>,destination=<directory-in-container>,<options>", for example:
201+
# "type=bind,source=/var/lib/foobar,destination=/var/lib/foobar,ro".
202+
# If it is empty or commented out, no mounts will be added
203+
#
204+
#mounts = []
205+
199206
# Default way to to create a Network namespace for the container
200207
# Options are:
201208
# `private` Create private Network Namespace for the container.
@@ -276,7 +283,7 @@ default_sysctls = [
276283
# If it is empty or commented out, no volumes will be added
277284
#
278285
#volumes = []
279-
#
286+
280287
#[engine.platform_to_oci_runtime]
281288
#"wasi/wasm" = ["crun-wasm"]
282289
#"wasi/wasm32" = ["crun-wasm"]

pkg/config/default.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,18 @@ func DefaultConfig() (*Config, error) {
186186

187187
return &Config{
188188
Containers: ContainersConfig{
189-
Devices: []string{},
190-
Volumes: []string{},
191189
Annotations: []string{},
192190
ApparmorProfile: DefaultApparmorProfile,
193191
BaseHostsFile: "",
194192
CgroupNS: cgroupNS,
195193
Cgroups: getDefaultCgroupsMode(),
194+
DNSOptions: []string{},
195+
DNSSearches: []string{},
196+
DNSServers: []string{},
196197
DefaultCapabilities: DefaultCapabilities,
197198
DefaultSysctls: []string{},
198199
DefaultUlimits: getDefaultProcessLimits(),
199-
DNSServers: []string{},
200-
DNSOptions: []string{},
201-
DNSSearches: []string{},
200+
Devices: []string{},
202201
EnableKeyring: true,
203202
EnableLabeling: selinuxEnabled(),
204203
Env: []string{
@@ -207,20 +206,22 @@ func DefaultConfig() (*Config, error) {
207206
},
208207
EnvHost: false,
209208
HTTPProxy: true,
209+
IPCNS: "shareable",
210210
Init: false,
211211
InitPath: "",
212-
IPCNS: "shareable",
213212
LogDriver: defaultLogDriver(),
214213
LogSizeMax: DefaultLogSizeMax,
214+
Mounts: []string{},
215215
NetNS: "private",
216216
NoHosts: false,
217-
PidsLimit: DefaultPidsLimit,
218217
PidNS: "private",
218+
PidsLimit: DefaultPidsLimit,
219219
ShmSize: DefaultShmSize,
220220
TZ: "",
221-
Umask: "0022",
222221
UTSNS: "private",
222+
Umask: "0022",
223223
UserNSSize: DefaultUserNSSize, // Deprecated
224+
Volumes: []string{},
224225
},
225226
Network: NetworkConfig{
226227
DefaultNetwork: "podman",
@@ -500,6 +501,11 @@ func (c *Config) Volumes() []string {
500501
return c.Containers.Volumes
501502
}
502503

504+
// Mounts returns the default set of mounts that should be mounted in containers.
505+
func (c *Config) Mounts() []string {
506+
return c.Containers.Mounts
507+
}
508+
503509
// Devices returns the default additional devices for containers.
504510
func (c *Config) Devices() []string {
505511
return c.Containers.Devices

pkg/config/testdata/containers_default.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ label = true
8181
# limit is never exceeded.
8282
log_size_max = -1
8383

84+
mounts= [
85+
"type=glob,source=/tmp/test2*,ro=true",
86+
"type=bind,source=/etc/services,destination=/etc/services,ro",
87+
]
88+
8489
oom_score_adj = 750
8590

8691
# Maximum number of processes allowed in a container.

0 commit comments

Comments
 (0)