Author SHA1 Message Date
kris a1ef6e76a5 Migrate Gitea to rootless Podman / SELinux
- Front git-over-SSH with host sshd and live key lookup
- Build and load custom SELinux policies oci_log and gitea_ssh
2026-09-01 01:42:33 -04:00
kris 601a889172 Fix forward-ssh.sh shebang 2026-08-23 02:37:03 -04:00
kris ccd04de8be Follow Ruby constant conventions for playbook var 2026-05-16 10:08:31 -04:00
kris 42fb86f5b1 Fix restart list to only include changed projects 2026-04-10 21:29:06 -04:00
kris 19a65cb742 Add zrepl role 2026-02-25 22:36:37 -05:00
kris 7404bab63f Set SSH UFW rule via role default 2026-02-24 00:50:20 -05:00
kris 929d549217 Enable SELinux deployment in dev config 2026-02-24 00:18:34 -05:00
kris 2bd80bcfed Simplify libvirt role configuration 2026-02-08 13:43:05 -05:00
kris 46e289d249 Add podman_compose tag for deployments 2026-02-02 23:47:53 -05:00
kris e7dd861d7a Add SELinux certbot_acmesh bool for Certbot DNS-01 2026-01-25 15:59:36 -05:00
kris cb828bdf53 Fix SELinux context for Cloudflare API files 2026-01-25 15:27:12 -05:00
kris 213e7ed175 Fix podman SSH key paths and add registry support
- Configure SELinux to permit nginx network connections
2026-01-25 13:01:29 -05:00
kris e2e5fdcd67 Add WireGuard routing and Podman playbook 2026-01-15 00:47:04 -05:00
kris 39e8f78adf Add SELinux support to the base role 2026-01-13 01:07:29 -05:00
kris ac33f8bf7d Optional IPv6 in nginx confs 2026-01-10 10:48:29 -05:00
kris d3a6b22199 Fix ansible-lint warnings in base and proxy roles 2026-01-10 10:36:08 -05:00
kris a3f723885d Prefix base role variables 2025-12-31 19:11:58 -05:00
kris 2298ca008e Add users tag to user management tasks 2025-11-26 20:07:28 -05:00
kris c713317e49 Add cron job deployment to base role 2025-11-24 16:35:11 -05:00
kris e5541315ec Implement Git-based script deployment system 2025-11-24 15:13:58 -05:00
49 changed files with 938 additions and 245 deletions
Vendored
+4 -4
View File
@@ -15,10 +15,10 @@ VAGRANT_MEM = settings['VAGRANT_MEM'] || 2048
SSH_FORWARD = settings['SSH_FORWARD'] || false SSH_FORWARD = settings['SSH_FORWARD'] || false
# Default to shell environment variable: PLAYBOOK (priority #1) # Default to shell environment variable: PLAYBOOK (priority #1)
PLAYBOOK=ENV["PLAYBOOK"] playbook=ENV["PLAYBOOK"]
if !PLAYBOOK || PLAYBOOK.empty? if !playbook || playbook.empty?
# PLAYBOOK setting in .vagrant.yml (priority #2) # PLAYBOOK setting in .vagrant.yml (priority #2)
PLAYBOOK = settings['PLAYBOOK'] || 'default' playbook = settings['PLAYBOOK'] || 'default'
end end
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
@@ -42,7 +42,7 @@ Vagrant.configure("2") do |config|
config.vm.provision "ansible" do |ansible| config.vm.provision "ansible" do |ansible|
ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles" ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles"
ansible.compatibility_mode = "2.0" ansible.compatibility_mode = "2.0"
ansible.playbook = "dev/" + PLAYBOOK + ".yml" ansible.playbook = "dev/" + playbook + ".yml"
ansible.raw_arguments = ["--diff"] ansible.raw_arguments = ["--diff"]
end end
end end
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
# docker # docker
docker_users: docker_users:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
# Import my GPG key for git signature verification # Import my GPG key for git signature verification
root_gpgkeys: root_gpgkeys:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
# Import my GPG key for git signature verification # Import my GPG key for git signature verification
root_gpgkeys: root_gpgkeys:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
users: users:
git: git:
+2 -2
View File
@@ -1,8 +1,8 @@
debian_version: 10.5.0 debian_version: 10.5.0
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
# libvirt # libvirt
libvirt_users: vagrant libvirt_users: vagrant
+2 -2
View File
@@ -1,8 +1,8 @@
base_domain: local.krislamo.org base_domain: local.krislamo.org
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
users: users:
jellyfin: jellyfin:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
# minecraft # minecraft
# Agree to EULA to start service in Vagrant # Agree to EULA to start service in Vagrant
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
# docker # docker
docker_users: docker_users:
+34 -19
View File
@@ -1,9 +1,25 @@
############## ##############
#### base #### #### base ####
############## ##############
selinux:
state: enforcing
allow_reboot: false base_allow_reboot: true
manage_network: false base_manage_network: false
root_gpgkeys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
scripts:
trusted_keys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
repos:
- name: dotfiles
url: https://github.com/krislamo/dotfiles
version: 999d745710b9db500e82d1a0d0107ac5d623a669
scripts:
- src: gotify/.local/bin/gotify
dest: /usr/local/bin/gotify
################ ################
#### proxy ##### #### proxy #####
@@ -11,35 +27,34 @@ manage_network: false
proxy: proxy:
servers: servers:
- domain: cloud.local.krislamo.org - domain: music.local.krislamo.org
proxy_pass: http://127.0.0.1:8000 proxy_pass: http://127.0.0.1:4533
################ ################
#### podman #### #### podman ####
################ ################
podman_label:
- path: /home/vagrant/navidrome
label: system_u:object_r:container_file_t:s0
owner: vagrant
group: vagrant
podman_compose: podman_compose:
vagrant: vagrant:
root: /opt/oci root: /opt/oci
trusted_keys: trusted_keys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96 - id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
compose: compose:
- name: traefik - name: navidrome
url: https://github.com/krislamo/traefik url: https://github.com/krislamo/navidrome
version: d7197ddd5b7019c60faf5d164e555b6374972d40 version: 305f92cff143c0d497d21277145f605d9da830de
enabled: true enabled: true
accept_newhostkey: true # Consider verifying manually instead accept_newhostkey: true # Consider verifying manually instead
env: env:
VERSION: latest VERSION: latest
SOCKET: /run/user/1000/podman/podman.sock BASEURL: https://music.local.krislamo.org
DASHBOARD: true MUSIC: /home/vagrant/navidrome
- name: nextcloud LASTFM_ENABLED: "false"
url: https://github.com/krislamo/nextcloud LASTFM_APIKEY: "n/a"
version: 245c91a22fa75e5dde1d423e88540529a4fa4f27 LASTFM_SECRET: "n/a"
enabled: true
env:
VERSION: latest
DOMAIN: cloud.local.krislamo.org
DATA: /opt/oci/nextcloud/data/
REDIS_VERSION: latest
REDIS_PASSWORD: changeme
+2 -2
View File
@@ -1,8 +1,8 @@
base_domain: local.krislamo.org base_domain: local.krislamo.org
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
users: users:
git: git:
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
#mail: #mail:
# host: smtp.gmail.com # host: smtp.gmail.com
+2 -2
View File
@@ -1,6 +1,6 @@
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
# UniFi version # UniFi version
unifi_version: 6.1.71 unifi_version: 6.1.71
+68
View File
@@ -0,0 +1,68 @@
##############
#### base ####
##############
base_allow_reboot: true
base_manage_network: false
selinux:
state: enforcing
permissive_domains:
# logind drops its D-Bus connection under enforcing on trixie and never
# reconnects; pidfs/refpolicy gap. https://trello.com/c/x49s4EdL
- systemd_logind_t
users:
git:
uid: 1001
gid: 1001
home: true
system: true
root_gpgkeys:
- name: kris@lamoureux.io
id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
###############
#### proxy ####
###############
base_domain: local.krislamo.org
proxy:
servers:
- domain: "git.{{ base_domain }}"
proxy_pass: "http://127.0.0.1:3000"
################
#### podman ####
################
podman_compose:
git:
root: /opt/oci
trusted_keys:
- id: 42A3A92C5DA0F3E5F71A3710105B748C1362EB96
compose:
- name: gitea
url: https://github.com/krislamo/gitea
version: 84e5880484e803fdcf53c7f70b699988d28021d0
enabled: true
env:
DATA: "{{ gitea_data }}"
SSH_DIR: "{{ gitea_data }}/git/.ssh"
USER_UID: "{{ gitea_uid }}"
USER_GID: "{{ gitea_uid }}"
SE_LEVEL: "{{ gitea_se_level }}"
DOMAIN: "git.{{ base_domain }}"
PROXY_TRUSTED_PROXIES: "{{ gitea_trusted_proxies }}"
DB_HOST: "{{ gitea.DB_HOST }}"
DB_NAME: "{{ gitea.DB_NAME }}"
DB_USER: "{{ gitea.DB_USER }}"
DB_PASSWD: "{{ gitea.DB_PASSWD }}"
###############
#### gitea ####
###############
gitea:
DB_HOST: host.containers.internal
DB_NAME: gitea
DB_USER: gitea
DB_PASSWD: password
+2 -3
View File
@@ -1,6 +1,6 @@
# base # base
allow_reboot: false base_allow_reboot: false
manage_network: false base_manage_network: false
# docker # docker
docker_users: docker_users:
@@ -22,7 +22,6 @@ wordpress_multisite: true
# database settings # database settings
wordpress_dbversion: latest wordpress_dbversion: latest
wordpress_dbpass: password wordpress_dbpass: password
# multisite (enable in admin panel then uncomment) # multisite (enable in admin panel then uncomment)
#wordpress_rule: "Host(`{{ wordpress_domain }}`) || #wordpress_rule: "Host(`{{ wordpress_domain }}`) ||
# Host(`site1.{{ wordpress_domain }}`) || # Host(`site1.{{ wordpress_domain }}`) ||
+11
View File
@@ -0,0 +1,11 @@
- name: Install VPS Server
hosts: all
become: true
vars_files:
- host_vars/vps.yml
roles:
- base
- proxy
- mariadb
- podman
- gitea
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Finds the SSH private key under ./.vagrant and connects to # Finds the SSH private key under ./.vagrant and connects to
# the Vagrant box, port forwarding localhost ports: 8443, 443, 80, 22 # the Vagrant box, port forwarding localhost ports: 8443, 443, 80, 22
+7
View File
@@ -0,0 +1,7 @@
- name: Install Podman server
hosts: "{{ PLAYBOOK_HOST | default('none') }}"
become: true
roles:
- base
- proxy
- podman
+10 -6
View File
@@ -1,10 +1,10 @@
allow_reboot: true base_allow_reboot: true
manage_firewall: true base_manage_firewall: true
manage_network: false base_manage_network: false
network_type: static base_network_type: static
locale_default: en_US.UTF-8 base_locale_default: en_US.UTF-8
packages: base_packages:
- apache2-utils - apache2-utils
- cryptsetup - cryptsetup
- curl - curl
@@ -20,3 +20,7 @@ packages:
- tree - tree
- vim - vim
- wget - wget
base_scripts: /srv/.scripts
base_ssh_ufw_rule: limit
+3 -1
View File
@@ -3,11 +3,13 @@
msg: "Reboot initiated by Ansible" msg: "Reboot initiated by Ansible"
connect_timeout: 5 connect_timeout: 5
listen: reboot_host listen: reboot_host
when: allow_reboot when: base_allow_reboot
- name: Reconfigure locales - name: Reconfigure locales
ansible.builtin.command: dpkg-reconfigure -f noninteractive locales ansible.builtin.command: dpkg-reconfigure -f noninteractive locales
changed_when: false
listen: reconfigure_locales listen: reconfigure_locales
when: not ansible_check_mode
- name: Restart WireGuard - name: Restart WireGuard
ansible.builtin.service: ansible.builtin.service:
+13 -2
View File
@@ -8,6 +8,17 @@
name: fail2ban name: fail2ban
state: present state: present
- name: Ensure Fail2ban's log file is correctly labelled
ansible.builtin.file:
path: /var/log/fail2ban.log
state: touch
mode: "0640"
access_time: preserve
modification_time: preserve
setype: fail2ban_log_t
when: selinux is defined and selinux is not false
notify: restart_fail2ban
- name: Deny incoming traffic by default - name: Deny incoming traffic by default
community.general.ufw: community.general.ufw:
default: deny default: deny
@@ -18,10 +29,10 @@
default: allow default: allow
direction: outgoing direction: outgoing
- name: Allow OpenSSH with rate limiting - name: "{{ base_ssh_ufw_rule | capitalize }} OpenSSH"
community.general.ufw: community.general.ufw:
name: ssh name: ssh
rule: limit rule: "{{ base_ssh_ufw_rule | default('limit') }}"
- name: Remove Fail2ban defaults-debian.conf - name: Remove Fail2ban defaults-debian.conf
ansible.builtin.file: ansible.builtin.file:
+2 -2
View File
@@ -9,12 +9,12 @@
- name: Import Firewall tasks - name: Import Firewall tasks
ansible.builtin.import_tasks: firewall.yml ansible.builtin.import_tasks: firewall.yml
tags: firewall tags: firewall
when: manage_firewall when: base_manage_firewall
- name: Import Network tasks - name: Import Network tasks
ansible.builtin.import_tasks: network.yml ansible.builtin.import_tasks: network.yml
tags: network tags: network
when: manage_network when: base_manage_network
- name: Import Mail tasks - name: Import Mail tasks
ansible.builtin.import_tasks: mail.yml ansible.builtin.import_tasks: mail.yml
+1 -1
View File
@@ -43,4 +43,4 @@
from: "{{ item }}" from: "{{ item }}"
state: enabled state: enabled
loop: "{{ samba.firewall }}" loop: "{{ samba.firewall }}"
when: manage_firewall when: base_manage_firewall
+145 -8
View File
@@ -1,16 +1,68 @@
- name: Install useful software - name: Install useful software
ansible.builtin.apt: ansible.builtin.apt:
name: "{{ packages }}" name: "{{ base_packages }}"
state: present state: present
update_cache: true update_cache: true
- name: Get the default policy and basic SELinux utilities
ansible.builtin.apt:
name: ["selinux-basics", "selinux-policy-default", "auditd"]
state: present
when: selinux is defined and selinux is not false
- name: Configure SELinux
ansible.posix.selinux:
state: "{{ selinux.state | default('permissive') }}"
policy: "{{ selinux.policy | default('default') }}"
when: selinux is defined and selinux is not false
- name: Set SELinux permissive domains
community.general.selinux_permissive:
domain: "{{ item }}"
permissive: true
loop: "{{ selinux.permissive_domains | default([]) }}"
when: selinux is defined and selinux is not false
- name: Check for GRUB
ansible.builtin.stat:
path: /etc/default/grub
register: grub_config
when: selinux is defined and selinux is not false
- name: Check if SELinux is already activated in GRUB
ansible.builtin.command: grep -q 'security=selinux' /etc/default/grub
register: selinux_grub
changed_when: false
failed_when: false
when:
- selinux is defined
- selinux is not false
- grub_config.stat.exists
- name: Activate SELinux
ansible.builtin.command: selinux-activate
changed_when: true
when:
- selinux is defined
- selinux is not false
- grub_config.stat.exists
- selinux_grub.rc != 0
register: selinux_activated
- name: Reboot after SELinux activation
ansible.builtin.reboot:
when:
- selinux_activated is changed
- base_allow_reboot
- name: Install GPG - name: Install GPG
ansible.builtin.apt: ansible.builtin.apt:
name: gpg name: gpg
state: present state: present
- name: Check for existing GPG keys - name: Check for existing GPG keys
ansible.builtin.command: "gpg --list-keys {{ item.id }} 2>/dev/null" ansible.builtin.command: >-
gpg --list-keys {{ item.id }} 2>/dev/null
register: gpg_check register: gpg_check
loop: "{{ root_gpgkeys }}" loop: "{{ root_gpgkeys }}"
failed_when: false failed_when: false
@@ -18,8 +70,9 @@
when: root_gpgkeys is defined when: root_gpgkeys is defined
- name: Import GPG keys - name: Import GPG keys
ansible.builtin.command: ansible.builtin.command: >-
"gpg --keyserver {{ item.item.server | default('keys.openpgp.org') }} --recv-key {{ item.item.id }}" gpg --keyserver {{ item.item.server | default('keys.openpgp.org') }}
--recv-key {{ item.item.id }}
register: gpg_check_import register: gpg_check_import
loop: "{{ gpg_check.results }}" loop: "{{ gpg_check.results }}"
loop_control: loop_control:
@@ -33,7 +86,85 @@
loop: "{{ gpg_check_import.results }}" loop: "{{ gpg_check_import.results }}"
loop_control: loop_control:
label: "{{ item.item.item }}" label: "{{ item.item.item }}"
when: root_gpgkeys is defined and (not item.skipped | default(false)) and ('imported' not in item.stderr) when:
- root_gpgkeys is defined
- not item.skipped | default(false)
- "'imported' not in item.stderr"
- name: Create scripts directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "700"
owner: root
group: root
loop:
- "{{ base_scripts }}"
- "{{ base_scripts }}/.keys"
when: scripts is defined
- name: Generate OpenSSH deploy keys for script clones
community.crypto.openssh_keypair:
path: "{{ base_scripts }}/.keys/id_ed25519"
type: ed25519
comment: "{{ ansible_facts['hostname'] }}-deploy-key"
mode: "400"
state: present
when: scripts is defined
- name: Check for git installation
ansible.builtin.apt:
name: git
state: present
when: scripts is defined
- name: Clone external scripts projects
ansible.builtin.git:
repo: "{{ item.url }}"
dest: "{{ base_scripts }}/{{ item.name }}"
version: "{{ item.version }}"
accept_newhostkey: "{{ item.accept_newhostkey | default(false) }}"
gpg_allowlist: >-
{{ (item.trusted_keys | default(scripts.trusted_keys) | default([]))
| map(attribute='id')
| list }}
verify_commit: >-
{{ true if
((item.trusted_keys | default(scripts.trusted_keys)) is defined
and (item.trusted_keys | default(scripts.trusted_keys)))
else false }}
key_file: "{{ base_scripts }}/.keys/id_ed25519"
loop: "{{ scripts.repos }}"
loop_control:
label: "{{ item.url }}"
when: scripts is defined
tags: scripts
- name: Synchronize scripts
ansible.posix.synchronize:
src: "{{ base_scripts }}/{{ item.0.name }}/{{ item.1.src }}"
dest: "{{ item.1.dest }}"
delegate_to: "{{ inventory_hostname }}"
loop: "{{ scripts.repos | default([]) | subelements('scripts') }}"
loop_control:
label: "{{ item.0.name }}: {{ item.1.src }}"
when: scripts is defined and scripts | length > 0
tags: scripts
- name: Deploy cron jobs
ansible.builtin.cron:
name: "{{ item.name }}"
job: "{{ item.job }}"
user: "{{ item.user | default('root') }}"
minute: "{{ item.minute | default('*') }}"
hour: "{{ item.hour | default('*') }}"
day: "{{ item.day | default('*') }}"
month: "{{ item.month | default('*') }}"
weekday: "{{ item.weekday | default('*') }}"
state: "{{ item.state | default('present') }}"
disabled: "{{ item.disabled | default(false) }}"
loop: "{{ cron }}"
when: cron is defined and cron | length > 0
- name: Install NTPsec - name: Install NTPsec
ansible.builtin.apt: ansible.builtin.apt:
@@ -47,7 +178,7 @@
- name: Generate locale - name: Generate locale
community.general.locale_gen: community.general.locale_gen:
name: "{{ locale_default }}" name: "{{ base_locale_default }}"
state: present state: present
notify: reconfigure_locales notify: reconfigure_locales
@@ -55,7 +186,7 @@
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: /etc/default/locale path: /etc/default/locale
regexp: "^LANG=" regexp: "^LANG="
line: "LANG={{ locale_default }}" line: "LANG={{ base_locale_default }}"
- name: Manage root authorized_keys - name: Manage root authorized_keys
ansible.builtin.template: ansible.builtin.template:
@@ -63,6 +194,7 @@
dest: /root/.ssh/authorized_keys dest: /root/.ssh/authorized_keys
mode: "400" mode: "400"
when: authorized_keys is defined when: authorized_keys is defined
tags: users
- name: Create system user groups - name: Create system user groups
ansible.builtin.group: ansible.builtin.group:
@@ -73,6 +205,7 @@
loop_control: loop_control:
label: "{{ item.key }}" label: "{{ item.key }}"
when: users is defined when: users is defined
tags: users
- name: Create system users - name: Create system users
ansible.builtin.user: ansible.builtin.user:
@@ -89,10 +222,12 @@
loop_control: loop_control:
label: "{{ item.key }}" label: "{{ item.key }}"
when: users is defined when: users is defined
tags: users
- name: Create Ansible's temporary remote directory for users - name: Create Ansible's temporary remote directory for users
ansible.builtin.file: ansible.builtin.file:
path: "{{ item.value.homedir | default('/home/' + item.key) }}/.ansible/tmp" path: >-
{{ item.value.homedir | default('/home/' + item.key) }}/.ansible/tmp
state: directory state: directory
mode: "700" mode: "700"
owner: "{{ item.key }}" owner: "{{ item.key }}"
@@ -103,6 +238,7 @@
when: when:
- users is defined - users is defined
- item.value.tmp | default(true) - item.value.tmp | default(true)
tags: users
- name: Set authorized_keys for system users - name: Set authorized_keys for system users
ansible.posix.authorized_key: ansible.posix.authorized_key:
@@ -113,6 +249,7 @@
loop_control: loop_control:
label: "{{ item.key }}" label: "{{ item.key }}"
when: users is defined and item.value.key is defined when: users is defined and item.value.key is defined
tags: users
- name: Manage filesystem mounts - name: Manage filesystem mounts
ansible.posix.mount: ansible.posix.mount:
+1 -1
View File
@@ -1,7 +1,7 @@
[global] [global]
workgroup = WORKGROUP workgroup = WORKGROUP
server string = Samba Server %v server string = Samba Server %v
netbios name = {{ ansible_hostname }} netbios name = {{ ansible_facts['hostname'] }}
security = user security = user
map to guest = bad user map to guest = bad user
dns proxy = no dns proxy = no
+12 -1
View File
@@ -1,11 +1,22 @@
# {{ ansible_managed }} # {{ ansible_managed }}
[Interface] # {{ ansible_hostname }} [Interface] # {{ ansible_facts['hostname'] }}
PrivateKey = {{ wgkey['content'] | b64decode | trim }} PrivateKey = {{ wgkey['content'] | b64decode | trim }}
Address = {{ wireguard.address }} Address = {{ wireguard.address }}
{% if wireguard.listenport is defined %} {% if wireguard.listenport is defined %}
ListenPort = {{ wireguard.listenport }} ListenPort = {{ wireguard.listenport }}
{% endif %} {% endif %}
{%- if wireguard.table is defined %}
Table = {{ wireguard.table }}
{% endif -%}
{%- if wireguard.postup is defined %}
PostUp = {{ wireguard.postup }}
{% endif -%}
{%- if wireguard.predown is defined %}
PreDown = {{ wireguard.predown }}
{% endif %}
{% for peer in wireguard.peers %} {% for peer in wireguard.peers %}
{% if peer.name is defined %} {% if peer.name is defined %}
+1 -1
View File
@@ -77,7 +77,7 @@
community.crypto.openssh_keypair: community.crypto.openssh_keypair:
path: "{{ docker_repos_keys }}/id_{{ docker_repos_keytype }}" path: "{{ docker_repos_keys }}/id_{{ docker_repos_keytype }}"
type: "{{ docker_repos_keytype }}" type: "{{ docker_repos_keytype }}"
comment: "{{ ansible_hostname }}-deploy-key" comment: "{{ ansible_facts['hostname'] }}-deploy-key"
mode: "400" mode: "400"
state: present state: present
when: docker_compose_deploy is defined when: docker_compose_deploy is defined
+8 -3
View File
@@ -1,6 +1,6 @@
# container settings # container settings
gitea_name: gitea gitea_name: gitea
gitea_sshport: "222" gitea_sshport: "2222"
gitea_webport: "3000" gitea_webport: "3000"
gitea_ssh: "127.0.0.1:{{ gitea_sshport }}" gitea_ssh: "127.0.0.1:{{ gitea_sshport }}"
gitea_web: "127.0.0.1:{{ gitea_webport }}" gitea_web: "127.0.0.1:{{ gitea_webport }}"
@@ -16,7 +16,12 @@ gitea_dbuser: "{{ gitea_name }}"
# proxy settings # proxy settings
gitea_proxy_limit: "1" gitea_proxy_limit: "1"
gitea_trusted_proxies: "172.16.0.0/12" gitea_trusted_proxies: "10.89.0.0/16"
# host # host
gitea_root: "{{ docker_compose_root }}/{{ gitea_name }}" gitea_root: "{{ podman_compose.git.root }}/{{ gitea_name }}"
gitea_logs: "{{ podman_log_root }}/{{ gitea_name }}"
gitea_data: /srv/gitea
gitea_se_level: "s0:c22,c222"
gitea_uid: 1000
gitea_oci_uid: "{{ podman_subuid_base['git'] | int + gitea_uid | int - 1 }}"
+9
View File
@@ -0,0 +1,9 @@
module gitea_ssh 1.0;
require {
type sshd_t;
type ssh_exec_t;
class file { getattr read open map execute execute_no_trans };
}
allow sshd_t ssh_exec_t:file { getattr read open map execute execute_no_trans };
+5 -5
View File
@@ -1,5 +1,5 @@
- name: Restart Gitea - name: Reload ssh
ansible.builtin.service: ansible.builtin.systemd_service:
name: "{{ docker_compose_service }}@{{ gitea_name }}" name: ssh
state: restarted state: reloaded
listen: restart_gitea listen: restart_ssh
+159 -22
View File
@@ -13,7 +13,7 @@
community.mysql.mysql_user: community.mysql.mysql_user:
name: "{{ gitea.DB_USER }}" name: "{{ gitea.DB_USER }}"
password: "{{ gitea.DB_PASSWD }}" password: "{{ gitea.DB_PASSWD }}"
host: '%' host: "%"
state: present state: present
priv: "{{ gitea.DB_NAME }}.*:ALL" priv: "{{ gitea.DB_NAME }}.*:ALL"
login_unix_socket: /var/run/mysqld/mysqld.sock login_unix_socket: /var/run/mysqld/mysqld.sock
@@ -21,35 +21,36 @@
- name: Create git's .ssh directory - name: Create git's .ssh directory
ansible.builtin.file: ansible.builtin.file:
path: /home/git/.ssh path: /home/git/.ssh
owner: git
group: git
mode: "700" mode: "700"
state: directory state: directory
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('ssh_home_t', omit) }}
- name: Generate git's SSH keys - name: Generate git's SSH keys
community.crypto.openssh_keypair: community.crypto.openssh_keypair:
path: /home/git/.ssh/id_rsa path: /home/git/.ssh/id_rsa
owner: git
group: git
mode: "600"
register: gitea_keypair
- name: Label git's SSH keys for sshd access
ansible.builtin.file:
path: "/home/git/.ssh/{{ item }}"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('ssh_home_t', omit) }}
loop:
- id_rsa
- id_rsa.pub
- name: Find git's public SSH key - name: Find git's public SSH key
ansible.builtin.slurp: ansible.builtin.slurp:
src: /home/git/.ssh/id_rsa.pub src: /home/git/.ssh/id_rsa.pub
register: git_rsapub register: gitea_rsapub
- name: Get stats on git's authorized_keys file
ansible.builtin.stat:
path: /home/git/.ssh/authorized_keys
register: git_authkeys
- name: Create git's authorized_keys file
ansible.builtin.file:
path: /home/git/.ssh/authorized_keys
mode: "600"
state: touch
when: not git_authkeys.stat.exists
- name: Add git's public SSH key to authorized_keys
ansible.builtin.lineinfile:
path: /home/git/.ssh/authorized_keys
regex: "^ssh-rsa"
line: "{{ git_rsapub['content'] | b64decode }}"
- name: Create Gitea host script for SSH - name: Create Gitea host script for SSH
ansible.builtin.template: ansible.builtin.template:
@@ -57,11 +58,147 @@
dest: /usr/local/bin/gitea dest: /usr/local/bin/gitea
mode: "755" mode: "755"
- name: Install Gitea SSH SELinux policy source
ansible.builtin.copy:
src: gitea_ssh.te
dest: "{{ podman_selinux_dir }}/gitea_ssh.te"
owner: root
group: root
mode: "0644"
register: gitea_selinux_src
when: selinux is defined and selinux is not false
- name: Clear stale Gitea SSH SELinux artifacts
ansible.builtin.file:
path: "{{ podman_selinux_dir }}/gitea_ssh.{{ item }}"
state: absent
loop: [mod, pp]
when:
- selinux is defined and selinux is not false
- gitea_selinux_src is changed
- name: Compile Gitea SSH SELinux policy module
ansible.builtin.command:
cmd: >-
checkmodule -M -m -o {{ podman_selinux_dir }}/gitea_ssh.mod
{{ podman_selinux_dir }}/gitea_ssh.te
creates: "{{ podman_selinux_dir }}/gitea_ssh.mod"
when: selinux is defined and selinux is not false
- name: Package Gitea SSH SELinux policy module
ansible.builtin.command:
cmd: >-
semodule_package -o {{ podman_selinux_dir }}/gitea_ssh.pp
-m {{ podman_selinux_dir }}/gitea_ssh.mod
creates: "{{ podman_selinux_dir }}/gitea_ssh.pp"
when: selinux is defined and selinux is not false
- name: List loaded SELinux policy modules for Gitea
ansible.builtin.command:
cmd: semodule -l
register: gitea_semodule_list
changed_when: false
when: selinux is defined and selinux is not false
- name: Load Gitea SSH SELinux policy module
ansible.builtin.command:
cmd: semodule -i {{ podman_selinux_dir }}/gitea_ssh.pp
register: gitea_semodule
changed_when: gitea_semodule.rc == 0
when:
- selinux is defined and selinux is not false
- gitea_selinux_src is changed or "gitea_ssh" not in gitea_semodule_list.stdout_lines
- name: Configure sshd for Gitea AuthorizedKeysCommand
ansible.builtin.template:
src: gitea_sshd.conf.j2
dest: /etc/ssh/sshd_config.d/gitea.conf
owner: root
group: root
mode: "0644"
validate: /usr/sbin/sshd -t -f %s
notify: restart_ssh
- name: Set SELinux context on Gitea's data directory
community.general.sefcontext:
target: "{{ gitea_data }}(/.*)?"
setype: container_file_t
selevel: "{{ gitea_se_level }}"
state: present
when: selinux is defined and selinux is not false
- name: Create Gitea's data directory
ansible.builtin.file:
path: "{{ gitea_data }}"
state: directory
owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "0750"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ gitea_se_level }}"
- name: Create Gitea's container-side SSH directories
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "{{ item.mode }}"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ gitea_se_level }}"
loop:
- { path: "{{ gitea_data }}/git", mode: "0755" }
- { path: "{{ gitea_data }}/git/.ssh", mode: "0700" }
- name: Authorise git's public SSH key inside the container
ansible.builtin.copy:
content: "{{ gitea_rsapub['content'] | b64decode }}"
dest: "{{ gitea_data }}/git/.ssh/authorized_keys"
owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "0600"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('container_file_t', omit) }}
selevel: "{{ gitea_se_level }}"
- name: Set SELinux context on Gitea's logging directory
community.general.sefcontext:
target: "{{ gitea_logs }}(/.*)?"
setype: oci_log_t
selevel: "{{ gitea_se_level }}"
state: present
when: selinux is defined and selinux is not false
- name: Create Gitea's logging directory - name: Create Gitea's logging directory
ansible.builtin.file: ansible.builtin.file:
name: /var/log/gitea name: "{{ gitea_logs }}"
state: directory state: directory
mode: "755" owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "0755"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('oci_log_t', omit) }}
selevel: "{{ gitea_se_level }}"
- name: Create Gitea's log file for Fail2ban
ansible.builtin.file:
path: /var/log/oci/gitea/gitea.log
state: touch
owner: "{{ gitea_oci_uid }}"
group: "{{ gitea_oci_uid }}"
mode: "0640"
modification_time: preserve
access_time: preserve
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('oci_log_t', omit) }}
selevel: "{{ gitea_se_level }}"
- name: Install Gitea's Fail2ban filter - name: Install Gitea's Fail2ban filter
ansible.builtin.template: ansible.builtin.template:
-19
View File
@@ -1,19 +0,0 @@
# {{ ansible_managed }}
gitea_version={{ gitea_version }}
gitea_name={{ gitea_name }}
gitea_domain={{ gitea_domain }}
gitea_rooturl={{ gitea_rooturl }}
gitea_web={{ gitea_web }}
gitea_ssh={{ gitea_ssh }}
gitea_dbtype={{ gitea_dbtype }}
gitea_dbhost={{ gitea_dbhost }}
gitea_dbname={{ gitea_dbname }}
gitea_dbuser={{ gitea_dbuser }}
gitea_dbpass={{ gitea_dbpass }}
gitea_proxy_limit={{ gitea_proxy_limit }}
gitea_trusted_proxies={{ gitea_trusted_proxies }}
{% if not gitea_signup %}
gitea_disable_registration=true
{% else %}
gitea_disable_registration=false
{% endif %}
@@ -1,36 +0,0 @@
version: '3.7'
services:
gitea:
image: "gitea/gitea:${gitea_version}"
container_name: "${gitea_name}"
ports:
- "${gitea_ssh}:22"
- "${gitea_web}:3000"
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
- USER_UID={{ getent_passwd.git[1] }}
- USER_GID={{ getent_group.git[1] }}
- GITEA__log__MODE=file
- GITEA__server__ROOT_URL=${gitea_rooturl}
- GITEA__server__DOMAIN=${gitea_domain}
- GITEA__server__SSH_DOMAIN=${gitea_domain}
- GITEA__database__DB_TYPE=${gitea_dbtype}
- GITEA__database__HOST=${gitea_dbhost}
- GITEA__database__NAME=${gitea_dbname}
- GITEA__database__USER=${gitea_dbuser}
- GITEA__database__PASSWD=${gitea_dbpass}
- GITEA__security__INSTALL_LOCK=true
- GITEA__security__REVERSE_PROXY_LIMIT=${gitea_proxy_limit}
- GITEA__security__REVERSE_PROXY_TRUSTED_PROXIES=${gitea_trusted_proxies}
- GITEA__service__DISABLE_REGISTRATION=${gitea_disable_registration}
volumes:
- {{ gitea_volume }}:/data
- /home/git/.ssh:/data/git/.ssh
- /var/log/gitea:/data/gitea/log
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
volumes:
{{ gitea_volume }}:
+1 -10
View File
@@ -2,17 +2,8 @@
[gitea] [gitea]
enabled = true enabled = true
filter = gitea filter = gitea
logpath = /var/log/gitea/gitea.log logpath = {{ gitea_logs }}/gitea.log
maxretry = 10 maxretry = 10
findtime = 3600 findtime = 3600
bantime = 900 bantime = 900
action = iptables-allports action = iptables-allports
[gitea-docker]
enabled = true
filter = gitea
logpath = /var/log/gitea/gitea.log
maxretry = 10
findtime = 3600
bantime = 900
action = iptables-allports[chain="FORWARD"]
+3
View File
@@ -0,0 +1,3 @@
# {{ ansible_managed }}
AuthorizedKeysCommand /usr/local/bin/gitea keys -e git -u %u -t %t -k %k
AuthorizedKeysCommandUser git
+4 -31
View File
@@ -1,40 +1,13 @@
- name: Install QEMU/KVM - name: Install QEMU/KVM and libvirt
ansible.builtin.apt: ansible.builtin.apt:
name: qemu-kvm name: ["qemu-system", "libvirt-clients", "libvirt-daemon-system"]
state: present install_recommends: false
- name: Install Libvirt
ansible.builtin.apt:
name: ["libvirt-clients", "libvirt-daemon-system"]
state: present state: present
- name: Add users to libvirt group - name: Add users to libvirt group
ansible.builtin.user: ansible.builtin.user:
name: "{{ item }}" name: "{{ item }}"
groups: libvirt groups: libvirt
append: yes append: true
with_items: "{{ libvirt_users }}" with_items: "{{ libvirt_users }}"
when: libvirt_users is defined when: libvirt_users is defined
- name: Check for NODOWNLOAD file
ansible.builtin.stat:
path: /var/lib/libvirt/images/NODOWNLOAD
register: NODOWNLOAD
- name: Download GNU/Linux ISOs
ansible.builtin.get_url:
url: "{{ item.url }}"
dest: /var/lib/libvirt/images
checksum: "{{ item.hash }}"
owner: libvirt-qemu
group: libvirt-qemu
loop: "{{ libvirt_isos }}"
register: download_isos
when: libvirt_isos is defined and NODOWNLOAD.stat.exists == false
# Prevent downloaded ISOs from being rehashed every run
- name: Create NODOWNLOAD file
ansible.builtin.file:
path: /var/lib/libvirt/images/NODOWNLOAD
state: touch
when: download_isos.changed
+13 -3
View File
@@ -16,12 +16,22 @@
regex: "^bind-address" regex: "^bind-address"
line: "bind-address = {{ ansible_facts.docker0.ipv4.address }}" line: "bind-address = {{ ansible_facts.docker0.ipv4.address }}"
notify: restart_mariadb notify: restart_mariadb
when: ansible_facts.docker0 is defined when: ansible_facts['docker0'] is defined
- name: Change the bind-address for rootless containers
ansible.builtin.lineinfile:
path: /etc/mysql/mariadb.conf.d/50-server.cnf
regexp: "^bind-address"
line: "bind-address = 0.0.0.0"
notify: restart_mariadb
when:
- ansible_facts['docker0'] is not defined
- podman_compose is defined
- name: Flush handlers to ensure MariaDB restarts immediately - name: Flush handlers to ensure MariaDB restarts immediately
ansible.builtin.meta: flush_handlers ansible.builtin.meta: flush_handlers
tags: restart_mariadb tags: restart_mariadb
when: ansible_facts.docker0 is defined when: ansible_facts['docker0'] is defined or podman_compose is defined
- name: Allow database connections from Docker - name: Allow database connections from Docker
community.general.ufw: community.general.ufw:
@@ -29,4 +39,4 @@
port: "3306" port: "3306"
proto: tcp proto: tcp
src: "{{ item }}" src: "{{ item }}"
loop: "{{ mariadb_trust | default(['172.16.0.0/12']) }}" loop: "{{ mariadb_trust | default(['169.254.0.0/16']) }}"
+4 -2
View File
@@ -1,4 +1,6 @@
# Default configuration for podman role # Default configuration for podman role
podman_repos_keytype: ed25519 podman_log_root: /var/log/oci
podman_ssh_key_path: "{{ ansible_user_dir }}/.ssh"
podman_nodocker: false podman_nodocker: false
podman_repos_keytype: ed25519
podman_selinux_dir: /usr/share/selinux
podman_ssh_key_path: "{{ ansible_user_dir }}/.ssh"
+19
View File
@@ -0,0 +1,19 @@
module oci_log 1.0;
require {
type container_t;
type fail2ban_t;
attribute logfile;
attribute file_type;
attribute non_security_file_type;
class dir { add_name search watch write };
class file { append create getattr open watch };
}
type oci_log_t;
typeattribute oci_log_t file_type, non_security_file_type, logfile;
allow container_t oci_log_t:dir { add_name search write };
allow container_t oci_log_t:file { append create getattr open };
allow fail2ban_t oci_log_t:dir watch;
allow fail2ban_t oci_log_t:file watch;
+19 -5
View File
@@ -3,6 +3,7 @@
database: passwd database: passwd
key: "{{ podman_user }}" key: "{{ podman_user }}"
register: podman_user_info register: podman_user_info
tags: podman_compose
- name: Set user-specific variables - name: Set user-specific variables
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -11,6 +12,7 @@
podman_homedir: "{{ podman_user_info.ansible_facts.getent_passwd[podman_user][4] }}" podman_homedir: "{{ podman_user_info.ansible_facts.getent_passwd[podman_user][4] }}"
podman_project: "{{ podman_compose_config.compose }}" podman_project: "{{ podman_compose_config.compose }}"
podman_repos: "{{ podman_compose_config.root }}/.compose_repos" podman_repos: "{{ podman_compose_config.root }}/.compose_repos"
tags: podman_compose
- name: Create docker compose (podman) root directory for user - name: Create docker compose (podman) root directory for user
ansible.builtin.file: ansible.builtin.file:
@@ -51,6 +53,7 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Create .ssh directory for podman compose user - name: Create .ssh directory for podman compose user
ansible.builtin.file: ansible.builtin.file:
@@ -62,17 +65,19 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Generate OpenSSH deploy keys for docker compose (podman) clones - name: Generate OpenSSH deploy keys for docker compose (podman) clones
community.crypto.openssh_keypair: community.crypto.openssh_keypair:
path: "{{ podman_ssh_key_path }}/podman-id_{{ podman_repos_keytype }}" path: "{{ podman_homedir }}/.ssh/podman-id_{{ podman_repos_keytype }}"
type: "{{ podman_repos_keytype }}" type: "{{ podman_repos_keytype }}"
comment: "{{ ansible_hostname }}-{{ podman_user }}-deploy-key" comment: "{{ ansible_facts['hostname'] }}-{{ podman_user }}-deploy-key"
owner: "{{ podman_user }}" owner: "{{ podman_user }}"
group: "{{ podman_user }}" group: "{{ podman_user }}"
mode: "0600" mode: "0600"
state: present state: present
when: podman_project is defined when: podman_project is defined
tags: podman_compose
- name: Import trusted GPG keys for docker compose (podman) projects - name: Import trusted GPG keys for docker compose (podman) projects
ansible.builtin.command: ansible.builtin.command:
@@ -85,6 +90,7 @@
label: "{{ key.id }}" label: "{{ key.id }}"
changed_when: false changed_when: false
when: podman_compose_config.trusted_keys is defined when: podman_compose_config.trusted_keys is defined
tags: podman_compose
- name: Clone external docker compose (podman) projects - name: Clone external docker compose (podman) projects
ansible.builtin.git: ansible.builtin.git:
@@ -105,7 +111,7 @@
) )
else false else false
}} }}
key_file: "{{ podman_ssh_key_path }}/podman-id_{{ podman_repos_keytype }}" key_file: "{{ podman_homedir }}/.ssh/podman-id_{{ podman_repos_keytype }}"
become: true become: true
become_user: "{{ podman_user }}" become_user: "{{ podman_user }}"
loop: "{{ podman_project }}" loop: "{{ podman_project }}"
@@ -115,6 +121,7 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Create directories for docker compose (podman) projects - name: Create directories for docker compose (podman) projects
ansible.builtin.file: ansible.builtin.file:
@@ -130,6 +137,7 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Synchronize docker-compose.yml - name: Synchronize docker-compose.yml
ansible.posix.synchronize: ansible.posix.synchronize:
@@ -152,6 +160,7 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Update list of compose projects updated - name: Update list of compose projects updated
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -161,7 +170,8 @@
loop: "{{ podman_compose_update.results }}" loop: "{{ podman_compose_update.results }}"
loop_control: loop_control:
label: "{{ podman_user }}/{{ item.project.name }}" label: "{{ podman_user }}/{{ item.project.name }}"
when: (podman_compose_update.results | default([]) | length) > 0 when: item.changed | default(false)
tags: podman_compose
- name: Fix ownership of synchronized compose files - name: Fix ownership of synchronized compose files
ansible.builtin.file: ansible.builtin.file:
@@ -176,6 +186,7 @@
when: when:
- podman_project is defined - podman_project is defined
- podman_project | length > 0 - podman_project | length > 0
tags: podman_compose
- name: Set environment variables for docker compose (podman) projects - name: Set environment variables for docker compose (podman) projects
ansible.builtin.template: ansible.builtin.template:
@@ -194,6 +205,7 @@
loop_var: project loop_var: project
label: "{{ project.name }}" label: "{{ project.name }}"
when: podman_project is defined and project.env is defined when: podman_project is defined and project.env is defined
tags: podman_compose
- name: Update list of compose projects who updated their .env - name: Update list of compose projects who updated their .env
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -208,7 +220,8 @@
loop: "{{ podman_compose_env_update.results }}" loop: "{{ podman_compose_env_update.results }}"
loop_control: loop_control:
label: "{{ podman_user }}/{{ item.project.name }}" label: "{{ podman_user }}/{{ item.project.name }}"
when: (podman_compose_env_update.results | default([]) | length) > 0 when: item.changed | default(false)
tags: podman_compose
- name: Update list of enabled compose projects - name: Update list of enabled compose projects
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -217,3 +230,4 @@
+ [{'user': podman_user, 'service': project.name}] }} + [{'user': podman_user, 'service': project.name}] }}
when: project.enabled | default(false) when: project.enabled | default(false)
notify: podman_compose_enable notify: podman_compose_enable
tags: podman_compose
+20
View File
@@ -0,0 +1,20 @@
- name: "Get UID for {{ podman_user.key }}"
ansible.builtin.getent:
database: passwd
key: "{{ podman_user.key }}"
- name: Login to private Podman registry via Docker CLI
community.docker.docker_login:
registry_url: "{{ registry.key }}"
username: "{{ registry.value.username }}"
password: "{{ registry.value.password }}"
docker_host: "unix:///run/user/{{ podman_uid }}/podman/podman.sock"
vars:
podman_uid: "{{ ansible_facts.getent_passwd[podman_user.key][1] }}"
loop: "{{ podman_user.value | dict2items }}"
loop_control:
loop_var: registry
label: "{{ podman_user.key }} => {{ registry.key }}"
become: true
become_user: "{{ podman_user.key }}"
no_log: true
+220 -13
View File
@@ -3,6 +3,91 @@
name: ["podman", "docker-cli", "docker-compose"] name: ["podman", "docker-cli", "docker-compose"]
state: present state: present
- name: Allow rootless containers to use capabilities in their user namespace
ansible.posix.seboolean:
name: container_use_userns_all_caps
state: true
persistent: true
when: selinux is defined and selinux is not false
- name: Create SELinux policy build directory
ansible.builtin.file:
path: "{{ podman_selinux_dir }}"
state: directory
owner: root
group: root
mode: "0755"
when: selinux is defined and selinux is not false
- name: Install container log SELinux policy source
ansible.builtin.copy:
src: oci_log.te
dest: "{{ podman_selinux_dir }}/oci_log.te"
owner: root
group: root
mode: "0644"
register: podman_selinux_src
when: selinux is defined and selinux is not false
- name: Clear stale container log SELinux artifacts
ansible.builtin.file:
path: "{{ podman_selinux_dir }}/oci_log.{{ item }}"
state: absent
loop: [mod, pp]
when:
- selinux is defined and selinux is not false
- podman_selinux_src is changed
- name: Compile container log SELinux policy module
ansible.builtin.command:
cmd: >-
checkmodule -M -m -o {{ podman_selinux_dir }}/oci_log.mod
{{ podman_selinux_dir }}/oci_log.te
creates: "{{ podman_selinux_dir }}/oci_log.mod"
when: selinux is defined and selinux is not false
- name: Package container log SELinux policy module
ansible.builtin.command:
cmd: >-
semodule_package -o {{ podman_selinux_dir }}/oci_log.pp
-m {{ podman_selinux_dir }}/oci_log.mod
creates: "{{ podman_selinux_dir }}/oci_log.pp"
when: selinux is defined and selinux is not false
- name: List loaded SELinux policy modules
ansible.builtin.command:
cmd: semodule -l
register: podman_semodule_list
changed_when: false
when: selinux is defined and selinux is not false
- name: Load container log SELinux policy module
ansible.builtin.command:
cmd: semodule -i {{ podman_selinux_dir }}/oci_log.pp
register: podman_semodule
changed_when: podman_semodule.rc == 0
when:
- selinux is defined and selinux is not false
- podman_selinux_src is changed or "oci_log" not in podman_semodule_list.stdout_lines
- name: Set SELinux context on container log directory
community.general.sefcontext:
target: "{{ podman_log_root }}(/.*)?"
setype: oci_log_t
state: present
when: selinux is defined and selinux is not false
- name: Create container log directory
ansible.builtin.file:
path: "{{ podman_log_root }}"
state: directory
owner: root
group: root
mode: "0755"
setype: >-
{{ (selinux is defined and selinux is not false)
| ternary('oci_log_t', omit) }}
- name: Install GnuPG tools and trusted CA bundle - name: Install GnuPG tools and trusted CA bundle
ansible.builtin.apt: ansible.builtin.apt:
name: ["gnupg", "ca-certificates"] name: ["gnupg", "ca-certificates"]
@@ -19,13 +104,19 @@
label: "{{ item }}" label: "{{ item }}"
when: podman_compose is defined when: podman_compose is defined
- name: Set subuid base facts for podman users
ansible.builtin.set_fact:
podman_subuid_base: "{{ podman_subuid_base | default({}) | combine({
item.item: 100000 + ((item.ansible_facts.getent_passwd[item.item][1]
| int - 1000) * 65536) }) }}"
loop: "{{ user_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Configure /etc/subuid for rootless users - name: Configure /etc/subuid for rootless users
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "/etc/subuid" path: "/etc/subuid"
line: line: "{{ item.item }}:{{ podman_subuid_base[item.item] }}:65536"
"{{ item.item }}:{{ 100000 +
((item.ansible_facts.getent_passwd[item.item][1] | int - 1000) * 65536)
}}:65536"
regexp: "^{{ item.item }}:" regexp: "^{{ item.item }}:"
create: true create: true
backup: true backup: true
@@ -37,10 +128,7 @@
- name: Configure /etc/subgid for rootless users - name: Configure /etc/subgid for rootless users
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "/etc/subgid" path: "/etc/subgid"
line: line: "{{ item.item }}:{{ podman_subuid_base[item.item] }}:65536"
"{{ item.item }}:{{ 100000 +
((item.ansible_facts.getent_passwd[item.item][1] | int - 1000) * 65536)
}}:65536"
regexp: "^{{ item.item }}:" regexp: "^{{ item.item }}:"
create: true create: true
backup: true backup: true
@@ -49,10 +137,39 @@
loop_control: loop_control:
label: "{{ item.item }}" label: "{{ item.item }}"
- name: Enable lingering for podman compose user - name: Ensure systemd linger directory exists
ansible.builtin.command: ansible.builtin.file:
cmd: "loginctl enable-linger {{ item.item }}" path: /var/lib/systemd/linger
changed_when: false state: directory
owner: root
group: root
mode: "0755"
- name: Enable lingering for podman compose users
ansible.builtin.file:
path: "/var/lib/systemd/linger/{{ item.item }}"
state: touch
owner: root
group: root
mode: "0644"
access_time: preserve
modification_time: preserve
loop: "{{ user_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Start user manager for podman compose users
ansible.builtin.systemd_service:
name: "user@{{ item.ansible_facts.getent_passwd[item.item][1] }}.service"
state: started
loop: "{{ user_info.results }}"
loop_control:
label: "{{ item.item }}"
- name: Wait for user runtime directory
ansible.builtin.wait_for:
path: "/run/user/{{ item.ansible_facts.getent_passwd[item.item][1] }}/bus"
timeout: 30
loop: "{{ user_info.results }}" loop: "{{ user_info.results }}"
loop_control: loop_control:
label: "{{ item.item }}" label: "{{ item.item }}"
@@ -97,7 +214,7 @@
dest: /etc/profile.d/docker-host.sh dest: /etc/profile.d/docker-host.sh
owner: root owner: root
group: root group: root
mode: '0755' mode: "0755"
- name: Install git for repository cloning - name: Install git for repository cloning
ansible.builtin.apt: ansible.builtin.apt:
@@ -105,6 +222,95 @@
state: present state: present
when: podman_compose is defined when: podman_compose is defined
- name: Login to private Podman registries with Docker CLI for each user
ansible.builtin.include_tasks: login.yml
loop: "{{ podman_login | dict2items }}"
loop_control:
loop_var: podman_user
when: podman_login is defined
- name: Stat rootless Podman directory
ansible.builtin.stat:
path: "/home/{{ compose_user.key }}/.local/share/containers"
loop: "{{ podman_compose | dict2items }}"
loop_control:
loop_var: compose_user
label: "{{ compose_user.key }}"
register: podman_user_containers_stat
when:
- podman_compose is defined
- selinux is defined
- selinux is not false
- name: Create rootless Podman directory
ansible.builtin.file:
path: "/home/{{ item.compose_user.key }}/.local/share/containers"
state: directory
owner: "{{ item.compose_user.key }}"
group: "{{ item.compose_user.key }}"
mode: "700"
loop: "{{ podman_user_containers_stat.results }}"
loop_control:
label: "{{ item.compose_user.key }}"
when:
- podman_compose is defined
- selinux is defined
- selinux is not false
- not item.stat.exists
- name: Label rootless Podman directory
ansible.builtin.command: >-
restorecon -Rv /home/{{ item.compose_user.key }}/.local/share/containers
loop: "{{ podman_user_containers_stat.results }}"
loop_control:
label: "/home/{{ item.compose_user.key }}/.local/share/containers"
changed_when: true
when:
- podman_compose is defined
- selinux is defined
- selinux is not false
- not item.stat.exists
- name: Stat Podman label directories
ansible.builtin.stat:
path: "{{ item.path }}"
loop: "{{ podman_label }}"
register: podman_label_stat
loop_control:
label: "{{ item.path }}"
when:
- podman_label is defined
- selinux is defined
- selinux is not false
- name: Create Podman label directories
ansible.builtin.file:
path: "{{ item.item.path }}"
owner: "{{ item.item.owner | default(omit) }}"
group: "{{ item.item.group | default(omit) }}"
mode: "{{ item.item.mode | default('700') }}"
state: directory
loop: "{{ podman_label_stat.results }}"
loop_control:
label: "{{ item.item.path }}"
when:
- podman_label is defined
- selinux is defined
- selinux is not false
- not item.stat.exists
- name: Set labels on Podman label directories
ansible.builtin.command: "chcon {{ item.item.label }} {{ item.item.path }}"
loop: "{{ podman_label_stat.results }}"
changed_when: true
loop_control:
label: "{{ item.item.path }} => {{ item.item.label }}"
when:
- podman_label is defined
- selinux is defined
- selinux is not false
- not item.stat.exists
- name: Deploy Podman compose projects for each user - name: Deploy Podman compose projects for each user
ansible.builtin.include_tasks: deploy.yml ansible.builtin.include_tasks: deploy.yml
vars: vars:
@@ -114,3 +320,4 @@
loop_control: loop_control:
loop_var: compose_user loop_var: compose_user
when: podman_compose is defined when: podman_compose is defined
tags: podman_compose
+1 -1
View File
@@ -1 +1 @@
cached_dhparams_pem: /vagrant/scratch/dhparams.pem proxy_cached_dhparams_pem: /vagrant/scratch/dhparams.pem
-10
View File
@@ -1,13 +1,3 @@
- name: Enable nginx sites configuration
ansible.builtin.file:
src: "/etc/nginx/sites-available/{{ item.item.domain }}.conf"
dest: "/etc/nginx/sites-enabled/{{ item.item.domain }}.conf"
state: link
mode: "400"
loop: "{{ nginx_sites.results }}"
when: item.changed
listen: reload_nginx
- name: Reload nginx - name: Reload nginx
ansible.builtin.service: ansible.builtin.service:
name: nginx name: nginx
+47 -13
View File
@@ -10,18 +10,17 @@
state: started state: started
enabled: true enabled: true
- name: Check for cached dhparams.pem file - name: Check if environment is vagrant
ansible.builtin.stat: ansible.builtin.stat:
path: "{{ cached_dhparams_pem }}" path: /home/vagrant
register: dhparams_file register: vagrant_home
- name: Copy cached dhparams.pem to /etc/ssl/ - name: Download Mozilla's standard DH params (dev only)
ansible.builtin.copy: ansible.builtin.get_url:
src: "{{ cached_dhparams_pem }}" url: https://ssl-config.mozilla.org/ffdhe4096.txt
dest: /etc/ssl/dhparams.pem dest: /etc/ssl/dhparams.pem
mode: "600" mode: "600"
remote_src: true when: vagrant_home.stat.exists
when: dhparams_file.stat.exists
- name: Generate DH Parameters - name: Generate DH Parameters
community.crypto.openssl_dhparam: community.crypto.openssl_dhparam:
@@ -41,8 +40,19 @@
dest: "/etc/nginx/sites-available/{{ item.domain }}.conf" dest: "/etc/nginx/sites-available/{{ item.domain }}.conf"
mode: "400" mode: "400"
loop: "{{ proxy.servers }}" loop: "{{ proxy.servers }}"
loop_control:
label: "{{ item.domain }}"
notify: reload_nginx
- name: Enable nginx sites configuration
ansible.builtin.file:
src: "/etc/nginx/sites-available/{{ item.domain }}.conf"
dest: "/etc/nginx/sites-enabled/{{ item.domain }}.conf"
state: "{{ item.enabled | default(true) | ternary('link', 'absent') }}"
loop: "{{ proxy.servers }}"
loop_control:
label: "{{ item.domain }}"
notify: reload_nginx notify: reload_nginx
register: nginx_sites
- name: Generate self-signed certificate - name: Generate self-signed certificate
ansible.builtin.command: ansible.builtin.command:
@@ -63,14 +73,14 @@
- name: Grab Cloudflare API token for configuration - name: Grab Cloudflare API token for configuration
ansible.builtin.slurp: ansible.builtin.slurp:
src: /root/.cloudflare-api src: /etc/letsencrypt/cloudflare-api.key
register: cfapi register: cfapi
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
- name: Install Cloudflare API token - name: Install Cloudflare API token
ansible.builtin.template: ansible.builtin.template:
src: cloudflare.ini.j2 src: cloudflare.ini.j2
dest: /root/.cloudflare.ini dest: /etc/letsencrypt/cloudflare.ini
mode: "400" mode: "400"
diff: false diff: false
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
@@ -89,22 +99,46 @@
mode: "0755" mode: "0755"
when: proxy.production is defined and proxy.production when: proxy.production is defined and proxy.production
- name: Enable SELinux bool certbot_acmesh to allow sh access for DNS-01
ansible.posix.seboolean:
name: certbot_acmesh
state: true
persistent: true
when:
- selinux is defined
- selinux is not false
- proxy is defined
- proxy.production is defined
- proxy.production
- proxy.dns_cloudflare is defined
- name: Run Cloudflare DNS-01 challenges on wildcard domains - name: Run Cloudflare DNS-01 challenges on wildcard domains
ansible.builtin.shell: '/usr/bin/certbot certonly \ ansible.builtin.shell: '/usr/bin/certbot certonly \
--non-interactive \ --non-interactive \
--agree-tos \ --agree-tos \
--email "{{ proxy.dns_cloudflare.email }}" \ --email "{{ proxy.dns_cloudflare.email }}" \
--dns-cloudflare \ --dns-cloudflare \
--dns-cloudflare-credentials /root/.cloudflare.ini \ --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini \
-d "*.{{ item }}" \ -d "*.{{ item }}" \
-d "{{ item }}" \ -d "{{ item }}" \
{{ proxy.dns_cloudflare.opts | default("") }}' {{ proxy.dns_cloudflare.opts | default("") }}
< /dev/null'
args: args:
creates: "/etc/letsencrypt/live/{{ item }}/fullchain.pem" creates: "/etc/letsencrypt/live/{{ item }}/fullchain.pem"
loop: "{{ proxy.dns_cloudflare.wildcard_domains }}" loop: "{{ proxy.dns_cloudflare.wildcard_domains }}"
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
notify: reload_nginx notify: reload_nginx
- name: Enable SELinux bool httpd_can_network_connect to give nginx networking
ansible.posix.seboolean:
name: httpd_can_network_connect
state: true
persistent: true
when:
- selinux is defined
- selinux is not false
- proxy is defined
- name: Add HTTP and HTTPS firewall rule - name: Add HTTP and HTTPS firewall rule
community.general.ufw: community.general.ufw:
rule: allow rule: allow
@@ -1,13 +1,17 @@
server { server {
listen 80; listen 80;
{% if proxy.ipv6 is defined and proxy.ipv6 %}
listen [::]:80; listen [::]:80;
{% endif %}
server_name {{ item.domain }}; server_name {{ item.domain }};
return 301 https://{{ item.domain }}$request_uri; return 301 https://{{ item.domain }}$request_uri;
} }
server { server {
listen 443 ssl http2; listen 443 ssl http2;
{% if proxy.ipv6 is defined and proxy.ipv6 %}
listen [::]:443 ssl http2; listen [::]:443 ssl http2;
{% endif %}
server_name {{ item.domain }}; server_name {{ item.domain }};
access_log /var/log/nginx/{{ item.domain }}.log main; access_log /var/log/nginx/{{ item.domain }}.log main;
{% if proxy.production is defined and proxy.production and proxy.dns_cloudflare.wildcard_domains is defined and item.tls.cert is not defined %} {% if proxy.production is defined and proxy.production and proxy.dns_cloudflare.wildcard_domains is defined and item.tls.cert is not defined %}
+1
View File
@@ -0,0 +1 @@
zrepl_pkg_hold: true
+40
View File
@@ -0,0 +1,40 @@
- name: Download zrepl APT signing key
ansible.builtin.get_url:
url: https://zrepl.cschwarz.com/apt/apt-key.asc
dest: /tmp/zrepl-apt-key.asc
mode: "600"
force: true
- name: Get fingerprint of downloaded key
ansible.builtin.shell: |
set -euo pipefail
gpg --with-colons --import-options show-only \
--import /tmp/zrepl-apt-key.asc | awk -F: '$1=="fpr"{print $10; exit}'
args:
executable: /bin/bash
changed_when: false
register: gpg_key_info
- name: Verify key fingerprint matches expected value
ansible.builtin.assert:
that: gpg_key_info.stdout == expected_fingerprint
vars:
expected_fingerprint: "E101418FD3D6FBCB9D65A62D708699FC5F2EBF16"
- name: Dearmor zrepl key into APT keyring
ansible.builtin.command:
cmd: >-
gpg --dearmor --yes --output /usr/share/keyrings/zrepl-archive-keyring.gpg
/tmp/zrepl-apt-key.asc
args:
creates: /usr/share/keyrings/zrepl-archive-keyring.gpg
- name: Add zrepl apt repository
ansible.builtin.apt_repository:
repo: "deb [signed-by={{ zrepl_keyring_path }}] {{ zrepl_url }} {{ zrepl_suite }} main"
filename: zrepl
state: present
vars:
zrepl_keyring_path: /usr/share/keyrings/zrepl-archive-keyring.gpg
zrepl_url: "https://zrepl.cschwarz.com/apt/debian"
zrepl_suite: "{{ ansible_distribution_release }}"
+24
View File
@@ -0,0 +1,24 @@
- name: Install GnuPG
ansible.builtin.apt:
name: gnupg
state: present
update_cache: true
- name: Check if zrepl repo exists
ansible.builtin.stat:
path: /etc/apt/sources.list.d/zrepl.list
register: zrepl_repo_file
- name: Install zrepl repo
ansible.builtin.include_tasks: install.yml
when: not zrepl_repo_file.stat.exists
- name: Install zrepl
ansible.builtin.apt:
name: zrepl
state: present
- name: Set zrepl package hold state
ansible.builtin.dpkg_selections:
name: zrepl
selection: "{{ 'hold' if zrepl_pkg_hold else 'install' }}"