diff --git a/playbook.yml b/playbook.yml index 1473c80..04d5a0e 100644 --- a/playbook.yml +++ b/playbook.yml @@ -61,6 +61,13 @@ tasks: - name: Update include_tasks: tasks/install_docker_debian.yml +- name: Aurbis access to /opt + hosts: all + become: true + remote_user: nerevar + tasks: + - import_tasks: tasks/aurbis.yml + tags: aurbis - name: Add utility scripts hosts: all become: true @@ -110,14 +117,10 @@ package: name: [rsync, curl, sqlite3] state: present - - name: Normalise /opt app ownership to root:aurbis (top dir only, not recursive) - file: - path: "/opt/{{ item }}" - state: directory - owner: root - group: aurbis - mode: "0775" - loop: [nextcloud, hdwiki, gitea, authentik, drone, "hoekveen.net"] + - import_tasks: tasks/aurbis_tree.yml + vars: + tree_path: /opt/hoekveen.net + tags: aurbis - import_tasks: tasks/swapfile.yml tags: swap - import_tasks: tasks/nextcloud.yml diff --git a/tasks/aurbis.yml b/tasks/aurbis.yml new file mode 100644 index 0000000..1e11797 --- /dev/null +++ b/tasks/aurbis.yml @@ -0,0 +1,41 @@ +# Service data below the top level stays with whatever uid its container runs as. +- name: Let aurbis create services in /opt + file: + path: /opt + state: directory + owner: root + group: aurbis + mode: "02775" +- name: Give aurbis every /opt service directory + ansible.builtin.command: + argv: [find, /opt, -mindepth, "1", -maxdepth, "1", -type, d, "!", -name, containerd, + "!", "(", -group, aurbis, -perm, "-2070", ")", + -print, -exec, chgrp, aurbis, "{}", "+", -exec, chmod, g+rwxs, "{}", "+"] + register: aurbis_opt_dirs + changed_when: aurbis_opt_dirs.stdout != "" +- name: Give aurbis the top-level files of every /opt service + ansible.builtin.command: + argv: [find, /opt, -mindepth, "2", -maxdepth, "2", -type, f, "!", -path, "/opt/containerd/*", + "!", "(", -group, aurbis, -perm, -g+rw, ")", + -print, -exec, chgrp, aurbis, "{}", "+", -exec, chmod, g+rw, "{}", "+"] + register: aurbis_opt_files + changed_when: aurbis_opt_files.stdout != "" +- name: Keep /opt .env files from other users + ansible.builtin.command: + argv: [find, /opt, -mindepth, "2", -maxdepth, "2", -type, f, -name, .env, -perm, /o+rwx, + -print, -exec, chmod, o-rwx, "{}", "+"] + register: aurbis_opt_env + changed_when: aurbis_opt_env.stdout != "" + +- name: Look up the docker group + getent: + database: group + key: docker + fail_key: false +- name: Let aurbis members run docker + user: + name: "{{ item }}" + groups: docker + append: true + loop: "{{ users | default([]) }}" + when: ansible_facts.getent_group.docker is not none diff --git a/tasks/aurbis_tree.yml b/tasks/aurbis_tree.yml new file mode 100644 index 0000000..eb446df --- /dev/null +++ b/tasks/aurbis_tree.yml @@ -0,0 +1,12 @@ +- name: Give aurbis write access to {{ tree_path }} + file: + path: "{{ tree_path }}" + state: directory + recurse: true + group: aurbis + mode: g+rwX +- name: Make {{ tree_path }} directories hand their group to new files + ansible.builtin.command: + cmd: "find {{ tree_path }} -type d ! -perm -g+s -print -exec chmod g+s {} +" + register: aurbis_tree_setgid + changed_when: aurbis_tree_setgid.stdout != "" diff --git a/tasks/docker_service.yml b/tasks/docker_service.yml index 5cc1e9f..2f6f538 100644 --- a/tasks/docker_service.yml +++ b/tasks/docker_service.yml @@ -10,7 +10,7 @@ state: directory owner: root group: "{{ service_group | default('aurbis') }}" - mode: "0775" + mode: "02775" - name: Copy docker-compose file template: src: "{{ service_name }}/docker-compose.yml.j2" diff --git a/tasks/gitea_checkout.yml b/tasks/gitea_checkout.yml index 20ad2ae..aea1d5d 100644 --- a/tasks/gitea_checkout.yml +++ b/tasks/gitea_checkout.yml @@ -46,15 +46,6 @@ register: checkout_pull changed_when: "'updated' in checkout_pull.stdout" when: checkout_update | default(true) -- name: Give aurbis write access to {{ checkout_repo }} - file: - path: "{{ checkout_dest }}" - state: directory - recurse: true - group: aurbis - mode: g+rwX -- name: Make {{ checkout_repo }} directories hand their group to new files - ansible.builtin.command: - cmd: "find {{ checkout_dest }} -type d ! -perm -g+s -print -exec chmod g+s {} +" - register: checkout_setgid - changed_when: checkout_setgid.stdout != "" +- import_tasks: aurbis_tree.yml + vars: + tree_path: "{{ checkout_dest }}" diff --git a/tasks/homeassistant.yml b/tasks/homeassistant.yml index 4968f78..31f2b5d 100644 --- a/tasks/homeassistant.yml +++ b/tasks/homeassistant.yml @@ -4,7 +4,7 @@ state: directory owner: root group: aurbis - mode: "0775" + mode: "02775" - name: Create mosquitto config directory file: diff --git a/tasks/nightingale.yml b/tasks/nightingale.yml index 9dd79ec..2a26eab 100644 --- a/tasks/nightingale.yml +++ b/tasks/nightingale.yml @@ -4,7 +4,7 @@ state: directory owner: root group: aurbis - mode: "0775" + mode: "02775" # Song library. Read-only for nightingale. # Keep this in sync with the /karaoke mount in nextcloud