Skip to content
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

Automatically update dom0 and VM configs over time #172

Merged
merged 9 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ endif

## Builds and provisions all VMs required for testing workstation
all: assert-dom0 validate clean update-fedora-templates \
update-whonix-templates prep-whonix sd-workstation-template \
update-whonix-templates prep-whonix prep-dom0 sd-workstation-template \
sd-whonix sd-svs sd-gpg \
sd-journalist sd-svs-disp

clone: assert-dom0 ## Pulls the latest repo from work VM to dom0
@./scripts/clone-to-dom0


sd-workstation-template: prep-salt ## Provisions base template for SDW AppVMs
sudo qubesctl top.enable sd-workstation-template
sudo qubesctl top.enable sd-workstation-template-files
Expand Down Expand Up @@ -128,6 +127,11 @@ prep-whonix: ## enables apparmor on whonix-ws-14 and whonix-gw-14
qvm-prefs -s whonix-gw-14 kernelopts "nopat apparmor=1 security=apparmor"
qvm-prefs -s whonix-ws-14 kernelopts "nopat apparmor=1 security=apparmor"

prep-dom0: prep-salt # Copies dom0 config files for VM updates
sudo qubesctl top.enable sd-vm-updates
sudo qubesctl top.enable sd-dom0-files
sudo qubesctl --targets dom0 state.highstate

list-vms: ## Prints all Qubes VMs managed by Workstation salt config
@./scripts/list-vms

Expand Down
48 changes: 48 additions & 0 deletions dom0/sd-dom0-files.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# vim: set syntax=yaml ts=2 sw=2 sts=2 et :

##
# Installs dom0 config scripts specific to tracking updates
# over time. These scripts should be ported to an RPM package.
##


# Copy script to system location so admins can run ad-hoc
dom0-update-securedrop-script:
file.managed:
- name: /usr/bin/securedrop-update
- source: salt://securedrop-update
- user: root
- group: root
- mode: 755

# Symlink update script into cron, for single point of update
dom0-update-securedrop-script-cron:
file.symlink:
- name: /etc/cron.daily/securedrop-update-cron
- target: /usr/bin/securedrop-update

# Create directory for storing SecureDrop-specific icons
dom0-securedrop-icons-directory:
file.directory:
- name: /usr/share/securedrop/icons
- user: root
- group: root
- mode: 755
- makedirs: True

# Copy SecureDrop icon for use in GUI feedback. It's also present in
# the Salt directory, but the permissions on that dir don't permit
# normal user reads.
dom0-securedrop-icon:
file.managed:
- name: /usr/share/securedrop/icons/sd-logo.png
- source: salt://sd/sd-journalist/logo-small.png
- user: root
- group: root
- mode: 644
# Dependency on parent dir should be explicitly declared,
# but the require syntax below was throwing an error that the
# referenced task was "not available".
# require:
# - dom0-securedrop-icons-directory
6 changes: 6 additions & 0 deletions dom0/sd-dom0-files.top
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# vim: set syntax=yaml ts=2 sw=2 sts=2 et :

base:
dom0:
- sd-dom0-files
9 changes: 9 additions & 0 deletions dom0/sd-vm-updates.top
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# vim: set syntax=yaml ts=2 sw=2 sts=2 et :

# "Placeholder" config to trigger TemplateVM boots,
# so upgrades can be applied automatically via cron.
base:
qubes:type:template:
- match: pillar
- topd
46 changes: 46 additions & 0 deletions dom0/securedrop-update
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Utility for dom- to ensure all updates are regularly installed
set -e
set -u

# Number of VMs to update in parallel. Default is 4,
# which can be memory-intensive.
SECUREDROP_MAX_CONCURRENCY=2


# Ensure elevated privileges
if [[ "$EUID" -ne 0 ]]; then
echo "Script must be run as root! Exiting..."
exit 1
fi

# Display GUI feedback about update process
function securedrop-update-feedback() {
# Unpack msg as arg1
local msg="$1"
shift

# Running `notify-send` as root doesn't work, must be normal user.
# Setting 30s expire time (in ms) since it's a long-running cmd.
su user -c "notify-send \
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps due to the configuration of my Qubes machine, my user in dom0 is not user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch, that's a good flag. We still need to drop privileges in here; or we could dig more in the notify-send settings. Off the cuff, inspecting /home/ for a single dirname should give us whatever the name of the (single) custom user is. Make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can safely assume that the normal user configured at install time has uid 1000; so:

id -nu 1000

Then we su to that user to run the notify-send commands.

--icon /usr/share/securedrop/icons/sd-logo.png \
--expire-time 30000 \
'$msg'"
}

# `qubesctl pkg.upgrade` will automatically update dom0 packages, as well,
# but we *first* want the freshest RPMs from dom0, *then* we'll want to
# update the VMs themselves.
securedrop-update-feedback "SecureDrop: Updating dom0 configuration..."
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit: "SecureDrop:" is added in securedrop-update-feedback(), so isn't needed in the message here.

sudo qubes-dom0-update -y
Copy link
Contributor

Choose a reason for hiding this comment

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

adding the --clean option here will refresh dnf cache, which might be useful in some cases.

I just had an issue where qubes-dom0-update was complaining of an unsigned package, due to me attempting to download an older whonix template in an effort to reproduce #122 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, probably worth adding here, lest we forget to circle back—feel free to append, @emkll.


securedrop-update-feedback "SecureDrop: Updating application..."
qubesctl --templates \
--max-concurrency "$SECUREDROP_MAX_CONCURRENCY" \
pkg.upgrade refresh=true

emkll marked this conversation as resolved.
Show resolved Hide resolved
# Here would be a good place for state.highstate, to re-apply the VM configs.
# Let's first make sure the package upgrade logic is stable, we can circle
# back to enforce the Salt configs regularly.

securedrop-update-feedback "SecureDrop: All updates complete!"