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

Restrict and test and qubes-rpc policies for dom0 #187

Merged
merged 4 commits into from
Nov 8, 2018
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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ endif
all: assert-dom0 validate clean update-fedora-templates \
update-whonix-templates prep-whonix prep-dom0 sd-workstation-template \
sd-whonix sd-svs sd-gpg \
sd-journalist sd-svs-disp
sd-journalist sd-svs-disp qubes-rpc

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

qubes-rpc: prep-salt ## Places default deny qubes-rpc policies for sd-svs and sd-gpg
sudo qubesctl top.enable sd-dom0-qvm-rpc
sudo qubesctl --show-output --targets sd-dom0-qvm-rpc state.highstate

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
114 changes: 114 additions & 0 deletions dom0/sd-dom0-qvm-rpc.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# -*- coding: utf-8 -*-
# vim: set syntax=yaml ts=2 sw=2 sts=2 et :
##
# Explicitly deny as a catch-all for SecureDrop workstation provisioned VMs.
# All SecureDrop-workstation provisioned VMS should have the sd-workstation tag.
# To be both be mindful of developers using the workstation and ensure
# RPC policies are not too permissive, this should be the first action
# performed by the install. All other provisioning steps will prepend to this
# list grants.
# using blockreplace will ensure that we will be able to more reliably update
# these policies during updates.
##
dom0-rpc-qubes.ClipboardPaste:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.ClipboardPaste
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
$anyvm sd-journalist ask
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.FeaturesRequest:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.FeaturesRequest
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.Filecopy:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.Filecopy
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
sd-journalist sd-svs allow
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.OpenInVM:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.OpenInVM
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
sd-journalist sd-svs allow
$tag:sd-svs-disp-vm sd-svs allow
sd-svs $dispvm:sd-svs-disp allow
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.OpenURL:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.OpenURL
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.PdfConvert:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.PdfConvert
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.StartApp:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.StartApp
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.USB:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.USB
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.VMRootShell:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.VMRootShell
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.VMshell:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.VMShell
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.Gpg:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.Gpg
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
sd-svs sd-gpg allow
$anyvm $tag:sd-workstation deny
dom0-rpc-qubes.GpgImportKey:
file.blockreplace:
- name: /etc/qubes-rpc/policy/qubes.GpgImportKey
- prepend_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: |
$anyvm $tag:sd-workstation deny
6 changes: 6 additions & 0 deletions dom0/sd-dom0-qvm-rpc.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-qvm-rpc
3 changes: 3 additions & 0 deletions dom0/sd-gpg.sls
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ sd-gpg:
- label: purple
- prefs:
- netvm: ""
- tags:
- add:
- sd-workstation
3 changes: 3 additions & 0 deletions dom0/sd-journalist-template.sls
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ sd-journalist-template:
- clone:
- source: whonix-ws-14
- label: blue
- tags:
- add:
- sd-workstation
require:
- pkg: qubes-template-whonix-ws-14
- qvm: sd-whonix
Expand Down
22 changes: 3 additions & 19 deletions dom0/sd-journalist.sls
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ sd-journalist:
- label: blue
- prefs:
- netvm: sd-whonix
- tags:
- add:
- sd-workstation
- require:
- pkg: qubes-template-whonix-ws-14
- qvm: sd-whonix
Expand All @@ -47,29 +50,10 @@ sd-journalist-install-python-futures:
{ sudo apt-get update && sudo apt-get install -qq python-futures ; }" &&
qvm-shutdown --wait whonix-ws-14

# When our Qubes bug is fixed, this will *not* be used
sd-journalist-dom0-qubes.OpenInVM:
file.prepend:
- name: /etc/qubes-rpc/policy/qubes.OpenInVM
- text: "sd-journalist sd-decrypt allow\n"

# Allow sd-journalist to open files in sd-decrypt-bsed dispVM's
# When our Qubes bug is fixed, this will be used.
sd-journalist-dom0-qubes.OpenInVM-disp:
file.prepend:
- name: /etc/qubes-rpc/policy/qubes.OpenInVM
- text: "sd-journalist sd-svs allow\n"

# Permit the SecureDrop Proxy to manage Client connections
sd-journalist-dom0-securedrop.Proxy:
file.prepend:
- name: /etc/qubes-rpc/policy/securedrop.Proxy
- text: |
sd-svs sd-journalist allow
$anyvm $anyvm deny

# Permit the SecureDrop Proxy to copy files to Client.
sd-journalist-dom0-qubes.Filecopy:
file.prepend:
- name: /etc/qubes-rpc/policy/qubes.Filecopy
- text: "sd-journalist sd-svs allow\n"
8 changes: 3 additions & 5 deletions dom0/sd-svs-disp.sls
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ sd-svs-disp:
- label: green
- prefs:
- netvm: ""
- tags:
- add:
- sd-workstation

# tell qubes this VM can be used as a disp VM template
qvm-prefs sd-svs-disp template_for_dispvms True:
Expand All @@ -38,8 +41,3 @@ qvm-prefs sd-svs-disp template_for_dispvms True:
# This feels like a Qubes bug.
qvm-tags sd-svs-disp add sd-svs-disp-vm:
cmd.run

sd-svs-disp-dom0-qubes.OpenInVM:
file.prepend:
- name: /etc/qubes-rpc/policy/qubes.OpenInVM
- text: "$tag:sd-svs-disp-vm sd-svs allow\n"
7 changes: 0 additions & 7 deletions dom0/sd-svs-files.sls
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,3 @@ sudo update-mime-database /usr/share/mime:

sudo update-desktop-database /usr/share/applications:
cmd.run

install nautilus in sd-svs:
pkg.installed:
- pkgs:
# Nautilus necessary for manual file browsing, remove when
# the securedrop-client code package is installed
- nautilus
17 changes: 6 additions & 11 deletions dom0/sd-svs.sls
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ sd-svs-template:
- clone:
- source: sd-workstation-template
- label: yellow
- tags:
- add:
- sd-workstation

sd-svs:
qvm.vm:
Expand All @@ -24,20 +27,12 @@ sd-svs:
- label: yellow
- prefs:
- netvm: ""
- tags:
- add:
- sd-workstation
require:
- qvm: sd-svs-template

sd-svs-dom0-qubes.OpenInVM:
file.prepend:
- name: /etc/qubes-rpc/policy/qubes.OpenInVM
- text: "sd-svs $dispvm:sd-svs-disp allow\n"

# Allow sd-svs to access gpg keys on sd-gpg
sd-svs-dom0-qubes.qubesGpg:
file.prepend:
- name: /etc/qubes-rpc/policy/qubes.Gpg
- text: "sd-svs sd-gpg allow\n"

# Ensure the Qubes menu is populated with relevant app entries,
# so that Nautilus/Files can be started via GUI interactions.
sd-svs-template-sync-appmenus:
Expand Down
6 changes: 6 additions & 0 deletions dom0/sd-whonix.sls
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ sd-whonix-template:
- clone:
- source: whonix-gw-14
- label: purple
- tags:
- add:
- sd-workstation
- require:
- pkg: qubes-template-whonix-gw-14
- qvm: sys-firewall
Expand All @@ -43,6 +46,9 @@ sd-whonix:
- provides-network: true
- netvm: "sys-firewall"
- autostart: true
- tags:
- add:
- sd-workstation
- require:
- pkg: qubes-template-whonix-gw-14
- qvm: sys-firewall
Expand Down
3 changes: 3 additions & 0 deletions dom0/sd-workstation-template.sls
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ sd-workstation-template:
- prefs:
- virt-mode: hvm
- kernel: ''
- tags:
- add:
- sd-workstation
52 changes: 52 additions & 0 deletions tests/test_qubes_rpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import io
import os
import unittest
import yaml

QUBES_POLICY_PREFIX = "/etc/qubes-rpc/policy/qubes."


class SD_Qubes_Rpc_Tests(unittest.TestCase):

def setUp(self):
self.expected = self._loadVars()

def tearDown(self):
pass

def test_Policies(self):
# Using a for loop instead of pytest.parametrize due to
# the absence of pytest in dom0.
fail = False
for policy in self.expected:
if not self._startsWith(policy['policy'],
policy['starts_with']):
fail = True
self.assertFalse(fail)

def _startsWith(self, filename, expectedPolicy):
filePath = os.path.join(QUBES_POLICY_PREFIX + filename)
with io.open(filePath, 'r') as f:
actualPolicy = f.read()
if actualPolicy.startswith(expectedPolicy):
return True
else:
print("\n\n#### BEGIN RPC policy error report ####\n\n")
print("Policy for {} is:\n{}".format(filename,
actualPolicy))
print("Policy for {} should be:\n{}".format(filename,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: more aggressive output would be helpful here for when the policies fail. Consider adding more newlines and header blocks like:

print("\n\n#### BEGIN RPC policy error report ####\n\n")
print("Policy for {} is:\n{}".format(filename,
                                                     actualPolicy))
print("Policy for {} should be:\n{}".format(filename,
                                                     expectedPolicy))
print("\n\n#### END RPC policy error report ####\n\n")

expectedPolicy))
print("\n\n#### END RPC policy error report ####\n\n")
return False

def _loadVars(self):
filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"vars", "qubes-rpc.yml")
with io.open(filepath, 'r') as f:
data = yaml.safe_load(f)
return data


def load_tests(loader, tests, pattern):
suite = unittest.TestLoader().loadTestsFromTestCase(SD_Qubes_Rpc_Tests)
return suite
Loading