Qubes extensions usage / installation

30 views
Skip to first unread message

nils....@gmail.com

unread,
Oct 18, 2018, 1:24:47 AM10/18/18
to qubes-users
Hi everyone,

I'm trying to run some commands whenever a VM is started or a device is attached to a VM. I came upon this Github comment by Marek which says that this is possible with Qubes extensions: https://github.com/QubesOS/qubes-issues/issues/4126#issuecomment-406888845

I wrote a simple Qubes extension with the following project structure:

my_extension/
* my_extension/
** __init__.py
* setup.py

With the following `setup.py`:

```
#!/usr/bin/env python3

import setuptools

if __name__ == '__main__':
setuptools.setup(
name='my_extension',
version="1.0",
author='Nils Amiet',
author_email='nils....@foobar.tld',
description='My extension',
license='GPLv3',
url='https://foobar.tld',

packages=('my_extension',),

entry_points={
'qubes.ext': [
'my_extension = my_extension:MyExtension',
],
}
)
```

And `__init__.py`:

```
import qubes.ext


class MyExtension(qubes.ext.Extension):
@qubes.ext.handler("domain-start", system=True)
def on_vm_start(self, app, event, vm, **kwargs):
with open("/tmp/my_extension.log", "a+") as fout:
print("Started vm: {}".format(vm), file=fout)

```

Now, I installed this extension on a deployed Qubes OS installation in dom0 with `sudo ./setup.py install` but the file `/tmp/my_extension.log` is never created after having started some VMs. I was expecting to see something being written there.

Why is my extension not being loaded? Am I missing something here? How can I debug extensions and make sure they are being loaded? Is there a log somewhere?

Is Qubes OS going to call my `on_vm_start()` function whenever a VM is started just by installing the extension with `setup.py install`? What should I do so that it does?

Thank you and have a nice day,

Nils

Marek Marczykowski-Górecki

unread,
Oct 19, 2018, 6:34:11 AM10/19/18
to nils....@gmail.com, qubes-users
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
'domain-start' event is called on VM object, so it should not have
system=True. system=True is needed for events on Qubes() main object
itself, like property-set:default_template.

> def on_vm_start(self, app, event, vm, **kwargs):

For system=False events, it should be:
def on_vm_start(self, vm, event, **kwargs):

If you need to access app, you can still do that through vm.app.

> with open("/tmp/my_extension.log", "a+") as fout:
> print("Started vm: {}".format(vm), file=fout)
>
> ```
>
> Now, I installed this extension on a deployed Qubes OS installation in dom0 with `sudo ./setup.py install` but the file `/tmp/my_extension.log` is never created after having started some VMs. I was expecting to see something being written there.

Besides the system=True, everything else looks ok. Remember to restart
qubesd service after installing the extension.

> Why is my extension not being loaded? Am I missing something here? How can I debug extensions and make sure they are being loaded? Is there a log somewhere?
>
> Is Qubes OS going to call my `on_vm_start()` function whenever a VM is started just by installing the extension with `setup.py install`? What should I do so that it does?
>
> Thank you and have a nice day,
>
> Nils
>


- --
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEhrpukzGPukRmQqkK24/THMrX1ywFAlvJsxsACgkQ24/THMrX
1ywpbAf+KLCp44W+yYOKRpNm3tvTUrvYb20KF4y4FiEoWE9vTapIfT9fLNI3yfZw
eHn52vb14VdtxPnZ7yNEopHbDAKwj2+u1RTrjszsBitjRqiAEFkFeDHCRQB1QAN8
HwPUWXCIvBNbUxQzpLYXvQX6V7/Ll6a/M/9DcanfRyHlU5yCHM+ZmdgBK4kU+Nb3
0cyCsA27CV2AGYuYRyYh5kyT+WX9nIPTwRUmRNi0lIuT45gBIWQ9OYo4kKjDCIUc
/YBqcHn7pTTOwz4e5ct+b/YQWLMKk3n1NX4DGYjnBbpt7E0y9vk3uNnXV8/z3dtt
4GgwIivDTAYx/5pU5AjklNksAL1pgw==
=3wtl
-----END PGP SIGNATURE-----

nils....@gmail.com

unread,
Oct 19, 2018, 7:13:27 AM10/19/18
to qubes-users
This is now working as expected! Thank you very much!
Reply all
Reply to author
Forward
0 new messages