10000 mounts: prohibit relative paths in YAML by AkihiroSuda · Pull Request #3950 · lima-vm/lima · GitHub
[go: up one dir, main page]

Skip to content

Conversation

AkihiroSuda
Copy link
Member
@AkihiroSuda AkihiroSuda commented Sep 3, 2025

YAMLs with relative paths like mounts: [{location: .}] are not longer allowed.

Relative paths are still allowed in CLI: limactl create --mount=DIR

Fix #3948

@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Sep 3, 2025
@AkihiroSuda AkihiroSuda force-pushed the fix-3948 branch 6 times, most recently from b6ee573 to 2837c7e Compare September 3, 2025 08:44
@jandubois
Copy link
Member
jandubois commented Sep 3, 2025

I've not looked in detail, but returning an error from FillDefaults seems wrong. This is a validation error that should be caught in Validate. Otherwise there is no reason to have 2 separate functions.

I also think the --mount-only option should be a separate PR and not mixed in with a bug fix.

EDIT: I see it is already a separate PR, and just stacked with this one.

@AkihiroSuda
Copy link
Member Author

Updated to avoid returning err from FillDefault

Copy link
Member
@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not the right fix. The regression was introduced by #3339. It unconditionally expands all local filenames to absolute names. We should only call Expand() when the location actually is a tilde-path:

--- pkg/limayaml/defaults.go
+++ pkg/limayaml/defaults.go
@@ -713,10 +713,12 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
 				mounts[i].NineP.Cache = ptr.Of(Default9pCacheForRO)
 			}
 		}
-		if location, err := localpathutil.Expand(mount.Location); err == nil {
-			mounts[i].Location = location
-		} else {
-			logrus.WithError(err).Warnf("Couldn't expand location %q", mount.Location)
+		if localpathutil.IsTildePath(mount.Location) {
+			if location, err := localpathutil.Expand(mount.Location); err == nil {
+				mounts[i].Location = location
+			} else {
+				logrus.WithError(err).Warnf("Couldn't expand location %q", mount.Location)
+			}
 		}
 		if mount.MountPoint == nil {
 			mountLocation := mounts[i].Location

This fixes the existing validation:

cat mount.yaml
images: [{location: /foo}]
mounts: [{location: foo}]l tmpl validate mount.yaml
FATA[0000] failed to validate YAML file "mount.yaml": field `mounts[0].location` must be an absolute path, got "foo"

@AkihiroSuda AkihiroSuda force-pushed the fix-3948 branch 2 times, most recently from 3b103d5 to b803a24 Compare September 5, 2025 03:51
jandubois
jandubois previously approved these changes Sep 5, 2025
Copy link
Member
@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

Relative paths are still allowed in CLI:
`limactl create --mount=DIR`

Fix issue 3948

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
@AkihiroSuda AkihiroSuda merged commit 4b46444 into lima-vm:master Sep 5, 2025
83 of 90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mounts: prohibit relative paths in YAML (while allowing them in limactl create --mount CLI)
2 participants
0