Files
lxd-profiles/profiles/applications/traefik.profile.yaml
T

156 lines
5.1 KiB
YAML

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
- git
# Users
users:
- default
- name: traefik
groups: sudo
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
# Configure second network interface
write_files:
- path: "/etc/systemd/system/traefik.path"
owner: root:root
permissions: "0644"
content: |
[Unit]
Description="Monitor the traefik config files"
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
[Path]
PathModified=/etc/traefik/traefik.yaml
PathModified=/etc/traefik/dynamic
Unit=traefik.service
[Install]
WantedBy=multi-user.target
- path: "/etc/systemd/system/traefik.service"
owner: root:root
permissions: "0644"
content: |
[Unit]
Description="traefik proxy service"
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
[Service]
; User and group the process will run as.
;User=traefik
;Group=traefik
;=> TODO : fix permissions issues on certificates
ExecStart=/usr/local/bin/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
Restart=on-abnormal
; 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"
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/traefik_v2.11.0_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
# => TODO : git clone
- [ 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, traefik:traefik, /etc/traefik/traefik.yaml ]
- [ chmod, '640', '/etc/traefik/traefik.yaml' ]
- [ 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.path ]
- [ systemctl, start, traefik.path ]
- [ systemctl, start, traefik.service ]