Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63b5d37883 | ||
|
|
5308e5312d | ||
|
|
cba507b077 | ||
|
|
4fdab81b9c | ||
|
|
472f04b98c | ||
|
|
0974c13751 | ||
|
|
6e4bd8eb92 | ||
|
|
d1714e0fa4 | ||
|
|
80a1ca0632 |
@@ -9,6 +9,3 @@ authors:
|
|||||||
description: Studio Ansible collection containing common roles
|
description: Studio Ansible collection containing common roles
|
||||||
license:
|
license:
|
||||||
- MIT
|
- MIT
|
||||||
|
|
||||||
dependencies:
|
|
||||||
"devsec.hardening": ">=9.0.0"
|
|
||||||
|
|||||||
@@ -35,5 +35,3 @@
|
|||||||
# APT::Periodic::Unattended-Upgrade "1";
|
# APT::Periodic::Unattended-Upgrade "1";
|
||||||
# mode: "0644"
|
# mode: "0644"
|
||||||
# when: ansible_facts['os_family'] == "Debian"
|
# when: ansible_facts['os_family'] == "Debian"
|
||||||
|
|
||||||
## SCHEDULE REBOOTS 4 kernel upgrades: with cron, unattended-upgrades or action workflows?
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
coolify_installer_url: "https://cdn.coollabs.io/coolify/install.sh"
|
||||||
|
coolify_installer_dest: "/tmp/coolify-install.sh"
|
||||||
|
coolify_data_dir: "/data/coolify"
|
||||||
|
coolify_compose_file: "{{ coolify_data_dir }}/source/docker-compose.yml"
|
||||||
|
|
||||||
|
## Pin to a release or leave empty for latest
|
||||||
|
coolify_version: ""
|
||||||
|
|
||||||
|
## Set to false to manage upgrades manually
|
||||||
|
coolify_autoupdate: true
|
||||||
|
|
||||||
|
## All 3 needed for sucessful user creation
|
||||||
|
coolify_root_username: ""
|
||||||
|
coolify_root_user_email: ""
|
||||||
|
coolify_root_user_password: ""
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
---
|
||||||
|
- name: Check if Coolify is already installed
|
||||||
|
become: true
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ coolify_compose_file }}"
|
||||||
|
register: coolify_installed
|
||||||
|
|
||||||
|
- name: Download Coolify installer
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "{{ coolify_installer_url }}"
|
||||||
|
dest: "{{ coolify_installer_dest }}"
|
||||||
|
mode: "0755"
|
||||||
|
when: not coolify_installed.stat.exists
|
||||||
|
|
||||||
|
- name: Run Coolify installer
|
||||||
|
become: true
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- "{{ coolify_installer_dest }}"
|
||||||
|
- "{{ coolify_version }}"
|
||||||
|
environment:
|
||||||
|
AUTOUPDATE: "{{ coolify_autoupdate | bool | ternary('true', 'false') }}"
|
||||||
|
ROOT_USERNAME: "{{ coolify_root_username }}"
|
||||||
|
ROOT_USER_EMAIL: "{{ coolify_root_user_email }}"
|
||||||
|
ROOT_USER_PASSWORD: "{{ coolify_root_user_password }}"
|
||||||
|
when: not coolify_installed.stat.exists
|
||||||
|
changed_when: true
|
||||||
|
async: 1800
|
||||||
|
poll: 15
|
||||||
|
no_log: true
|
||||||
+65
-63
@@ -1,74 +1,76 @@
|
|||||||
---
|
---
|
||||||
- name: Install Docker prerequisites
|
- name: Install Docker
|
||||||
ansible.builtin.apt:
|
|
||||||
name:
|
|
||||||
- ca-certificates
|
|
||||||
- curl
|
|
||||||
- python3-debian ## needed for the deb822 module
|
|
||||||
state: present
|
|
||||||
update_cache: true
|
|
||||||
become: true
|
become: true
|
||||||
|
block:
|
||||||
|
- name: Install Docker prerequisites
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- ca-certificates
|
||||||
|
- curl
|
||||||
|
- python3-debian ## needed for the deb822 module
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
|
||||||
- name: Add Docker official APT repository (DEB822 format)
|
- name: Add Docker official APT repository (DEB822 format)
|
||||||
ansible.builtin.deb822_repository:
|
ansible.builtin.deb822_repository:
|
||||||
name: docker
|
name: docker
|
||||||
types: deb
|
types: deb
|
||||||
uris: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}"
|
uris: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}"
|
||||||
suites: "{{ ansible_facts['distribution_release'] }}"
|
suites: "{{ ansible_facts['distribution_release'] }}"
|
||||||
components: stable
|
components: stable
|
||||||
signed_by: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}/gpg"
|
signed_by: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}/gpg"
|
||||||
state: present
|
state: present
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Install Docker CE packages
|
- name: Install Docker CE packages
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- docker-ce
|
- docker-ce
|
||||||
- docker-ce-cli
|
- docker-ce-cli
|
||||||
- containerd.io
|
- containerd.io
|
||||||
- docker-buildx-plugin
|
- docker-buildx-plugin
|
||||||
- docker-compose-plugin
|
- docker-compose-plugin
|
||||||
state: present
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Ensure Docker service is running and enabled
|
- name: Ensure Docker service is running and enabled
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: docker
|
name: docker
|
||||||
state: started
|
state: started
|
||||||
enabled: true
|
enabled: true
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Add deployment user to docker group
|
- name: Configure deployment user for Docker
|
||||||
ansible.builtin.user:
|
when: deployment_public_ssh_key is defined
|
||||||
name: deployment
|
|
||||||
groups: docker
|
|
||||||
append: true
|
|
||||||
become: true
|
become: true
|
||||||
|
block:
|
||||||
|
- name: Add deployment user to docker group
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: deployment
|
||||||
|
groups: docker
|
||||||
|
append: true
|
||||||
|
|
||||||
- name: Create target for docker compose files
|
- name: Create target for docker compose
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /opt/docker
|
path: /opt/docker
|
||||||
state: directory
|
state: directory
|
||||||
owner: deployment
|
owner: deployment
|
||||||
group: deployment
|
group: deployment
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Create appuser group
|
|
||||||
ansible.builtin.group:
|
|
||||||
name: appuser
|
|
||||||
state: present
|
|
||||||
gid: 9999
|
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Create app user for secure container execution
|
- name: Create app user for secure container execution
|
||||||
ansible.builtin.user:
|
|
||||||
name: appuser
|
|
||||||
state: present
|
|
||||||
uid: 9999
|
|
||||||
group: appuser
|
|
||||||
system: true
|
|
||||||
shell: /usr/sbin/nologin
|
|
||||||
create_home: false
|
|
||||||
become: true
|
become: true
|
||||||
|
block:
|
||||||
|
- name: Create appuser group
|
||||||
|
ansible.builtin.group:
|
||||||
|
name: appuser
|
||||||
|
state: present
|
||||||
|
gid: 9999
|
||||||
|
|
||||||
|
- name: Create appuser
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: appuser
|
||||||
|
state: present
|
||||||
|
uid: 9999
|
||||||
|
group: appuser
|
||||||
|
system: true
|
||||||
|
shell: /usr/sbin/nologin
|
||||||
|
create_home: false
|
||||||
|
|||||||
@@ -1,20 +1,35 @@
|
|||||||
---
|
---
|
||||||
- name: Harden SSH configuration
|
- name: Harden SSH configuration
|
||||||
ansible.builtin.import_role:
|
|
||||||
name: devsec.hardening.ssh_hardening
|
|
||||||
vars:
|
|
||||||
ssh_permit_root_login: "no"
|
|
||||||
ssh_password_authentication: "no"
|
|
||||||
|
|
||||||
- name: Install fail2ban
|
|
||||||
ansible.builtin.apt:
|
|
||||||
name:
|
|
||||||
- fail2ban
|
|
||||||
state: present
|
|
||||||
become: true
|
become: true
|
||||||
|
block:
|
||||||
|
- name: Create SSH drop-in directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/ssh/sshd_config.d
|
||||||
|
state: directory
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0755"
|
||||||
|
|
||||||
- name: Start fail2ban
|
- name: Harden SSH configuration with drop-in template
|
||||||
ansible.builtin.service:
|
ansible.builtin.template:
|
||||||
name: fail2ban
|
src: sshd.conf.j2
|
||||||
state: started
|
dest: /etc/ssh/sshd_config.d/sshd.conf
|
||||||
enabled: yes
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
notify: Restart sshd
|
||||||
|
|
||||||
|
- name: Enable fail2ban
|
||||||
|
become: true
|
||||||
|
block:
|
||||||
|
- name: Install fail2ban
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- fail2ban
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Start fail2ban
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: fail2ban
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
## Disable root login
|
||||||
|
PermitRootLogin no
|
||||||
|
|
||||||
|
## Disable password authentication
|
||||||
|
PasswordAuthentication no
|
||||||
+35
-31
@@ -1,38 +1,42 @@
|
|||||||
---
|
---
|
||||||
- name: Create primary sysadmin user
|
- name: Set up primary sysadmin user
|
||||||
ansible.builtin.user:
|
when: sysadmin_public_ssh_key is defined
|
||||||
name: "{{ sysadmin_user }}"
|
|
||||||
groups: sudo
|
|
||||||
append: yes
|
|
||||||
shell: /bin/bash
|
|
||||||
create_home: yes
|
|
||||||
become: true
|
become: true
|
||||||
|
block:
|
||||||
|
- name: Create sysadmin user
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: "{{ sysadmin_user }}"
|
||||||
|
groups: sudo
|
||||||
|
append: yes
|
||||||
|
shell: /bin/bash
|
||||||
|
create_home: yes
|
||||||
|
|
||||||
- name: Add SSH public key for sysadmin
|
- name: Add SSH public key
|
||||||
ansible.posix.authorized_key:
|
ansible.posix.authorized_key:
|
||||||
user: "{{ sysadmin_user }}"
|
user: "{{ sysadmin_user }}"
|
||||||
state: present
|
state: present
|
||||||
key: "{{ sysadmin_public_ssh_key }}"
|
key: "{{ sysadmin_public_ssh_key }}"
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Allow passwordless sudo for sudo group
|
- name: Allow passwordless sudo
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
dest: /etc/sudoers.d/sudo-nopasswd
|
dest: /etc/sudoers.d/sudo-nopasswd
|
||||||
content: "%sudo ALL=(ALL) NOPASSWD: ALL"
|
content: "%sudo ALL=(ALL) NOPASSWD: ALL"
|
||||||
mode: "0440"
|
mode: "0440"
|
||||||
validate: /usr/sbin/visudo -cf %s
|
validate: /usr/sbin/visudo -cf %s
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Create deployment user for CI/CD
|
|
||||||
ansible.builtin.user:
|
|
||||||
name: deployment
|
|
||||||
shell: /bin/bash
|
|
||||||
create_home: yes
|
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Add SSH public key for deployment user
|
- name: Set up deployment user for CI/CD
|
||||||
ansible.posix.authorized_key:
|
when: deployment_public_ssh_key is defined
|
||||||
user: deployment
|
|
||||||
state: present
|
|
||||||
key: "{{ deployment_public_ssh_key }}"
|
|
||||||
become: true
|
become: true
|
||||||
|
block:
|
||||||
|
- name: Create deployment user
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: deployment
|
||||||
|
shell: /bin/bash
|
||||||
|
create_home: yes
|
||||||
|
|
||||||
|
- name: Add SSH public key
|
||||||
|
ansible.posix.authorized_key:
|
||||||
|
user: deployment
|
||||||
|
state: present
|
||||||
|
key: "{{ deployment_public_ssh_key }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user