Skip to content

Commit

Permalink
salt: add logging VM
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Nov 18, 2019
1 parent ea2e751 commit 093fc5f
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ sd-export: prep-salt ## Provisions SD Export VM
sudo qubesctl --show-output --targets sd-export-template state.highstate
sudo qubesctl --show-output --targets sd-export-export-dvm state.highstate

sd-log: prep-salt ## Provisions SD logging VM
sudo qubesctl top.enable sd-log
sudo qubesctl top.enable sd-log-template-files
sudo qubesctl --show-output --targets sd-log-template state.highstate
sudo qubesctl --show-output --targets sd-log state.highstate

clean-salt: assert-dom0 ## Purges SD Salt configuration from dom0
@echo "Purging Salt config..."
@sudo rm -rf /srv/salt/sd
Expand Down Expand Up @@ -89,6 +95,9 @@ remove-sd-export: assert-dom0 ## Destroys SD EXPORT VMs
@./scripts/destroy-vm sd-export-usb
@./scripts/destroy-vm sd-export-usb-dvm

remove-sd-log: assert-dom0 ## Destroys SD logging VM
@./scripts/destroy-vm sd-log

clean: assert-dom0 destroy-all clean-salt ## Destroys all SD VMs
sudo dnf -y -q remove securedrop-workstation-dom0-config 2>/dev/null || true
sudo rm -f /usr/bin/securedrop-update \
Expand Down
19 changes: 19 additions & 0 deletions dom0/sd-log-template-files.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# vim: set syntax=yaml ts=2 sw=2 sts=2 et :

# We should package this so we can easily update
sd-log-script:
file.managed:
- name: /usr/sbin/oqubes-logging
- source: salt://sd/sd-log/oqubes-logging
- user: root
- group: root
- mode: 755

sd-log-qrexec:
file.managed:
- name: /etc/qubes-rpc/oqubes.Logging
- source: salt://sd/sd-log/oqubes.Logging
- user: root
- group: root
- mode: 755
6 changes: 6 additions & 0 deletions dom0/sd-log-template-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:
sd-log-template:
- sd-log-template-files
48 changes: 48 additions & 0 deletions dom0/sd-log.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 'sd-log' AppVM for collecting and storing logs
# from all SecureDrop related VMs.
# This VM has no network configured.
##
include:
- sd-workstation-template

sd-log-template:
qvm.vm:
- name: sd-log-template
- clone:
- source: securedrop-workstation
- label: red
- tags:
- add:
- sd-workstation
- require:
- sls: sd-workstation-template

sd-log:
qvm.vm:
- name: sd-log
- present:
- template: sd-log-template
- label: red
- prefs:
- netvm: ""
- autostart: true
- tags:
- add:
- sd-workstation
- features:
- enable:
- service.paxctld
- require:
- qvm: sd-log-template

# Allow any SecureDrop VM to log to the centralized log VM
sd-log-dom0-oqubes.Logging:
file.prepend:
- name: /etc/qubes-rpc/policy/oqubes.Logging
- text: |
@tag:sd-workstation sd-log allow
@anyvm @anyvm deny
6 changes: 6 additions & 0 deletions dom0/sd-log.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-log
2 changes: 2 additions & 0 deletions scripts/list-vms
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ declare -a sd_workstation_vm_names=(
sd-export-usb
sd-export-usb-dvm
sd-export-template
sd-log
sd-log-template
)

for vm in "${sd_workstation_vm_names[@]}" ; do
Expand Down
1 change: 1 addition & 0 deletions scripts/prep-salt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if [[ ! -d "$SDW_SALT_DIR" ]]; then
sudo mkdir -p /srv/salt/sd
sudo cp -r sd-proxy /srv/salt/sd
sudo cp -r sd-svs /srv/salt/sd
sudo cp -r sd-log /srv/salt/sd
sudo cp -r sd-workstation /srv/salt/sd
sudo cp -r sys-firewall /srv/salt/sd
sudo cp dom0/* /srv/salt/
Expand Down
1 change: 1 addition & 0 deletions sd-log/oqubes.Logging
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/sbin/oqubes-logging
1 change: 1 addition & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Reusable constant for DRY import across tests
WANTED_VMS = [
"sd-gpg",
"sd-log",
"sd-proxy",
"sd-svs",
"sd-svs-disp",
Expand Down
18 changes: 18 additions & 0 deletions tests/test_log_vm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest

from base import SD_VM_Local_Test


class SD_Log_Tests(SD_VM_Local_Test):
def setUp(self):
self.vm_name = "sd-log"
super(SD_Log_Tests, self).setUp()

def test_log_utility_installed(self):
self.assertTrue(self._fileExists("/usr/sbin/oqubes-logging"))
self.assertTrue(self._fileExists("/etc/qubes-rpc/oqubes.Logging"))


def load_tests(loader, tests, pattern):
suite = unittest.TestLoader().loadTestsFromTestCase(SD_Log_Tests)
return suite
21 changes: 21 additions & 0 deletions tests/test_vms_exist.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ def test_sd_gpg_config(self):
self._check_kernel(vm)
self.assertTrue('sd-workstation' in vm.tags)

def test_sd_log_config(self):
vm = self.app.domains["sd-log"]
nvm = vm.netvm
self.assertTrue(nvm is None)
self.assertTrue(vm.template == "sd-log-template")
self.assertTrue(vm.autostart is True)
self.assertFalse(vm.provides_network)
self.assertFalse(vm.template_for_dispvms)
self._check_kernel(vm)
self._check_service_running(vm, "paxctld")
self.assertFalse(vm.template_for_dispvms)
self.assertTrue('sd-workstation' in vm.tags)

def test_sd_workstation_template(self):
vm = self.app.domains["securedrop-workstation"]
nvm = vm.netvm
Expand Down Expand Up @@ -156,6 +169,14 @@ def sd_export(self):
self.assertTrue('sd-workstation' in vm.tags)
self._check_kernel(vm)

def sd_log_template(self):
vm = self.app.domains["sd-log-template"]
nvm = vm.netvm
self.assertTrue(nvm is None)
self.assertTrue('sd-workstation' in vm.tags)
self.assertFalse(vm.template_for_dispvms)
self._check_kernel(vm)


def load_tests(loader, tests, pattern):
suite = unittest.TestLoader().loadTestsFromTestCase(SD_VM_Tests)
Expand Down

0 comments on commit 093fc5f

Please sign in to comment.