Creating VM via api - needs root privilages.

Daxcor

Member
Oct 31, 2021
43
2
13
57
Hello,

I am using the api to create a fresh vm by importing a qcow2 image, in this case a default debain 12 qcow2 image. Here is my json string that I am using to create the vm .
Code:
{
    "vmid": "222",
    "name": "jack",
    "agent": 1,
    "balloon": 512,
    "cores": 1,
    "description": "Server for jack",
    "ipconfig0": "ip=dhcp",
    "memory": "4096",
    "net0": "virtio,bridge=vmbr0,firewall=0,tag=20",
    "ostype": "l26",
    "scsihw": "virtio-scsi-single",
    "serial0": "socket",
    "start": 0,
    "vga": "type=serial0",
    "virtio0": "file=local:222,import-from=/root/debian-12-generic-amd64-12.qcow2,size=12G,discard=on",
    "cipassword": "debian",
    "storage":"local"
}

The issue I am running into is that the image is located in the home dir of the root user. So if I am doing it via the cli, I am able to import the image to the newly created vm with no boot disk. When I try to do this via the api POST call to this endpoint

pve0.mgmt.local:8006/api2/json/nodes/pve0/qemu

I get the following error.

500 Only root can pass arbitrary filesystem paths. at /usr/share/perl5/PVE/Storage.pm line 561.

I did try to use the root account by creating a token for it, but I still get the same error. I guess, I need to place the image somewhere where we don't require root privileges. Existing image live at /var/lib/vz/images/{vmdi}/ Do I just make up a vmid and save the image in that dir? Not really sure what to do. I am sure I am missing something obvious.

Any help would be greatly appreciated.
thanks
Brad
 
Last edited:
Hi,
tokens for root do not grant permissions for things that are root-user-only currently. You can assign all other permission to such a token, but special things require being actually logged-in as root. Relevant feature request: https://bugzilla.proxmox.com/show_bug.cgi?id=2582
 
  • Like
Reactions: Johannes S