canonical / multipass

Multipass orchestrates virtual Ubuntu instances
https://multipass.run
GNU General Public License v3.0
7.54k stars 635 forks source link

Incomplete handling of file URLs #3421

Closed Batalex closed 3 months ago

Batalex commented 4 months ago

Describe the bug The CLI cannot expand paths containing ~, or handle hidden folders in file URLs.

To Reproduce Create a minimal blueprint ~/blueprint.yaml .

Using ~:

multipass launch file://~/blueprint.yaml

launch failed: Wrong file '/home/alex/~/blueprint.yaml'

Hidden file

mv blueprint.yaml .blueprint.yaml
multipass launch file://.blueprint.yaml

[2024-02-29T10:14:52.896] [error] [blueprint provider] Invalid Blueprint name '': must be a valid host name
launch failed: Invalid Blueprint name '': must be a valid host name

Hidden folder

mkdir .directory
mv .blueprint.yaml .directory/blueprint.yaml
multipass launch file://.directory/blueprint.yaml

launch failed: Wrong file '/home/alex/.directory/blueprint.yaml'

Logs

Multipass logs ```text Feb 29 09:05:27 alex-frame multipassd[1887]: Starting Multipass 1.13.1 Feb 29 09:05:27 alex-frame multipassd[1887]: Daemon arguments: /snap/multipass/11732/bin/multipassd --v> Feb 29 09:05:32 alex-frame dnsmasq[3172]: reading /etc/resolv.conf Feb 29 09:05:32 alex-frame dnsmasq[3172]: using nameserver 127.0.0.53#53 Feb 29 09:05:32 alex-frame dnsmasq[3172]: using only locally-known addresses for multipass Feb 29 09:05:32 alex-frame dnsmasq[3172]: reading /etc/resolv.conf Feb 29 09:05:32 alex-frame dnsmasq[3172]: using nameserver 127.0.0.53#53 Feb 29 09:05:32 alex-frame dnsmasq[3172]: using only locally-known addresses for multipass Feb 29 09:20:28 alex-frame multipassd[1887]: fetch manifest periodically Feb 29 09:35:28 alex-frame multipassd[1887]: fetch manifest periodically Feb 29 09:50:28 alex-frame multipassd[1887]: fetch manifest periodically Feb 29 10:05:28 alex-frame multipassd[1887]: fetch manifest periodically Feb 29 10:14:22 alex-frame multipassd[1887]: Loading "anbox-cloud-appliance" v1 Feb 29 10:14:22 alex-frame multipassd[1887]: Loading "charm-dev" v1 Feb 29 10:14:22 alex-frame multipassd[1887]: Loading "docker" v1 Feb 29 10:14:22 alex-frame multipassd[1887]: Loading "jellyfin" v1 Feb 29 10:14:22 alex-frame multipassd[1887]: Loading "minikube" v1 Feb 29 10:14:22 alex-frame multipassd[1887]: Loading "ros-noetic" v1 Feb 29 10:14:22 alex-frame multipassd[1887]: Loading "ros2-humble" v1 Feb 29 10:14:22 alex-frame multipassd[1887]: [92399] started: qemu-system-x86_64 --version Feb 29 10:14:22 alex-frame multipassd[1887]: Reading Blueprint 'blueprint' from file /home/alex/~/bluep> Feb 29 10:14:52 alex-frame multipassd[1887]: [93182] started: qemu-system-x86_64 --version Feb 29 10:14:52 alex-frame multipassd[1887]: Reading Blueprint '.blueprint' from file /home/alex/.bluep> Feb 29 10:14:52 alex-frame multipassd[1887]: Invalid Blueprint name '': must be a valid host name Feb 29 10:16:28 alex-frame multipassd[1887]: [95638] started: qemu-system-x86_64 --version Feb 29 10:16:28 alex-frame multipassd[1887]: Reading Blueprint '.blueprint' from file /home/alex/direct> Feb 29 10:16:28 alex-frame multipassd[1887]: Invalid Blueprint name '': must be a valid host name Feb 29 10:16:54 alex-frame multipassd[1887]: [96352] started: qemu-system-x86_64 --version Feb 29 10:16:54 alex-frame multipassd[1887]: Reading Blueprint '.blueprint' from file /home/alex/.direc> Feb 29 10:16:54 alex-frame multipassd[1887]: Invalid Blueprint name '': must be a valid host name Feb 29 10:17:19 alex-frame multipassd[1887]: [96953] started: qemu-system-x86_64 --version Feb 29 10:17:19 alex-frame multipassd[1887]: Reading Blueprint 'blueprint' from file /home/alex/.direct> Feb 29 10:20:28 alex-frame multipassd[1887]: fetch manifest periodically Feb 29 10:25:59 alex-frame multipassd[1887]: Returning setting local.driver=qemu lines 10323-10381/10381 (END) ```

Additional info

luis4a0 commented 4 months ago

Hi @Batalex! These cases are indeed not well handled. ~ is not correctly expanded and the . in the beginning of the name makes Multipass think the file name is instead a host name and the . in the folder name is very strange. We'll address these issues soon. Thanks for reporting!

luis4a0 commented 4 months ago

Hi @Batalex! Sorry for the delay. I've been taking a look to your three issues. My findings follow.

First issue: Multipass does a bad expansion of ~, this must be corrected.

Second issue: the file name of a blueprint must match exactly the name of the blueprint being defined. For this reason, the issue that Multipass is reporting is that inside your file the name of the defined blueprint is incorrect (that is, an instance name cannot start with .). As a corollary of this, no blueprint file name can start with ..

Third issue: I can't reproduce.

I'll issue a PR to fix the first one. Please confirm that you still have the third issue with a blueprint named exactly as the file is named (without the .yaml suffix, of course).

Thanks!

Batalex commented 4 months ago

Hi @luis4a0, thanks for looking into it. I confirm that I still have the third issue:

multipass launch file://.blueprints/custom.yaml

launch failed: Wrong file '/home/alex/.blueprints/custom.yaml'

head .blueprints/custom.yaml
description: My custom VM configuration
version: latest
runs-on:
  - amd64

instances:
  custom:
    image: 22.04
    workspace: true
    limits:

logs:

Mar 15 09:12:02 alex-frame multipassd[1849]: [26513] started: qemu-system-x86_64 --version
Mar 15 09:12:02 alex-frame multipassd[1849]: Reading Blueprint 'custom' from file /home/alex/.blueprints/custom.yaml
luis4a0 commented 4 months ago

Hi @Batalex, thanks for confirming!

luis4a0 commented 3 months ago

Hi @Batalex, I investigated the third issue and I'm afraid we can't to something about it. It happens that snapd does not allow accessing dot folders in the home directory. This is a security feature. If you move your dot-folder to a non-dot subfolder of your home directory, Multipass will be able to read it. For instance, this will work:

mkdir test
mv .directory test
multipass launch file://test/.directory/blueprint.yaml

I was running a locally-compiled version of Multipass, so I couldn't reproduce the issue. But when switching to the snap, everything became clearer.

Batalex commented 3 months ago

Oh right, now that you mention it, this seems obvious since I recently read about the personal-files slot. Thank you for looking into it!

luis4a0 commented 3 months ago

@Batalex Finally, the only issue was the first. But indeed, we found the following: who does ~ expansion is the shell itself. For instance, writing on the Firefox address bar file://~/blah does not expand the ~. So we don't think we have to expand the ~. However, if running from the multipass launch file://blueprint.yaml will correctly look for your file on the current folder. Anyway, thanks a lot for your report it helped us to understand the ~ expansion.