Files
Kamino/roles/gitea/molecule/default/verify.yml
T
Defame1297andClaude Opus 5.5 f060461152
Build / build (pull_request) Successful in 12s
Lint / lint (pull_request) Failing after 43s
Molecule / molecule (pull_request) Successful in 1m20s
feat(gitea): add the gitea role
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
2026-11-21 21:53:20 +00:00

303 lines
11 KiB
YAML

---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Stat the Gitea binary
ansible.builtin.stat:
path: /usr/local/bin/gitea
register: gitea_verify_binary
- name: Gitea was not installed
ansible.builtin.assert:
that: not gitea_verify_binary.stat.exists
quiet: true
# The signature check of the download, against local files: two throwaway keys made here,
# A pinned and B not, both in the key file the role imports, so B's signature is checked in the
# same keyring as the pinned key. Only a binary signed by A is placed. The keys exist only in
# this container. gpg is preinstalled in the image (the role's prereqs install it on a real
# host).
- name: Verify the signature check
hosts: all
gather_facts: false
vars:
gitea_sig_dir: /tmp/molecule-signature
gitea_sig_home: /tmp/molecule-signature/gnupg
tasks:
- name: Create the test directories
ansible.builtin.file:
path: "{{ gitea_sig_path }}"
state: directory
mode: "0700"
loop: ["{{ gitea_sig_dir }}", "{{ gitea_sig_home }}"]
loop_control:
loop_var: gitea_sig_path
- name: Make the test keys
ansible.builtin.command:
argv:
- gpg
- --homedir
- "{{ gitea_sig_home }}"
- --batch
- --pinentry-mode
- loopback
- --passphrase
- ""
- --quick-gen-key
- "Molecule {{ gitea_sig_key }} <{{ gitea_sig_key }}@molecule.invalid>"
- ed25519
- sign
- never
loop: [a, b]
loop_control:
loop_var: gitea_sig_key
changed_when: true
- name: Read the test key fingerprints
ansible.builtin.command:
argv: [gpg, --homedir, "{{ gitea_sig_home }}", --batch, --with-colons, --fingerprint, "{{ gitea_sig_key }}@molecule.invalid"]
loop: [a, b]
loop_control:
loop_var: gitea_sig_key
register: gitea_sig_listing
changed_when: false
- name: Keep the test key fingerprints
ansible.builtin.set_fact:
gitea_sig_fpr: >-
{{ dict(['a', 'b'] | zip(gitea_sig_listing.results
| map(attribute='stdout')
| map('regex_findall', '(?m)^fpr:(?:[^:]*:){8}([0-9A-F]+):')
| map('first'))) }}
- name: Write the stub binary and a tampered copy
ansible.builtin.copy:
dest: "{{ gitea_sig_dir }}/{{ gitea_sig_stub.name }}"
content: "{{ gitea_sig_stub.content }}"
mode: "0755"
loop:
- {name: stub, content: "#!/bin/sh\necho molecule\n"}
- {name: tampered, content: "#!/bin/sh\necho tampered\n"}
loop_control:
loop_var: gitea_sig_stub
label: "{{ gitea_sig_stub.name }}"
- name: Sign the stub with each key
ansible.builtin.command:
argv:
- gpg
- --homedir
- "{{ gitea_sig_home }}"
- --batch
- --yes
- --local-user
- "{{ gitea_sig_fpr[gitea_sig_key] }}"
- --armor
- --output
- "{{ gitea_sig_dir }}/stub.{{ gitea_sig_key }}.asc"
- --detach-sign
- "{{ gitea_sig_dir }}/stub"
loop: [a, b]
loop_control:
loop_var: gitea_sig_key
changed_when: true
- name: Export the key files the role imports
ansible.builtin.command:
argv: >-
{{ ['gpg', '--homedir', gitea_sig_home, '--batch', '--yes', '--armor',
'--output', gitea_sig_dir ~ '/' ~ gitea_sig_export.file, '--export']
+ (gitea_sig_export.key_names | map('extract', gitea_sig_fpr) | list) }}
loop:
- {file: keys-ab.asc, key_names: [a, b]}
- {file: keys-b.asc, key_names: [b]}
loop_control:
loop_var: gitea_sig_export
label: "{{ gitea_sig_export.file }}"
changed_when: true
- name: Run each case
ansible.builtin.include_tasks: tasks/signature_case.yml
loop:
- {name: good, binary: stub, signature: stub.a.asc, key: keys-ab.asc, expect: placed}
- {name: other-key, binary: stub, signature: stub.b.asc, key: keys-ab.asc, expect: Verify Gitea binary signature}
- {name: tampered, binary: tampered, signature: stub.a.asc, key: keys-ab.asc, expect: Verify Gitea binary signature}
- {name: pinned-key-missing, binary: stub, signature: stub.a.asc, key: keys-b.asc, expect: Require the pinned release key}
loop_control:
loop_var: gitea_sig_case
label: "{{ gitea_sig_case.name }}"
- name: Find download directories left behind
ansible.builtin.find:
paths: /tmp
patterns: gitea-download.*
file_type: directory
register: gitea_sig_leftovers
- name: Every case removed its download directory
ansible.builtin.assert:
that: gitea_sig_leftovers.files | length == 0
fail_msg: "Left behind: {{ gitea_sig_leftovers.files | map(attribute='path') | join(', ') }}"
quiet: true
- name: Stop the gpg daemons of the test keyring
ansible.builtin.command:
argv: [gpgconf, --homedir, "{{ gitea_sig_home }}", --kill, all]
changed_when: false
# The remove path. Last on purpose: it runs once, outside the idempotence step (a converge
# play that changed state would fail that step), and nothing runs after verify except molecule's
# own cleanup and destroy of the container. Gitea itself is never installed, so this play seeds
# what the removal acts on: a stub unit and binary (the systemd stop of a unit that does not
# exist fails), and the firewall, set up through the real entry points (mortis.kamino.ufw, then
# tasks_from: service_rules with the role's own gitea_ufw_service_rules).
# gitea_remove_data stays false, so the data directories and the user are not touched; their
# absence below shows that prereqs, install and configure (which create them) did not run.
- name: Verify the remove path
hosts: all
gather_facts: true
vars_files:
- ../../defaults/main.yml
tasks:
- name: Enable ufw with the SSH rule, as the base play does
ansible.builtin.include_role:
name: mortis.kamino.ufw
vars:
ufw_rules:
- {rule: allow, port: 22, proto: tcp, comment: ssh}
- name: Add the Gitea rules through the service_rules entry point
ansible.builtin.include_role:
name: mortis.kamino.ufw
tasks_from: service_rules
vars:
ufw_service_name: gitea
ufw_service_rules: "{{ gitea_ufw_service_rules }}"
- name: Seed a rule without an owner tag, which the removal must keep
ansible.builtin.command: ufw allow 8123/tcp comment 'molecule manual rule'
changed_when: true
- name: Seed a stub binary and a stub unit for the removal to delete
ansible.builtin.copy:
dest: "{{ gitea_rm_stub.dest }}"
content: "{{ gitea_rm_stub.content }}"
mode: "{{ gitea_rm_stub.mode }}"
loop:
- dest: "{{ gitea_install_dir }}/gitea"
mode: "0755"
content: "#!/bin/sh\nexit 0\n"
- dest: "{{ gitea_service_unit }}"
mode: "0644"
content: |
[Unit]
Description=Gitea stub for molecule
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
loop_control:
loop_var: gitea_rm_stub
label: "{{ gitea_rm_stub.dest }}"
- name: Let systemd read the stub unit
ansible.builtin.systemd:
daemon_reload: true
- name: Start and enable the stub unit, so the removal has something to stop and disable
ansible.builtin.systemd:
name: gitea
state: started
enabled: true
- name: Ask systemd about the stub unit before the removal
ansible.builtin.systemd:
name: gitea
register: gitea_rm_active_before
- name: Read the rules ufw has stored before the removal
ansible.builtin.command: ufw show added
register: gitea_rm_before
changed_when: false
environment: {LC_ALL: C}
- name: The Gitea rules, the manual rule and the SSH rule exist before the removal
ansible.builtin.assert:
that:
- gitea_rm_before.stdout_lines | select('search', 'ansible-ufw\[gitea:') | list | length == gitea_ufw_service_rules | length
- gitea_rm_before.stdout_lines | select('search', '8123/tcp') | list | length == 1
- gitea_rm_before.stdout_lines | select('search', '(^|[ ])22/tcp') | list | length > 0
quiet: true
- name: The stub unit is active and enabled before the removal
ansible.builtin.assert:
that:
- gitea_rm_active_before.status.ActiveState == 'active'
- gitea_rm_active_before.status.UnitFileState == 'enabled'
quiet: true
- name: Run the role with the remove flag
ansible.builtin.include_role:
name: mortis.kamino.gitea
vars:
gitea_remove: true
# Required by the argument spec of the main entry point; the values are never used.
gitea_domain: gitea.example.test
gitea_admin_user: molecule-admin
gitea_admin_email: [email protected]
gitea_admin_password: molecule-not-a-password
gitea_secret_key: molecule-not-a-key
gitea_internal_token: molecule-not-a-token
gitea_jwt_secret: molecule-not-a-secret
gitea_ssh_keys: []
- name: Read the rules ufw has stored after the removal
ansible.builtin.command: ufw show added
register: gitea_rm_after
changed_when: false
environment: {LC_ALL: C}
- name: Stat what the removal deletes and what install or configure would create
ansible.builtin.stat:
path: "{{ gitea_rm_path }}"
loop:
- "{{ gitea_service_unit }}"
- "{{ gitea_install_dir }}/gitea"
- "{{ gitea_app_dir }}"
- "{{ gitea_data_dirs | first }}"
- /etc/systemd/system/multi-user.target.wants/gitea.service
loop_control:
loop_var: gitea_rm_path
register: gitea_rm_files
- name: Look up the Gitea system user
ansible.builtin.getent:
database: passwd
key: "{{ gitea_user }}"
fail_key: false
register: gitea_rm_user
- name: Ask systemd whether the service is still active
ansible.builtin.systemd:
name: gitea
register: gitea_rm_active
failed_when: false
- name: Only the Gitea rules are gone, and nothing was installed or configured
ansible.builtin.assert:
that:
- gitea_rm_after.stdout_lines | select('search', 'ansible-ufw\[gitea:') | list | length == 0
- gitea_rm_after.stdout_lines | select('search', '(^|[ ])22/tcp') | list | length > 0
- gitea_rm_after.stdout_lines | select('search', '8123/tcp') | list | length == 1
# unit and binary are deleted, and the config and data directories never came into being
- gitea_rm_files.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
# the account is only created by prereqs, which the removal skips
- gitea_rm_user.ansible_facts.getent_passwd[gitea_user] is none
# the module errors for a unit that no longer exists, which is also a pass
- (gitea_rm_active.status | default({})).ActiveState | default('inactive') != 'active'
quiet: true