Skip to content

Instantly share code, notes, and snippets.

@tomdaley92
Last active July 22, 2024 11:13
Show Gist options
  • Save tomdaley92/789688fc68e77477d468f7b9e59af51c to your computer and use it in GitHub Desktop.
Save tomdaley92/789688fc68e77477d468f7b9e59af51c to your computer and use it in GitHub Desktop.
Proxmox - SPICE Client setup for MacOS

Proxmox - SPICE client setup for MacOS

  1. Install a working (and compiled) version of virt-viewer. You may view the homebrew package's upstream source on GitHub.

    brew tap jeffreywildman/homebrew-virt-manager
    brew install virt-viewer
  2. Once that's installed should be able make a call remote-viewer with a pve-spice.vv file downloaded from proxmox web interface

    remote-viewer pve-spice.vv

    Check out this useful script for debugging. There are also several other cli tools like this one on GitHub that can be used to test the same sort of thing.

Improving Quality of Life

We want remote-viewer to automatically start and open the session when we double click the VM entry in proxmox. To do that we need to first create a small helper application.

  1. Launch Automator and select Application from the dropdown list, when prompted.

    Screen Shot 2021-07-15 at 1 39 31 PM

  2. Search for shell and drag to the right. The contents:

    /usr/local/bin/remote-viewer "$@"

    Make sure to select as arguments for passing the input. Save as ~/Applications/pve-spice-launcher.app.

    Screen Shot 2021-07-15 at 2 13 01 PM

  3. Locate a pve-spice.vv file and right click, and go to Get Info -> Open With -> Change All, look for the .app file you just made.

    Screen Shot 2022-02-16 at 11 26 22 AM

  4. In Chrome, click on the small arrow on the list of downloads at the bottom, and select "Always open files of this type"

    Screen Shot 2021-07-15 at 2 02 46 PM

  5. If everything is set up correctly you should be able to double-click on the VM in the left pane of Proxmox and remote-viewer should start up and take care of the rest.

    Note: the pve-spice.vv files will be automatically deleted by remote-viewer

    Screen Shot 2021-07-15 at 2 05 57 PM

    Screen Shot 2021-07-15 at 4 42 21 PM

Enjoy!

#!/usr/bin/env bash
set -e
# needs pve-manager >= 3.1-44
usage() {
echo "Usage: $0 [-u <string>] [-p <string>] vmid [node [proxy]]"
echo
echo "-u username. Default root@pam"
echo "-p password. Default ''"
echo
echo "vmid: id for VM"
echo "node: Proxmox cluster node name"
echo "proxy: DNS or IP (use <node> as default)"
exit 1
}
PASSWORD=""
USERNAME=""
while getopts ":u:p:" o; do
case "${o}" in
u)
USERNAME="${OPTARG}"
;;
p)
PASSWORD="${OPTARG}"
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [[ -z "$PASSWORD" ]]; then
PASSWORD=""
fi
if [[ -z "$USERNAME" ]]; then
USERNAME='root@pam'
fi
DEFAULTHOST="$(hostname -f)"
# select VM
[[ -z "$1" ]] && usage
VMID="$1"
#[[ -z "$2" ]] && usage
NODE="${2:-$DEFAULTHOST}"
if [[ -z "$3" ]]; then
PROXY="$NODE"
else
PROXY="$3"
fi
NODE="${NODE%%\.*}"
DATA="$(curl -f -s -S -k --data-urlencode "username=$USERNAME" --data-urlencode "password=$PASSWORD" "https://$PROXY:8006/api2/json/access/ticket")"
echo "AUTH OK"
TICKET="${DATA//\"/}"
TICKET="${TICKET##*ticket:}"
TICKET="${TICKET%%,*}"
TICKET="${TICKET%%\}*}"
CSRF="${DATA//\"/}"
CSRF="${CSRF##*CSRFPreventionToken:}"
CSRF="${CSRF%%,*}"
CSRF="${CSRF%%\}*}"
curl -f -s -S -k -b "PVEAuthCookie=$TICKET" -H "CSRFPreventionToken: $CSRF" "https://$PROXY:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy" -d "proxy=$PROXY" > $NODE-$VMID.vv
exec remote-viewer $NODE-$VMID.vv
@martibi
Copy link

martibi commented Apr 7, 2023

I'm facing a different sort of issue. Whenever I try to run the .vv file via remote-viewer it returns with this error: Unsupported graphics type 'spice' error. A quick search indicates that this is due to spice-gtk being excluded. I am using https://github.com/jeffreywildman/homebrew-virt-manager which already includes spice-gtk so not sure what is wrong. I am using macOS 12.6 Monterey on Intel Core.

$ sw_vers
ProductName:	macOS
ProductVersion:	12.6
BuildVersion:	21G115

$ remote-viewer --version
remote-viewer version 11.0
$ remote-viewer -v --debug Unknown-24
(remote-viewer:90666): virt-viewer-DEBUG: 11:29:10.442: keymap string is empty - nothing to do

(remote-viewer:90666): virt-viewer-WARNING **: 11:29:10.463: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)

(remote-viewer:90666): virt-viewer-WARNING **: 11:29:10.463: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)

(remote-viewer:90666): virt-viewer-WARNING **: 11:29:10.463: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)

(remote-viewer:90666): virt-viewer-WARNING **: 11:29:10.463: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)

(remote-viewer:90666): virt-viewer-WARNING **: 11:29:10.463: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)

(remote-viewer:90666): virt-viewer-WARNING **: 11:29:10.463: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)
(remote-viewer:90666): virt-viewer-DEBUG: 11:29:10.985: Opening display to Unknown-24
(remote-viewer:90666): virt-viewer-DEBUG: 11:29:10.986: Guest (null) has unsupported spice display type
Guest (null) has unsupported spice display type

@martibi
Copy link

martibi commented Apr 7, 2023

I'm facing a different sort of issue. Whenever I try to run the .vv file via remote-viewer it returns with this error: Unsupported graphics type 'spice' error. A quick search indicates that this is due to spice-gtk being excluded. I am using https://github.com/jeffreywildman/homebrew-virt-manager which already includes spice-gtk so not sure what is wrong. I am using macOS 12.6 Monterey on Intel Core.

This fixed the issue jeffreywildman/homebrew-virt-manager#200 (comment) basically depends_on "gobject-introspection" had to be added

@ted1735
Copy link

ted1735 commented May 11, 2023

Working perfectly!!!

@Makishima
Copy link

Search for shell and drag to the right. The contents:
/usr/local/bin/remote-viewer "$@"

For me it is /opt/homebrew/bin/remote-viewer "$@"

@Mimiz06
Copy link

Mimiz06 commented Sep 13, 2023

hello !! im newbie, and have this error when trying to lunch the command remote-viewer console.vv
(remote-viewer:75521): Gtk-WARNING **: 11:47:56.382: cannot open display
i'm under MAC M1 Pro 12.6
thanks for help

@jfberry
Copy link

jfberry commented Dec 20, 2023

This is excellent... and working well. But when I try and open a second connection it blocks until the first is closed. this is probably a tick box somewhere to get it to launch a new instance rather than use an existing one, but I don't know where to look!

@julian4646
Copy link

julian4646 commented Jan 18, 2024

working great (OSX M1 Ventura 13.6.2) - the only issue I have is my Proxmox is not handing out the spice file with a "vv" extension - it gives no extension - so i have to do something like this in terminal: remote-viewer XXrTt33t

any one know how to get Proxmox to supply the shortcut file with a .vv ext ?

EDIT FIXED - works fine with Chrome (not ffox)

@ballo
Copy link

ballo commented Jan 24, 2024

Hello. I'm a little confused as to what systems this can target. The bundle definitely fails to execute on an old PowerPC system.

@sbussard
Copy link

Who else is here because the new version of TrueNAS Scale comes with a SPICE client with a bad user experience?

@boretom
Copy link

boretom commented Jan 28, 2024

This is excellent... and working well. But when I try and open a second connection it blocks until the first is closed. this is probably a tick box somewhere to get it to launch a new instance rather than use an existing one, but I don't know where to look!

Same here and it tool me way to long to find the right search query to solve it ... but I got there:

You have to start the script in the background (that was clear to me) and redirect the stdout and stderr output to /dev/null otherwise the Applescript will wait until the script exits:

If using 'Run Shell Script' (Pass input : as arguments)

/opt/homebrew/bin/remote-viewer "$@" &> /dev/null &

If using 'Run AppleScript':

on run {input, parameters}
	set f to POSIX path of (input as text)
	do shell script "/opt/homebrew/bin/remote-viewer" & " '" & f & "' &> /dev/null &"
end run

Both ways work for me on a Macbook Air M2 with Firefox 122.0

References to where I got it from:

@jfberry
Copy link

jfberry commented Jan 28, 2024

This is excellent... and working well. But when I try and open a second connection it blocks until the first is closed. this is probably a tick box somewhere to get it to launch a new instance rather than use an existing one, but I don't know where to look!

Same here and it tool me way to long to find the right search query to solve it ... but I got there:

I experimented with this for ages, including ending up a few times with thousands of processes being executed and taking my whole machine down. Thanks for persevering!

@eskerda
Copy link

eskerda commented Jan 29, 2024

Via script, easier and more secure access can be granted by using an API token instead of generating the cookie with the username and password

Create API Token

Go to pool view / datacenter / API Tokens / Add
Select user / Add token ID / Either disable privilage separation or grant ["perm","/vms/{vmid}",["VM.Console"]]

Sample

Set host, node, vm-id, and token accordingly.
Token looks like user@realm!some-key-id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

remote-viewer <(
    curl "https://$HOST:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy" \
         -H "Authorization: PVEAPIToken=$TOKEN" \
         -d "proxy=$HOST" \
         -f -s -S -k
)

Here's a simple cli tool I made for my setup https://github.com/eskerda/px

@ropelletier
Copy link

Ran into this error when installing virt-viewer "Error: Too many open files - /usr/bin/xcrun clang"

The fix was this command:

ulimit -Sn 512

Maybe add this to your instructions. Thank you very much, this was extremely helpful.

@uamarchuan
Copy link

Somebody knows how to pack virt-viewer to the app file with all necessary dependencies?
Any instructions or bash scripts for that?
like this one:
http://people.freedesktop.org/~teuf/spice-gtk-osx/dmg/0.5.7/RemoteViewer-0.5.7-1.dmg

@fskale
Copy link

fskale commented Feb 5, 2024

Hi, i forgot about this particular thread ;-)
If i use the provided taps (homebrew), the app cannot open encrypted connections.
I gladly would provide my self compiled app but how ?
I don't wann run into license issues…

@fskale
Copy link

fskale commented Feb 6, 2024

Hi again,
i uploaded the App on my private cloud:
https://wolke.dah.am/s/pbK73ZAXxpaskis
It's compiled only for x86_64.
The porting to AARCH64 is work in progress (>= 20%) . (Many header files must be patched)
Tested OS: 12.x and 13.x x86_64
Please report back.

@uamarchuan
Copy link

Please report back.

Hi Fskale,
Thanks for sharing, for me it works. I have old MacBook Air with the latest Sonoma 14.3.

@fskale
Copy link

fskale commented Feb 6, 2024

Please report back.

Hi Fskale, Thanks for sharing, for me it works. I have old MacBook Air with the latest Sonoma 14.3.

Did you try multi monitoring as well ?
It took me several weeks to get a compiled binary. (metal framework etc.)

@uamarchuan
Copy link

yes, there seems to be no problem with multi-monitoring... I turn on the second monitor and can move firefox to the other display
Screenshot 2024-02-06 at 19 55 11
I can do several tests for you on my mac, just let me know.

@fskale
Copy link

fskale commented Feb 6, 2024

Is the mouse in sync ?
If i connect to an ovirt 4.3 vm using encryption and the spice protocol, my mouse is not in sync.
But this could be because of the nature of the spice protocol compatibility issues and "ancient" ovirt 4.3 ;-)

@uamarchuan
Copy link

I don't have problem with mouse sync.
What I've noticed that share clipboard is not work properly. From Spice to host I can copy but from host to Spice not :(

@fskale
Copy link

fskale commented Feb 10, 2024

I don't have problem with mouse sync. What I've noticed that share clipboard is not work properly. From Spice to host I can copy but from host to Spice not :(

For that to work, you've to install spice-vdagent.
Docs:
https://www.spice-space.org/spice-user-manual.html#agent

@fskale
Copy link

fskale commented Feb 11, 2024

Today i started my "cross compile challenge" for arm64e support.
About 30% done so far. (base and dep libs)
Will keep you informed…

@maximko
Copy link

maximko commented Feb 28, 2024

Please report back.

Thank you, works for me on Ventura but crash happens when I copy text inside vm:
Gdk:ERROR:../../../../spice-jhbuild/source/gtk+-3.24.36/gdk/quartz/gdkeventloop-quartz.c:585:select_thread_collect_poll: assertion failed: (ufds[i].fd == current_pollfds[i].fd) Bail out! Gdk:ERROR:../../../../spice-jhbuild/source/gtk+-3.24.36/gdk/quartz/gdkeventloop-quartz.c:585:select_thread_collect_poll: assertion failed: (ufds[i].fd == current_pollfds[i].fd) RemoteViewer.app/Contents/MacOS/RemoteViewer: line 107: 82349 Abort trap: 6 "$bundle_contents/MacOS/$name-bin" "$@" $EXTRA_ARGS
Also clipboard sharing from macos to guest doesn't work.

@fskale
Copy link

fskale commented Feb 28, 2024

Since the assertion failed, there must a problem with the poll syscall in the vda agent plugin.
Are you using the vda agent in the vm ?
Check using dmesg on the vm side if there's a segfault…
Same issue already reported: jeffreywildman/homebrew-virt-manager#204
I will test it on my own, but not until next week…
I'm quite busy at the moment…

@fskale
Copy link

fskale commented Feb 28, 2024

There are some patch which could be applied to gtk+ version 3.24.
There were some changes to the UI in gdkevents-quartz.c.
Not sure when i've time for that to patch, compile and test. (takes a lot of time ;-) )

@fskale
Copy link

fskale commented Apr 15, 2024

Hi again, i uploaded the App on my private cloud: https://wolke.dah.am/s/pbK73ZAXxpaskis It's compiled only for x86_64. The porting to AARCH64 is work in progress (>= 20%) . (Many header files must be patched) Tested OS: 12.x and 13.x x86_64 Please report back.

Since there's suspicious traffic, i'm adding the SH256 of the ZIP file here.
d21d6003f57935b275b1190a3405cbf65931d35aacaf8d360a51372aa40b3279

Check before running the app !

@TheQL
Copy link

TheQL commented May 3, 2024

It's not entirely related to this gist, but it would improve my quality of life greatly!
I have a German keyboard layout Mac and whilst most characters work out of the box I cannot get \ and | working for the life of it.
"<>" and "^°" are just switched but basically work. I tried to get it remapped using --keymap but even some of the most basic remappings I tried didn't work, like ALT or ALT_L modifiers were completely ignored. Does anybody have any experience with this and can point my into the right direction? Thanks!

@fskale
Copy link

fskale commented May 3, 2024

It's not entirely related to this gist, but it would improve my quality of life greatly! I have a German keyboard layout Mac and whilst most characters work out of the box I cannot get \ and | working for the life of it. "<>" and "^°" are just switched but basically work. I tried to get it remapped using --keymap but even some of the most basic remappings I tried didn't work, like ALT or ALT_L modifiers were completely ignored. Does anybody have any experience with this and can point my into the right direction? Thanks!

It works, using my compiled app:

| -> right option key + ?
\ -> right option key + 7

Be sure to load the german keymap if not defined (console-data).
if not: loadkeys de

@TheQL
Copy link

TheQL commented May 3, 2024

It works, using my compiled app:

| -> right option key + ?
\ -> right option key + 7

Slightly different for me, but using the right option key was the hint I needed! Found what I searched for plus some brackets ;)

@jamesgreenblue
Copy link

Does this require rosetta?

@fskale
Copy link

fskale commented May 15, 2024

Does this require rosetta?

Not if you're using an Intel Mac.
Porting to ARM is still work in progress…

@TheQL
Copy link

TheQL commented May 15, 2024

Does this require rosetta?

Hm, the remote-viewer itself doesn't require Rosetta if you're using brew for arm. Not sure if any dependencies do, but thought that not.

# file /opt/homebrew/bin/remote-viewer
/opt/homebrew/bin/remote-viewer: Mach-O 64-bit executable arm64

@fskale
Copy link

fskale commented May 16, 2024

Does this require rosetta?

Hm, the remote-viewer itself doesn't require Rosetta if you're using brew for arm. Not sure if any dependencies do, but thought that not.

# file /opt/homebrew/bin/remote-viewer
/opt/homebrew/bin/remote-viewer: Mach-O 64-bit executable arm64

Sidenote.
The thing is, that the homebrew version doesn't support encrypted connections, which are used by OVIRT etc.
So i rebuilt the whole dependecy tree as well as the app itself.
Fyi.

@benjenj
Copy link

benjenj commented Jun 28, 2024

I'm using the BETA macOS 15.0, it won't work.
The command virt-viewer pve-spice.vv just gave me errors
(remote-viewer:54950): virt-viewer-WARNING **: 02:45:03.484: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0)
Totally have no idea WTF it is after 10 hours tweaking.

@aanikolaeff
Copy link

All works fine on M2MAX except USB redirection. I got error "Could not redirect USB device: could not claim interface 0 (configuration 1): LIBUSB_ERROR_ACCESS (0)"

@fskale
Copy link

fskale commented Jul 18, 2024

I'm using the BETA macOS 15.0, it won't work. The command virt-viewer pve-spice.vv just gave me errors (remote-viewer:54950): virt-viewer-WARNING **: 02:45:03.484: (../src/virt-viewer-window.c:831):accel_key_to_keys: runtime check failed: ((accel_mods & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0) Totally have no idea WTF it is after 10 hours tweaking.

What version of gdk did you build remote-viewer with ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment