Add qubes_shell_rpc option#5
Conversation
The human user should be able to predict which qube user each play will use to connect to the remote qube.
Allow the user to select the qubes shell RPC the task should use to
connect to the remote qube with the `qubes_shell_rpc` option. Default
to `qubes.VMShell`. For example:
```yaml
- name: Example
vars:
qubes_shell_rpc: qubes.VMRootShell
tasks:
- name: Run whoami
ansible.builtins.command:
cmd: whoami
```
The README describes running Ansible from mgmtvm instead of dom0, but the `-u` option is disallowed from domUs: ```console mgmtvm$ qvm-run --pass-io --service -u user workvm qubes.VMShell ... ValueError: non-default user not possible for calls from VM ``` This change unifies the interface for running tasks as non-default users on dom0 and domUs under the qubes_shell_rpc option.
|
Can the |
|
Suggestion: If you intend for this pull request to resolve the associated issue and would like for it to be linked to the issue automatically, you can put |
It might be possible, but I think it would be messy. The The user would need to enable the no-op become plugin on specific hosts or groups with the An alternative could be restoring the Is it worth pursuing Edit: If the user can use |
Yes, this makes sense. And implementing |
|
Closing in favor of PR #8 |
This PR replaces the ansible_user option with the qubes_shell_rpc option, which defaults to qubes.VMShell. The plugin always uses the qubes_shell_rpc value instead of trying other RPCs.
Combined with the updated qubes.VMRootShell policy in the README in PR https://github.com/fepitre/qubes-ansible/pull/4, this fixes running privileged tasks on qubes without passwordless root, like minimal qubes. It also enables other functionalities.
Root connections to minimal qubes
There was no way to run tasks as root on qubes without the qubes-core-agent-passwordless-root package installed. Plays that use
become: truefail on minimal qubes because the default user can't assume root privileges at all.This fix depends on the updated qubes.VMRootShell policy described in PR https://github.com/fepitre/qubes-ansible/pull/4:
This change enables connecting to minimal qubes as the default user by default:
As well as root:
become: truestill works on qubes with qubes-core-agent-passwordless-root installed:become: truewill still fail on minimal qubes, as expected.qubes_shell_rpc: qubes.VMRootShellalso works on regular qubes:Shell predictability
This change makes the connection plugin always use the value of qubes_shell_rpc to connect to remote qubes. This option defaults to qubes.VMShell.
Previously, the connection plugin tried qubes.VMRootShell to transfer files and only used qubes.VMShell if qubes.VMRootShell failed.
The qubes.VMRootShell policy in the README doesn't set the user parameter to root. With this configuration, qubes.VMRootShell is the same as qubes.VMShell, anyway.
I'm not sure why elevating privileges in the put_file method was necessary. In my limited testing, using a shell with default user privileges hasn't caused any obvious problems.
Custom users and shells
This change also enables connecting to qubes as arbitrary users through policy parameters and arbitrary shells through custom RPCs.
With qubes.VMAliceShell symlinked to qubes.VMShell, this policy allows Ansible to connect as alice:
Users can define their own RPCs to run non-Bourne shells (see ansible_shell_type) or even shells in containers.
Unified interface between dom0 and domUs
The ansible_user option is unusable on domUs like the mgmtvm described in the README. This option is only usable on dom0. The qvm-run command's
-uoption is disallowed on VMs:Instead of providing two methods of configuring the remote user, one of which only works on dom0, this change removes the half-functional ansible_user option.
Closes QubesOS/qubes-issues#9934
Closes QubesOS/qubes-issues#9938