PhoenyxRLP

Untitled

Nov 20th, 2024 (edited)
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 10.30 KB | Source Code | 0 0
  1. Authelia Integration in Traefik-Crowdsec-Stack (Traefik3)
  2.  
  3. Anlegen von Verzeichnissen.
  4.  
  5. —
  6. mkdir -p /opt/containers/traefik-crowdsec-stack/data/authelia/config
  7. mkdir -p /root/secrets/authelia
  8. chmod 644 /root/secrets/authelia
  9. —
  10.  
  11. Erstellen der Secrets
  12.  
  13. —
  14. tr -cd '[:alnum:]' </dev/urandom | fold -w "64" | head -n 1 | tr -d '\n' | sudo tee /root/secrets/authelia/authelia_jwt_secret
  15. tr -cd '[:alnum:]' </dev/urandom | fold -w "64" | head -n 1 | tr -d '\n' | sudo tee /root/secrets/authelia/authelia_storage_encryption_key
  16. tr -cd '[:alnum:]' </dev/urandom | fold -w "64" | head -n 1 | tr -d '\n' | sudo tee /root/secrets/authelia/authelia_session_secret
  17. —
  18.  
  19. Das Secret authelia_notifier_smtp_password enthält euch Password zum Email Account wenn Ihr SMTP Notifications nutzen wollt.
  20. Wenn ihr File Notifications nutzen wollte dann lasst dies bitte weg.
  21.  
  22. Ergänzen der docker-compose.yml
  23.  
  24. —
  25.  
  26. include:
  27.  ...
  28.   - compose/authelia.yml
  29.  
  30. —
  31.  
  32. Erstellen der .env File in /opt/containers/traefik-crowdsec-stack/data/authelia/
  33. Legt hier bitte eine .env File mit folgendem Inhalt an.
  34.  
  35. —
  36.  
  37. SECRETDIR=/root/secrets
  38. TZ=$TZ
  39. # Rest ist optional, wenn ihr hier was anpassen wollt.
  40. # Da ich lieber Feste IP Adressen einsetze auch bei Docker werden diese hier bei mir festgelegt.
  41. # Damit ich keine vergesse, wird das in der authelia.yml noch mal wiederholt.
  42. # Wenn ihr das nicht wollt dann lasst es einfach weg.
  43. SERVICES_AUTHELIA_HOSTNAME=authelia
  44. SERVICES_TRAEFIK_LABELS_AUTHELIA_HOST=HOST(your.domain.tld)
  45. SERVICES_AUTHELIA_NETWORKS_PROXY_IPV4=172.31.191.200
  46. SERVICES_AUTHELIA_NETWORKS_PROXY_IPV6=fd00:1:be:a:7001:0:3e:7f00
  47. SERVICES_AUTHELIA_NETWORKS_SOCKET_PROXY_IPV4=172.31.255.200
  48. SERVICES_AUTHELIA_NETWORKS_SOCKET_PROXY_IPV6=fd00:1:be:a:7001:0:3e:8f00
  49.  
  50. —
  51.  
  52. Erstellen authelia.yml im compose Verzeichnis.
  53. nano /opt/containers/traefik-crowdsec-stack/compose/authelia.yml
  54.  
  55. —
  56.  
  57. services:
  58.   authelia:
  59.     container_name: 'authelia'
  60.     depends_on:
  61.       traefik:
  62.         condition: service_healthy
  63.     hostname: ${SERVICES_AUTHELIA_HOSTNAME:-authelia}
  64.     image: 'docker.io/authelia/authelia:latest'
  65.     restart: 'unless-stopped'
  66.     env_file: ${ABSOLUTE_PATH}/data/authelia/.env
  67.     networks:
  68.       proxy:
  69.         ipv4_address: ${SERVICES_AUTHELIA_NETWORKS_PROXY_IPV4:-172.31.191.200}
  70.         ipv6_address: ${SERVICES_AUTHELIA_NETWORKS_PROXY_IPV6:-fd00:1:be:a:7001:0:3e:7f00}
  71.       socket_proxy:
  72.         ipv4_address: ${SERVICES_AUTHELIA_NETWORKS_SOCKET_PROXY_IPV4:-172.31.255.200}
  73.         ipv6_address: ${SERVICES_AUTHELIA_NETWORKS_SOCKET_PROXY_IPV6:-fd00:1:be:a:7001:0:3e:8f00}
  74.     volumes:
  75.      - /etc/localtime:/etc/localtime:ro
  76.       - ${ABSOLUTE_PATH}/data/authelia/config:/config
  77.     secrets: ['JWT_SECRET', 'SESSION_SECRET', 'STORAGE_ENCRYPTION_KEY', 'NOTIFIER_SMTP_PASSWORD']
  78.     environment:
  79.       AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET_FILE: '/run/secrets/JWT_SECRET'
  80.       AUTHELIA_SESSION_SECRET_FILE: '/run/secrets/SESSION_SECRET'
  81.       AUTHELIA_STORAGE_ENCRYPTION_KEY_FILE: '/run/secrets/STORAGE_ENCRYPTION_KEY'
  82.       AUTHELIA_NOTIFIER_SMTP_PASSWORD_FILE: '/run/secrets/NOTIFIER_SMTP_PASSWORD'
  83.     labels:
  84.       traefik.enable: true
  85.       traefik.http.routers.authelia.rule: HOST(auth.domain.tld)
  86.       traefik.http.routers.authelia.entryPoints: websecure
  87.       traefik.http.routers.authelia.tls: true
  88.       traefik.http.routers.authelia.tls.certresolver: tls_resolver
  89.       traefik.http.services.authelia.loadbalancer.server.port: 9091
  90.       traefik.http.middlewares.authelia.forwardAuth.address: https://authelia:9091/api/authz/forward-auth
  91.       traefik.http.routers.authelia.middlewares: default@file
  92.       traefik.http.routers.authelia.service: authelia
  93.     security_opt:
  94.      - no-new-privileges:true
  95. secrets:
  96.   JWT_SECRET:
  97.     file: ${SECRETDIR}/authelia/authelia_jwt_secret
  98.   SESSION_SECRET:
  99.     file: ${SECRETDIR}/authelia/authelia_session_secret
  100.   STORAGE_ENCRYPTION_KEY:
  101.     file: ${SECRETDIR}/authelia/authelia_storage_encryption_key
  102.   NOTIFIER_SMTP_PASSWORD:
  103.     file: ${SECRETDIR}/authelia/authelia_notifier_smtp_password
  104.  
  105. …
  106.  
  107. Erzeugen Traefik Middelware Yml für Authelia.
  108. Erzeugt im Verzeichnis /opt/containers/traefik-crowdsec-stack/data/traefik/dynamic_conf
  109. eine Datei http.middlewares.middlewares-authelia.yml mit folgendem Inhalt.
  110.  
  111. —
  112.  
  113. http:
  114.   middlewares:
  115.     middlewares-authelia:
  116.       forwardAuth:
  117.         address: "http://authelia:9091/api/verify?rd=https://auth.domain.tld"
  118.         trustForwardHeader: true
  119.         authResponseHeaders:
  120.          - "Remote-User"
  121.           - "Remote-Groups"
  122.  
  123. —
  124.  
  125. Erzeugen der Authelia Configuration in /opt/containers/traefik-crowdsec-stack/data/authelia/config
  126. mit nano /opt/containers/traefik-crowdsec-stack/data/authelia/config/configuration.yml die entsprechende Datei erstellen.
  127.  
  128. Inhalt:
  129. —
  130. ###############################################################
  131. #Authelia configuration#
  132. ###############################################################
  133.  
  134. theme: dark
  135. identity_validation:
  136.   reset_password:
  137.  # Wird durch das Secret gesetzt
  138.     jwt_secret:
  139. server:
  140.   address: tcp://0.0.0.0:9091/
  141.  
  142. # https://www.authelia.com/configuration/miscellaneous/logging/
  143. log:
  144.   level: error
  145.   format: json
  146.   file_path: /config/authelia.log
  147.   keep_stdout: true
  148.  
  149. # https://www.authelia.com/configuration/second-factor/time-based-one-time-password/
  150. totp:
  151.   issuer: domain.tld
  152.   period: 30
  153.   skew: 1
  154.  
  155. # https://www.authelia.com/reference/guides/passwords/
  156. authentication_backend:
  157.   password_reset:
  158.     disable: false
  159.   refresh_interval: 5m
  160.   file:
  161.     path: /config/users.yml
  162.     password:
  163.       algorithm: argon2id
  164.       iterations: 1
  165.       salt_length: 16
  166.       parallelism: 8
  167.       memory: 256
  168.  
  169. # https://www.authelia.com/overview/authorization/access-control/
  170. access_control:
  171.   default_policy: deny
  172.   rules:
  173.     - domain: "auth.domain.tld" # Hier deine Authelia Domain einsetzen.
  174.       policy: bypass
  175.       networks: # Optional
  176.         - 10.0.0.0/8
  177.         - 192.168.0.0/16
  178.         - 172.16.0.0/12
  179.     - domain:
  180.      - "*.domain.tld" # Wildcard Adresse für Domain optional
  181.       - "traefik.domain.tld" # Hier deine Traefik Domain einsetzen.
  182.       - "domain.tld" # Hier deine Domain einsetzen.
  183.       policy: two_factor
  184.  
  185. # https://www.authelia.com/configuration/session/introduction/
  186.  
  187. session:
  188.   name: authelia_session
  189.   same_site: lax
  190.   secret:
  191.   expiration: 5h
  192.   inactivity: 15m
  193.   remember_me: 10M
  194.   cookies:
  195.     - domain: 'domain.tld'
  196.       authelia_url: https://auth.domain.tld # Authelia URL
  197.       default_redirection_url: https://auth.domain.tld/ # Default Redirect URL
  198.  
  199. # https://www.authelia.com/configuration/security/regulation/
  200. regulation:
  201.   max_retries: 3
  202.   find_time: 10m
  203.   ban_time: 12h
  204.  
  205. # https://www.authelia.com/configuration/storage/introduction/
  206. storage:
  207.  # For local storage, uncomment lines below and comment out mysql. https://docs.authelia.com/configuration/storage/sqlite.html
  208.   # This is good for the beginning. If you have a busy site then switch to other databases.
  209.   local:
  210.     path: '/config/db.sqlite3'
  211.   # Wird durch Secret gesetzt
  212.   encryption_key:
  213. # https://www.authelia.com/configuration/notifications/introduction/
  214. notifier:
  215.   disable_startup_check: false
  216.   # For testing purposes, notifications can be sent in a file. Be sure to map the volume in docker-compose.
  217.   filesystem:
  218.     filename: '/config/notification.txt'
  219.  
  220. # SMTP nur aktivieren wenn es sicher funktioniert bei euch 
  221. #notifier:
  222. #disable_startup_check: false
  223. #   smtp:
  224. #     username: '[email protected]' # Username für deinen Mailserver
  225. #     password:
  226. #     address: 'smtp://mail.domain.tld:587'
  227. #     sender: 'Authelia Notifier <[email protected]>'
  228. #     subject: "[Notification domain.tld] {titel}"
  229. #     startup_check_address: '[email protected]'
  230. #     disable_starttls: false
  231. #     disable_html_emails: false
  232. #     disable_require_tls: false
  233. —
  234.  
  235. Mit diesem Befehl erzeugt ihr den Hash für Euren User:
  236. docker run -v /opt/containers/authelia/compose/config/configuration.yml:/configuration.yml -it authelia/authelia:latest authelia crypto hash generate --config /configuration.yml --password "SicheresPassword"
  237.  
  238. den angezeigten String tragt ihr dann in die users.yml ein als password:
  239. Mit nano /opt/containers/traefik-crowdsec-stack/data/authelia/config/users.yml die entsprechende Datei erstellen.
  240.  
  241. Inhalt:
  242. —
  243.  
  244. ###############################################################
  245. #             Users Database           #
  246. ###############################################################
  247.  
  248. # This file can be used if you do not have an LDAP set up.
  249.  
  250. # List of users
  251. users:
  252.   username: # hier euren eigenen Login Namen eintragen
  253.     displayname: "Mein Name mit Nachname"
  254.     password:
  255.     email: # Eure valide Email Adresse
  256.     groups:
  257.      - admins
  258.       - dev
  259. —
  260.  
  261. Nach dem ihr dann alle Container mit docker compose -up -d –force-recreate neugestartet habt, ruft ihr
  262. eure Authelia domain auf auth.domain.tld und log euch mit den angelegten Zugangsdaten ein.
  263.  
  264. Durch den rest führt euch dann Authelia. Beachtet der 6 stellige Code der angefordert wird wird euch in der Notification.txt im config Verzeichnis angezeigt.
  265.  
  266. Nach dem erfolgreichen Anlegen des 2FA könnt ihr nun folgende Anpassungen vornehmen:
  267. Manuelle Anpassungen an der traefik.yml im /compose
  268. um Traefik hinter die Authelia Middleware zu bekommen muss folgende Zeile angeasst werden.
  269.  
  270. Original:
  271. traefik.http.routers.traefik-dashboad.middlewares: default@file,traefik-dashboard-auth@file
  272.  
  273. Angepasst:
  274. traefik.http.routers.traefik-dashboad.middlewares: default@file,middlewares-authelia@file
  275.  
  276. Macht das bitte erst wenn euer Authelia Container läuft und ihr euch bei Authelia mindestens einmal angemeldet habt.
  277.  
  278. alternativ kann man hier auch eine traefik.override.yml anlegen.
  279.  
  280. ---
  281. services:
  282.   traefik:
  283.     labels:
  284.       traefik.http.routers.traefik-dashboad.middlewares: default@file,middlewares-authelia@file
  285. ---
  286.  
  287. nach einem erneuten restart mit
  288. docker compose up -d --force-recreate
  289. und ein paar minuten Wartezeit sollte sich beim Aufruf eurer Traefik Domain nun erst Authelia melden.
  290.  
  291. Ich hoffe ich habe dies nun vollständig dokumentiert. Falls doch was schiefgehen sollte fragt einfach.
  292. Ich habe dies auch gleichzeitig an Psycho0verload geschickt zur Prüfung und ggf einbau in den Stack.
Advertisement
Add Comment
Please, Sign In to add comment