Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf66355832 | ||
|
|
b031c08b66 | ||
|
|
1370cd2b8a | ||
|
|
7c9d7050e9 | ||
|
|
bdd1c07d76 | ||
|
|
f59952df2b | ||
|
|
f9e26303d0 | ||
|
|
b6d861a8d4 | ||
|
|
ff9d9adc96 | ||
|
|
960379bd16 | ||
|
|
16e403a439 | ||
|
|
d4587423a1 | ||
|
|
9fbba9ffd6 |
@@ -1,3 +1,5 @@
|
|||||||
# Ansible Collection
|
# Ansible Collection
|
||||||
|
|
||||||
Opinionated set of roles to configure reasonable defaults for newly provisioned Debian / Ubuntu VMs running Docker. The repository provides a ready-to-use Ansible Collection (`studio.ansible`) containing reusable roles.
|
Opinionated set of roles to configure reasonable defaults for newly provisioned virtual machines. The repository provides a ready-to-use Ansible Collection (`studio.ansible`) containing reusable roles.
|
||||||
|
|
||||||
|
Currently only supports Debian-based systems.
|
||||||
|
|||||||
+6
-2
@@ -3,8 +3,12 @@
|
|||||||
namespace: studio
|
namespace: studio
|
||||||
name: ansible
|
name: ansible
|
||||||
readme: README.md
|
readme: README.md
|
||||||
version: 1.0.0
|
version: 0.0.1
|
||||||
authors:
|
authors:
|
||||||
- Studio Vitali
|
- Studio Vitali
|
||||||
description: Studio Ansible collection containing common roles
|
description: Studio Ansible collection containing common roles
|
||||||
license: MIT
|
license:
|
||||||
|
- MIT
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
"devsec.hardening": ">=9.0.0"
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
requires_ansible: ">=2.15.0"
|
||||||
@@ -10,7 +10,6 @@
|
|||||||
update_cache: true
|
update_cache: true
|
||||||
upgrade: dist
|
upgrade: dist
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
when: ansible_facts['os_family'] == "Debian" ## only on Debian / Ubuntu systems
|
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Install essential system utilities
|
- name: Install essential system utilities
|
||||||
@@ -26,7 +25,6 @@
|
|||||||
- unattended-upgrades
|
- unattended-upgrades
|
||||||
state: present
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
when: ansible_facts['os_family'] == "Debian"
|
|
||||||
become: true
|
become: true
|
||||||
#
|
#
|
||||||
# - name: Enable unattended-upgrades
|
# - name: Enable unattended-upgrades
|
||||||
|
|||||||
+55
-16
@@ -1,31 +1,52 @@
|
|||||||
---
|
---
|
||||||
- name: Install necessary Docker packages
|
- name: Install Docker prerequisites
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- docker.io
|
- ca-certificates
|
||||||
- docker-compose
|
- curl
|
||||||
|
- python3-debian ## needed for the deb822 module
|
||||||
state: present
|
state: present
|
||||||
when: ansible_facts['os_family'] == "Debian" ## Debian / Ubuntu
|
update_cache: true
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Ensure Docker service is running
|
- name: Add Docker official APT repository (DEB822 format)
|
||||||
|
ansible.builtin.deb822_repository:
|
||||||
|
name: docker
|
||||||
|
types: deb
|
||||||
|
uris: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}"
|
||||||
|
suites: "{{ ansible_facts['distribution_release'] }}"
|
||||||
|
components: stable
|
||||||
|
signed_by: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}/gpg"
|
||||||
|
state: present
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Install Docker CE packages
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- docker-ce
|
||||||
|
- docker-ce-cli
|
||||||
|
- containerd.io
|
||||||
|
- docker-buildx-plugin
|
||||||
|
- docker-compose-plugin
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
- name: Create docker user for container execution
|
|
||||||
ansible.builtin.user:
|
|
||||||
name: docker
|
|
||||||
state: present
|
|
||||||
system: true
|
|
||||||
shell: /usr/sbin/nologin
|
|
||||||
groups: docker
|
|
||||||
append: true
|
|
||||||
create_home: false
|
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Create target for docker compose
|
- name: Add deployment user to docker group
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: deployment
|
||||||
|
groups: docker
|
||||||
|
append: true
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Create target for docker compose files
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /opt/docker
|
path: /opt/docker
|
||||||
state: directory
|
state: directory
|
||||||
@@ -33,3 +54,21 @@
|
|||||||
group: deployment
|
group: deployment
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
become: true
|
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
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: appuser
|
||||||
|
state: present
|
||||||
|
uid: 9999
|
||||||
|
group: appuser
|
||||||
|
system: true
|
||||||
|
shell: /usr/sbin/nologin
|
||||||
|
create_home: false
|
||||||
|
become: true
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: Restart sshd
|
- name: Restart sshd
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: sshd
|
name: ssh
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|||||||
@@ -1,30 +1,16 @@
|
|||||||
---
|
---
|
||||||
- name: Create SSH drop-in directory
|
- name: Harden SSH configuration
|
||||||
ansible.builtin.file:
|
ansible.builtin.import_role:
|
||||||
path: /etc/ssh/sshd_config.d
|
name: devsec.hardening.ssh_hardening
|
||||||
state: directory
|
vars:
|
||||||
owner: root
|
ssh_permit_root_login: "no"
|
||||||
group: root
|
ssh_password_authentication: "no"
|
||||||
mode: "0755"
|
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Harden SSH configuration with drop-in template
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: sshd.conf.j2
|
|
||||||
dest: /etc/ssh/sshd_config.d/sshd.conf
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: "0644"
|
|
||||||
validate: "sshd -t -f %s"
|
|
||||||
notify: Restart sshd
|
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Install fail2ban
|
- name: Install fail2ban
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- fail2ban
|
- fail2ban
|
||||||
state: present
|
state: present
|
||||||
when: ansible_facts['os_family'] == "Debian"
|
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Start fail2ban
|
- name: Start fail2ban
|
||||||
@@ -32,4 +18,3 @@
|
|||||||
name: fail2ban
|
name: fail2ban
|
||||||
state: started
|
state: started
|
||||||
enabled: yes
|
enabled: yes
|
||||||
when: ansible_facts['os_family'] == "Debian"
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
## Disable root login
|
|
||||||
PermitRootLogin no
|
|
||||||
|
|
||||||
## Disable password authentication
|
|
||||||
PasswordAuthentication no
|
|
||||||
+21
-21
@@ -1,27 +1,27 @@
|
|||||||
---
|
---
|
||||||
# - name: Create primary admin user
|
- name: Create primary sysadmin user
|
||||||
# ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
# name: sysadmin
|
name: "{{ sysadmin_user }}"
|
||||||
# groups: sudo
|
groups: sudo
|
||||||
# append: yes
|
append: yes
|
||||||
# shell: /bin/bash
|
shell: /bin/bash
|
||||||
# create_home: yes
|
create_home: yes
|
||||||
# become: true
|
become: true
|
||||||
|
|
||||||
# - name: Add SSH public key for sysadmin
|
- name: Add SSH public key for sysadmin
|
||||||
# ansible.posix.authorized_key:
|
ansible.posix.authorized_key:
|
||||||
# user: sysadmin
|
user: "{{ sysadmin_user }}"
|
||||||
# state: present
|
state: present
|
||||||
# key: "{{ sysadmin_public_ssh_key }}"
|
key: "{{ sysadmin_public_ssh_key }}"
|
||||||
# become: true
|
become: true
|
||||||
|
|
||||||
# - name: Allow passwordless sudo to sysadmin user
|
- name: Allow passwordless sudo for sudo group
|
||||||
# ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
# dest: /etc/sudoers.d/sysadmin
|
dest: /etc/sudoers.d/sudo-nopasswd
|
||||||
# content: "sysadmin 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
|
become: true
|
||||||
|
|
||||||
- name: Create deployment user for CI/CD
|
- name: Create deployment user for CI/CD
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
|
|||||||
Reference in New Issue
Block a user