Skip to content

Commit a773a29

Browse files
author
Mrunal Patel
authored
Merge pull request #253 from Mashimiao/generate-add-masked-readonly-options
generate: add maskedPaths and readonlyPaths options
2 parents 1c3dfd6 + 6afe0d8 commit a773a29

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var generateFlags = []cli.Flag{
4545
cli.Int64Flag{Name: "linux-pids-limit", Usage: "maximum number of PIDs"},
4646
cli.Uint64Flag{Name: "linux-realtime-period", Usage: "CPU period to be used for realtime scheduling (in usecs)"},
4747
cli.Uint64Flag{Name: "linux-realtime-runtime", Usage: "the time realtime scheduling may use (in usecs)"},
48+
cli.StringSliceFlag{Name: "masked-paths", Usage: "specifies paths can not be read inside container"},
4849
cli.StringFlag{Name: "mount", Usage: "mount namespace"},
4950
cli.StringFlag{Name: "mount-cgroups", Value: "no", Usage: "mount cgroups (rw,ro,no)"},
5051
cli.StringFlag{Name: "mount-label", Usage: "selinux mount context label"},
@@ -59,6 +60,7 @@ var generateFlags = []cli.Flag{
5960
cli.StringSliceFlag{Name: "prestart", Usage: "set command to run in prestart hooks"},
6061
cli.BoolFlag{Name: "privileged", Usage: "enable privileged container settings"},
6162
cli.BoolFlag{Name: "read-only", Usage: "make the container's rootfs read-only"},
63+
cli.StringSliceFlag{Name: "readonly-paths", Usage: "specifies paths readonly inside container"},
6264
cli.StringFlag{Name: "root-propagation", Usage: "mount propagation for root"},
6365
cli.StringFlag{Name: "rootfs", Value: "rootfs", Usage: "path to the rootfs"},
6466
cli.StringFlag{Name: "seccomp-allow", Usage: "specifies syscalls to respond with allow"},
@@ -211,6 +213,20 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
211213
g.SetLinuxCgroupsPath(context.String("cgroups-path"))
212214
}
213215

216+
if context.IsSet("masked-paths") {
217+
paths := context.StringSlice("masked-paths")
218+
for _, path := range paths {
219+
g.AddLinuxMaskedPaths(path)
220+
}
221+
}
222+
223+
if context.IsSet("readonly-paths") {
224+
paths := context.StringSlice("readonly-paths")
225+
for _, path := range paths {
226+
g.AddLinuxReadonlyPaths(path)
227+
}
228+
}
229+
214230
if context.IsSet("mount-label") {
215231
g.SetLinuxMountLabel(context.String("mount-label"))
216232
}

completions/bash/oci-runtime-tool

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ _oci-runtime-tool_generate() {
287287
--ipc
288288
--label
289289
--linux-pids-limit
290+
--masked-paths
290291
--mount
291292
--mount-cgroups
292293
--mount-label
@@ -297,6 +298,7 @@ _oci-runtime-tool_generate() {
297298
--poststart
298299
--poststop
299300
--prestart
301+
--readonly-paths
300302
--root-propagation
301303
--rootfs
302304
--seccomp-allow

generate/generate.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,3 +851,15 @@ func (g *Generator) RemoveAllSeccompRules() error {
851851
g.initSpecLinuxSeccomp()
852852
return seccomp.RemoveAllSeccompRules(g.spec.Linux.Seccomp)
853853
}
854+
855+
// AddLinuxMaskedPaths adds masked paths into g.spec.Linux.MaskedPaths.
856+
func (g *Generator) AddLinuxMaskedPaths(path string) {
857+
g.initSpecLinux()
858+
g.spec.Linux.MaskedPaths = append(g.spec.Linux.MaskedPaths, path)
859+
}
860+
861+
// AddLinuxReadonlyPaths adds readonly paths into g.spec.Linux.MaskedPaths.
862+
func (g *Generator) AddLinuxReadonlyPaths(path string) {
863+
g.initSpecLinux()
864+
g.spec.Linux.ReadonlyPaths = append(g.spec.Linux.ReadonlyPaths, path)
865+
}

man/oci-runtime-tool-generate.1.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ read the configuration from `config.json`.
132132
**--linux-realtime-runtime**=REALTIMERUNTIME
133133
Specifies a period of time in microseconds for the longest continuous period in which the tasks in a cgroup have access to CPU resources.
134134

135+
**--masked-paths**=[]
136+
Specifies paths can not be read inside container. e.g. --masked-paths=/proc/kcore
137+
This option can be specified multiple times.
138+
135139
**--mount**=*PATH*
136140
Use a mount namespace where *PATH* is an existing mount namespace file
137141
to join. The special *PATH* empty-string creates a new namespace.
@@ -206,6 +210,10 @@ read the configuration from `config.json`.
206210

207211
When the operator executes **oci-runtime-tool generate --privileged**, OCI will enable access to all devices on the host as well as disable some of the confinement mechanisms like AppArmor, SELinux, and seccomp from blocking access to privileged processes. This gives the container processes nearly all the same access to the host as processes generating outside of a container on the host.
208212

213+
**--readonly-paths**=[]
214+
Specifies paths readonly inside container. e.g. --readonly-paths=/proc/sys
215+
This option can be specified multiple times.
216+
209217
**--read-only**=true|false
210218
Mount the container's root filesystem as read only.
211219

0 commit comments

Comments
 (0)