Skip to content

Conversation

@jelly
Copy link
Member

@jelly jelly commented Nov 22, 2024

This throws an error when trying to create a system session vm as limited user.

@jelly jelly requested a review from mvollmer November 22, 2024 09:53
@jelly jelly force-pushed the dont-show-system-session-for-user branch from b3dcf68 to 54f83f0 Compare November 26, 2024 16:40
Comment on lines 2805 to 2807
b.click("#create-new-vm")
b.wait_visible("#create-vm-dialog")
b.wait_not_present("#connection")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any other test which covers VM creation in unprivileged mode? If so, this would better fit there. If not, that's a major gap indeed, and this test should actually create the VM and check that it starts and boots fine (including the "wait for login prompt").

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is confusingly what TestMachinesLifecycle does:

    def _testBasic(self, user=None, superuser=True, expect_empty_list=False, run_pixel_tests=False):
        b = self.browser
        m = self.machine

        # We want no initial watchdog
        args = self.createVm("subVmTest1", os="linux2016")

        self.login_and_go("/machines", user=user, superuser=superuser)

So we can drop this test


const detailsTab = (
<>
{superuser.allowed &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think people can create polkit rules to allow non-priv users access to the "system" connection. In fact cockpit-machines always connects to both "system" and "session" on initialization and tolerates AccessDenied errors for non-priv users.

So I think we should make a new global flag that says "can't access system connection", and use that instead of superuser.allowed in this PR. The place to set that flag is app.jsx:94, I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polkit is a disaster if you ask me, we have no way to detect it. But plumbing the state through should work. But looking at our code this is all a bit confusing I guess we look at systemSocketInactive?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turns into a yakshave...

    } else if ((superuser.allowed && systemSocketInactive) || loadingResources) {

So seems my solution is "correct" :) But ofcourse we can rework this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or not, not sure why this even exists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and with the move virt-xml, being able to connect to the system session vuia D-Bus does not mean that you can successfully run virt-xml.

Let's keep the superuser.allowed check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you changed it already....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or does virt-xml call the D-Bus API?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but polkit works inside th actual libvirt daemon as well, and I expect virt-install, virt-xml etc to be subject to the same polkit rules as D-Bus clients.

I'll research this properly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's complicated. There are two places to define policy, one for native policy for libvirtd that affects direct clients like virsh and virt-xml, and another one for the D-Bus API, which affects clients using that, like half of cockpit-machines.

This is annoying but it can be made to work, and we should not break people arbitrarily that do that.

@jelly jelly force-pushed the dont-show-system-session-for-user branch from 54f83f0 to 3a96bad Compare December 3, 2024 09:34
@jelly jelly force-pushed the dont-show-system-session-for-user branch from 3a96bad to 09ec08f Compare December 16, 2024 12:55
@mvollmer mvollmer self-requested a review September 3, 2025 13:10
@mvollmer
Copy link
Member

mvollmer commented Sep 3, 2025

Sorry, I have to look at this again. Luckily I learned a thing or two about c-machines in the mean time.

Copy link
Member

@mvollmer mvollmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this is the right thing to do.

Being able to connecting to the qemu:///system connection does indeed mean that virt-install and virt-xml are also able to work. For example, a limited user in the libvirt group can create and manage VMs on the system connection, using our mix of D-Bus, virt-install, and virt-xml.

Libvirt can use polkit internally (not via D-Bus) for fine grained access control. I have not tested it, but I expect that the D-Bus interface as well as virt-install and virt-xml are subject to it equally.


const detailsTab = (
<>
{this.props.systemSocketAvailable &&
Copy link
Member

@mvollmer mvollmer Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of completely hiding the connection selector, it should turn read-only and just say "User session" without any radio buttons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure :) But I did something else woops just disabled both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I have pushed a version without radio buttons.

@jelly jelly force-pushed the dont-show-system-session-for-user branch 4 times, most recently from df841ed to 009b375 Compare September 4, 2025 16:23
@mvollmer
Copy link
Member

mvollmer commented Sep 5, 2025

but I expect that the D-Bus interface as well as virt-install and virt-xml are subject to it equally.

Hah, being young and naive...

mvollmer
mvollmer previously approved these changes Sep 5, 2025
Copy link
Member

@mvollmer mvollmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mvollmer
Copy link
Member

The tests don't want to go green... I'll have a look.

jelly and others added 2 commits September 15, 2025 14:07
A limited access user cannot create a system session virtual machine so
this would just throw an error after creation.
@mvollmer
Copy link
Member

Rebased. Now looking at the tests...

@mvollmer mvollmer force-pushed the dont-show-system-session-for-user branch from 342d31e to 76ac05d Compare September 15, 2025 11:14
id="connectionName-session"
label={rephraseUI("connections", LIBVIRT_SESSION_CONNECTION)} />
{ isDisabled
? rephraseUI("connections", connectionName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

? rephraseUI("connections", connectionName)
: <>
<Radio isChecked={connectionName === LIBVIRT_SYSTEM_CONNECTION}
onChange={() => onValueChanged('connectionName', LIBVIRT_SYSTEM_CONNECTION)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

vmName: '',
suggestedVmName: '',
connectionName: LIBVIRT_SYSTEM_CONNECTION,
connectionName: this.props.systemSocketAvailable ? LIBVIRT_SYSTEM_CONNECTION : LIBVIRT_SESSION_CONNECTION,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test. Details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants