Skip to content

Commit 899afea

Browse files
committed
validate: Test config.json and rootfs sibling-hood
Test the spec's [1]: While these artifacts MUST all be present in a single directory on the local filesystem, ... which is a condition it imposes on config.json and the directory referenced by root.path. I think we should drop that restriction from the spec, but my attempt to remove the restriction was rejected [2]. If a future spec drops the restriction, we can revert this commit. Using path/filepath for the path manipulation will break when validating cross-platform configs (e.g. trying to validate a Windows bundle on a Linux machine). But that's a bigger issue than this commit, so I've left it alone for now. [1]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc5/bundle.md#container-format [2]: opencontainers/runtime-spec#469 Signed-off-by: W. Trevor King <wking@tremily.us>
1 parent 21af41d commit 899afea

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

validate/validate.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,23 @@ func (v *Validator) CheckAll() (msgs []string) {
115115
func (v *Validator) CheckRootfsPath() (msgs []string) {
116116
logrus.Debugf("check rootfs path")
117117

118+
absBundlePath, err := filepath.Abs(v.bundlePath)
119+
if err != nil {
120+
msgs = append(msgs, fmt.Sprintf("unable to convert %q to an absolute path", v.bundlePath))
121+
}
122+
118123
var rootfsPath string
124+
var absRootPath string
119125
if filepath.IsAbs(v.spec.Root.Path) {
120126
rootfsPath = v.spec.Root.Path
127+
absRootPath = filepath.Clean(rootfsPath)
121128
} else {
129+
var err error
122130
rootfsPath = filepath.Join(v.bundlePath, v.spec.Root.Path)
131+
absRootPath, err = filepath.Abs(rootfsPath)
132+
if err != nil {
133+
msgs = append(msgs, fmt.Sprintf("unable to convert %q to an absolute path", rootfsPath))
134+
}
123135
}
124136

125137
if fi, err := os.Stat(rootfsPath); err != nil {
@@ -128,6 +140,11 @@ func (v *Validator) CheckRootfsPath() (msgs []string) {
128140
msgs = append(msgs, fmt.Sprintf("The root path %q is not a directory.", rootfsPath))
129141
}
130142

143+
rootParent := filepath.Dir(absRootPath)
144+
if absRootPath == string(filepath.Separator) || rootParent != absBundlePath {
145+
msgs = append(msgs, fmt.Sprintf("root.path is %q, but it MUST be a child of %q", v.spec.Root.Path, absBundlePath))
146+
}
147+
131148
return
132149

133150
}

0 commit comments

Comments
 (0)