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

securedrop-admin --uninstall for staging and prod #489

Merged
merged 7 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 14 additions & 4 deletions dom0/sd-clean-all.sls
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ dom0-reset-power-management-xfce:
- runas: {{ gui_user }}
{% endif %}

# Removes all salt-provisioned files (if these files are also provisioned via
# RPM, they should be removed as part of remove-dom0-sdw-config-files-dev)
remove-dom0-sdw-config-files:
file.absent:
- names:
- /opt/securedrop
- /etc/yum.repos.d/securedrop-workstation-dom0.repo
- /usr/bin/securedrop-update
- /etc/pki/rpm-gpg/RPM-GPG-KEY-securedrop-workstation
- /etc/pki/rpm-gpg/RPM-GPG-KEY-securedrop-workstation-test
- /etc/cron.daily/securedrop-update-cron
- /srv/salt/securedrop-update
- /srv/salt/update-xfce-settings
- /usr/share/securedrop/icons
- /home/{{ gui_user }}/.config/autostart/SDWLogin.desktop
- /usr/bin/securedrop-login
Expand All @@ -47,6 +46,17 @@ remove-dom0-sdw-config-files:
- /home/{{ gui_user }}/Desktop/securedrop-launcher.desktop
- /home/{{ gui_user }}/.securedrop_launcher

# Removes files that are provisioned by the dom0 RPM, only for the development
# environment, since dnf takes care of those provisioned in the RPM
{% if d.environment == "dev" %}
remove-dom0-sdw-config-files-dev:
file.absent:
- names:
- /opt/securedrop
- /srv/salt/securedrop-update
- /srv/salt/update-xfce-settings
{% endif %}

sd-cleanup-etc-changes:
file.replace:
- names:
Expand Down Expand Up @@ -94,4 +104,4 @@ sd-cleanup-rpc-policy-grants:
- DOTALL
- repl: ''
- backup: no
{% endif %}
{% endif %}
14 changes: 10 additions & 4 deletions dom0/sd-whonix-hidserv-key.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
# add hidden service auth key to torrc
{% if d.hidserv.hostname|length == 22 %}
sd-whonix-hidserv-key:
file.append:
file.blockreplace:
- name: /usr/local/etc/torrc.d/50_user.conf
- text: HidServAuth {{ d.hidserv.hostname }} {{ d.hidserv.key }}
- append_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: HidServAuth {{ d.hidserv.hostname }} {{ d.hidserv.key }}
{% else %}
sd-whonix-hidservv3-directory-path:
file.append:
file.blockreplace:
- name: /usr/local/etc/torrc.d/50_user.conf
- text: ClientOnionAuthDir /var/lib/tor/keys
- append_if_not_found: True
- marker_start: "### BEGIN securedrop-workstation ###"
- marker_end: "### END securedrop-workstation ###"
- content: ClientOnionAuthDir /var/lib/tor/keys

{% set hostname_without_onion = d.hidserv.hostname.split('.')[0] %}
install-sd-whonix-tor-private-key:
Expand Down
60 changes: 60 additions & 0 deletions scripts/securedrop-admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def parse_args():
action="store_true",
help="Validate the configuration",
)
parser.add_argument(
"--uninstall",
default=False,
required=False,
action="store_true",
help="Completely Uninstalls the SecureDrop Workstation",
)
args = parser.parse_args()

return args
Expand Down Expand Up @@ -72,6 +79,49 @@ def validate_config(path):
raise SDAdminException("Error while validating configuration")


def perform_uninstall():

try:
subprocess.check_call(
["sudo", "qubesctl", "state.sls", "sd-clean-default-dispvm"]
)
print("Destroying all VMs")
subprocess.check_call(
[os.path.join(SCRIPTS_PATH, "scripts/destroy-vm"), "--all"]
)
subprocess.check_call(
[
"sudo", "qubesctl", "--skip-dom0", "--targets",
"whonix-gw-15", "state.sls", "sd-clean-whonix"
]
)
print("Reverting dom0 configuration")
subprocess.check_call(
["sudo", "rm", "/srv/salt/sd/sd-journalist.sec"]
)
subprocess.check_call(
["sudo", "rm", "/srv/salt/sd/config.json"]
)
subprocess.check_call(
["sudo", "qubesctl", "state.sls", "sd-clean-all"]
)
print("Uninstalling Template")
subprocess.check_call(
["sudo", "dnf", "-y", "-q", "remove", "qubes-template-securedrop-workstation-buster"]
)
print("Uninstalling dom0 config package")
subprocess.check_call(
["sudo", "dnf", "-y", "-q", "remove", "securedrop-workstation-dom0-config"]
)
except subprocess.CalledProcessError:
raise SDAdminException("Error during uninstall")

print(
"Instance secrets (Journalist Interface token and Submission private key) are still"
"present on disk. You can delete them in /usr/share/securedrop-workstation-dom0-config"
)


def main():
args = parse_args()
if args.validate:
Expand All @@ -82,6 +132,16 @@ def main():
validate_config(SCRIPTS_PATH)
copy_config()
provision_all()
elif args.uninstall:
print(
"Uninstalling SecureDrop workstation will uninstall all packages and destroy all VMs"
)
response = input("Are you sure you would want to uninstall (y/N)? ")
if response.lower() != 'y':
print("Exiting.")
sys.exit(0)
else:
perform_uninstall()
else:
sys.exit(0)

Expand Down