Skip to content

Commit

Permalink
Merge pull request #5684 from freedomofpress/5295-unattended-upgrades
Browse files Browse the repository at this point in the history
Replace cron-apt with unattended-upgrades on Focal
  • Loading branch information
conorsch authored Feb 5, 2021
2 parents 31d1b7a + 733bd11 commit 5395bbc
Show file tree
Hide file tree
Showing 26 changed files with 547 additions and 179 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ common-steps:
- /focalcaches/layers.tar



version: 2
jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion devops/apt-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
rep_dist: "focal"
molecule_dir: "../molecule/upgrade"
dpkg_dir: /var/repos/debs
rep_origin: SecureDrop
rep_component: main
rep_arch: i386 amd64
release_file: "/var/repos/base/dists/{{ rep_dist }}/Release"
Expand All @@ -45,4 +46,3 @@
- ssl_certificate_key /etc/ssl/private/apt_freedom_press.priv
- root "/var/repos/base"
- location / { autoindex on; }

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ip_info:
### Used by the install_local_deb_pkgs role ###
local_deb_packages:
- "securedrop-keyring-0.1.4+{{ securedrop_version }}+{{ securedrop_target_distribution }}-amd64.deb"
- "securedrop-config-0.1.3+{{ securedrop_version }}+{{ securedrop_target_distribution }}-amd64.deb"
- "securedrop-config-0.1.4+{{ securedrop_version }}+{{ securedrop_target_distribution }}-amd64.deb"
- "securedrop-ossec-agent-3.6.0+{{ securedrop_version }}+{{ securedrop_target_distribution }}-amd64.deb"
- "{{ securedrop_app_code_deb }}.deb"
- "ossec-agent-3.6.0+{{ securedrop_target_distribution }}-amd64.deb"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ip_info:
### Used by the install_local_deb_pkgs role ###
local_deb_packages:
- "securedrop-keyring-0.1.4+{{ securedrop_version }}+{{ securedrop_target_distribution }}-amd64.deb"
- "securedrop-config-0.1.3+{{ securedrop_version }}+{{ securedrop_target_distribution }}-amd64.deb"
- "securedrop-config-0.1.4+{{ securedrop_version }}+{{ securedrop_target_distribution }}-amd64.deb"
- "securedrop-ossec-server-3.6.0+{{ securedrop_version }}+{{ securedrop_target_distribution }}-amd64.deb"
- ossec-server-3.6.0+{{ securedrop_target_distribution }}-amd64.deb

Expand Down
9 changes: 0 additions & 9 deletions install_files/ansible-base/roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
# and aid in clearing memory. Only the hour is configurable.
daily_reboot_time: 4 # An integer between 0 and 23

securedrop_common_packages:
- apt-transport-https
- aptitude
- cron-apt
- ntp
- ntpdate
- resolvconf
- tmux

disabled_kernel_modules:
- btusb
- bluetooth
Expand Down
8 changes: 8 additions & 0 deletions install_files/ansible-base/roles/common/tasks/apt_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Configure apt sources.
template:
src: sources.list.j2
dest: /etc/apt/sources.list
mode: "0644"
owner: root
tags:
- apt
12 changes: 12 additions & 0 deletions install_files/ansible-base/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
- include_vars: "{{ ansible_distribution }}_{{ ansible_distribution_release }}.yml"

- include: apt_sources.yml
when:
- ansible_distribution_release == "focal"

- include: install_packages.yml

- include: post_ubuntu_install_checks.yml
Expand All @@ -12,6 +16,14 @@
- include: harden_dns.yml

- include: cron_apt.yml
when:
- ansible_distribution_release == "xenial"
tags:
- reboot

- include: unattended_upgrades.yml
when:
- ansible_distribution_release == "focal"
tags:
- reboot

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# Configuration for unattended upgrades is almost exclusively managed by the
# securedrop-config package under Focal.

- name: Configure unattended-upgrades to reboot daily at the scheduled time.
template:
src: 80securedrop.j2
dest: /etc/apt/apt.conf.d/80securedrop
mode: 0644
owner: root
group: root
tags:
- apt
- unattended-upgrades

- name: Ensure apt-daily and apt-daily-upgrade services are unmasked, started and enabled.
systemd:
name: "{{ item }}"
state: started
enabled: yes
masked: no
with_items:
- 'apt-daily'
- 'apt-daily-upgrade'
tags:
- apt
- unattended-upgrades

- name: Ensure apt-daily and apt-daily-upgrade timers are started, and enabled.
systemd:
name: "{{ item }}"
state: started
enabled: yes
with_items:
- 'apt-daily.timer'
- 'apt-daily-upgrade.timer'
tags:
- apt
- unattended-upgrades
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// If automatic reboot is enabled and needed, reboot at the specific
// time instead of immediately
// Default: "now"
Unattended-Upgrade::Automatic-Reboot-Time "{{ daily_reboot_time }}:00";
13 changes: 13 additions & 0 deletions install_files/ansible-base/roles/common/templates/sources.list.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }} main

## newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }} universe

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }}-updates main

### Security fixes for distribution packages
deb http://security.ubuntu.com/ubuntu {{ ansible_distribution_release }}-security main
deb http://security.ubuntu.com/ubuntu {{ ansible_distribution_release }}-security universe
9 changes: 9 additions & 0 deletions install_files/ansible-base/roles/common/vars/Ubuntu_focal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ securedrop_kernel_packages_to_remove:
- 'linux-image-.*generic'

resolvconf_target_filepath: /etc/resolv.conf

securedrop_common_packages:
- apt-transport-https
- aptitude
- unattended-upgrades
- ntp
- ntpdate
- resolvconf
- tmux
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ securedrop_kernel_packages_to_remove:
- 'linux-headers-.*'

resolvconf_target_filepath: /etc/resolvconf/resolv.conf.d/base

securedrop_common_packages:
- apt-transport-https
- aptitude
- cron-apt
- ntp
- ntpdate
- resolvconf
- tmux
1 change: 0 additions & 1 deletion install_files/ansible-base/securedrop-apt-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@
state: present
update_cache: yes
become: yes

11 changes: 11 additions & 0 deletions install_files/securedrop-config-focal/DEBIAN/control.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Source: securedrop
Section: web
Priority: optional
Maintainer: SecureDrop Team <securedrop@freedom.press>
Homepage: https://securedrop.org
Package: securedrop-config
Version: 0.1.4+{{ securedrop_version }}+{{ securedrop_target_distribution }}
Depends: unattended-upgrades,update-notifier-common
Architecture: all
Description: Establishes baseline system state for running SecureDrop.
Configures apt repositories.
24 changes: 24 additions & 0 deletions install_files/securedrop-config-focal/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
# postinst script for securedrop-config-focal

set -e
set -x

case "$1" in
configure)
# Configuration required for unattended-upgrades
cp /opt/securedrop/20auto-upgrades /etc/apt/apt.conf.d/
cp /opt/securedrop/50unattended-upgrades /etc/apt/apt.conf.d/
cp /opt/securedrop/reboot-flag /etc/cron.d/

;;
abort-upgrade|abort-remove|abort-deconfigure)
;;

*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac

exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[[ $- != *i* ]] && return

which tmux >/dev/null 2>&1 || return

tmux_attach_via_proc() {
# If the tmux package is upgraded during the lifetime of a
# session, attaching with the new binary can fail due to different
# protocol versions. This function attaches using the reference to
# the old executable found in the /proc tree of an existing
# session.
pid=$(pgrep --newest tmux)
if test -n "$pid"
then
/proc/$pid/exe attach
fi
return 1
}

if test -z "$TMUX"
then
(tmux attach || tmux_attach_via_proc || tmux new-session)
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "1";
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Automatically upgrade packages from these (origin:archive/codename) pairs
Unattended-Upgrade::Origins-Pattern {
"origin=${distro_id},archive=${distro_codename}";
"origin=${distro_id},archive=${distro_codename}-security";
"origin=${distro_id},archive=${distro_codename}-updates";
"origin=SecureDrop,codename=${distro_codename}";
};

// List of packages to not update (regexp are supported)
Unattended-Upgrade::Package-Blacklist {
};

// This option allows you to control if on a unclean dpkg exit
// unattended-upgrades will automatically run
// dpkg --force-confold --configure -a
// The default is true, to ensure updates keep getting installed
// This mirrors the previous cron=apt config
Unattended-Upgrade::AutoFixInterruptedDpkg "true";

// Split the upgrade into the smallest possible chunks so that
// they can be interrupted with SIGUSR1. This makes the upgrade
// a bit slower but it has the benefit that shutdown while a upgrade
// is running is possible (with a small delay)
//Unattended-Upgrade::MinimalSteps "true";

// Install all unattended-upgrades when the machine is shuting down
// instead of doing it in the background while the machine is running
// This will (obviously) make shutdown slower
//Unattended-Upgrade::InstallOnShutdown "true";

// Send email to this address for problems or packages upgrades
// If empty or unset then no email is sent, make sure that you
// have a working mail setup on your system. A package that provides
// 'mailx' must be installed. E.g. "[email protected]"
//Unattended-Upgrade::Mail "root";

// Set this value to "true" to get emails only on errors. Default
// is to always send a mail if Unattended-Upgrade::Mail is set
//Unattended-Upgrade::MailOnlyOnError "true";

// Do automatic removal of new unused dependencies after the upgrade
// (equivalent to apt-get autoremove)
//Unattended-Upgrade::Remove-Unused-Dependencies "false";

// Automatically reboot *WITHOUT CONFIRMATION*
// if the file /var/run/reboot-required is found after the upgrade
Unattended-Upgrade::Automatic-Reboot "true";

// If automatic reboot is enabled and needed, reboot at the specific
// time instead of immediately
// Default: "now"
// This is set in a template in the common role under the file 80securedrop

// Automatically reboot even if there are users currently logged in
// when Unattended-Upgrade::Automatic-Reboot is set to true
Unattended-Upgrade::Automatic-Reboot-WithUsers "true";

// Use apt bandwidth limit feature, this example limits the download
// speed to 70kb/sec
//Acquire::http::Dl-Limit "70";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The purpose of this cron is to drop the reboot-required flag every 12 hours
# to ensure the system is rebooted nightly, regardless of updates being installed
# or not.
* */12 * * * touch /var/run/reboot-required
2 changes: 1 addition & 1 deletion install_files/securedrop-config/DEBIAN/control.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Priority: optional
Maintainer: SecureDrop Team <securedrop@freedom.press>
Homepage: https://securedrop.org
Package: securedrop-config
Version: 0.1.3+{{ securedrop_version }}+{{ securedrop_target_distribution }}
Version: 0.1.4+{{ securedrop_version }}+{{ securedrop_target_distribution }}
Architecture: all
Description: Establishes baseline system state for running SecureDrop.
Configures apt repositories.
1 change: 1 addition & 0 deletions molecule/builder-focal/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- role: build-generic-pkg
tags: securedrop-config
package_name: securedrop-config
package_dirname: securedrop-config-focal
when: ansible_host.endswith("-sd-config") or ansible_host == "localhost"
tags: rebuild

Expand Down
16 changes: 12 additions & 4 deletions molecule/builder-xenial/tests/test_securedrop_deb_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,18 @@ def test_config_package_contains_expected_files(host: Host) -> None:
Inspect the package contents to ensure all config files are included in
the package.
"""
wanted_files = [
"/etc/cron-apt/action.d/9-remove",
"/etc/profile.d/securedrop_additions.sh",
]
if SECUREDROP_TARGET_DISTRIBUTION == "xenial":
wanted_files = [
"/etc/cron-apt/action.d/9-remove",
"/etc/profile.d/securedrop_additions.sh",
]
else:
wanted_files = [
"/etc/profile.d/securedrop_additions.sh",
"/opt/securedrop/20auto-upgrades",
"/opt/securedrop/50unattended-upgrades",
"/opt/securedrop/reboot-flag",
]
c = host.run("dpkg-deb --contents {}".format(deb_paths["securedrop_config"]))
for wanted_file in wanted_files:
assert re.search(
Expand Down
2 changes: 1 addition & 1 deletion molecule/builder-xenial/tests/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
securedrop_version: "1.8.0~rc1"
ossec_version: "3.6.0"
keyring_version: "0.1.4"
config_version: "0.1.3"
config_version: "0.1.4"
grsec_version: "4.14.188"

# These values will be interpolated with values populated above
Expand Down
Loading

0 comments on commit 5395bbc

Please sign in to comment.