Skip to content

Commit 02e3d25

Browse files
committed
Configure fully automated ownCloud security updates by default.
Closes: debops#28 Requires: debops/ansible-unattended_upgrades#6 (Test should pass even without this patch.)
1 parent 46eba38 commit 02e3d25

File tree

7 files changed

+155
-3
lines changed

7 files changed

+155
-3
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Added
4040
by default according to the `official ownCloud Dokumentation
4141
<https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/caching_configuration.html>`_. [ypid]
4242

43+
- Configure fully automated ownCloud security updates by default. [ypid]
44+
4345
Changed
4446
~~~~~~~
4547

defaults/main.yml

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,69 @@ owncloud__packages_host: []
9393
owncloud__deploy_state: 'present'
9494

9595

96+
# .. ownCloud upgrades [[[1
97+
#
98+
# ---------------------
99+
# ownCloud upgrades
100+
# ---------------------
101+
102+
# .. envvar:: owncloud__auto_database_upgrade_enabled
103+
#
104+
# On each update of ownCloud, a database update must be performed before
105+
# ownCloud can be used again.
106+
# The ownCloud package maintainers have not automated this setup so that even
107+
# security upgrades can not be installed unattended.
108+
#
109+
# Refer to the `official ownCloud Dokumentation <https://doc.owncloud.org/server/9.0/admin_manual/maintenance/package_upgrade.html#upgrade-quickstart>`__ for details.
110+
#
111+
# When this option is set to ``True``, the role enables a hook script for
112+
# ``dpkg`` so that when ``dpkg`` upgrades ownCloud, the database upgrade is
113+
# automatically performed.
114+
#
115+
# Change to ``False`` when you want to do database upgrades manually after upgrading the ownCloud packages.
116+
#
117+
# .. note:: :envvar:`owncloud__auto_database_upgrade_enabled` depends on
118+
# automatic database upgrades to be enabled.
119+
#
120+
owncloud__auto_database_upgrade_enabled: True
121+
122+
123+
# .. envvar:: owncloud__auto_database_upgrade_hook_script
124+
#
125+
# File path where the package manager hook script is stored.
126+
owncloud__auto_database_upgrade_hook_script: '{{ (ansible_local.root.lib
127+
if (ansible_local|d() and ansible_local.root|d() and
128+
ansible_local.root.lib|d())
129+
else "/usr/local/lib") + "/owncloud_db_upgrade_hook" }}'
130+
131+
132+
# .. envvar:: owncloud__auto_database_upgrade_migration_test
133+
#
134+
# Whether database schema migration should be simulated before upgrading the production database.
135+
# Refer to the `official ownCloud Dokumentation <https://doc.owncloud.org/server/9.0/admin_manual/maintenance/package_upgrade.html#migration-test>`__ for details.
136+
owncloud__auto_database_upgrade_migration_test: True
137+
138+
139+
# .. envvar:: owncloud__auto_database_upgrade_hook_script_packages_trigger
140+
#
141+
# List of packages for which the package manager hook script should attempt to
142+
# do a database upgrade when :envvar:`owncloud__auto_database_upgrade_enabled`
143+
# is ``True``.
144+
#
145+
# This variable is currently not being used.
146+
# The check if ownCloud needs an upgrade is performed for each
147+
# installed/upgraded package but in an very efficient way.
148+
owncloud__auto_database_upgrade_hook_script_packages_trigger:
149+
- 'owncloud'
150+
151+
152+
# .. envvar:: owncloud__auto_security_updates_enabled
153+
#
154+
# Whether automatic ownCloud upgrades should be performed by
155+
# ``unattended_upgrades``.
156+
owncloud__auto_security_updates_enabled: True
157+
158+
96159
# .. Basic options [[[1
97160
#
98161
# -----------------
@@ -536,9 +599,10 @@ owncloud__config_host: {}
536599
# It can be used to enable apps, add users and more which can be useful when
537600
# deploying ownCloud.
538601
#
539-
# Refer to the `official ownCloud Dokumentation <https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/occ_command.html>`__ for details.
602+
# Examples:
540603
#
541-
# Examples::
604+
# .. code-block:: yaml
605+
# :linenos:
542606
#
543607
# owncloud__run_occ_global_commands
544608
#
@@ -568,6 +632,7 @@ owncloud__config_host: {}
568632
# ansible_fqdn + '/owncloud/users/' + 'user' +
569633
# '/password length=' + owncloud__password_length) }}"
570634
#
635+
# Refer to the `official ownCloud Dokumentation <https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/occ_command.html>`__ for details.
571636
owncloud__run_occ_global_commands:
572637
## Disable the updater because it does not work anyway with the way ownCloud
573638
## is setup by this role using packages.
@@ -594,7 +659,10 @@ owncloud__run_occ_host_commands: []
594659
# .. envvar:: owncloud__occ_bin_file_path
595660
#
596661
# Where the :command:`occ` wrapper script should be installed.
597-
owncloud__occ_bin_file_path: '/usr/local/bin/occ'
662+
owncloud__occ_bin_file_path: '{{ (ansible_local.root.bin
663+
if (ansible_local|d() and ansible_local.root|d() and
664+
ansible_local.root.bin|d())
665+
else "/usr/local/bin") + "/occ" }}'
598666

599667

600668
# .. ownCloud applications [[[1
@@ -1265,3 +1333,12 @@ owncloud__php5__pool:
12651333
## Fixes warning (ownCloud 8.1): "The test with getenv('PATH') only returns an empty response"
12661334
PATH: '/usr/local/bin:/usr/bin:/bin'
12671335

1336+
1337+
# .. envvar:: owncloud__unattended_upgrades__dependent_origins
1338+
#
1339+
# List of List of origin patterns managed by the ``debops.unattended_upgrades``
1340+
# role.
1341+
owncloud__unattended_upgrades__dependent_origins:
1342+
- origin: 'site=download.owncloud.org'
1343+
state: '{{ "present" if (owncloud__auto_security_updates_enabled | bool) else "absent" }}'
1344+

docs/getting-started.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ Available role tags:
8181
``role::owncloud:occ``
8282
Run tasks related to the :command:`occ` command.
8383

84+
``role::owncloud:auto_upgrade``
85+
Run tasks related preparing ownCloud auto upgrade.
86+
8487
``role::owncloud:ldap``
8588
Run tasks related to the LDAP configuration.
8689

docs/playbooks/owncloud.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
when: (owncloud__database == 'postgresql')
4545
tags: [ 'role::postgresql' ]
4646

47+
- role: debops.unattended_upgrades
48+
tags: [ 'role::unattended_upgrades' ]
49+
unattended_upgrades__dependent_origins: '{{ owncloud__unattended_upgrades__dependent_origins }}'
50+
4751
- role: debops.php5
4852
tags: [ 'role::php5' ]
4953
php5_pools:

tasks/setup_owncloud.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,32 @@
165165
cron_file: 'owncloud'
166166

167167
# .. ]]]
168+
169+
# ownCloud upgrades [[[
170+
171+
- name: Install the package manager hook script for auto ownCloud DB upgrades
172+
template:
173+
src: 'usr/local/bin/owncloud_db_upgrade_hook.j2'
174+
dest: '{{ owncloud__auto_database_upgrade_hook_script }}'
175+
owner: 'root'
176+
group: 'root'
177+
mode: '0755'
178+
tags: [ 'role::owncloud:auto_upgrade' ]
179+
180+
- name: Enable the package manager hook for auto ownCloud DB upgrades
181+
template:
182+
src: 'etc/apt/apt.conf.d/db_upgrade.j2'
183+
dest: '/etc/apt/apt.conf.d/80ownCloud-db-upgrade'
184+
owner: 'root'
185+
group: 'root'
186+
mode: '0644'
187+
tags: [ 'role::owncloud:auto_upgrade' ]
188+
when: (owncloud__auto_database_upgrade_enabled | bool)
189+
190+
- name: Disable the package manager hook for auto ownCloud DB upgrades
191+
file:
192+
path: '/etc/apt/apt.conf.d/80ownCloud-db-upgrade'
193+
state: 'absent'
194+
when: not (owncloud__auto_database_upgrade_enabled | bool)
195+
196+
# .. ]]]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# {{ ansible_managed }}
2+
3+
DPkg::Post-Invoke {"test -x '{{ owncloud__auto_database_upgrade_hook_script }}' && '{{ owncloud__auto_database_upgrade_hook_script }}' || true";};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# {{ ansible_managed }}
3+
#
4+
# Package manager hook script for auto ownCloud DB upgrades.
5+
# This script is run for each single package being installed or upgraded.
6+
#
7+
# https://unix.stackexchange.com/questions/226993/whats-the-difference-between-dpkgpost-invoke-and-dpkgpost-invoke-success
8+
# https://unix.stackexchange.com/questions/236833/apt-hook-to-check-for-specific-package-changes
9+
10+
set -e
11+
12+
## Check if one of the trigger packages was touched by `dpkg`.
13+
## The script might not be executed as `dpkg` hook.
14+
## Unfortunately, checking against `$SUDO_COMMAND` does not work when the upgrade is done by `unattended-upgrades`.
15+
# echo "$SUDO_COMMAND" | egrep -q '\<(:?{{ owncloud__auto_database_upgrade_hook_script_packages_trigger | join("|") }})\>' || exit 0
16+
17+
## Check if ownCloud is installed.
18+
test -r '{{ owncloud__deploy_path }}/config/config.php' || exit 0
19+
grep -q 'installed.*true' '{{ owncloud__deploy_path }}/config/config.php' || exit 0
20+
21+
## Performance optimization. Check if ownCloud is in maintenance mode (package upgrades put ownCloud in maintenance mode).
22+
grep -q 'maintenance.*true' '{{ owncloud__deploy_path }}/config/config.php' || exit 0
23+
24+
## Check if ownCloud requires an upgrade.
25+
'{{ owncloud__occ_bin_file_path }}' status | egrep -q 'require upgrade' || exit 0
26+
27+
## The ownCloud system package puts ownCloud into maintenance mode as of ownCloud 9.0. Ensure it anyway.
28+
'{{ owncloud__occ_bin_file_path }}' maintenance:mode --on
29+
30+
## Do the upgrade.
31+
'{{ owncloud__occ_bin_file_path }}' upgrade{{ "" if (owncloud__auto_database_upgrade_migration_test | bool) else " --skip-migration-test" }}
32+
33+
## Turn maintenance mode off.
34+
'{{ owncloud__occ_bin_file_path }}' maintenance:mode --off

0 commit comments

Comments
 (0)