1
0
Fork 0

add bastion fail2ban config

This commit is contained in:
Massaki Archambault 2021-12-17 18:17:18 -05:00
parent 387f5bccc7
commit 8deddf3c0b
9 changed files with 74 additions and 9 deletions

View File

@ -12,6 +12,11 @@ haproxy:
- 192.168.20.22 - 192.168.20.22
- 192.168.20.23 - 192.168.20.23
- 192.168.20.24 - 192.168.20.24
- src:
- s3.badjware.dev
dst:
- 192.168.20.30:9000
ssl: false
# - src: # - src:
# - kubernetes-dashboard.badjnet.home # - kubernetes-dashboard.badjnet.home
# - traefik.badjnet.home # - traefik.badjnet.home
@ -26,6 +31,7 @@ haproxy:
tcp: tcp:
- src: "30022" - src: "30022"
dst: dst:
- 192.168.20.20:30022
- 192.168.20.21:30022 - 192.168.20.21:30022
- 192.168.20.22:30022 - 192.168.20.22:30022
- 192.168.20.23:30022 - 192.168.20.23:30022

7
hosts
View File

@ -35,10 +35,11 @@ all:
ansible_host: 192.168.10.11 ansible_host: 192.168.10.11
vfio_pci_ids: vfio_pci_ids:
- '1000:0086' # Broadcom / LSI SAS2308 PCI-Express Fusion-MPT SAS-2 - '1000:0086' # Broadcom / LSI SAS2308 PCI-Express Fusion-MPT SAS-2
lb: bastions:
hosts: hosts:
lb: bastion:
ansible_host: 192.168.20.10 ansible_host: 192.168.20.10
users_enable_sudo: false
k3s: k3s:
children: children:
k3s-server: k3s-server:
@ -69,7 +70,7 @@ all:
ansible_host: 192.168.20.2 ansible_host: 192.168.20.2
children: children:
proxmox: proxmox:
lb: bastions:
k3s: k3s:
vars: vars:
<<: *user_config <<: *user_config

View File

@ -6,9 +6,10 @@
roles: roles:
- common - common
- hosts: lb - hosts: bastion
roles: roles:
- haproxy - haproxy
- bastion
- hosts: k3s-server - hosts: k3s-server
roles: roles:

View File

@ -0,0 +1,10 @@
[DEFAULT]
bantime = 1h
findtime = 5m
maxretry = 3
ignoreip = 192.168.0.0/16
[sshd]
enabled = true
mode = aggressive

View File

@ -0,0 +1,11 @@
- name: Restart fail2ban
service:
name: fail2ban
enabled: true
state: reloaded
- name: Restart sshd
service:
name: sshd
enabled: true
state: reloaded

View File

@ -0,0 +1,34 @@
- name: Install fail2ban
apt:
name:
- fail2ban
- name: Configure fail2ban
copy:
src: fail2ban/jail.local
dest: /etc/fail2ban/jail.local
notify: Restart fail2ban
- name: Disable ssh password authentication for all but user of ansible
blockinfile:
path: /etc/ssh/sshd_config
block: |
Match User {{ ansible_user }}
PasswordAuthentication yes
Match all
PasswordAuthentication no
notify: Restart sshd
- name: Configure sshd ClientAliveInterval
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?ClientAliveInterval'
line: ClientAliveInterval 5m
notify: Restart sshd
- name: Configure sshd ClientAliveCountMax
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?ClientAliveCountMax'
line: ClientAliveCountMax 3
notify: Restart sshd

View File

@ -1 +1,2 @@
users: {} users: {}
users_enable_sudo: true

View File

@ -4,7 +4,7 @@
password: '{{ item.value.default_password }}' password: '{{ item.value.default_password }}'
update_password: on_create update_password: on_create
shell: /bin/bash shell: /bin/bash
groups: sudo groups: '{{["sudo"] if users_enable_sudo else []}}'
- name: '{{ item.key }}: Configure ssh public keys' - name: '{{ item.key }}: Configure ssh public keys'
authorized_key: authorized_key:

View File

@ -79,14 +79,15 @@ backend haproxy_metrics
http-request use-service prometheus-exporter http-request use-service prometheus-exporter
{% for http_route in https_routing %} {% for http_route in https_routing %}
# backend for {{ http_route.src[0] }} # backend for {{ ', '.join(http_route.src) }}
backend https_{{ http_route.src[0]|replace('.','_') }} backend https_{{ http_route.src[0]|replace('.','_') }}
mode http mode http
balance roundrobin balance roundrobin
{% for dst in http_route.dst %} {% for dst in http_route.dst %}
server {{ dst }} {{ dst }}{% if ':' not in dst %}:443{% endif %} check ssl verify none alpn h2 server {{ dst }} {{ dst }}{% if ':' not in dst %}:443{% endif %} check {% if http_route.ssl|default(true) %}ssl verify none alpn h2{% endif %}
#server {{ dst }} {{ dst }}{% if ':' not in dst %}:80{% endif %} check
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
## TCP ## ## TCP ##