Skip to content
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
1 change: 1 addition & 0 deletions admin_salt/sd-admin-vault.sls
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sd-admin-vault:
- service.custom-persist
- set:
- custom-persist.persistent: dir:user:user:0700:/home/user/Persistent
- menu-items: "org.keepassxc.KeePassXC.desktop"
- tags:
- add:
- sd-workstation
Expand Down
5 changes: 3 additions & 2 deletions admin_salt/sd-admin.sls
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ sd-admin:
org.gnome.Nautilus.desktop
org.gnome.DiskUtility.desktop
xfce4-terminal.desktop
press.freedom.SecureDropAdminKeePassXC.desktop
press.freedom.SecureDropJournalistInterface.desktop
press.freedom.SecureDropSourceInterface.desktop
press.freedom.SecureDropSshApp.desktop
Expand All @@ -55,7 +54,8 @@ sd-admin-custom-persist:
- custom-persist.tor_config: dir:root:root:0700:/etc/tor
- custom-persist.home: /home

sd-admin-dom0-menu-favorites:
# Open Qubes menu to Favorites page by default and add launchers
sd-admin-dom0-menu:
qvm.features:
- name: dom0
- set:
Expand All @@ -65,3 +65,4 @@ sd-admin-dom0-menu-favorites:
press.freedom.SecureDropSourceInterface.desktop
press.freedom.SecureDropSshApp.desktop
press.freedom.SecureDropSshMon.desktop
- menu-initial-page: favorites_page
27 changes: 27 additions & 0 deletions securedrop_manage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,38 @@ def destroy_all_tagged(tag: str) -> None:
run_cmd(["qvm-remove", "-f", "--", vm.name])


# dom0 app menu settings applied by admin_salt.sd-admin
ADMIN_DOM0_MENU_FEATURES = {
"menu-favorites": " ".join(
[
"press.freedom.SecureDropAdminKeePassXC.desktop",
"press.freedom.SecureDropJournalistInterface.desktop",
"press.freedom.SecureDropSourceInterface.desktop",
"press.freedom.SecureDropSshApp.desktop",
"press.freedom.SecureDropSshMon.desktop",
]
),
"menu-initial-page": "favorites_page",
}


def revert_admin_dom0_menu() -> None:
"""
Undo the dom0 app menu settings applied by admin_salt.sd-admin, leaving
alone any that have since been changed to something else.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we really need to worry about this, just because on each dom0 salt run (updater), it's going to override any user customized changes anyways. So I think we could just unconditionally unset these.

Since this is just for uninstall code I'll leave it for a follow-up.

"""
dom0 = Qubes().domains["dom0"]
for feature, value in ADMIN_DOM0_MENU_FEATURES.items():
if dom0.features.get(feature) == value:
del dom0.features[feature]


def perform_uninstall(product: Product) -> None:
packages = []
if product.contains_admin:
print("Destroying all admin VMs")
destroy_all_tagged("sd-admin")
revert_admin_dom0_menu()
packages.append("securedrop-admin-dom0-config")

if product.contains_journalist:
Expand Down
31 changes: 31 additions & 0 deletions tests/test_securedrop_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,34 @@ def test_parse_args_invalid(mocker: Any, prog: str, argv: list[str]) -> None:
mocker.patch.object(manage, "get_installed_product", return_value=manage.Product.JOURNALIST)
with pytest.raises(SystemExit):
manage.parse_args(prog, argv)


@pytest.mark.parametrize(
("features", "expected"),
[
# set by admin_salt.sd-admin: reverted
(dict(manage.ADMIN_DOM0_MENU_FEATURES), {}),
# changed by the user: left alone
(
{"menu-favorites": "my-app.desktop", "menu-initial-page": "search_page"},
{"menu-favorites": "my-app.desktop", "menu-initial-page": "search_page"},
),
# only some still match: only those reverted
(
{**manage.ADMIN_DOM0_MENU_FEATURES, "menu-favorites": "my-app.desktop"},
{"menu-favorites": "my-app.desktop"},
),
# not set: nothing to do
({}, {}),
],
)
def test_revert_admin_dom0_menu(
mocker: Any, features: dict[str, str], expected: dict[str, str]
) -> None:
app = mocker.MagicMock()
app.domains = {"dom0": mocker.MagicMock(features=features)}
mocker.patch.object(manage, "Qubes", return_value=app)

manage.revert_admin_dom0_menu()

assert features == expected
25 changes: 25 additions & 0 deletions tests/test_vm_sd_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
from qubesadmin.app import VMCollection

from securedrop_manage import main as manage
from tests.markers import needs_admin

pytestmark = needs_admin


@pytest.mark.provisioning
def test_app_menu_opens_to_favorites(all_vms: VMCollection) -> None:
assert all_vms["dom0"].features.get("menu-initial-page") == "favorites_page"


@pytest.mark.provisioning
def test_admin_menu_favorites(all_vms: VMCollection) -> None:
"""
Favorites point at the dom0 launchers, so apps start via sdw-updater.
For dom0 apps the menu matches against the full .desktop file name.
"""
favorites = all_vms["dom0"].features.get("menu-favorites", "")
assert favorites == manage.ADMIN_DOM0_MENU_FEATURES["menu-favorites"]
# No favorites on the qubes themselves, which would bypass sdw-updater
for vm in ("sd-admin", "sd-admin-vault"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice, maybe this should be for all VMs?

assert not all_vms[vm].features.get("menu-favorites")
Loading