Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
content:serverbasics:docker-authentik [2025/03/28 20:27] – [Dockerfile] Danielcontent:serverbasics:docker-authentik [2025/04/14 19:26] (aktuell) – [Secure LDAP- Users with TOTP] Daniel
Zeile 1: Zeile 1:
 ====== Docker: Authentik ====== ====== Docker: Authentik ======
  
-Authentik is a middleware expanding the basic authentication- features of FreeIPA by many additional, modern ways of authentication which is used by modern Software. It will make SSO possible (Single-Sign-On: only logging into your pc will be enough to open all apps) by using the Kerberos-Credentials to login to authentik and than to authenticate the third-aprty app like Nextcloud without any user or Password. +Authentik is a middleware expanding the basic authentication- features of FreeIPA by many additional, modern ways of authentication which is used by modern Software. It will make SSO possible (Single-Sign-On: only logging into your pc will be enough to open all apps) by using the Kerberos-Credentials to login to authentik and than to authenticate the third-aprty app like Nextcloud without any additional User or Password- Dialog.
- +
-TODO+
  
 ===== Dockerfile ===== ===== Dockerfile =====
Zeile 15: Zeile 13:
 #Authentik: https://goauthentik.io/docs/installation/docker-compose #Authentik: https://goauthentik.io/docs/installation/docker-compose
 AUTHENTIK_TAG=latest AUTHENTIK_TAG=latest
 +#use maybe: openssl rand -base64 60 | tr -d '\n'
 AUTHENTIK_SECRET_KEY=SEEDOCS AUTHENTIK_SECRET_KEY=SEEDOCS
 AUTHENTIK_ERROR_REPORTING__ENABLED=true AUTHENTIK_ERROR_REPORTING__ENABLED=true
 # #
 #Postgres-DB Authentik #Postgres-DB Authentik
-AUTHENTIK_POSTGRESQL__HOST=nextcloud-aio-database+AUTHENTIK_POSTGRESQL__HOST=servername-authentik_pgsql-1
 AUTHENTIK_POSTGRESQL__USER=authentik AUTHENTIK_POSTGRESQL__USER=authentik
 AUTHENTIK_POSTGRESQL__NAME=authentik AUTHENTIK_POSTGRESQL__NAME=authentik
Zeile 29: Zeile 28:
 # #
 ## SMTP Host Emails are sent to ## SMTP Host Emails are sent to
-#AUTHENTIK_EMAIL__HOST=mailserver+#AUTHENTIK_EMAIL__HOST=mailserver.smtp.de
 #AUTHENTIK_EMAIL__PORT=465 #AUTHENTIK_EMAIL__PORT=465
 ## Optionally authenticate (don't add quotation marks to your password) ## Optionally authenticate (don't add quotation marks to your password)
Zeile 45: Zeile 44:
  
 The File ''docker-compose.yml'' contains: The File ''docker-compose.yml'' contains:
- 
 <file> <file>
 +
 # Source: https://docs.goauthentik.io/docs/releases/2024.10 # Source: https://docs.goauthentik.io/docs/releases/2024.10
 # wget -O docker-compose.yml https://goauthentik.io/version/2024.10/docker-compose.yml # wget -O docker-compose.yml https://goauthentik.io/version/2024.10/docker-compose.yml
Zeile 62: Zeile 61:
     volumes:     volumes:
       - authentik_pgsql_data:/var/lib/postgresql/data       - authentik_pgsql_data:/var/lib/postgresql/data
-    environment: +      - authentik_backup:/tmp/backup 
-      POSTGRES_PASSWORD: ${PG_PASS:?database password required} +#Defined in .env 
-      POSTGRES_USER: ${PG_USER:-authentik} +#    environment: 
-      POSTGRES_DB: ${PG_DB:-authentik}+     POSTGRES_PASSWORD: ${PG_PASS:?database password required} 
 +     POSTGRES_USER: ${PG_USER:-authentik} 
 +     POSTGRES_DB: ${PG_DB:-authentik}
     env_file:     env_file:
       - .env       - .env
Zeile 106: Zeile 107:
 #      - "${COMPOSE_PORT_HTTP:-9000}:9000" #      - "${COMPOSE_PORT_HTTP:-9000}:9000"
 #      - "${COMPOSE_PORT_HTTPS:-9443}:9443" #      - "${COMPOSE_PORT_HTTPS:-9443}:9443"
 +   networks:
 +     - nextcloud-aio
 +     - default
  
 # Authentik Worker # Authentik Worker
Zeile 136: Zeile 140:
     env_file:     env_file:
       - .env       - .env
 +   networks:
 +     - nextcloud-aio
 +     - default
  
 volumes: volumes:
   authentik_pgsql_data:   authentik_pgsql_data:
-    driverlocal +  authentik_backup:
-#  redis: +
-#    driver: local+
   authentik_media:   authentik_media:
-    driver: local 
   authentik_custom_templates:   authentik_custom_templates:
-    driver: local 
   authentik_certs:   authentik_certs:
-    driverlocal+# redis: 
 + 
 +networks: 
 + nextcloud-aio: 
 +   external: true
  
 </file> </file>
 +
 +Carefully look at each line to fit your needs.
 +
 +===== Caddy =====
 +
 +in docker Caddy- Service enhance the lines:
 +<file>
 +
 +# Authentik
 +https://authentik.domain.tld:443 {
 +       header Strict-Transport-Security max-age=31536000;
 +       reverse_proxy servername-authentik_server-1:9000
 +}
 +
 +</file>
 +
 +===== First start =====
 +
 +After doing ''docker compose up -d'' and restarting Caddy you should be able to Navigate to
 +
 +[[https://authentik.domain.tld/if/flow/initial-setup/|https://authentik.domain.tld/if/flow/initial-setup/]]
 +
 +and set the Password for the admin user ''akadmin''.
 +===== Backup PostgresSQL Database =====
 +
 +This is really VERY Important! The reason is, that every PostgresDB- Version has it own Database- File- Format and if you update Postgres from on Major Version to the next, you WILL NOT BE ABLE to start your DB with the old Volume- Data!
 +
 +You NEED to have the DB-Backed up and restored to the next Version!
 +
 +Create a File in your Docker- Dir named e.g. ''docker_backup_authentik_db.sh:''
 +<file>
 +
 +#!/bin/bash
 +# Make Postgres-Backup of Authentik
 +echo "Backup of authentik-postgres to servername-authentik_pgsql-1:/tmp/backup"
 +/home/docker/bin/docker exec -t -e PGPASSWORD=YOURPASSWORD servername-authentik_pgsql-1 pg_dump --compress=zstd:8 -f /tmp/backup/pg_dump_authentik.sql -U authentik authentik
 +echo "Done Backup of Authentik-DB."
 +
 +</file>
 +
 +Now add this script to  ''backup/docker_backup_all.sh'' .
 +
 +Don't forget to extend your ''backup/docker_backup_all.sh'' by adding ''authentik'' to the service- list if you have not done so far.
 +
 +If you Update the Major- Version, make sure to create a new Volume for your pgsql- data.
 +
 +===== Configuring =====
 +
 +Now that Authentik is working, we are glueing all services together.
 +
 +==== Sync of FreeIPA/LDAP ====
 +
 +Don't use Kerberos-Sync, because the kadmin-interface of FreeIPA is blocked to not have someone messing around with kerberos without FreeIPA not beeing informed. So use LDAP- Sync for the Users.
 +
 +To Sync FreeIPA with Authentik, follow this Guide: [[https://docs.goauthentik.io/docs/users-sources/sources/directory-sync/freeipa/|https://docs.goauthentik.io/docs/users-sources/sources/directory-sync/freeipa/]]
 +
 +When the Sync has been configured, all FreeIPA- Users should show up in Authentik.
 +
 +After SVC- user is created, use the following commands to modify password reset as written in the doc:
 +<file>
 +
 +ldapmodify -x -D "cn=Directory Manager" -H ldaps://ipa.domain.tld:636 -W
 +dn: cn=ipa_pwd_extop,cn=plugins,cn=config
 +changetype: modify
 +add: passSyncManagersDNs
 +passSyncManagersDNs: uid=svc_authentik,cn=users,cn=accounts,dc=domain,dc=tld
 +
 +</file>
 +
 +At the next line, hit CTRL+D and the modification should be set, check with:
 +
 +<file>
 +ldapsearch -xv -Z -W -H ldap://ipa.domain.tld -b "cn=ipa_pwd_extop,cn=plugins,cn=config" -D "cn=Directory Manager"
 +
 +</file>
 +
 +which should show the entry for ''passsyncmanagersdns'' .
 +=== Secure LDAP- Users with TOTP ===
 +
 +Now any User can login with its FreeIPA- Password, also if SPNEGO/ kerberos as beneath is not setup yet.
 +
 +This is quite insecure, so you shoul add a second factor for that type of Login (for SPNEGO the second factor is your integrated Machine, which has the key stored already).
 +
 +To do so, in the Autentik Admin- Panel go to Stages and edit the Stage "default-authentication-mfa-validation"\\
 +Change "Not configured action" → Force…\\
 +At "Configuration stages" → default.authenticator-totp-setup
 +
 +The Next time you are logging in with User and Password in Authentik, it will ask to setup a TOTP- Device. You can for example use [[https://f-droid.org/de/packages/org.liberty.android.freeotpplus/|https://f-droid.org/de/packages/org.liberty.android.freeotpplus/]]
 +
 +Hint: There is also an default Flow for this to import in Authentik here [[https://docs.goauthentik.io/docs/add-secure-apps/flows-stages/flow/examples/flows#two-factor-login|https://docs.goauthentik.io/docs/add-secure-apps/flows-stages/flow/examples/flows#two-factor-login]]
 +
 +== Current Bug ==
 +
 +At the time of writing this, there was a bug here: https://github.com/goauthentik/authentik/issues/5972#issuecomment-2075631779
 +
 +So if you have to enter the OTP twice, than go to Flows, click on ''default-authentication-flow'', Tab Stage Bindings and delete the ''default-authentication-mfa-validation'' Stage (not the other MFA!)
 +
 +
 +==== Attaching SPNEGO ====
 +
 +With SPNEGO, you gain access to SSO in Authentik.
 +
 +Here is the link to the Docs: [[https://docs.goauthentik.io/docs/users-sources/sources/protocols/kerberos/|https://docs.goauthentik.io/docs/users-sources/sources/protocols/kerberos/]]
 +
 +You need to logon to FreeIPA as Admin and do the following:
 +
 +  * Go to Hosts, add Host ''authentik.domain.tld''
 +  * Go to Services, Add an new HTTP- Service for that Host, called HTTP/ipa.domain.tld@DOMAIN.TLD
 +  * Add the Ipa- User admin to the "Allowed to create Keytab"- Section
 +
 +After that, you need to the Docker- Console into the running FreeIPA-Container and use the commands there:
 +<code>
 +
 +#~> docker exec -it servername-ipa-1 bash
 +# Logon as Admin
 +kinit admin
 +# Create and read the Keytab for that service
 +ipa-getkeytab -s ipa.domain.tld -p HTTP/authentik.domain.tld -k /tmp/authentik.keytab
 +cat /tmp/authentik.keytab | base64
 +rm /tmp/authentik.keytab
 +
 +</code>
 +
 +This is the Keytab (a better "Password") that you will use for SPNEGO in Authentik.
 +
 +Use the Servicename ''HTTP@authentik.domain.tld''  as the Servername!
 +
 +Important: Use "User matching mode" = "Link to User with identical Username. …“ - otherwise Kerberos may fail!
 +
 +Than activate Kerberos in Flows and Stages > Stages > default-authentication-identification > Source settings
 +
 +Make sure, that your client is able to login with FreeIPA using SSSD/Kerberos as written in [[.:docker-freeipa#client_setup|docker-freeipa]] - or at least, that krb5 client is installed and is able to login to your IPA- Instance with ''kinit username''  and that you have configured your Browser to work with the certificate. You can also check your Browser on the site ipa.damon.tld after using kinit - it should automatically log you into ipa without a new Password.
  
  
  • content/serverbasics/docker-authentik.1743193643.txt.gz
  • Zuletzt geändert: 2025/03/28 20:27
  • von Daniel