alinoaimi / multighost

A GUI for Multipass
13 stars 2 forks source link

gRPC / protobuf interface should be used instead of bash CLI #1

Open ethicnology opened 1 year ago

ethicnology commented 1 year ago

Hi fellow, I also wanted to do a Flutter GUI for Multipass, glad you did a nice work already.

I discovered that multipass CLI use a gRPC / Protobuf interface to communicate with multipassd. You should definitely use the gRPC interface instead of wrapping the gRPC "wrapper", the CLI.

It would improve the performances by removing useless steps such as bash execution and JSON encoding / decoding. It would also unlock new features such as remote monitoring of multipass host by using address:port to address gRPCalls

https://github.com/canonical/multipass/blob/main/src/rpc/multipass.proto

alinoaimi commented 1 year ago

Hi ethicnology,

thanks for sharing,

I couldn't find an official documentation for the gPRC interface, and I'm not sure if it is accessible from outside Multipass but I'm interested in experimenting with it.

It is being used by the official systray app and clients https://github.com/canonical/multipass/blob/main/src/client/gui/client_gui.cpp https://github.com/canonical/multipass/blob/main/src/client/cli/cmd/aliases.h https://github.com/canonical/multipass/blob/main/src/daemon/daemon_rpc.cpp (gPRC server initialization)

I found this reply from a canonical dev, mentioning that it's not public, it's from 2021, not sure if this has changed. https://discourse.ubuntu.com/t/multipass-cloud-server/20835/4

I'm also planning to enable connecting to a remote Multipass server via SSH, then adjust the UI for Android and iOS, to enable controlling and accessing the instances via the mobile app, if I go the gPRC path, it could be more difficult to access it remotely, without extra code running on the server/host-machine as a middleman to expose it.

ethicnology commented 1 year ago

I go the gPRC path, it could be more difficult to access it remotely, without extra code running on the server/host-machine as a middleman to expose it.

I thought the same but in fact, Multipass already provide the remote feature, it will run the gRPC API, you can then play with it by using an env variable like this:

MULTIPASS_SERVER_ADDRESS=<hostname>:51005 multipass find

I just tried, it works.

Now I'm trying to use gRPCurl to access the gRPC in the same way without the CLI. We should investigate this way, because if it works everything will be fine from flutter, all the structs will be generated thanks to protobuf.

Currently, I'm stuck here:

$ grpcurl -insecure -proto multipass.proto -d '' pop-os:51005 multipass.Rpc/ping
ERROR:
  Code: Unauthenticated
  Message:
$ grpcurl -proto multipass.proto -d '' pop-os:51005 multipass.Rpc/ping
Failed to dial target host "pop-os:51005": x509: certificate relies on legacy Common Name field, use SANs instead
$ grpcurl -plaintext -proto multipass.proto -d '' pop-os:51005 multipass.Rpc/ping
Failed to dial target host "pop-os:51005": context deadline exceeded

I don't know how to deal with auth because I'm pretty new to gRPC…

ethicnology commented 1 year ago

@alinoaimi I found this reply from a canonical dev, mentioning that it's not public

I opened an issue on multipass repository. Maybe they can help us to understand how to consume gRPC or confirm that it's not public.