Go library for interfacing with QEMU guest agent via libvirt
Find a file
2024-07-07 18:57:06 +02:00
bin Initial commit 2024-07-07 18:51:49 +02:00
cmd Initial commit 2024-07-07 18:51:49 +02:00
pkg/libguestd Initial commit 2024-07-07 18:51:49 +02:00
.gitignore Initial commit 2024-07-07 18:51:49 +02:00
go.mod Initial commit 2024-07-07 18:51:49 +02:00
go.sum Initial commit 2024-07-07 18:51:49 +02:00
LICENSE Initial commit 2024-07-07 18:51:49 +02:00
Makefile Initial commit 2024-07-07 18:51:49 +02:00
README.md Update README 2024-07-07 18:57:06 +02:00

Libguestd

This is supposed to be a library that helps with operations on qemu-guest-agent.

You need to connect to libvirt daemon on your own. Take a look at cmd/libguestd-cli for example.

Keep in mind that not all implementations of qemu-guest-agent support every option. This library makes effort to check if required features are supported before trying to execute something. Some features may be intentionally disabled (see security chapter) or may not be supported on target platform.

This library implements some(most?) functions described in QEMU Guest Agent Protocol Reference.

Not implemented:

  • guest-sync-delimited (my understanding is that libvirt does this for me)
  • guest-sync (same as above)
  • guest-set-time
  • guest-shutdown (there is a libvirt command for that already)
  • guest-shutdown (there is a libvirt command for that already)
  • guest-file-seek (this library only reads/writes whole file)
  • guest-file-flush (this library only writes whole file, then closes it immediately)
  • guest-fsfreeze-* (there are libvirt commands for that)
  • guest-fstrim (I don't need this)
  • guest-suspend-*
  • guest-get-vcpus (I don't need this)
  • guest-set-vcpus (I don't need this)
  • guest-get-memory-blocks
  • guest-get-memory-block-info
  • guest-set-memory-blocks
  • guest-get-users (I don't think this is usefull)
  • guest-get-timezone
  • guest-get-devices (windows only)

Not implemented but I want to implement it:

  • guest-get-cpustats

CLI tools

Alongside this library, a few tools are provided. You can build them simply by executing make in cloned repo.

cp2guest

Allows copying files from/to guest using qemu guest agent.

Example usage:

./bin/cp2guest -domain guesttools -src README.md -dst /tmp/README.md

Or, to copy from VM to host:

./bin/cp2guest -domain guesttools -src /root/anaconda-ks.cfg -dst /tmp/anaconda-ks.cfg -reverse

guestrun

Execute command in guest

Example usage:

./bin/guestrun -domain guesttools -cmd 'ls -ltrh /bin/'

Command will be executed as /bin/sh -c 'ls -ltrh /bin'.

Libguestd-cli

This tool implements most functions of this library.

Since usage should be self-explainatory, I will just leave a few example commands here:

./bin/libguestd-cli -domain guesttools -username root -password 12345
./bin/libguestd-cli -domain guesttools -username root -sshkey-add 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID8qp7UQUINxLXog/sFgRKDtddiJHzkypyB7/OlmUbK2 lmoskala'
./bin/libguestd-cli -domain guesttools -username root -sshkey-remove 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID8qp7UQUINxLXog/sFgRKDtddiJHzkypyB7/OlmUbK2 lmoskala'
./bin/libguestd-cli -domain guesttools -username root -listkeys
./bin/libguestd-cli -domain guesttools -username root -fsinfo

Security

Some distributions (rocky linux for example) disables some functionalities of qemu-guest-agent by default. Most notably, all operations involving files and commands. Which actually seems like a good idea.

Also, selinux is known to cause problems when manipulating SSH keys: bug report