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

Fixes #348 resizes private volume sizes of sd-app sd-log #405

Merged
merged 1 commit into from
Jan 23, 2020
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ clean-salt: assert-dom0 ## Purges SD Salt configuration from dom0

prep-salt: assert-dom0 ## Configures Salt layout for SD workstation VMs
@./scripts/prep-salt
@./scripts/validate-config
Copy link
Contributor

Choose a reason for hiding this comment

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

there's a validate makefile target that could be used here. We should validate the config before running prep-salt here, since prep-salt is not strictly required if the config fails to validate


remove-sd-whonix: assert-dom0 ## Destroys SD Whonix VM
@./scripts/destroy-vm sd-whonix
Expand Down
6 changes: 5 additions & 1 deletion config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"hidserv": {
"hostname": "avgfxawdn6c3coe3.onion",
"key": "Il8Xas7uf6rjtc0LxYwhrx"
}
},
"vmsizes": {
emkll marked this conversation as resolved.
Show resolved Hide resolved
"sd_app": 10,
emkll marked this conversation as resolved.
Show resolved Hide resolved
"sd_log": 5
}
}
10 changes: 10 additions & 0 deletions dom0/sd-app.sls
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ sd-app:
- require:
- qvm: sd-app-buster-template

{% import_json "sd/config.json" as d %}

# The private volume size should be defined in the config.json
sd-app-private-volume-size:
cmd.run:
- name: >
qvm-volume resize sd-app:private {{ d.vmsizes.sd_app }}GiB
- require:
- qvm: sd-app

# Ensure the Qubes menu is populated with relevant app entries,
# so that Nautilus/Files can be started via GUI interactions.
sd-app-template-sync-appmenus:
Expand Down
10 changes: 10 additions & 0 deletions dom0/sd-log.sls
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ sd-log-dom0-securedrop.Log:
- text: |
@tag:sd-workstation sd-log allow
@anyvm @anyvm deny

{% import_json "sd/config.json" as d %}

# The private volume size should be set in config.json
sd-log-private-volume-size:
cmd.run:
- name: >
qvm-volume resize sd-log:private {{ d.vmsizes.sd_log }}GiB
- require:
- qvm: sd-log
29 changes: 29 additions & 0 deletions scripts/validate-config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import json
import re
import os
import subprocess
from qubesadmin import Qubes
emkll marked this conversation as resolved.
Show resolved Hide resolved


TOR_V3_HOSTNAME_REGEX = r'^[a-z2-7]{56}\.onion$'
Expand All @@ -31,6 +32,7 @@ class SDWConfigValidator(object):
self.confirm_onion_config_valid()
self.confirm_submission_privkey_file()
self.confirm_submission_privkey_fingerprint()
self.validate_existing_size()

def confirm_config_file_exists(self):
try:
Expand Down Expand Up @@ -88,6 +90,33 @@ class SDWConfigValidator(object):
j = json.load(f)
return j

def validate_existing_size(self):
"""This method checks for existing private volume size and new
values in the config.json"""
assert "vmsizes" in self.config
assert "sd_app" in self.config["vmsizes"]
assert "sd_log" in self.config["vmsizes"]

assert isinstance(self.config["vmsizes"]["sd_app"], int), \
"Private volume size of sd-app must be an integer value."
assert isinstance(self.config["vmsizes"]["sd_log"], int), \
"Private volume size of sd-log must be an integer value."

app = Qubes()
if "sd-app" in app.domains:
vm = app.domains["sd-app"]
vol = vm.volumes["private"]
assert (
vol.size <= self.config["vmsizes"]["sd_app"] * 1024 * 1024 * 1024
), "sd-app private volume is already bigger than configuration."

if "sd-log" in app.domains:
vm = app.domains["sd-log"]
vol = vm.volumes["private"]
assert (
vol.size <= self.config["vmsizes"]["sd_log"] * 1024 * 1024 * 1024
), "sd-log private volume is already bigger than configuration."


if __name__ == "__main__":
validator = SDWConfigValidator()
15 changes: 15 additions & 0 deletions tests/test_vms_exist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import json

from qubesadmin import Qubes
from base import WANTED_VMS
Expand All @@ -10,6 +11,8 @@
class SD_VM_Tests(unittest.TestCase):
def setUp(self):
self.app = Qubes()
with open("config.json") as c:
self.config = json.load(c)

def tearDown(self):
pass
Expand Down Expand Up @@ -78,6 +81,12 @@ def test_sd_app_config(self):
self._check_service_running(vm, "paxctld")
self.assertTrue('sd-workstation' in vm.tags)
self.assertTrue('sd-client' in vm.tags)
# Check the size of the private volume
# Should be 10GB
# >>> 1024 * 1024 * 10 * 1024
size = self.config["vmsizes"]["sd_app"]
vol = vm.volumes["private"]
self.assertEqual(vol.size, size * 1024 * 1024 * 1024)

def test_sd_viewer_config(self):
vm = self.app.domains["sd-viewer"]
Expand Down Expand Up @@ -114,6 +123,12 @@ def test_sd_log_config(self):
self._check_service_running(vm, "paxctld")
self.assertFalse(vm.template_for_dispvms)
self.assertTrue('sd-workstation' in vm.tags)
# Check the size of the private volume
# Should be same of config.json
# >>> 1024 * 1024 * 5 * 1024
size = self.config["vmsizes"]["sd_log"]
vol = vm.volumes["private"]
self.assertEqual(vol.size, size * 1024 * 1024 * 1024)

def test_sd_workstation_template(self):
vm = self.app.domains["securedrop-workstation-buster"]
Expand Down