feat: Mejorar la configuración y seguridad de Koji

Este commit introduce varias mejoras en los roles de Ansible para Koji:

- **Rol koji_hub:**
  - Se reemplazó `lineinfile` con una plantilla completa para `hub.conf` para mejorar la legibilidad y mantenibilidad.
  - Se aseguró la instalación del paquete `python3-koji-hub-plugins` para soportar el plugin `echo`.
  - Se eliminó una tarea `blockinfile` redundante que duplicaba la configuración de la base de datos en `hub.conf`.
  - Se rehabilitó el plugin `echo` en `hub.conf` después de asegurar su disponibilidad.

- **Rol postgresql:**
  - Se modificó la configuración de `pg_hba.conf` para iterar correctamente sobre todos los hosts en el grupo `kojihub`, asegurando que todas las instancias del hub puedan conectarse a la base de datos.

- **Rol dist_git:**
  - Se implementó el etiquetado persistente de contextos SELinux para los directorios de `dist-git` usando `semanage fcontext` y `restorecon`, asegurando que los contextos persistan tras reetiquetados del sistema de archivos.

- **Rol common:**
  - Se mejoró la seguridad en la generación de claves GPG usando un archivo temporal para el script por lotes, el cual se elimina de forma segura después de la generación de la clave.

- **Configuración Global:**
  - Se introdujo la variable `koji_source_script_path` en `vars/default.yaml` para centralizar la ruta del script `mxos-get-sources.bash`, eliminando rutas hardcodeadas en `kojid_allowed_scms` y las tareas de `kojid`.

- **Documentación:**
  - Se actualizó `docs/instalación.rst` para reflejar los cambios en la configuración de Dist-Git, plugins y variables.
This commit is contained in:
Rénich Bon Ćirić 2025-11-22 11:48:06 -06:00
commit f14c01da0b
Signed by: renich
GPG key ID: AB2A9F49384FE324
25 changed files with 731 additions and 123 deletions

View file

@ -59,38 +59,48 @@
- name: Create GPG key batch file
when: inventory_hostname == 'localhost'
ansible.builtin.copy:
content: |
%echo Generating a basic OpenPGP key
Key-Type: RSA
Key-Length: 4096
Subkey-Type: RSA
Subkey-Length: 4096
Name-Real: Koji Signing Key
Name-Email: koji@{{ koji_hub_fqdn }}
Expire-Date: 0
Passphrase: {{ gpg_key_passphrase }}
%commit
%echo done
dest: "{{ koji_pki_dir }}/gpg_batch"
mode: "0600"
delegate_to: localhost
run_once: true
tags: gpg
block:
- name: Create temporary GPG batch file
ansible.builtin.tempfile:
state: file
suffix: .gpg
register: gpg_batch_file
- name: Generate GPG key
ansible.builtin.command:
cmd: "gpg --batch --gen-key {{ koji_pki_dir }}/gpg_batch"
delegate_to: localhost
run_once: true
args:
creates: "{{ koji_pki_dir }}/gpg_key.pub"
- name: Populate GPG batch file
ansible.builtin.copy:
content: |
%echo Generating a basic OpenPGP key
Key-Type: RSA
Key-Length: 4096
Subkey-Type: RSA
Subkey-Length: 4096
Name-Real: Koji Signing Key
Name-Email: koji@{{ koji_hub_fqdn }}
Expire-Date: 0
Passphrase: {{ gpg_key_passphrase }}
%commit
%echo done
dest: "{{ gpg_batch_file.path }}"
mode: "0600"
- name: Export GPG public key
ansible.builtin.shell:
cmd: "gpg --armor --export 'Koji Signing Key' > {{ koji_pki_dir }}/gpg_key.pub"
changed_when: false
delegate_to: localhost
run_once: true
- name: Generate GPG key
ansible.builtin.command:
cmd: "gpg --batch --gen-key {{ gpg_batch_file.path }}"
args:
creates: "{{ koji_pki_dir }}/gpg_key.pub"
- name: Export GPG public key
ansible.builtin.shell:
cmd: "gpg --armor --export 'Koji Signing Key' > {{ koji_pki_dir }}/gpg_key.pub"
changed_when: false
always:
- name: Remove temporary GPG batch file
ansible.builtin.file:
path: "{{ gpg_batch_file.path }}"
state: absent
when: gpg_batch_file.path is defined
- name: Set hostname
ansible.builtin.hostname:
@ -119,10 +129,21 @@
state: absent
loop: "{{ groups['all'] }}"
- name: Scan SSH keys
ansible.builtin.command: ssh-keyscan -t rsa {{ item }}
loop: "{{ groups['all'] }}"
register: scanned_keys
delegate_to: localhost
run_once: true
changed_when: false
until: scanned_keys.rc == 0
retries: 3
delay: 2
- name: "Add current host keys"
ansible.builtin.known_hosts:
path: "~/.ssh/known_hosts"
name: "{{ item }}"
key: "{{ lookup('pipe', 'ssh-keyscan -t rsa ' + item) }}"
name: "{{ item.item }}"
key: "{{ item.stdout }}"
state: present
loop: "{{ groups['all'] }}"
loop: "{{ scanned_keys.results }}"