Moves the gitea role from the environment repository, the second wave 2 role and the second caller of the internal _binary_update role. Against the source: - The update path stages the downloaded, signature-verified binary in a directory next to the live one and hands the stop, backup, swap, restart, version check and rollback to mortis.kamino._binary_update (include_role with apply tags, so --tags update reaches it). A download or signature failure still leaves the running service untouched and says so; a failure in the swap keeps the rollback message of _binary_update. Its default version regex is the one the source used. - The same two small behaviour changes as for traefik come with _binary_update: the backup is taken whenever a live binary exists, and a failure before the stop no longer restarts the running service. - The update no longer removes a PID file between the stop and the start, and gitea_pid_file is gone: the unit runs `gitea web` without --pid and has no PIDFile=, so Gitea writes no PID file and systemd reads none. - The database-migration warning of the source's rollback message (the previous binary may refuse a migrated schema) moves to the gitea_update docs in the README and the argument_specs, since _binary_update owns the failure message. - The legacy name guard (pre-rename variables of the environment) is dropped, as in the wave 1 roles, and the argument_specs and README no longer mention it. The jwt secret, mailer and e-mail confirmation asserts stay. - Environment references are gone from comments, app.ini.j2, the README and the argument_specs: issue numbers, decision records, host names, inventory paths, playbooks, the network and proxy layout and other roles' copies of the paths. The Renovate comment on gitea_version is dropped; the README and argument_specs recommend pinning the version in inventory. The mint messages no longer name a playbook. - On a fresh host the token assert and the SSH-key upload ran before the unit was written and Gitea started, so a first install could never complete. Both now run after the service check, and the upload first waits (up to 60 s, not under --check) for the local listener; the listener address is resolved once for both. - REVERSE_PROXY_LIMIT, hard-coded to 2, is now gitea_reverse_proxy_limit with default 1: a limit above the real number of proxies lets a client forge the address Gitea logs and Fail2Ban bans. A setup with two proxies sets it to 2. - The gitea commands with user-supplied values (migrate, admin user list and create, and the token mint) take argv instead of a command string; still run through sudo -u. - gitea_version is asserted at role start to be a plain X.Y.Z, with no leading v. - meta namespace mortis; the scenario follows the Kamino conventions (header, test_sequence, no provisioner env) and calls the role by FQCN, also in the child ansible-playbook of the mint CI-guard cases. Coverage is unchanged. No other default changed; DISABLE_REGISTRATION stays hard-coded to true. Changelog fragment, README Roadmap and the CLAUDE.md role list updated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
137 lines
5.5 KiB
YAML
137 lines
5.5 KiB
YAML
---
|
|
# The one download of the Gitea binary, shared by install.yml (copied straight onto the live
|
|
# path, since nothing runs yet) and update.yml (copied to a staging path next to it, before the
|
|
# service is stopped). The binary, its signature and the release key land in a throwaway
|
|
# directory that also serves as an empty GNUPGHOME, so the check sees no key but the one fetched
|
|
# here, never the login user's keyring. Only a verified binary is copied to
|
|
# gitea_download_dest.
|
|
# Input: gitea_download_dest, the path the verified binary is copied to.
|
|
# Tagged install and update: an include does not pass its tags on to the tasks it includes,
|
|
# so under --tags update a task tagged install only would be skipped.
|
|
- name: Download, verify and place the Gitea binary
|
|
block:
|
|
# Created under --check too (and removed below), so the paths of the tasks after it resolve.
|
|
# mkdtemp makes it 0700, which gpg requires of a home directory.
|
|
- name: Create the download directory
|
|
ansible.builtin.tempfile:
|
|
state: directory
|
|
prefix: gitea-download.
|
|
register: gitea_download_tmp
|
|
check_mode: false
|
|
tags: [gitea, install, update]
|
|
|
|
- name: Download Gitea binary
|
|
ansible.builtin.get_url:
|
|
url: "{{ gitea_download_url }}"
|
|
dest: "{{ gitea_download_tmp.path }}/gitea"
|
|
mode: "0755"
|
|
tags: [gitea, install, update]
|
|
|
|
- name: Download Gitea signature
|
|
ansible.builtin.get_url:
|
|
url: "{{ gitea_signature_url }}"
|
|
dest: "{{ gitea_download_tmp.path }}/gitea.asc"
|
|
mode: "0644"
|
|
tags: [gitea, install, update]
|
|
|
|
- name: Download the Gitea release key
|
|
ansible.builtin.get_url:
|
|
url: "{{ gitea_gpg_key_url }}"
|
|
dest: "{{ gitea_download_tmp.path }}/release-key.asc"
|
|
mode: "0644"
|
|
tags: [gitea, install, update]
|
|
|
|
# gpg checks the self-signatures and subkey bindings on import, so whatever is imported
|
|
# under the pinned primary fingerprint is that key's own material.
|
|
- name: Import the Gitea release key into the throwaway keyring
|
|
ansible.builtin.command:
|
|
argv:
|
|
- gpg
|
|
- --homedir
|
|
- "{{ gitea_download_tmp.path }}"
|
|
- --batch
|
|
- --import
|
|
- "{{ gitea_download_tmp.path }}/release-key.asc"
|
|
changed_when: false
|
|
tags: [gitea, install, update]
|
|
|
|
- name: List the imported keys
|
|
ansible.builtin.command:
|
|
argv: [gpg, --homedir, "{{ gitea_download_tmp.path }}", --batch, --with-colons, --fingerprint]
|
|
register: gitea_gpg_keys
|
|
changed_when: false
|
|
tags: [gitea, install, update]
|
|
|
|
# In --with-colons output the fpr line right after a pub line is the primary key's.
|
|
- name: Require the pinned release key
|
|
ansible.builtin.assert:
|
|
that: gitea_gpg_key_id | upper in gitea_gpg_primaries
|
|
fail_msg: >-
|
|
{{ gitea_gpg_key_url }} did not provide the key {{ gitea_gpg_key_id }}
|
|
(primary keys found: {{ gitea_gpg_primaries | join(', ') or 'none' }}).
|
|
quiet: true
|
|
vars:
|
|
gitea_gpg_primaries: >-
|
|
{{ gitea_gpg_keys.stdout
|
|
| regex_findall('(?m)^pub:.*\n(?:fpr|fp2):(?:[^:]*:){8}([0-9A-F]+):') }}
|
|
when: not ansible_check_mode
|
|
tags: [gitea, install, update]
|
|
|
|
# Every signature in the file must be good and made by the pinned key (or one of its
|
|
# subkeys: the last VALIDSIG field is the primary fingerprint). A good signature by an
|
|
# expired or revoked key, an unknown key or a bad signature fails the check.
|
|
- name: Verify Gitea binary signature
|
|
ansible.builtin.command:
|
|
argv:
|
|
- gpg
|
|
- --homedir
|
|
- "{{ gitea_download_tmp.path }}"
|
|
- --batch
|
|
- --status-fd
|
|
- "1"
|
|
- --verify
|
|
- "{{ gitea_download_tmp.path }}/gitea.asc"
|
|
- "{{ gitea_download_tmp.path }}/gitea"
|
|
register: gitea_gpg_verify
|
|
changed_when: false
|
|
failed_when: >-
|
|
gitea_gpg_verify.rc != 0
|
|
or gitea_gpg_verify.stdout is search('^\[GNUPG:\] (BADSIG|ERRSIG|EXPSIG|EXPKEYSIG|REVKEYSIG) ', multiline=True)
|
|
or (gitea_gpg_verify.stdout | regex_findall('(?m)^\[GNUPG:\] NEWSIG( |$)') | length)
|
|
!= (gitea_gpg_verify.stdout | regex_findall('(?m)^\[GNUPG:\] VALIDSIG ') | length)
|
|
or (gitea_gpg_verify.stdout | regex_findall('(?m)^\[GNUPG:\] VALIDSIG .* ([0-9A-F]{40})$') | unique)
|
|
!= [gitea_gpg_key_id | upper]
|
|
tags: [gitea, install, update]
|
|
|
|
- name: Place the verified Gitea binary
|
|
become: true
|
|
ansible.builtin.copy:
|
|
src: "{{ gitea_download_tmp.path }}/gitea"
|
|
dest: "{{ gitea_download_dest }}"
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
remote_src: true
|
|
# The binary is not downloaded under --check, so there is nothing to copy.
|
|
when: not ansible_check_mode
|
|
tags: [gitea, install, update]
|
|
always:
|
|
# gpg may have started an agent for the throwaway home; stop it before the directory goes.
|
|
- name: Stop the gpg daemons of the throwaway keyring
|
|
ansible.builtin.command:
|
|
argv: [gpgconf, --homedir, "{{ gitea_download_tmp.path }}", --kill, all]
|
|
changed_when: false
|
|
failed_when: false
|
|
when:
|
|
- gitea_download_tmp.path is defined
|
|
- not ansible_check_mode
|
|
tags: [gitea, install, update]
|
|
|
|
- name: Remove the download directory
|
|
ansible.builtin.file:
|
|
path: "{{ gitea_download_tmp.path }}"
|
|
state: absent
|
|
check_mode: false
|
|
when: gitea_download_tmp.path is defined
|
|
tags: [gitea, install, update]
|