Skip to content

Commit 913f12d

Browse files
committed
runtimetest: fix root readonly check
Instead of trying to write a file on the rootfs, check the "ro" per-mount option on the root mountpoint. The rootfs might not be readable despite spec.Root.Readonly being false. Example: the rootfs belong to an unmapped uid. Signed-off-by: Alban Crequy <alban@kinvolk.io>
1 parent 3532c53 commit 913f12d

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

cmd/runtimetest/main.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,37 @@ func validateRootFS(spec *rspec.Spec) error {
323323
return nil
324324
}
325325

326+
// We don't use testWriteAccess() because the rootfs might not be readable
327+
// despite spec.Root.Readonly being false. Example: the rootfs belong to an
328+
// unmapped uid.
329+
330+
mountInfos, err := mount.GetMounts()
331+
if err != nil {
332+
return err
333+
}
334+
335+
optRO := false
336+
for _, mountInfo := range mountInfos {
337+
if mountInfo.Mountpoint != "/" {
338+
continue
339+
}
340+
341+
// Check the per-mount options rather than the per-sb options
342+
optsList := strings.Split(mountInfo.Opts, ",")
343+
for _, opt := range optsList {
344+
if opt == "ro" {
345+
optRO = true
346+
break
347+
}
348+
}
349+
}
350+
326351
if spec.Root.Readonly {
327-
err := testWriteAccess("/")
328-
if err == nil {
352+
if !optRO {
329353
return specerror.NewError(specerror.RootReadonlyImplement, fmt.Errorf("rootfs must be readonly"), rspec.Version)
330354
}
331355
} else {
332-
err := testWriteAccess("/")
333-
if err != nil {
356+
if optRO {
334357
return specerror.NewError(specerror.RootReadonlyImplement, fmt.Errorf("rootfs must not be readonly"), rspec.Version)
335358
}
336359
}

0 commit comments

Comments
 (0)