From 0a62df7352bcff0be94deaf419f7cc04c8b9de49 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Sat, 10 Feb 2024 01:13:40 +0000 Subject: [PATCH] feat: Ajout des profiles --- profiles/applications/gitea.profile.yaml | 42 ++++++ profiles/applications/nextcloud.profile.yaml | 33 +++++ .../applications/postgresql-snap.profile.yaml | 17 +++ profiles/applications/postgresql.profile.yaml | 17 +++ .../applications/traefik-user.profile.yaml | 42 ++++++ profiles/applications/traefik.profile.yaml | 140 ++++++++++++++++++ profiles/networking/back.profile.yaml | 7 + profiles/networking/front.profile.yaml | 7 + profiles/networking/frontback.profile.yaml | 12 ++ profiles/networking/home.profile.yaml | 7 + profiles/networking/public.profile.yaml | 7 + setup-profiles.bash | 23 +++ 12 files changed, 354 insertions(+) create mode 100644 profiles/applications/gitea.profile.yaml create mode 100644 profiles/applications/nextcloud.profile.yaml create mode 100644 profiles/applications/postgresql-snap.profile.yaml create mode 100644 profiles/applications/postgresql.profile.yaml create mode 100644 profiles/applications/traefik-user.profile.yaml create mode 100644 profiles/applications/traefik.profile.yaml create mode 100644 profiles/networking/back.profile.yaml create mode 100644 profiles/networking/front.profile.yaml create mode 100644 profiles/networking/frontback.profile.yaml create mode 100644 profiles/networking/home.profile.yaml create mode 100644 profiles/networking/public.profile.yaml create mode 100755 setup-profiles.bash diff --git a/profiles/applications/gitea.profile.yaml b/profiles/applications/gitea.profile.yaml new file mode 100644 index 0000000..229def4 --- /dev/null +++ b/profiles/applications/gitea.profile.yaml @@ -0,0 +1,42 @@ +name: gitea +description: Install gitea +config: + cloud-init.vendor-data: | + #cloud-config + + timezone: Europe/Paris + locale: fr_FR.UTF-8 + + # Packages + package_update: true + package_upgrade: true + packages: + - unzip + + # Users + users: + - default + - name: gitea + groups: sudo + shell: /bin/bash + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + + # Configure second network interface + write_files: + - path: "/etc/netplan/eth1.yaml" + permissions: "0755" + content: | + network: + version: 2 + ethernets: + eth1: + dhcp4: true + + runcmd: + # Apply network config + - [ netplan, generate ] + - [ netplan, apply ] + + # Install gitea + - [ snap, install, gitea ] + diff --git a/profiles/applications/nextcloud.profile.yaml b/profiles/applications/nextcloud.profile.yaml new file mode 100644 index 0000000..0e4dbef --- /dev/null +++ b/profiles/applications/nextcloud.profile.yaml @@ -0,0 +1,33 @@ +name: nextcloud +description: Install Nextcloud +config: + cloud-init.vendor-data: | + #cloud-config + + # Regional settings + timezone: Europe/Paris + locale: fr_FR.UTF-8 + + # Packages + package_update: true + package_upgrade: true + packages: [] + + # Users + users: + - default + - name: nextcloud + groups: sudo + shell: /bin/bash + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + + runcmd: + # Install Nextcloud + - [ snap, install, nextcloud ] + +devices: + nextcloud-data: + type: disk + pool: zfs + source: nextcloud-data + path: /var/snap/nextcloud diff --git a/profiles/applications/postgresql-snap.profile.yaml b/profiles/applications/postgresql-snap.profile.yaml new file mode 100644 index 0000000..c42498c --- /dev/null +++ b/profiles/applications/postgresql-snap.profile.yaml @@ -0,0 +1,17 @@ +name: postgresql +description: Install postgresql +config: + cloud-init.vendor-data: | + #cloud-config + package_update: true + package_upgrade: true + timezone: Europe/Paris + locale: fr_FR.UTF-8 + users: + - default + - name: postgres + groups: sudo + shell: /bin/bash + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + runcmd: + - [ snap, install, postgresql96 ] diff --git a/profiles/applications/postgresql.profile.yaml b/profiles/applications/postgresql.profile.yaml new file mode 100644 index 0000000..dd33479 --- /dev/null +++ b/profiles/applications/postgresql.profile.yaml @@ -0,0 +1,17 @@ +name: postgresql +description: Install postgresql +config: + cloud-init.vendor-data: | + #cloud-config + package_update: true + package_upgrade: true + packages: + - postgresql + timezone: Europe/Paris + locale: fr_FR.UTF-8 +devices: + postgresql-data: + type: disk + pool: zfs + source: postgresql-data + path: /var/lib/postgresql diff --git a/profiles/applications/traefik-user.profile.yaml b/profiles/applications/traefik-user.profile.yaml new file mode 100644 index 0000000..e68bbf5 --- /dev/null +++ b/profiles/applications/traefik-user.profile.yaml @@ -0,0 +1,42 @@ +name: traefik +description: Install traefik +config: + cloud-init.user-data: | + #cloud-config + + write_files: + - path: "/etc/traefik/traefik.yaml" + owner: traefik:traefik + permissions: "0644" + content: | + ## Static configuration + entryPoints: + web: + address: ":80" + http: + redirections: + entryPoint: + to: websecure + scheme: https + + websecure: + address: ":443" + + providers: + file: + directory: "./dynamic" + + log: + level: DEBUG + + accessLog: + filePath: "/var/log/traefik/access.log.json" + format: "json" + api: + # Dashboard + # + # Optional + # Default: true + # + dashboard: true + insecure: true diff --git a/profiles/applications/traefik.profile.yaml b/profiles/applications/traefik.profile.yaml new file mode 100644 index 0000000..9e5bd43 --- /dev/null +++ b/profiles/applications/traefik.profile.yaml @@ -0,0 +1,140 @@ +name: traefik +description: Install traefik +config: + cloud-init.vendor-data: | + #cloud-config + + timezone: Europe/Paris + locale: fr_FR.UTF-8 + + # Packages + package_update: true + package_upgrade: true + packages: + - tar + - unzip + - wget + + # Users + users: + - default + - name: traefik + groups: sudo + shell: /bin/bash + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + + # Configure second network interface + write_files: + - path: "/etc/netplan/eth1.yaml" + permissions: "0644" + content: | + network: + version: 2 + ethernets: + eth1: + dhcp4: true + - path: "/etc/systemd/system/traefik.service" + owner: root:root + permissions: "0644" + content: | + [Unit] + Description=traefik proxy + After=network-online.target + Wants=network-online.target systemd-networkd-wait-online.service + + [Service] + Restart=on-abnormal + + ; User and group the process will run as. + User=traefik + Group=traefik + + ; Always set "-root" to something safe in case it gets forgotten in the traefikfile. + ExecStart=/usr/local/bin/traefik --configfile=/etc/traefik/traefik.yaml + + ; Limit the number of file descriptors; see `man systemd.exec` for more limit settings. + LimitNOFILE=1048576 + + ; Use private /tmp and /var/tmp, which are discarded after traefik stops. + PrivateTmp=true + ; Use a minimal /dev (May bring additional security if switched to 'true', but it may not work on Raspberry Pi's or other devices, so it has been disabled in this dist.) + PrivateDevices=true + ; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys. + ProtectHome=true + ; Make /usr, /boot, /etc and possibly some more folders read-only. + ProtectSystem=full + ; … except /etc/ssl/traefik, because we want Letsencrypt-certificates there. + ; This merely retains r/w access rights, it does not add any new. Must still be writable on the host! + ReadWriteDirectories=/etc/traefik/acme + ; The following additional security directives only work with systemd v229 or later. + ; They further restrict privileges that can be gained by traefik. Uncomment if you like. + ; Note that you may have to add capabilities required by any plugins in use. + CapabilityBoundingSet=CAP_NET_BIND_SERVICE + AmbientCapabilities=CAP_NET_BIND_SERVICE + NoNewPrivileges=true + [Install] + WantedBy=multi-user.target + - path: "/etc/traefik/traefik.yaml" + owner: traefik:traefik + permissions: "0644" + content: | + ## Static configuration + entryPoints: + web: + address: ":80" + http: + redirections: + entryPoint: + to: websecure + scheme: https + + websecure: + address: ":443" + + providers: + file: + directory: "./dynamic" + + log: + level: DEBUG + + accessLog: + filePath: "/var/log/traefik/access.log.json" + format: "json" + api: + # Dashboard + # + # Optional + # Default: true + # + dashboard: true + insecure: true + + + runcmd: + # Apply network config + - [ netplan, generate ] + - [ netplan, apply ] + + # Install traefik binary + - [ sleep, 5 ] + - [ wget, "https://github.com/traefik/traefik/releases/download/v2.11.0-rc2/traefik_v2.11.0-rc2_linux_amd64.tar.gz", -O, /tmp/traefik.tar.gz ] + - [ tar, vxzf, /tmp/traefik.tar.gz, -C, /tmp ] + - [ cp, /tmp/traefik, /usr/local/bin ] + - [ chown, root:root, /usr/local/bin/traefik ] + - [ chmod, 755, /usr/local/bin/traefik ] + - [ setcap, 'cap_net_bind_service=+ep', /usr/local/bin/traefik ] + # Prepare traefik config + - [ mkdir, -p, /etc/traefik ] + - [ mkdir, -p, /etc/traefik/acme ] + - [ mkdir, -p, /etc/traefik/dynamic ] + - [ mkdir, -p, /var/log/traefik ] + - [ chown, -R, root:root, /etc/traefik ] + - [ chown, -R, traefik:traefik, /etc/traefik/acme ] + - [ chown, -R, traefik:traefik, /etc/traefik/dynamic ] + - [ chown, -R, traefik:traefik, /var/log/traefik ] + # Enable and start the service + - [ systemctl, daemon-reload ] + - [ systemctl, enable, traefik.service ] + - [ systemctl, start, traefik.service ] + diff --git a/profiles/networking/back.profile.yaml b/profiles/networking/back.profile.yaml new file mode 100644 index 0000000..8f42b16 --- /dev/null +++ b/profiles/networking/back.profile.yaml @@ -0,0 +1,7 @@ +name: back +description: Profile that provide a network interface attached to the back bridge +devices: + eth0: + nictype: bridged + parent: back + type: nic diff --git a/profiles/networking/front.profile.yaml b/profiles/networking/front.profile.yaml new file mode 100644 index 0000000..ab952cc --- /dev/null +++ b/profiles/networking/front.profile.yaml @@ -0,0 +1,7 @@ +name: front +description: Profile that provide a network interface attached to the front bridge +devices: + eth0: + nictype: bridged + parent: front + type: nic diff --git a/profiles/networking/frontback.profile.yaml b/profiles/networking/frontback.profile.yaml new file mode 100644 index 0000000..18fc687 --- /dev/null +++ b/profiles/networking/frontback.profile.yaml @@ -0,0 +1,12 @@ +name: frontback +description: Profile that provide a network interface attached to the front bridge + and a network interface attached to the back bridge +devices: + eth0: + nictype: bridged + parent: front + type: nic + eth1: + nictype: bridged + parent: back + type: nic diff --git a/profiles/networking/home.profile.yaml b/profiles/networking/home.profile.yaml new file mode 100644 index 0000000..1abc54e --- /dev/null +++ b/profiles/networking/home.profile.yaml @@ -0,0 +1,7 @@ +name: home +description: Profile that provide a network interface attached to the home bridge +devices: + eth0: + nictype: bridged + parent: home + type: nic diff --git a/profiles/networking/public.profile.yaml b/profiles/networking/public.profile.yaml new file mode 100644 index 0000000..6b3ed22 --- /dev/null +++ b/profiles/networking/public.profile.yaml @@ -0,0 +1,7 @@ +name: public +description: Profile that provide a network interface attached to the public bridge +devices: + eth0: + nictype: bridged + parent: public + type: nic diff --git a/setup-profiles.bash b/setup-profiles.bash new file mode 100755 index 0000000..494cd1c --- /dev/null +++ b/setup-profiles.bash @@ -0,0 +1,23 @@ +#!/bin/bash + +export BASEDIR=$( cd $(dirname $0) && pwd ) + +echo "BASEDIR=$BASEDIR" + +( + cd $BASEDIR + for file in profiles/*/*profile.yaml + do + name=$(basename $file .profile.yaml) + echo "--- Profile ${name} ---" + if ( lxc profile show "${name}" &> /dev/null ) + then + echo "Profile ${name} already exists. Skipping..." + else + echo "Profile ${name} does not exists. Creating..." + lxc profile create "${name}" + fi + echo "Updating..." + echo lxc profile edit "${name}" < "${file}" + done +)