Skip to content

Add the feature to prohibit starting of a qube #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions qubes/tests/integ/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,22 @@ def test_206_shutdown_paused(self):
self.loop.run_until_complete(self.vm.start())
self.shutdown_paused(self.vm)

def test_207_domain_start_prohibition(self):
vmname = self.make_vm_name("compromised_vm")
self.vm = self.app.add_new_vm(
qubes.vm.appvm.AppVM,
name=vmname,
template=self.app.default_template,
label="red",
)
self.loop.run_until_complete(self.vm.create_on_disk())
with self.assertRaises(qubes.exc.QubesException):
self.vm.features["prohibit-start"] = (
"The qube is compromised and awaits forensic analysis"
)
self.loop.run_until_complete(self.vm.start())
self.assertFalse(self.vm.is_running())


class TC_01_Properties(qubes.tests.SystemTestCase):
# pylint: disable=attribute-defined-outside-init
Expand Down
12 changes: 12 additions & 0 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
.. event:: domain-start-failed (subject, event, reason)

Fired when :py:meth:`start` method fails.
or if domain has a `prohibit-start` feature.
*reason* argument is a textual error message.

Handler for this event may be asynchronous.
Expand Down Expand Up @@ -1302,6 +1303,17 @@

await self._ensure_shutdown_handled()

prohibit_rationale: str = self.features.get("prohibit-start", False)
if prohibit_rationale:
await self.fire_event_async(

Check warning on line 1308 in qubes/vm/qubesvm.py

View check run for this annotation

Codecov / codecov/patch

qubes/vm/qubesvm.py#L1306-L1308

Added lines #L1306 - L1308 were not covered by tests
"domain-start-failed",
reason="Qube start is prohibited. "
f"Rationale: {prohibit_rationale}",
)
raise qubes.exc.QubesException(

Check warning on line 1313 in qubes/vm/qubesvm.py

View check run for this annotation

Codecov / codecov/patch

qubes/vm/qubesvm.py#L1313

Added line #L1313 was not covered by tests
f"Qube start is prohibited. Rationale: {prohibit_rationale}"
)

self.log.info("Starting {}".format(self.name))

try:
Expand Down