Début du déploiement via ANSIBLE
parent
b21da67c88
commit
e480ed1a68
|
@ -27,13 +27,11 @@ charge de former leur successeurs.
|
|||
4. [Cluster](proxmox/cluster)
|
||||
5. [Haute Disponibilitée](#)
|
||||
6. [Gestion de l'authentification](#)
|
||||
7. [Sécurisation des container / VM](#)
|
||||
3. [Réseau](reseau)
|
||||
1. [Introduction à OpenvSwitch](reseau/introduction_ovs.md)
|
||||
2. [Topologie du réseau matériel](reseau/topologie_reseau_physique.md)
|
||||
3. [Topologie du réseau virtuel](reseau/topologie_reseau_virtuel.md)
|
||||
4. [Mise en place du réseau](reseau/mise_en_place.md)
|
||||
5. [Logique de l'assignation des adresses IP](reseau/logique_ip_ct_vm.md)
|
||||
4. [Applicatif](applicatif)
|
||||
1. [Répartition des services dans les zones](applicatif/repartition_en_zones.md)
|
||||
2. [Zone WAN](applicatif/zone_wan)
|
||||
|
@ -41,7 +39,3 @@ charge de former leur successeurs.
|
|||
4. [Zone Proxy](applicatif/zone_proxy)
|
||||
5. [Zone Interne](applicatif/zone_interne)
|
||||
6. [Zone CTF](applicatif/zone_ctf)
|
||||
5. [Aide au déploiement](deploiement)
|
||||
1. [Introduction à Ansible](#)
|
||||
1. [Déploiement via Ansible](deploiement/deploiement_avec_ansible.md)
|
||||
3. [Notes et conseils](#)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# Aide au déploiement
|
||||
|
||||
Vous trouverez ici toute la documentation relative au déploiement via Ansible ainsi que des notes et des conseils issue des précédents déploiement.
|
||||
|
||||
1. [Introduction à Ansible](#)
|
||||
1. [Déploiement via Ansible](deploiement_avec_ansible.md)
|
||||
3. [Notes et conseils](#)
|
|
@ -0,0 +1,107 @@
|
|||
# Ansible
|
||||
|
||||
Nous allons utilisé Ansible pour la création et la configuration de base (mise à jours, proxy...) de tout les container.
|
||||
|
||||
## Création du container Ansible
|
||||
Avant de lancer la création et l'installation de tout les container il vous faut mettre en place le réseau et les pare-feux ainsi au minimum l'interface admin sur le pare-feu (avec ip virtuelle en .254).
|
||||
|
||||
Une fois que c'est fait, créer un container Ansible avec un numéro élevée (253 max).
|
||||
|
||||
### Réseau
|
||||
Au niveau des interfaces réseau, une sur la partie admin, l'autre sur le zone proxy pour l'accès au futur proxy interne.
|
||||
|
||||
- eth0 : vmbr2 VLAN: 100 IP: 10.1.0.253/24 GW: 10.1.0.254
|
||||
- eth1 : vmbr1 VLAN: 20 IP:10.0.1.200/24 GW:10.0.1.254
|
||||
|
||||
### Configuration initiale
|
||||
Vous allez générer une clé ed25519 qui servira à l'administation des container.
|
||||
```
|
||||
ssh-keygen -o -a 100 -t ed25519 -f /root/.ssh/id_ed25519
|
||||
```
|
||||
|
||||
Avant d'installer Ansible, il faut que vous mettiez en place (vous-même) le container du proxy interne. C'est le seul container, avec celui d'Ansible, que vous aurez à créer.
|
||||
|
||||
### Connexion au proxy
|
||||
On doit connecter le container au proxy pour qu'il puisse utiliser wget et apt.
|
||||
|
||||
#### /root/.wgetrc
|
||||
```
|
||||
http_proxy = http://10.0.1.252:3128/
|
||||
https_proxy = http://10.0.1.252:3128/
|
||||
use_proxy = on
|
||||
```
|
||||
#### /etc/apt/apt.conf.d/01proxy
|
||||
```
|
||||
Acquire::http {
|
||||
Proxy "http://10.0.1.252:9999";
|
||||
};
|
||||
```
|
||||
|
||||
## Installation d'Ansible
|
||||
|
||||
```
|
||||
apt-get update
|
||||
apt-get dist-upgrade
|
||||
apt-get install -y ansible python python3-proxmoxer
|
||||
```
|
||||
Il faut maintenant remplacer `/usr/lib/python3/dist-packages/ansible/modules/cloud/misc/proxmox.py` par le fichier proxmox.py qui est dans le même dossier.
|
||||
|
||||
Maintenant que Ansible est en place, on va pouvoir installer tous les container nécessaires. L'installation va se faire par zone, en commençant par la zone DMZ.
|
||||
|
||||
Pour la création des container, nous allons utiliser la librairie python `proxmoxer` qui s'exécute en local. Pour toutes les autres tâches, Ansible se connectera via SSH au container. Pour savoir sur quel container exécuter son playbook, Ansible utilise un inventaire trouvable dans `/etc/ansible/hosts`.
|
||||
|
||||
Pour notre usage, nous allons faire des groupes pour chaque type de container et un groupe pour chaque zone.
|
||||
|
||||
Il vous faut mettre le mot de passe root de proxmox et la clé publique du container Ansible dans un fichier à l'adresse `/root/src/source_pve.yml` et restreindre la lecture `chmod 640 /root/src/source_pve.yml`.
|
||||
|
||||
Structure du fichier source_pve.yml :
|
||||
```
|
||||
pass_pve:
|
||||
ssh_pub:
|
||||
```
|
||||
|
||||
Par exemple, il y aura un groupe HAProxy regroupant tous les container HAProxy et un groupe DMZ regroupant tous les groupes de container DMZ.
|
||||
|
||||
|
||||
## Zone DMZ
|
||||
|
||||
Un playbook Ansible est disponible pour la préparation de la zone DMZ, il s'occupera de l'installation de base. A vous de suivre la documentation pour la suite des opérations (sauf mention contraire).
|
||||
|
||||
Voici les tâches à réaliser avant de lancer le playbook.
|
||||
|
||||
### /etc/ansible/hosts
|
||||
Ajoutez
|
||||
```
|
||||
[haproxy]
|
||||
10.1.0.100 #HAProxy Alpha
|
||||
10.1.0.101 #HAProxy Beta
|
||||
|
||||
[dns]
|
||||
10.1.0.106 #DNS
|
||||
|
||||
[zonedmz:children]
|
||||
haproxy
|
||||
dmz
|
||||
```
|
||||
|
||||
Pour les mots de passe à vous de les générer, il vous faut ensuite les mettre dans ce fichier. Le mot de passe pour hasync et le même sur les deux HAProxy.
|
||||
|
||||
### /root/src/password_dmz.yml
|
||||
```
|
||||
pass_haproxy_master:
|
||||
pass_haproxy_slave:
|
||||
pass_hasync_same:
|
||||
pass_dns:
|
||||
```
|
||||
|
||||
### Templace Ferm pour les container
|
||||
|
||||
Le playbook Ansible s'occupe aussi de la mise en place d'un pare-feu. Une template a été réalisée pour la sécurisation des container avec ferm. Le détail de cette template est dans proxmox/securisation/template_ferm.md
|
||||
|
||||
Il vous faut mettre dans `/root/src/ferm/` les deux fichiers de configuration fournis (haproxy_ferm.conf & dns_ferm.conf)
|
||||
|
||||
Une fois que tout est fait, vous trouverez le playbook sous le nom de `ct_dmz.yml` dans le dossier zone_dmz.
|
||||
|
||||
Lancez le avec `ansible-playbook ct_dmz.yml`.
|
||||
|
||||
Normalement tout est prêt, vous pouvez passer à la configuration des services de la zone DMZ.
|
|
@ -0,0 +1,188 @@
|
|||
# Déploiement de l'infrastructure
|
||||
|
||||
Ce document regroupe uniquement des notes et des conseils non ordonné, certains éléments peuvent être erronés.
|
||||
|
||||
## Bonne manière
|
||||
|
||||
- Des qu'un mot de passe est demandé, en générer un avec un gestionnaire de mot de passe (externalisé) du style KeePass (keepass2 ou keepassx).
|
||||
- Toujours désactiver le Firewall Proxmox sur les interfaces
|
||||
- En cas de soucis avec un service faire un `systemctl restart <service>` avant de tout modifier. Possibilité de problème dans les interfaces.
|
||||
|
||||
|
||||
- Les adresses IP et VLAN à suivre sont dans mise_en_place.md
|
||||
|
||||
- Pour se connecter à un container : SSH l'hyperviseur puis lxc-attact <number>
|
||||
Voilà l'ordre à suivre
|
||||
|
||||
installation_hyperviseurs.md
|
||||
mise_en_place.md
|
||||
opnsense.md
|
||||
|
||||
Dans mon cas pas d'IP sur les VM donc adaptation
|
||||
Rajout de vmbr3 pour link PVE et OPN via DNAT.
|
||||
|
||||
Lors de l'installation d'OPNSense on met le clavier en français et on met un mot de passe simple que l'on changera par la suite.
|
||||
|
||||
On alloue uniquement dmz et wan pour le moment
|
||||
|
||||
vmbr1.10 C9:64 (dmz) -> 10.0.0.{3,4}/24 GW None
|
||||
vmbr2.100 42:85 (admin)
|
||||
vmbr3 21:73 (wan) -> 10.2.0.3/24 GW 10.2.0.1
|
||||
|
||||
Attribution du sous réseau 10.2.0.0/24 au lien entre PVE et OPNSense
|
||||
PVE : 10.2.0.1
|
||||
OPN : 10.2.0.3
|
||||
|
||||
Ferm nécessaire car pas d'IP publique possible sur les VM
|
||||
```
|
||||
@def $IF_OPN = lan;
|
||||
@def $IF_EXT = vmbr0;
|
||||
@def $IF_DMZ = dmz;
|
||||
@def $IF_ADMIN = admin;
|
||||
|
||||
@def $IP_PUBLIQUE = 195.154.163.18;
|
||||
@def $IP_OPNSENSE = 10.2.0.3;
|
||||
@def $NET_OPN = 10.2.0.0/24;
|
||||
|
||||
|
||||
@def $NET_INT = 10.0.2.0/24;
|
||||
@def $IP_PROXY = 10.0.1.10;
|
||||
|
||||
@def $PORTS_OPN = (80 443 8080);
|
||||
|
||||
@def &FORWARD_TCP($proto, $port, $dest) = {
|
||||
table filter chain FORWARD interface $IF_EXT outerface $IF_OPN daddr $dest proto $proto dport $port ACCEPT;
|
||||
table nat chain PREROUTING interface $IF_EXT daddr $IP_PUBLIQUE proto $proto dport $port DNAT to $dest;
|
||||
}
|
||||
|
||||
table filter {
|
||||
chain INPUT {
|
||||
policy DROP;
|
||||
mod state state INVALID DROP;
|
||||
mod state state (ESTABLISHED RELATED) ACCEPT;
|
||||
interface lo ACCEPT;
|
||||
interface $IF_ADMIN ACCEPT;
|
||||
interface $IF_DMZ proto tcp dport 8006 ACCEPT;
|
||||
interface $IF_EXT proto tcp dport 8006 ACCEPT;
|
||||
proto icmp icmp-type echo-request ACCEPT;
|
||||
proto tcp dport 22 ACCEPT;
|
||||
}
|
||||
|
||||
chain OUTPUT policy ACCEPT;
|
||||
|
||||
chain FORWARD {
|
||||
policy DROP;
|
||||
mod state state INVALID DROP;
|
||||
mod state state (ESTABLISHED RELATED) ACCEPT;
|
||||
interface $IF_DMZ {
|
||||
outerface $IF_EXT ACCEPT;
|
||||
REJECT reject-with icmp-net-prohibited;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
table nat {
|
||||
chain POSTROUTING {
|
||||
saddr $NET_OPN outerface $IF_EXT SNAT to $IP_PUBLIQUE;
|
||||
}
|
||||
}
|
||||
|
||||
&FORWARD_TCP((tcp udp), $PORTS_OPN, $IP_OPNSENSE);
|
||||
```
|
||||
|
||||
|
||||
Pour rentrer sur l'interface web via Wan
|
||||
|
||||
On désactive toute les protections
|
||||
|
||||
pfctl -d
|
||||
touch /tmp/disable_security_checks
|
||||
|
||||
|
||||
Faire une règle de DNAT
|
||||
|
||||
Interface : WAN
|
||||
Protocole : TCP ou UDP ou les deux
|
||||
Destination : A voir
|
||||
Plage de ports de destination : Port Source
|
||||
Rediriger Vers : IP du service
|
||||
Rediriger port cible : Port Cible
|
||||
|
||||
NAT Redirection de ports
|
||||
WAN 80 et 443 vers 10.0.0.8 80 et 443
|
||||
|
||||
|
||||
Pour assuré nos arrière je vais faire le choix de laisser le port 8080 ouvert pour acceder au firewall. Destination : ce pare-feu de 8080 vers 10.0.0.3:443
|
||||
|
||||
|
||||
|
||||
haproxy.md
|
||||
|
||||
A la fin de la configuration de HAProxy tester le master surtout sur les zones admin (pve, opn...) et ensuite couper le master pour tester le slave. Les deux doivent fonctionner pareil et l'ip 10.0.0.8/32 doit passer d'un serveur à l'autre.
|
||||
|
||||
Maintenant que OPNSense est accessible à l'adresse
|
||||
opn.sessionkrkn.fr il faut autorisé cet host à accéder au Panel.
|
||||
|
||||
Système/Paramètres/Administration/Nomsd'hôte alternatifs
|
||||
et mettre `opn.sessionkrkn.fr`
|
||||
il n'est donc plus neccessaire d'enlever la vérification web d'OPNSense.
|
||||
|
||||
|
||||
Normalement à ce stade
|
||||
pve.sessionkrkn.fr
|
||||
opn.sessionkrkn.fr
|
||||
sont accessible et fonctionne.
|
||||
|
||||
proxy_interne.md
|
||||
Rien de bien dur pour la mise en place
|
||||
Pour l'utilisation
|
||||
- Chaque container dans une zone autre que DMZ doit avoir comme gateway l'adresse du proxy dans la bonne zone
|
||||
- Il faut configurer impérativement wget et apt vers l'adresse du proxy
|
||||
- Mettre en place une interface dans chaque zone avec l'adresse en .252 avec comme gateway .254 (OPNSense)
|
||||
|
||||
nginx_principal.md
|
||||
|
||||
Création des deux container et connexion au proxy interne
|
||||
|
||||
#### /root/.wgetrc
|
||||
```
|
||||
http_proxy = http://10.0.1.252:3128/
|
||||
https_proxy = http://10.0.1.252:3128/
|
||||
use_proxy = on
|
||||
```
|
||||
#### /etc/apt/apt.conf.d/01proxy
|
||||
```
|
||||
Acquire::http {
|
||||
Proxy "http://10.0.1.252:9999";
|
||||
};
|
||||
```
|
||||
|
||||
#### /root/.wgetrc
|
||||
```
|
||||
http_proxy = http://10.0.2.252:3128/
|
||||
https_proxy = http://10.0.2.252:3128/
|
||||
use_proxy = on
|
||||
```
|
||||
#### /etc/apt/apt.conf.d/01proxy
|
||||
```
|
||||
Acquire::http {
|
||||
Proxy "http://10.0.2.252:9999";
|
||||
};
|
||||
```
|
||||
|
||||
Pour tester le fonctionnement jusqu'ici redémarrer le serveur et vérifier que tout fonctionne.
|
||||
Problème classique :
|
||||
- Service non activé
|
||||
- Interfaces mal configuré (firewall proxmox)
|
||||
- Dans le cas de ferm bug a l'allumage
|
||||
|
||||
dns.md
|
||||
Une interface DMZ gateway 10.0.0.3 ou VIP OPN
|
||||
Une interface PROXY gateway 10.0.1.254
|
||||
Une interface INT gateway 10.0.2.254
|
||||
|
||||
ldap.md
|
||||
|
||||
Vérification de la mise en place des certifs SSL
|
||||
|
||||
ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config |grep olcTLS
|
|
@ -0,0 +1,275 @@
|
|||
# HAProxy et DNS
|
||||
# HAProxy Master (CT100) : 10.0.0.6 | 10.0.1.1 | 10.0.3.1 | 10.1.0.100
|
||||
# HAProxy Slave (CT101) : 10.0.0.7 | 10.0.1.2 10.0.3.2 | 10.1.0.101
|
||||
# DNS (CT106): 10.0.0.253 | | 10.0.1.253 | 10.0.2.253 | 10.1.0.106
|
||||
# Gateway 10.0.0.0/24 -> 10.0.0.254
|
||||
# Gateway 10.0.1.0/24 -> 10.0.1.254
|
||||
# Gateway 10.0.3.0/24 -> 10.0.3.254
|
||||
# Gateway 10.1.0.0/24 -> 10.1.0.254
|
||||
|
||||
# Créer les containers, les mets à jours, configure les mises à jours de sécurité automatique,
|
||||
# installe des paquets utile et ceux des services, met en place ferm via notre template.
|
||||
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- include_vars: /root/src/source_pve.yml
|
||||
- include_vars: /root/src/password_dmz.yml
|
||||
|
||||
- name: Create LXC for HAProxy Master (CT101)
|
||||
proxmox:
|
||||
api_user: root@pam
|
||||
api_password: "{{ pass_pve }}"
|
||||
api_host: '10.1.0.1'
|
||||
node: alpha
|
||||
cpus: 1
|
||||
cores: 2
|
||||
memory: 2048
|
||||
disk: 16
|
||||
swap: 1024
|
||||
storage: local-zfs
|
||||
ostemplate: 'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz'
|
||||
password: "{{ pass_haproxy_master }}"
|
||||
hostname: HAProxyMaster
|
||||
vmid: 101
|
||||
onboot: yes
|
||||
unprivileged: yes
|
||||
nameserver: '10.0.0.253'
|
||||
netif: '{"net0":"name=eth0,ip=10.0.0.6/24,gw=10.0.0.254,bridge=vmbr1,tag=10","net1":"name=eth1,ip=10.0.1.1/24,gw=10.0.1.254,bridge=vmbr1,tag=20","net2":"name=eth2,ip=10.0.3.1/24,gw=10.0.3.254,bridge=vmbr1,tag=40","net3":"name=eth3,ip=10.1.0.101/24,gw=10.1.0.254,bridge=vmbr2,tag=100"}'
|
||||
pubkey: "{{ ssh_pub }}"
|
||||
state: present
|
||||
|
||||
- name: Create LXC for HAProxy Slave (CT102)
|
||||
proxmox:
|
||||
api_user: root@pam
|
||||
api_password: "{{ pass_pve }}"
|
||||
api_host: '10.1.0.1'
|
||||
node: beta
|
||||
cpus: 1
|
||||
cores: 2
|
||||
memory: 2048
|
||||
disk: 16
|
||||
swap: 1024
|
||||
storage: local-zfs
|
||||
ostemplate: 'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz'
|
||||
password: "{{ pass_haproxy_slave }}"
|
||||
hostname: HAProxySlave
|
||||
vmid: 102
|
||||
onboot: yes
|
||||
unprivileged: yes
|
||||
nameserver: '10.0.0.253'
|
||||
netif: '{"net0":"name=eth0,ip=10.0.0.7/24,gw=10.0.0.254,bridge=vmbr1,tag=10","net1":"name=eth1,ip=10.0.1.2/24,gw=10.0.1.254,bridge=vmbr1,tag=20","net2":"name=eth2,ip=10.0.3.2/24,gw=10.0.3.254,bridge=vmbr1,tag=40","net3":"name=eth3,ip=10.1.0.102/24,gw=10.1.0.254,bridge=vmbr2,tag=100"}'
|
||||
pubkey: "{{ ssh_pub }}"
|
||||
state: present
|
||||
|
||||
- name: Create LXC for Bind9 (CT106)
|
||||
proxmox:
|
||||
api_user: root@pam
|
||||
api_password: "{{ pass_pve }}"
|
||||
api_host: '10.1.0.1'
|
||||
node: beta
|
||||
cpus: 1
|
||||
cores: 1
|
||||
memory: 1024
|
||||
disk: 16
|
||||
swap: 1024
|
||||
storage: local-zfs
|
||||
ostemplate: 'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz'
|
||||
password: "{{ pass_dns }}"
|
||||
hostname: DNS
|
||||
vmid: 106
|
||||
onboot: yes
|
||||
unprivileged: yes
|
||||
nameserver: '80.67.169.12,80.67.169.40'
|
||||
netif: '{"net0":"name=eth0,ip=10.0.0.253/24,gw=10.0.0.254,bridge=vmbr1,tag=10","net1":"name=eth1,ip=10.0.1.253/24,gw=10.0.1.254,bridge=vmbr1,tag=20","net2":"name=eth2,ip=10.0.2.253/24,gw=10.0.2.254,bridge=vmbr1,tag=30","net3":"name=eth3,ip=10.1.0.106/24,gw=10.1.0.254,bridge=vmbr2,tag=100"}'
|
||||
pubkey: "{{ ssh_pub }}"
|
||||
state: present
|
||||
|
||||
- name: Start DMZ containers
|
||||
proxmox:
|
||||
api_user: root@pam
|
||||
api_password: "{{ pass_pve }}"
|
||||
api_host: '10.1.0.1'
|
||||
vmid: "{{ item }}"
|
||||
state: started
|
||||
with_items:
|
||||
- '101'
|
||||
- '102'
|
||||
- '106'
|
||||
|
||||
# Pas de config des proxy car sur accès au net depuis la DMZ.
|
||||
|
||||
- hosts: zonedmz
|
||||
tasks:
|
||||
- name: Apt Update for DMZ
|
||||
apt:
|
||||
update_cache: yes
|
||||
|
||||
- name: Apt Upgrade for DMZ
|
||||
apt:
|
||||
upgrade: dist
|
||||
|
||||
- name: Install utils for DMZ
|
||||
apt:
|
||||
pkg:
|
||||
- vim
|
||||
- net-tools
|
||||
- nmap
|
||||
- dnsutils
|
||||
- ferm
|
||||
- unattended-upgrades
|
||||
- apt-listchanges
|
||||
- wget
|
||||
- curl
|
||||
- git
|
||||
|
||||
- name: Unattended-Upgrades Activation for DMZ
|
||||
shell: |
|
||||
echo unattended-upgrades unattended-upgrades/enable_auto_updates boolean true | debconf-set-selections
|
||||
dpkg-reconfigure -f noninteractive unattended-upgrades
|
||||
echo 'Unattended-Upgrade::Mail "root";' >> /etc/apt/apt.conf.d/50unattended-upgrades
|
||||
|
||||
- hosts: haproxy
|
||||
tasks:
|
||||
- name: Install requirement for HAProxy
|
||||
apt:
|
||||
pkg:
|
||||
- haproxy
|
||||
- hatop
|
||||
- certbot
|
||||
- nginx
|
||||
- psmisc
|
||||
- keepalived
|
||||
|
||||
- name: Create hasync for HAProxy
|
||||
user:
|
||||
name: hasync
|
||||
password: "{{ pass_hasync_same }}"
|
||||
state: present
|
||||
|
||||
- name: Enable service for HAProxy
|
||||
systemd:
|
||||
name: "{{ item }}"
|
||||
enabled: yes
|
||||
with_items:
|
||||
- 'haproxy'
|
||||
- 'nginx'
|
||||
- 'keepalived'
|
||||
|
||||
- name: Prepare NGINX for HAProxy
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- '/etc/nginx/sites-enabled/default'
|
||||
- '/etc/nginx/sites-available/default'
|
||||
- '/etc/letsencrypt/live/README'
|
||||
|
||||
- name: Prepare HAProxy for HAProxy
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
with_items:
|
||||
- '/home/hasync/letsencrypt-requests'
|
||||
- '/etc/ssl/letsencrypt'
|
||||
|
||||
- name: Prepare keepalived for HAProxy
|
||||
sysctl:
|
||||
name: net.ipv4.ip_forward
|
||||
value: '1'
|
||||
sysctl_set: yes
|
||||
state: present
|
||||
reload: yes
|
||||
|
||||
- name: Prepare keepalived for HAProxy
|
||||
sysctl:
|
||||
name: net.ipv4.ip_nonlocal_bind
|
||||
value: '1'
|
||||
sysctl_set: yes
|
||||
state: present
|
||||
reload: yes
|
||||
|
||||
- name: Copy cert deploy script for HAProxy
|
||||
copy:
|
||||
src: /root/src/script_haproxy_deploy_cert.sh
|
||||
dest: /root/install-certs.sh
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0740'
|
||||
|
||||
- name: Copy cert renew script for HAProxy
|
||||
copy:
|
||||
src: /root/src/script_haproxy_renew_cert.sh
|
||||
dest: /home/hasync/renew.sh
|
||||
owner: hasync
|
||||
group: hasync
|
||||
mode: '0740'
|
||||
|
||||
- name: Copy ferm configuration for HAProxy
|
||||
copy:
|
||||
src: /root/src/ferm/haproxy_ferm.conf
|
||||
dest: /etc/ferm/ferm.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0640'
|
||||
|
||||
- name: Restart ferm for HAProxy
|
||||
systemd:
|
||||
name: "ferm"
|
||||
state: restarted
|
||||
|
||||
- hosts: dns
|
||||
tasks:
|
||||
- name: Install requirement for Bind9
|
||||
apt:
|
||||
pkg:
|
||||
- bind9
|
||||
|
||||
- name: Enable service for Bind9
|
||||
systemd:
|
||||
name: "{{ item }}"
|
||||
enabled: yes
|
||||
with_items:
|
||||
- 'bind9'
|
||||
|
||||
- name: Prepare NGINX for HAProxy
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- '/etc/nginx/sites-enabled/default'
|
||||
- '/etc/nginx/sites-available/default'
|
||||
- '/etc/letsencrypt/live/README'
|
||||
|
||||
- name: Prepare Bind9
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
with_items:
|
||||
- '/var/log/dns/'
|
||||
- '/etc/bind/zones'
|
||||
|
||||
- name: Prepare Bind9
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: touch
|
||||
owner: bind
|
||||
group: bind
|
||||
mode: '0640'
|
||||
with_items:
|
||||
- '/var/log/dns/query.log'
|
||||
- '/var/log/dns/error.log'
|
||||
|
||||
- name: Copy ferm configuration for HAProxy
|
||||
copy:
|
||||
src: /root/src/ferm/dns_ferm.conf
|
||||
dest: /etc/ferm/ferm.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0640'
|
||||
|
||||
- name: Restart ferm for HAProxy
|
||||
systemd:
|
||||
name: "ferm"
|
||||
state: restarted
|
|
@ -0,0 +1,29 @@
|
|||
@def $IF_ADMIN = eth3;
|
||||
@def $IF_FRONT = eth0;
|
||||
@def $IF_BACK = (eth1 eth2);
|
||||
@def $OPEN_PORT_FRONT = (22 53);
|
||||
@def $PROTO_FRONT = (tcp udp);
|
||||
@def $OPEN_PORT_BACK = (22 53);
|
||||
@def $PROTO_BACK = (tcp udp);
|
||||
@def $HAVE_BACK = 1; #0 pour NON 1 pour OUI
|
||||
|
||||
table filter {
|
||||
chain INPUT {
|
||||
policy DROP;
|
||||
mod state state INVALID DROP;
|
||||
mod state state (ESTABLISHED RELATED) ACCEPT;
|
||||
interface lo ACCEPT;
|
||||
interface $IF_ADMIN ACCEPT;
|
||||
interface $IF_FRONT proto $PROTO_FRONT dport $OPEN_PORT_FRONT ACCEPT;
|
||||
|
||||
@if $HAVE_BACK {
|
||||
interface $IF_BACK proto $PROTO_BACK dport $OPEN_PORT_BACK ACCEPT;
|
||||
}
|
||||
|
||||
proto icmp icmp-type echo-request ACCEPT;
|
||||
}
|
||||
|
||||
chain OUTPUT policy ACCEPT;
|
||||
|
||||
chain FORWARD policy DROP;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
@def $IF_ADMIN = eth3;
|
||||
@def $IF_FRONT = eth0;
|
||||
@def $IF_BACK = (eth1 eth2);
|
||||
@def $OPEN_PORT_FRONT = (22 80 443);
|
||||
@def $PROTO_FRONT = (tcp);
|
||||
@def $OPEN_PORT_BACK = (22 80);
|
||||
@def $PROTO_BACK = (tcp);
|
||||
@def $HAVE_BACK = 1; #0 pour NON 1 pour OUI
|
||||
|
||||
table filter {
|
||||
chain INPUT {
|
||||
policy DROP;
|
||||
mod state state INVALID DROP;
|
||||
mod state state (ESTABLISHED RELATED) ACCEPT;
|
||||
interface lo ACCEPT;
|
||||
interface $IF_ADMIN ACCEPT;
|
||||
interface $IF_FRONT proto $PROTO_FRONT dport $OPEN_PORT_FRONT ACCEPT;
|
||||
|
||||
@if $HAVE_BACK {
|
||||
interface $IF_BACK proto $PROTO_BACK dport $OPEN_PORT_BACK ACCEPT;
|
||||
}
|
||||
|
||||
proto icmp icmp-type echo-request ACCEPT;
|
||||
}
|
||||
|
||||
chain OUTPUT policy ACCEPT;
|
||||
|
||||
chain FORWARD policy DROP;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
if [ "$(ip a | grep -c "10.0.0.8")" -ge 1 ]; then
|
||||
ct_ip=$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 | tail -c2)
|
||||
if [ $ct_ip = 6 ]
|
||||
then
|
||||
other_ip=10.0.0.7
|
||||
fi
|
||||
if [ $ct_ip = 7 ]
|
||||
then
|
||||
other_ip=10.0.0.6
|
||||
fi
|
||||
certbot renew
|
||||
rm -rf /etc/ssl/letsencrypt/*
|
||||
for domain in $(ls /etc/letsencrypt/live); do
|
||||
cat /etc/letsencrypt/live/$domain/privkey.pem /etc/letsencrypt/live/$domain/fullchain.pem > /etc/ssl/letsencrypt/$domain.pem
|
||||
done
|
||||
scp -r /etc/ssl/letsencrypt/* hasync@$other_ip:/etc/ssl/letsencrypt
|
||||
else
|
||||
fi
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
if [ "$(ip a | grep -c "10.0.0.8")" -ge 1 ]; then
|
||||
ct_ip=$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 | tail -c2)
|
||||
if [ $ct_ip = 6 ]
|
||||
then
|
||||
other_ip=10.0.0.7
|
||||
fi
|
||||
if [ $ct_ip = 7 ]
|
||||
then
|
||||
other_ip=10.0.0.6
|
||||
fi
|
||||
certbot renew
|
||||
rm -rf /etc/ssl/letsencrypt/*
|
||||
for domain in $(ls /etc/letsencrypt/live); do
|
||||
cat /etc/letsencrypt/live/$domain/privkey.pem /etc/letsencrypt/live/$domain/fullchain.pem > /etc/ssl/letsencrypt/$domain.pem
|
||||
done
|
||||
scp -r /etc/ssl/letsencrypt/* hasync@$other_ip:/etc/ssl/letsencrypt
|
||||
else
|
||||
fi
|
|
@ -0,0 +1,170 @@
|
|||
# NGINX REVERSE
|
||||
# Nginx Alpha (CT104) : 10.0.1.3 | 10.0.2.4 | 10.1.0.104
|
||||
# Nginx Beta (CT105) : 10.0.1.4 | 10.0.2.5 | 10.1.0.105
|
||||
# Gateway 10.0.1.0/24 -> 10.0.1.254
|
||||
# Gateway 10.0.2.0/24 -> 10.0.2.254
|
||||
# Gateway 10.1.0.0/24 -> 10.1.0.254
|
||||
|
||||
# Créer les containers, les mets à jours, configure les mises à jours de sécurité automatique,
|
||||
# installe des paquets utile et ceux des services, met en place ferm via notre template.
|
||||
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- include_vars: /root/src/source_pve.yml
|
||||
- include_vars: /root/src/password_proxy.yml
|
||||
|
||||
- name: Create LXC for Nginx Master (CT104)
|
||||
proxmox:
|
||||
api_user: root@pam
|
||||
api_password: "{{ pass_pve }}"
|
||||
api_host: '10.1.0.1'
|
||||
node: alpha
|
||||
cpus: 1
|
||||
cores: 2
|
||||
memory: 2048
|
||||
disk: 16
|
||||
swap: 1024
|
||||
storage: local-zfs
|
||||
ostemplate: 'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz'
|
||||
password: "{{ pass_nginx_alpha }}"
|
||||
hostname: NginxMaster
|
||||
vmid: 104
|
||||
onboot: yes
|
||||
unprivileged: yes
|
||||
nameserver: '10.0.1.253'
|
||||
netif: '{"net0":"name=eth0,ip=10.0.1.3/24,gw=10.0.1.254,bridge=vmbr1,tag=20","net1":"name=eth1,ip=10.0.2.4/24,gw=10.0.2.254,bridge=vmbr1,tag=30","net3":"name=eth3,ip=10.1.0.104/24,gw=10.1.0.254,bridge=vmbr2,tag=100"}'
|
||||
pubkey: "{{ ssh_pub }}"
|
||||
state: present
|
||||
|
||||
- name: Create LXC for Nginx Slave (CT105)
|
||||
proxmox:
|
||||
api_user: root@pam
|
||||
api_password: "{{ pass_pve }}"
|
||||
api_host: '10.1.0.1'
|
||||
node: beta
|
||||
cpus: 1
|
||||
cores: 2
|
||||
memory: 2048
|
||||
disk: 16
|
||||
swap: 1024
|
||||
storage: local-zfs
|
||||
ostemplate: 'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz'
|
||||
password: "{{ pass_nginx_slave }}"
|
||||
hostname: NginxSlave
|
||||
vmid: 105
|
||||
onboot: yes
|
||||
unprivileged: yes
|
||||
nameserver: '10.0.1.253'
|
||||
netif: '{"net0":"name=eth0,ip=10.0.1.4/24,gw=10.0.1.254,bridge=vmbr1,tag=20","net1":"name=eth1,ip=10.0.2.5/24,gw=10.0.2.254,bridge=vmbr1,tag=30","net3":"name=eth3,ip=10.1.0.105/24,gw=10.1.0.254,bridge=vmbr2,tag=100"}'
|
||||
pubkey: "{{ ssh_pub }}"
|
||||
state: present
|
||||
|
||||
- name: Start Proxy containers
|
||||
proxmox:
|
||||
api_user: root@pam
|
||||
api_password: "{{ pass_pve }}"
|
||||
api_host: '10.1.0.1'
|
||||
vmid: "{{ item }}"
|
||||
state: started
|
||||
with_items:
|
||||
- '104'
|
||||
- '105'
|
||||
|
||||
- hosts: zoneproxy
|
||||
tasks:
|
||||
- name: APT configuration for Proxy
|
||||
copy:
|
||||
dest: "/etc/apt/apt.conf.d/01proxy"
|
||||
content: |
|
||||
Acquire::http {
|
||||
Proxy "http://10.0.1.252:9999";
|
||||
};
|
||||
|
||||
- name: WGET configuration for Proxy
|
||||
copy:
|
||||
dest: "/root/.wgetrc"
|
||||
content: |
|
||||
http_proxy = http://10.0.1.252:3128/
|
||||
https_proxy = http://10.0.1.252:3128/
|
||||
use_proxy = on
|
||||
|
||||
- name: Apt Update for Proxy
|
||||
apt:
|
||||
update_cache: yes
|
||||
|
||||
- name: Apt Upgrade for Proxy
|
||||
apt:
|
||||
upgrade: dist
|
||||
|
||||
- name: Install utils for Proxy
|
||||
apt:
|
||||
pkg:
|
||||
- vim
|
||||
- net-tools
|
||||
- nmap
|
||||
- dnsutils
|
||||
- ferm
|
||||
- unattended-upgrades
|
||||
- apt-listchanges
|
||||
- wget
|
||||
- curl
|
||||
- git
|
||||
|
||||
- name: Unattended-Upgrades Activation for Proxy
|
||||
shell: |
|
||||
echo unattended-upgrades unattended-upgrades/enable_auto_updates boolean true | debconf-set-selections
|
||||
dpkg-reconfigure -f noninteractive unattended-upgrades
|
||||
echo 'Unattended-Upgrade::Mail "root";' >> /etc/apt/apt.conf.d/50unattended-upgrades
|
||||
|
||||
- hosts: nginx
|
||||
tasks:
|
||||
- name: Install requirement for Nginx
|
||||
apt:
|
||||
pkg:
|
||||
- nginx
|
||||
|
||||
- name: Enable service for Nginx
|
||||
systemd:
|
||||
name: "{{ item }}"
|
||||
enabled: yes
|
||||
with_items:
|
||||
- 'nginx'
|
||||
|
||||
- name: Prepare NGINX for Nginx
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- '/etc/nginx/sites-enabled/default'
|
||||
- '/etc/nginx/sites-available/default'
|
||||
|
||||
- name: Prepare Nginx for Nginx
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
with_items:
|
||||
- '/home/hasync/letsencrypt-requests'
|
||||
- '/etc/ssl/letsencrypt'
|
||||
|
||||
- name: Copy webhost deploy script for Nginx
|
||||
copy:
|
||||
src: /root/src/script_nginx.sh
|
||||
dest: /root/deploy-webhost.sh
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0740'
|
||||
|
||||
- name: Copy ferm configuration for Nginx
|
||||
copy:
|
||||
src: /root/src/ferm/nginx_ferm.conf
|
||||
dest: /etc/ferm/ferm.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0640'
|
||||
|
||||
- name: Restart ferm for Nginx
|
||||
systemd:
|
||||
name: "ferm"
|
||||
state: restarted
|
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
if [ "$#" -eq "0" ]
|
||||
then
|
||||
echo "Bad Usage !"
|
||||
else
|
||||
ct_ip=$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 | tail -c2)
|
||||
if [ $ct_ip = 3 ]
|
||||
then
|
||||
other_ip=10.0.1.4
|
||||
fi
|
||||
if [ $ct_ip = 4 ]
|
||||
then
|
||||
other_ip=10.0.1.3
|
||||
fi
|
||||
if [ -f "/etc/nginx/sites-available/$1" ]
|
||||
then
|
||||
ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled
|
||||
systemctl restart nginx.service
|
||||
scp /etc/nginx/sites-available/$1 root@$other_ip:/etc/nginx/sites-available/
|
||||
ssh root@$other_ip "ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled"
|
||||
ssh root@$other_ip 'systemctl restart nginx.service'
|
||||
else
|
||||
echo "Not exist !"
|
||||
fi
|
||||
fi
|
Loading…
Reference in New Issue