Qubes-Community-Content/docs/common-tasks/opening-urls-in-vms.md

188 lines
12 KiB
Markdown
Raw Normal View History

2023-06-05 00:44:25 -04:00
*Note: there is an ongoing [pull request](https://github.com/QubesOS/qubes-doc/pull/1314) to add most of the content of this document to the official Qubes OS documentation.*
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
<!-- BEGIN PR content -->
2018-09-27 04:04:45 -04:00
2023-06-05 00:44:25 -04:00
This page is about opening URLs and files from one qube in a different qube. The most straightforward way to do this is simply to [copy and paste URLs](/doc/how-to-copy-and-paste-text/) or [copy and move files](/doc/how-to-copy-and-move-files/) from the source qube to the target qube, then manually open them in the target qube. However, some users might wish to use [RPC policies](/doc/rpc-policy/) in order to regiment their workflows and safeguard themselves from making mistakes.
2023-06-05 00:44:25 -04:00
Naming conventions:
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
- `<SOURCE_QUBE>` is the qube in which the URL or file originates.
- `<TARGET_QUBE>` is the qube in which we wish to open the URL or file.
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
## Configuring RPC policies
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
The `qvm-open-in-vm` and `qvm-open-in-dvm` scripts are invoked in a qube to open files and URLs in another qube. Those scripts make use of the `qubes.OpenInVM` and `qubes.OpenURL` [RPC services](/doc/qrexec/#qubes-rpc-services). Qubes [RPC policies](/doc/rpc-policy/) control which RPC services are allowed between qubes.
2018-09-27 04:21:05 -04:00
2023-06-05 00:44:25 -04:00
Policy files are in `/etc/qubes/policy.d/`.
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
### Using the `ask` action
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
This action displays a confirmation prompt in dom0 with a drop-down list of allowed target qubes each time the associated RPC service is called. This setup makes it possible to always control whether and in which qube a URL or file opened.
2018-09-27 04:04:45 -04:00
2023-06-05 00:44:25 -04:00
The selected qube will automatically start if it wasn't running.
2018-09-27 05:45:58 -04:00
2023-06-05 00:44:25 -04:00
**Note:** When using `ask`, the target qube given as an argument to `qvm-open-in-vm` is ignored if no `allow` rule matches the current RPC service and source/target qubes.
2018-09-27 05:45:58 -04:00
2023-06-05 00:44:25 -04:00
### Using the `allow` action
2018-09-27 05:45:58 -04:00
2023-06-05 00:44:25 -04:00
This action allows a specified RPC service to be invoked between source and target qubes without displaying a confirmation prompt in dom0.
2018-09-28 05:16:34 -04:00
2023-06-05 00:44:25 -04:00
When an `allow` action is defined for a target other than `@dispvm`, the target qube is the one given as an argument to `qvm-open-in-vm` in `<SOURCE_QUBE>`. The corresponding RPC policies must be configured accordingly.
2018-09-28 05:16:34 -04:00
2023-06-05 00:44:25 -04:00
**Warning:** Since there is no user confirmation with `allow`, applications in `<SOURCE_QUBE>` could leak data through URLs or file names.
2018-09-27 05:45:58 -04:00
2023-06-05 00:44:25 -04:00
### Using disposables and the `@dispvm` keyword in policies
2018-09-27 04:21:05 -04:00
2023-06-05 00:44:25 -04:00
It is possible to further restrict a target disposable qube by specifying the template on which it is based with the `@dispvm:<DISPOSABLE_TEMPLATE>` syntax ([learn more](/doc/how-to-use-disposables/#opening-a-link-in-a-disposable-based-on-a-non-default-disposable-template-from-a-qube)).
2018-09-27 04:21:05 -04:00
2023-06-05 00:44:25 -04:00
**Note:** The keyword `@dispvm` designates any disposable based on the calling qube's default disposable template. It does *not* designate any disposable whatsoever. For example, if you were to run `qvm-open-in-vm @dispvm:<ONLINE_DISPOSABLE_TEMPLATE> https://www.qubes-os.org` in `<SOURCE_QUBE>` while `<ONLINE_DISPOSABLE_TEMPLATE>` is *not* `<SOURCE_QUBE>`'s default disposable template, it wouldn't work if your policy line merely had `@dispvm` as the target. You would have to use `@dispvm:<ONLINE_DISPOSABLE_TEMPLATE>` as the target instead.
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
## Sample RPC user policy
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
_See the main document, [RPC policies](/doc/rpc-policy/), for more information._
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
The following is a partial example of the kinds of `qubes.OpenInVM` and `qubes.OpenURL` rules that you could write in `/etc/qubes/policy.d/30-user.policy`:
2018-09-25 16:04:29 -04:00
~~~
2023-06-05 00:44:25 -04:00
# Deny opening files or URLs from or in 'vault'
qubes.OpenInVM * @anyvm vault deny
qubes.OpenURL * @anyvm vault deny
qubes.OpenInVM * vault @anyvm deny
qubes.OpenURL * vault @anyvm deny
# Allow 'work' to open URLs in disposable qubes without prompting the user
qubes.OpenURL * work @dispvm allow
# Allow 'work' to open files in 'untrusted' without prompting the user
qubes.OpenInVM * work @dispvm allow target=untrusted
# Allow any qube to open files and URLs in disposables based on the
# disposable templates 'foo' and 'bar'
qubes.OpenInVM * @anyvm @dispvm:foo allow
qubes.OpenURL * @anyvm @dispvm:bar allow
# Prompt the user before opening any file or URL in any other qube, but prefill
# the target with 'personal' for files and 'untrusted' for URLs
qubes.OpenInVM * @anyvm @anyvm ask default_target=personal
qubes.OpenURL * @anyvm @anyvm ask default_target=untrusted
2018-09-25 16:04:29 -04:00
~~~
2023-06-05 00:44:25 -04:00
## Configuring application handlers
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
It is possible to (re)define a default application handler so that it is automatically called by *any* application in `<SOURCE_QUBE>` to open files or URLs provided that the applications adhere to the [freedesktop](https://en.wikipedia.org/wiki/Freedesktop.org) standard (which is almost always the case nowadays).
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
For application-specific configurations or applications that don't adhere to the freedesktop standard, please refer to the unofficial, external [community documentation](https://github.com/Qubes-Community/Contents/blob/master/docs/common-tasks/opening-urls-in-vms.md).
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
Defining a new handler simply requires creating a [.desktop](https://specifications.freedesktop.org/desktop-entry-spec/latest/) file and registering it. The following example shows how to open http/https URLs (along with common "web" [media types](https://en.wikipedia.org/wiki/Media_type)) with `qvm-open-in-vm`:
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
- Create `$HOME/.local/share/applications/mybrowser.desktop` with the following content:
2018-09-28 04:56:00 -04:00
~~~
[Desktop Entry]
Encoding=UTF-8
2023-06-05 00:44:25 -04:00
Name=MyBrowser
Exec=qvm-open-in-vm <TARGET_QUBE> %u
2018-09-28 04:56:00 -04:00
Terminal=false
X-MultipleArgs=false
Type=Application
Categories=Network;WebBrowser;
MimeType=x-scheme-handler/unknown;x-scheme-handler/about;text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;
~~~
2023-06-05 00:44:25 -04:00
- Register the `.desktop` file with `xdg-settings set default-web-browser mybrowser.desktop`.
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
The same can be done with any other media type (see `man xdg-mime` and `xdg-settings`).
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
### Notes
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
- Some applications may not use the new XDG application handler (e.g., if you had previously configured default applications), in which case you'd have to manually configure the application to use the XDG handler.
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
- `qvm-open-in-vm target-qube %u` can be replaced by a user wrapper with custom logic for selecting different target qubes depending on the URL/file type, level of trust, etc. The RPC policies should be configured accordingly.
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
- Advanced users may wish to consider basing app qubes on [minimal templates](/doc/templates/minimal/). That way, unless a default handler is set, it is unlikely that any other program will be present that can open the URL or file.
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
<!-- END PR content -->
2018-09-27 04:04:45 -04:00
2023-06-05 00:44:25 -04:00
## Configuring specific applications
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
Most applications provide a way to select a given program to use for opening specific URL/file (MIME) types. We can use that feature to select the `/usr/bin/qvm-open-in-{vm,dvm}` scripts instead of the default programs.
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
The subsections below show how to configure popular applications in case the "default handler" approach above doesn't work / isn't sufficient.
### Firefox, Chrome/Chromium
2018-09-28 05:16:34 -04:00
Those browsers have an option to define programs associated to a file (MIME) type. It is pretty straightforward to configure and is outside the scope of this document.
An alternative is to use Raffaele Florio's [qubes-url-redirector](https://github.com/raffaeleflorio/qubes-url-redirector) add-on, which provides a lot of flexibility when opening links without the hassle of having to write custom shell wrappers to `qvm-open-in-vm`. For instance links can be opened with a context menu and the add-on's default behavior can be configured, even with whitelist regexes.
2018-09-28 11:24:58 -04:00
Notes:
2018-09-28 05:16:34 -04:00
2023-06-05 00:44:25 -04:00
- the qubes-url-redirector add-on will likely be included officialy in Qubes (see [this](https://github.com/QubesOS/qubes-issues/issues/3152) issue).
- the add-on can actually be used with applications other than firefox/chrome/chromium, the only requirement is that URLs open in a browser in `<SOURCE_QUBE>`. It works like so:
- the application in `<SOURCE_QUBE>` opens an URL in the default browser in `<SOURCE_QUBE>` (eg. firefox)
- firefox starts on `<SOURCE_QUBE>`, the add-on processes the URL and according to its configuration "sends" the URL to `<TARGET_QUBE>` with `qubes.OpenURL`
- the URL opens in the `<TARGET_QUBE>`'s browser
2018-09-28 05:16:34 -04:00
2023-06-05 00:44:25 -04:00
### Thunderbird
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
**Opening attachments**: "actions" must be defined, see section "Download Actions" settings" in [this document](http://kb.mozillazine.org/Actions_for_attachment_file_types).
2018-09-27 13:31:52 -04:00
2018-09-28 05:52:38 -04:00
**Opening URLs**: changing the way http and https URLs are opened requires tweaking configuration options; see [this](http://kb.mozillazine.org/Changing_the_web_browser_invoked_by_Thunderbird) and [this](http://kb.mozillazine.org/Network.protocol-handler.expose-all) document for more information. Those changes can be made in Thunderbird's built-in config editor, or by adding the following lines to `$HOME/.thunderbird/user.js`:
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
```
2018-09-25 16:04:29 -04:00
user_pref("network.protocol-handler.warn-external.http", true);
user_pref("network.protocol-handler.warn-external.https", true);
user_pref("network.protocol-handler.expose-all", true);
2023-06-05 00:44:25 -04:00
```
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
Thunderbird will then ask which program to use the next time a link is opened. If `<TARGET_QUBE>` is a standard (random) dispVM, choose `/usr/bin/qvm-open-in-dvm`. Otherwise you'll have to create a wrapper to `qvm-open-in-vm` since arguments cannot be passed to programs selected in Thunderbird's dialog gui. For instance, put the following text in `$HOME/bin/thunderbird-open-url`, make it executable, and select that program when asked which program to use:
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
```
2018-09-25 16:04:29 -04:00
#!/bin/sh
2023-06-05 00:44:25 -04:00
qvm-open-in-vm <TARGET_QUBE> "$@"
```
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
### Vi
2018-09-25 16:04:29 -04:00
2018-09-27 13:31:52 -04:00
Opening URLs: put the following in `$HOME/.vimrc`:
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
```
let g:netrw_browsex_viewer = 'qvm-open-in-vm <TARGET_QUBE>'
```
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
Typing `gx` when the cursor is over an URL will then open it in `<TARGET_QUBE>` (or will trigger a dialog if `ask` policy is configured, ignoring the `<TARGET_QUBE>` argument).
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
# Considerations on dispVMs
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
## Re-using dispVMs
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
In the section above we've seen how using the 'ask' RPC policy allowed us to start a (disp)VM once and use it for opening subsequent URLs (or files) to avoid having to wait insane amounts of time for dispVMs to start. However this comes at the price of a loss in compartmentalization. It is thus up to the user to carefully pick destination VMs and to manage the lifecycle of dispVMs, killing it/them when necessary when a clean state is required.
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
## Managing changes
2018-09-25 16:04:29 -04:00
2023-06-05 00:44:25 -04:00
When opening and modifying a document in a dispVM the content is sent back to `<SOURCE_QUBE>` when the dispVM's process (eg. LibreOffice) closes. The dispVM's private volume is then wiped and any change that was made to the VM are discarded - eg. automatically updated add-ons, blacklists, tweaked browser preferences, ... ; The following ideas show how to cope with those "deliberate" changes:
2023-06-05 00:44:25 -04:00
- inter-VM copy/paste is probably the easiest way to synchronize small amounts of data in text form from the dispVM to `<SOURCE_QUBE>` (or to another dedicated VM like the oft-used 'vault' VM). Eg.:
- passwords: copy/paste from/to KeepassX (or one of its forks).
- bookmarks: copy/paste from/to
- a plain text file
- or an html bookmark file (most browsers can export/import such file)
- or a dedicated bookmark manager like [buku](https://github.com/jarun/Buku) (command line manager, available in Fedora 28 repo - `dnf install buku`).
- other content/changes will have to be copied, usually to the dispVM templateVM. Care must be taken not to replicate compromised files: working with a freshly started dispVM and performing only the required update actions before synchronizing files with the templateVM is a good idea.
2018-09-27 04:04:45 -04:00
2023-06-05 00:44:25 -04:00
## Using "named" dispVMs
2018-09-28 04:56:00 -04:00
2023-06-05 00:44:25 -04:00
If for some reason a user needs to have use a dispVM with a given name - which is for instance handy when using `allow` RPC policies - he/she can do like so (replace `fedora-28-dvm` with the dvm template you want to use):
```
qvm-create -C DispVM -t fedora-28-dvm -l red <TARGET_QUBE>
```
This VM works like a regular VM, with the difference that its private disk is wiped after it's powered off. However it doesn't "auto power off" like random dispVMs so it's up to the user to power off (and optionally restart) the VM when he/she deems necessary.
------------------------------------------------------------------------
`Credits:` @raffaeleflorio, [Micah Lee](https://micahflee.com/2016/06/qubes-tip-opening-links-in-your-preferred-appvm/)