-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admins can run `./securedrop-admin noble_migration` to trigger a manual noble migration. At a high level the playbook: * disables OSSEC notifications * triggers the app upgrade, waiting through two reboots * triggers the mon upgrade, again waiting through reboots * re-enables OSSEC notifications The most complicated part is how we for the reboots. We first have a `wait_for` that looks for a specific stage in the state file. Because the upgrade script writes the state file and then immediately reboots, it should never actually succeed and fail because the connection is interrupted. So we set `ignore_unreachable` and `ignore_errors`, and the next block is `wait_for_connection` for the server to come back up. There is a delay before we begin checking just in case the wait_for did succeed and we need to wait for the reboot to happen. Because of this sequencing, there isn't any support for the playbook failing mid-host and restarting it. It is probably unnecessary since, once started, the upgrade will automatically finish by itself. The script does support one host already being upgraded and the other still needing migration. So if e.g. app migration fails, you can manually fix the host, let it auto finish the upgrade, and then re-run the playbook to migrate mon. Fixes #7416.
- Loading branch information
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
install_files/ansible-base/roles/noble-migration/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
|
||
- name: Check migration JSON on mon server | ||
ansible.builtin.slurp: | ||
src: /etc/securedrop-noble-migration-state.json | ||
register: migration_json | ||
ignore_errors: yes | ||
|
||
- name: Skip migration if already done | ||
set_fact: | ||
already_finished: "{{ not migration_json.failed and (migration_json.content | b64decode | from_json)['finished'] == 'Done' }}" | ||
|
||
- name: Perform migration | ||
when: not already_finished | ||
block: | ||
- name: Instruct upgrade to begin | ||
ansible.builtin.copy: | ||
# It's okay to enable both app and mon here to simplify the logic, | ||
# as this only affects the server the file is updated on. | ||
content: | | ||
{ | ||
"app": {"enabled": true, "bucket": 5}, | ||
"mon": {"enabled": true, "bucket": 5} | ||
} | ||
dest: /usr/share/securedrop/noble-upgrade.json | ||
|
||
# Start the systemd service manually to avoid waiting for the timer to pick it up | ||
- name: Start upgrade systemd service | ||
ansible.builtin.systemd: | ||
name: securedrop-noble-migration-upgrade | ||
state: started | ||
|
||
# Wait until we've finished the PendingUpdates stage. It's highly unlikely | ||
# we'll ever successfully complete this stage because as soon as the script | ||
# reaches finishes that stage, it reboots. Most likely this step will fail | ||
# as unreachable, which we ignore and wait_for_connection. | ||
- name: Wait for pending updates to be applied | ||
ansible.builtin.wait_for: | ||
path: /etc/securedrop-noble-migration-state.json | ||
search_regex: '"finished":"PendingUpdates"' | ||
sleep: 1 | ||
timeout: 300 | ||
ignore_unreachable: yes | ||
ignore_errors: yes | ||
|
||
- name: Wait for the first reboot | ||
ansible.builtin.wait_for_connection: | ||
connect_timeout: 20 | ||
sleep: 5 | ||
delay: 10 | ||
timeout: 300 | ||
|
||
# Start the systemd service manually to avoid waiting for the timer to pick it up | ||
- name: Resume upgrade systemd service | ||
ansible.builtin.systemd: | ||
name: securedrop-noble-migration-upgrade | ||
state: started | ||
|
||
- debug: | ||
msg: "The upgrade is in progress; it may take up to 30 minutes." | ||
|
||
# Same as above, this will most likely fail as unreachable when the server | ||
# actually reboots. | ||
- name: Wait for system upgrade to noble | ||
ansible.builtin.wait_for: | ||
path: /etc/securedrop-noble-migration-state.json | ||
search_regex: '"finished":"Reboot"' | ||
sleep: 5 | ||
# Should finish in less than 30 minutes | ||
timeout: 1800 | ||
ignore_unreachable: yes | ||
ignore_errors: yes | ||
|
||
- name: Wait for the second reboot | ||
ansible.builtin.wait_for_connection: | ||
connect_timeout: 20 | ||
sleep: 5 | ||
delay: 10 | ||
timeout: 300 | ||
|
||
- name: Re-resume upgrade systemd service | ||
ansible.builtin.systemd: | ||
name: securedrop-noble-migration-upgrade | ||
state: started | ||
|
||
# This final check should actually succeed. | ||
- name: Wait for migration to complete | ||
ansible.builtin.wait_for: | ||
path: /etc/securedrop-noble-migration-state.json | ||
search_regex: '"finished":"Done"' | ||
sleep: 5 | ||
timeout: 300 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
- name: Disable OSSEC notifications | ||
hosts: securedrop_monitor_server | ||
max_fail_percentage: 0 | ||
any_errors_fatal: yes | ||
environment: | ||
LC_ALL: C | ||
tasks: | ||
- name: Disable OSSEC notifications | ||
ansible.builtin.lineinfile: | ||
path: /var/ossec/etc/ossec.conf | ||
regexp: '<email_alert_level>7</email_alert_level>' | ||
line: '<email_alert_level>15</email_alert_level>' | ||
register: ossec_config | ||
|
||
- name: Restart OSSEC service | ||
ansible.builtin.systemd: | ||
name: ossec | ||
state: restarted | ||
when: ossec_config.changed | ||
become: yes | ||
|
||
- name: Perform upgrade on application server | ||
hosts: securedrop_application_server | ||
max_fail_percentage: 0 | ||
any_errors_fatal: yes | ||
environment: | ||
LC_ALL: C | ||
roles: | ||
- role: noble-migration | ||
tags: noble-migration | ||
become: yes | ||
|
||
- name: Perform upgrade on monitor server | ||
hosts: securedrop_monitor_server | ||
max_fail_percentage: 0 | ||
any_errors_fatal: yes | ||
environment: | ||
LC_ALL: C | ||
roles: | ||
- role: noble-migration | ||
tags: noble-migration | ||
become: yes | ||
|
||
# This is not really necessary since the mon migration will restore the old | ||
# configuration back, but let's include it for completeness. | ||
- name: Restore OSSEC notifications | ||
hosts: securedrop_monitor_server | ||
max_fail_percentage: 0 | ||
any_errors_fatal: yes | ||
environment: | ||
LC_ALL: C | ||
tasks: | ||
- name: Re-enable OSSEC email alerts | ||
ansible.builtin.lineinfile: | ||
path: /var/ossec/etc/ossec.conf | ||
regexp: '<email_alert_level>(.*?)</email_alert_level>' | ||
line: '<email_alert_level>7</email_alert_level>' | ||
register: ossec_config | ||
|
||
- name: Restart OSSEC service | ||
ansible.builtin.systemd: | ||
name: ossec | ||
state: restarted | ||
when: ossec_config.changed | ||
become: yes |