Skip to content

About

Identity Provider for use with Traefik reverse-proxy

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-authentik

Docker container for use as Identity Provider and authentication portal in front of a Traefik reverse-proxy.

Table of Contents:

1. Docker Setup

  1. Initialize config by running init.sh: ./init.sh
  2. Input personal information into .env
  3. Generate postgresql password and authentik secret key, by using e.g. openssl rand 56 | base64, and input into .env
  4. Make sure that Docker network traefik exists, docker network ls
  5. Run docker compose up and check logs

1.1. Troubleshooting

1.1.1. Lost MFA token

  1. Find the TOTP table name: docker exec authentik-db psql -U authentik -c "\dt *totp*" (probably named authentik_stages_authenticator_totp_totpdevice)
  2. Delete TOTP device for USER: docker exec authentik-db psql -U authentik -c "DELETE FROM authentik_stages_authenticator_totp_totpdevice WHERE user_id = (SELECT id FROM authentik_core_user WHERE username = '<USER>');"
  3. Log in with the USER account and you should be promted to connect a new MFA device

2. Authentik Setup

Updated for version 2025.6.3

2.1. Set up your first user

  1. Open browser and go to auth.YOURDOMAIN.COM and verify that you reach the Authentik login screen
  2. Add /if/flow/initial-setup/ at the end of the URL to reach the dialogue for setting up the initial admin account
  3. Input the email and password you want to use for the default akadmin account and press Continue
  4. Log into the default admin account using either usename akadmin or the email you entered in the previous step
  5. Click the Admin interface button on the top-right
  6. Go to Directory->Users in the menu on the left side and click Create
  7. Input Username and Name, select User type: Internal, input Email, finally click Create
  8. Click on your recently created user and go to the Groups tab and click Add to existing group
  9. Click on the plus sign, select authentik Admins and press Add, then press Add again
  10. Go back to the Overview tab and click Set password under the Recovery section
  11. Log out of the current session and log in with your new user account instead
  12. Go back to Directory->Users and click on the akadmin user
  13. In the User Info pane scroll down to the Actions section and press the Deactivate button, then press Update in the popup prompt

You have now logged in for the first time, created your own user account and disabled the default admin account.

2.2. Configuring Authentik Embedded Outpost

  1. In the Admin interface, go to Applications->Outposts, locate the authentik Embedded Outpost and verify that is says Loggin in via https://auth.YOURDOMAIN.COM in green below the name
  2. Go to Applications->Providers and click Create
  3. Select Proxy Provider and click Next
  4. Input a Name, e.g. Traefik Provider and select Authorization flow with either implicit or explicit consent (determines if you are presented with an explicit prompt when being forwarded after logging in or not, prefer implicit)
  5. Click Forward auth (domain level), check that Authentication URL is https://auth.YOURDOMAIN.COM and set Cookie domain simply as YOURDOMAIN.COM
  6. Change Token validity to your taste and click Finish
  7. Go to Applications->Applications and click Create
  8. Input Name and Slug, e.g. Traefik//traefik
  9. Click the Provider field and select Traefik Provider (or whatever you named it in the previous step) and finally click Create
  10. Go back to Applications->Providers and verify that Traefik Provider has a green checkmark and the text Assigned to application Traefik under the Application column
  11. Go back to Applications->Outposts and click the Edit button for the authentik Embedded Outpost (under the Actions column)
  12. In the Applications section click on Traefik and press the > button to add it to Selected Applications, then press Update

You have now set up Authentik to be ready to be used with Traefik reverse-proxy with domain level forward auth.

2.3. Configuring Traefik

  1. Go to your Traefik dir and open dynamic_config.yml
  2. Add an Authentik middleware:
    middlewares:
        authentik-auth:
            forwardAuth:
            # Match base url to authentik server container name
            address: http://authentik-server:9000/outpost.goauthentik.io/auth/traefik
            trustForwardHeader: true
            authResponseHeaders:
                - X-authentik-username
                - X-authentik-groups
                - X-authentik-email
                - X-authentik-name
                - X-authentik-uid
                - X-authentik-jwt
                - X-authentik-meta-jwks
                - X-authentik-meta-outpost
                - X-authentik-meta-provider
                - X-authentik-meta-app
                - X-authentik-meta-version
    
  3. Optionally create a middleware chain that includes default security headers:
    middlewares:
        authentik:
            chain:
                middlewares:
                - authentik-auth
                - default-security-headers
    

Now you can use Authentik together with Traefik by including the authentik middleware in container labels, e.g.: traefik.http.routers.APP_NAME.middlewares=authentik@file.

3. Authentik configuration

3.1. Check if email config is correct

To verify that the email settings in .env are correct run docker compose exec worker ak test_email RECIPIENT_EMAIL to send a test email to RECIPIENT_EMAIL.

3.2. Condensed login screen

Certain password managers will have an easier time auto-typing your login info if the username and password fields are both presented at once.

  1. Go to Flows and Stages->Stages and click Edit for the default-authentication-identification stage
  2. Under Password stage select default-authentication-password
  3. (Optional) Enable Enable "Remember me on this device"
  4. Click Update
  5. Go to Flows and Stages->Flows and click the default-authentication-flow stage
  6. Go to the Stage Bindings tab and delete the default-authentication-password stage

3.3. Password complexity policy

It's a good idea to enforce some kind of password policy.

  1. Go to Customisation->Policies and click Create
  2. Select Password Policyand click Next
  3. Set a suitable Name, e.g. password-complexity
  4. Expand the Static rules section
  5. Input your choice of rules and enter an Error message that reflects the requirements, e.g. Please enter a minimum of 12 characters with at least 1 uppercase, 1 lowercase, 1 digit and 1 symbol character.
  6. Click Finish
  7. Go to Flows and Stages->Stages, click Edit for the default-source-enrollment-prompt stage
  8. Scroll down to Validation Policies, select the password policy created previously under Available Policies and click > to add it to `Selected Policies.
  9. Make sure to remove any other default policies and click Update
  10. Repeat above for the default-password-change-prompt stage while also removing the default-password-change-password-policy if present

3.4. MFA forced on login

It's a good idea to enforce MFA for something that provides such powerful means of access. Here's how to force setup of MFA using TOTP using e.g. Google Authenticator app.

  1. Go to Flows and Stages->Stages, click Edit for default-authentication-mfa-validation
  2. Under Stage-specific settings->Device classes select the MFA types you want to allow, in this case only TOTP Authenticators for Google Authenticator app
  3. Set Not configured action to Force the user to configure an authenticator
  4. Under Configuration stages select only default-authenticator-totp-setup, click Update
  5. Go to Flows and Stages->Flows and click on default-source-enrollment
  6. Go to the Stage Bindings tab, click Bind existing stage and input:
    • Stage: default-authentication-mfa-validation
    • Order: 2
  7. Update the order of the default-source-enrollment-login stage to 3, the resulting list should be:
    Order Name
    0 default-source-enrollment-prompt
    1 default-source-enrollment-write
    2 default-authentication-mfa-validation
    3 default-source-enrollment-login

3.5. Password recovery

If users forget their password it's nice if they're able to reset their passwords on their own.

  1. Go to Flows and Stages->Stages and click Create
  2. Select Identification Stage and click Next
  3. Set a suitable name, e.g. recovery-authentication-identification, under User fields select Username and Email and click Finish
  4. Click Create again and select Email Stage, click Next
  5. Set a suitable Name, e.g. recovery-email
  6. Set Subject to e.g. Authentik password recovery, click Finish
  7. Go to Flows and Stages->Flows and click Create
  8. Set Name/Title/Slug as Recovery/Recovery/recovery
  9. Set Designation as Recovery
  10. Click Create
  11. Click on the recovery flow we just created and go to the Stage Bindings tab
  12. Add bindings by clicking Bind existing stage and setting up according to the table below:
    Order Stage Type
    10 recovery-authentication-identification Identification Stage
    20 recovery-email Email Stage
    30 default-password-change-prompt Prompt Stage
    40 default-password-change-write User Write Stage
  13. Go to Flows and Stages->Stages and click Edit for the default-authentication-identification stage
  14. Under Flow settings->Recovery flow select recovery (Recovery) and click Update

To be able to manually generate a recovery link for a user also:

  1. Go to System->Brands and click Edit for the relevant brand (probably authentik-default)
  2. Expand the Default flows section and set Recovery flow to recovery (Recovery)
  3. Click Update

3.6. Invitation

It's a bad idea to allow anyone visiting the login page to register for an account. Invitation link with a set expiration time is a better solution.

  1. Go to Directory->Groups and click Create

  2. Set a suitable name, e.g. authentik Users

  3. Make sure Is superuser is switched OFF, click Create

  4. Click on your recently created group, go to the Users tab and click on Add existing user

  5. Click on the plus sign, select your currently existing normal user accounts, press Add and then press Add again

  6. Go to Flows and Stages->Stages and click Create

  7. Select User Write Stage and click Next

  8. Set a suitable name, e.g. enrollment-invitation-write

  9. Under Stage-specific settings make sure Create users when required is selected and uncheck Create users as inactive

  10. Under User type make sure Internal is selected

  11. Under Group select the recently created authentik Users group

  12. Click Finish

  13. Click Create again and select Invitation Stage, click Next

  14. Set a suitable name, e.g. enrollment-invitation

  15. Make sure Continue flow without invitation is OFF and click Finish

  16. Click Create again and select Email Stage

  17. Set Name to enrollment-invitation-email, Subject to Account Confirmation and Template to Account Confirmation, finally click Finish

  18. Go to Flows and Stages->Flows and click Create

  19. Set Name and Titleto Enrollment Invitation

  20. Set Designation to Enrollment

  21. Under Behavior settings check Compatibility mode and click Create

  22. Click the recently created enrollment-invitation flow and go to the Stage Bindings tab

  23. Add bindings by clicking Bind existing stage and setting up according to the table below:

    Order Stage Type
    10 enrollment-invitation Invitation Stage
    20 default-source-enrollment-prompt Prompt Stage
    30 enrollment-invitation-write User Write Stage
    40 enrollment-invitation-email Email Stage
    50 default-source-enrollment-login User Login Stage
  24. Click on Edit Stage for the default-source-enrollment-prompt stage

  25. Under Stage-specific settings->Fields select the following entries:

    • default-user-settings-field-username
    • default-user-settings-field-name
    • default-user-settings-field-email
    • initial-setup-field-password
    • initial-setup-field-password-repeat
  26. Check under Validation Policies that password-complexity is selected, click Update

You can now go to Directory->Invitations and click Create to create an invitation link. Set a suitable name and expiration time. Make sure to select the enrollment-invitation flow and make sure Single use is checked.

  1. Expand the recently created invite and Link to use the invitation will contain the link to be distributed.

4. Applications setup

4.1. Forgejo

4.1.1. Authentik settings

  1. Go to Directory->Groups and create the following groups:

    • forgejo Restricted
    • forgejo User
    • forgejo Admin
  2. Add your user to the relevant group

  3. Go to Customization->Property Mappings and click Create

  4. Select Scope Mapping and click Next

  5. Enter the following:

    • Name: Forgejo Profile
    • Scope name: forgejo
    • Expression:
    entitlement_names = {
        entitlement.name
        for entitlement in request.user.app_entitlements(provider.application)
    }
    forgejo_claims = {}
    
    if "gitrestricted" in entitlement_names:
        forgejo_claims["forgejo"] = "restricted"
    if "gituser" in entitlement_names:
        forgejo_claims["forgejo"] = "user"
    if "gitadmin" in entitlement_names:
        forgejo_claims["forgejo"] = "admin"
    
    return forgejo_claims
    
  6. Click Finish

  7. Go to Applications->Applications and click Create with Provider

  8. Enter the following:

    • Application Name: Forgejo
    • Slug: forgejo
  9. Click Next

  10. Select Oauth2/OpenID Provider and click Next

  11. Enter the following:

    • Provider Name: Forgejo Provider
    • Authorization flow: implicit-consent
    • Redirect URIs/Origins: Strict - https://git.DOMAIN.COM/user/oauth2/authentik/callback
    • Advanced protocol settings->Scopes: Add authentik default OAuth Mapping: Application Entitlements and Forgejo Profile
    • Advanced protocol settings->Subject mode: Based on User's username
  12. Click Next twice

  13. Click Submit

  14. Click on the created Application, go to the Application entitlements tab and create these entitlements:

    • gitrestricted
    • gituser
    • gitadmin
  15. Bind the entitlements to the previously created groups

4.1.2. Application settings

  1. Click on the profile button at the top-right and select Site administration
  2. Go to Identity & access->Authentication sources and click Add authentication source
  3. Enter the following:
  • Authentication type: OAuth2
  • Authentication name: authentik
  • OAuth2 provider: OpenID Connect
  • Client ID (Key): Copy from Forgejo Provider in Authentik
  • CLient Secret: Copy from Forgejo Provider in Authentik
  • Icon URL: https://auth.DOMAIN.COM/static/dist/assets/icons/icon.png
  • OpenID Connect Auto Discovery URL: https://auth.DOMAIN.COM/application/o/forgejo/.well-known/openid-configuration
  • Additional scopes: email profile forgejo
  • Required claim name: forgejo
  • Claim name providing group names for this source: forgejo
  • Group claim value for administrator users: admin
  • Group claim value for restricted users: restricted

4.2. Gramps

4.2.1. Authentik settings

4.2.1.1. Group
  1. Go to Directory->Groups and create the following groups:
    • gramps-0-guest
    • gramps-1-member
    • gramps-2-contributor
    • gramps-3-editor
    • gramps-4-owner
    • gramps-5-admin
4.2.1.2. Property Mapping
  1. Go to Customization->Property Mappings and click Create
  2. Select Scope Mapping and click Next
  3. Enter the following:
    • Name: Gramps Groups
    • Scope name: groups
    • Description: https://www.grampsweb.org/install_setup/users/#user-roles
    • Expression:
return {
      "groups": [g.name for g in request.user.ak_groups.all()]
}
  1. Click Finish
  2. Open the authentik default OAuth Mapping: OpenID 'email' scope mapping and make sure the Expression field contains email_verified: True
4.2.1.3. Provider
  1. Go to Applications->Providers and click Create
  2. Select OAuth2/OpenID Provider and click Next
  3. Enter the following:
    • Name: Gramps Provider
    • Authorization flow: implicit-consent
    • Client type: Confidential
    • Redirect URIs/Origins (RegEx): RegEx, https://gramps.b3rl1n.com/api/oidc/callback/.*
  4. Take note of the Client ID and Client Secret, we will need these in the application setup
  5. Expand the Advanced protocol settings section and make sure the following scopes are listed under Selected Scopes:
    • authentik default OAuth Mapping: OpenID 'email'
    • authentik default OAuth Mapping: OpenID 'openid'
    • authentik default OAuth Mapping: OpenID 'profile'
    • Gramps Groups
  6. Set Subject mode to Based on the User's username
  7. Click Finish
4.2.1.4. Application
  1. Go to Applications->Applications and click Create
  2. Enter the following:
    • Name: Gramps
    • Slug: gramps
    • Provider: Gramps Provider
  3. Click Create

4.2.2. Application settings

Input the Client ID and Client Secret values (and possibly adjust the value of the OIDC_GROUP_* parameters if you named your Authentik groups differently) and you are good to go.

4.3. Home-Assistant

4.3.1. Authentik settings

  1. Go to Applications->Providers and click Create
  2. Select OAuth2/OpenID Provider and click Next
  3. Enter the following:
    • Name: HomeAssistant Provider
    • Authorization flow:: implicit-consent
    • Client type: Confidential
    • Redirect URIs/Origins (RegEx): Strict,
      • https://hass.DOMAIN.COM/auth/openid/callback
  4. Take note of the Client ID and Client Secret, we will need transfer these into HomeAssistant config
  5. Click Finish
  6. Go to Applications->Applications and click Create
  7. Enter the following:
    • Name: HomeAssistant
    • Slug: home-assistant
    • Provider: HomeAssistant Provider
  8. Click Create

4.3.2. Application settings

  1. Log into HomeAssistant as the admin user via local ip
  2. Install the Terminal & SSH addon by going to Settings->Add-ons, clicking on the Add-on store button at the bottom right, searching for Terminal & SSH and clicking Install
  3. Click Terminal in the left-side menu and run wget -O - https://get.hacs.xyz | bash - to install Home Assistant Community Store (HACS)
  4. Go to Settings->Devices & services, click Add integration at the bottom right, search for HACS, acknowledge the statements and click SUBMIT
  5. Link HACS to your GitHub account (read-only access)
  6. Open HACS in the left-side menu and search for the addon Simple OpenID Connect (OIDC / SSO) by user cavefire, install it
  7. Open /homeassistant/configuration.yaml, e.g. by using the Terminal & SSH addon
  8. Enter the following config at the bottom of the file:
homeassistant:
    external_url: https://hass.DOMAIN.COM
    internal_url: http://LOCAL_HASS_SERVER_IP:8123

http:
    use_x_forwarded_for: true
    trusted_proxies:
        - LOCAL_TRAEFIK_SERVER_IP

openid:
    client_id: FROM_AUTHENTIK
    client_secret: FROM_AUTHENTIK
    configure_url: "https://auth.DOMAIN.COM/application/o/home-assistant/.well-known/openid-configuration"
    username_filed: "preferred_username"
    scope: "openid profile email"
    block_login: true
    trusted_ips: #List of CIDR blocks that are not affected by block_login
        - "10.0.0.0/24" # e.g.
    openid_text: "Login with Authentik" # Text to display on the login page
    create_user: true # Automatically create users on first login

4.4. Immich

Authentik has a community integration for Immich to allow user login and provisioning via Authentik.

4.4.1. Authentik settings

  1. Open the Authentik Admin Interface
  2. Go to Applications->Providers and click Create
  3. Select OAuth2/OpenID Provider and click Next
  4. Enter the following:
    • Name: Immich Provider
    • Authorization flow: implicit-consent
    • Client type: Confidential
    • Redirect URIs/Origins (RegEx):
      • https://immich.DOMAIN.COM/auth/login
      • https://immich.DOMAIN.COM/user-settings
      • app.immich://oauth-callback
  5. Take note of the Client ID and Client Secret, we will need these in the Immich setup
  6. Click Finish
  7. Go to Applications->Applications and click Create
  8. Enter the following:
    • Name: Immich
    • Slug: immich
    • Provider: Immich Provider
  9. Click Create

4.4.2. Application settings

  1. Log in with the admin account initially set up for Immich
  2. Click the top-right circle icon and select Administration
  3. From the left-side menu select Settings and then Authentication Settings->OAuth
  4. Enable Login with OAuth and fill out:
    • ISSUER_URL: https://auth.DOMAIN.COM/application/o/immich/
    • CLIENT_ID: Use value from Authentik Provider setup
    • CLIENT_SECRET: Use value from Authentik Provider setup
    • AUTO LAUNCH: Set to ON
  5. Click Save at the bottom of the form

4.5. Inventree

Authentik doesn't have an outright integration for Inventree but Inventree supports general OIDC.

4.5.1. Authentik settings

  1. Go to Customization->Propery Mappings and click Create
  2. Select Scope Mapping and click Next
  3. Enter the following:
    • Name: Inventree Profile Mapping
    • Scope name: profile
    • Description: Split Authentik displayname into separate First and Last Name entities for conformity with how Inventree handles user names
    • Expression:
    name_parts = request.user.name.split(" ", 1)
    given = name_parts[0]
    family = name_parts[1] if len(name_parts) > 1 else ""
    
    return {
        "name": request.user.name,
        "given_name": given,
        "family_name": family,
        "preferred_username": request.user.username,
        "nickname": request.user.username,
        "groups": [group.name for group in request.user.groups.all()],
    }
    
  4. Click Finish
  5. Go to Applications->Providers and click Create
  6. Select OAuth2/OpenID Provider and click Next
  7. Enter the following:
    • Name: Inventree Provider
    • Authorization flow:: implicit-consent
    • Client type: Confidential
    • Redirect URIs/Origins (RegEx): ("authentik" refers to the provider id set in Inventree)
      • https://parts.DOMAIN.COM/accounts/authentik/login/callback/
      • https://inventree.DOMAIN.COM/accounts/authentik/login/callback/
  8. Take note of the Client ID and Client Secret, we will need these in the Inventree setup
  9. Expand the Advanced protocol settings section and look at the Selected Scopes list
  10. Remove authentik default OAuth Mapping: OpenID 'profile' and add Inventree Profile Mapping
  11. Set Subject mode to Based on the User's username
  12. Click Finish
  13. Go to Applications->Applications and click Create
  14. Enter the following:
    • Name: Inventree
    • Slug: inventree
    • Provider: Inventree Provider
  15. Click Create

4.5.2. Application settings

  1. Log in as superuser/admin and go to Admin Center
  2. Under Operations->Users / Access, expand the Groups section and add groups called Admins and Users
  3. Go to System Settings->Authentication
  4. Make sure that the following options are ON:
    • Enable SSO
    • Enable SSO registration
    • Auto-fill SSO users
    • Enable SSO group sync
    • Remove groups outside of SSO
  5. Make sure that the following option is OFF:
    • Enable registration
  6. Set SSO group map to {"inventree Admins": "Admins"}
  7. Set Group on signup to Users
  8. Go to the Django admin panel by entering https://inventree.DOMAIN.COM/admin/, scroll down to SOCIAL ACCOUNTS and click on Social applications
  9. Click ADD SOCIAL APPLICATION + and enter:
    • Provider: OpenID Connect
    • Provider ID: authentik
    • Name: Authentik
    • Client id: As per the Authentik Provider
    • Secret key: As per the Authentik Provider
    • Settings: {"server_url": "https://auth.DOMAIN.COM/application/o/inventree/"}
  10. Click SAVE

Note that you will need to promote users to staff/superuser status manually as at the time of writing there's no natively supported way to automate it.

4.6. Jellyfin

We're not using Authentik middleware here but instead relying on LDAP for automating user setup and logging in via the regular Jellyfin login

4.6.1. Authentik settings

First we need to setup a flow for allowing the service account access

  1. Create a LDAP service password stage by going to Flows and Stages->Stages->Create and entering:
  • Select type: Password Stage
  • Name: ldap-service-password
  • Backends: User database + standard password (only)
  1. Click Finish

  2. Create an Identificaton Stage by going to Flows and Stages->Stages->Create and entering:

  • Select type: Identification Stage
  • Name: ldap-service-identification
  • User fields: Username
  • Password stage: ldap-service-password
  1. Click Finish

  2. Create a User Login stage by goign to Flows and Stages->Stages->Create and entering:

  • Select type: User Login Stage
  • Name: ldap-service-login
  1. Click Finish

  2. Create an authentication flow specifically for LDAP service accounts by going to Flows and Stages->Flows->Create and entering:

  • Name: LDAP Service Account Bind
  • Title: LDAP Service Account Bind
  • Slug: ldap-service-account-bind
  • Designation: Authentication
  • Authentication: No requirement
  1. Click Create
  2. Open the created flow and go to the Stage Bindings tab
  3. Click Bind existing Stage and enter:
  • Stage: ldap-service-identification
  • Order: 10
  1. Click Create
  2. Click Bind existing Stage again and enter:
  • Stage: ldap-service-login
  • Order: 30
  1. Click Create

  2. Create a LDAP service account for the LDAP plugin in Jellyfin to use to lookup users (read-only) by going to Directory->Users->Create Service account and entering:

  • Username: jellyfin-ldap
  • Create group: Disable
  • Expiring: Disable
  1. Click Create and take note of the generated Password, click Close

  2. Create a role for LDAP search by going to Directory->Roles->Create, naming it LDAP Search and clicking Create

  3. Go to Applications->Providers and click on the Jellyfin LDAP provider (not edit)

  4. Go to the Permissions tab, click Assign Object Permission and enter:

  • Role: LDAP Search
  • Search full LDAP directory: Enabled
  1. Click Assign

  2. Go to Directory->Users->jellyfin-ldap->Roles

  3. Click Add to existing role, select the LDAP Searchrole and click Add, then Add again

  4. Create an LDAP provider by going to Applications->Providers->Create->LDAP Provider and entering:

  • Name: Jellyfin LDAP
  • Bind mode: Direct binding
  • Search mode: Direct querying
  • Code-based MFA Support: Disabled
  • Bind flow: ldap-service-account-bind (has to be flow without MFA enforced!)
  • Unbind flow: default-invalidation-flow
  • Base DN: Leave as default (`DC=ldap,DC=goauthentik,DC=io)
  1. Click Finish

  2. Create a matching Application by going to Applications->Applications->Create and entering:

  • Name: Jellyfin
  • Slug: jellyfin
  • Provider: Jellyfin LDAP
  1. Click Create

  2. Create an LDAP outpost by going to Applications->Outposts->Create and entering:

  • Name: Jellyfin LDAP Outpost
  • Type: LDAP
  1. Move the Jellyfin application to Selected Applications
  2. Click Create
  3. Click the View Deployment Info on the newly create outpost and then on Click to copy token under AUTHENTIK_TOKEN
  4. Click Close
  5. Open your .env file and set AUTHENTIK_LDAP_TOKEN to the value you just copied from the outpost
  6. Restart the LDAP container: docker compose up -d --force-restart ldap

4.6.2. Application settings

  1. Install the LDAP plugin by logging in as an admin account and going to Dashboard->Catalog and locating LDAP Authentication and clicking Install
  2. Restart jellyfin: docker compose up -d --force-recreate jellyfin
  3. Configure the plugin with the following:
  • LDAP Server: authentik-ldap
  • LDAP Port: 389
  • Bind User: cn=ldapservice,ou=serviceaccounts,dc=ldap,dc=goauthentik,dc=io
  • Bind Password: The password for the Service account you created earlier
  • Base DN: dc=ldap,dc=goauthentik,dc=io
  • User filter: (objectClass=user)
  • Username attribute: cn

5. 2.8 Jellyseerr

Jellyseerr needs to connect to the Jellyfin server with an account that has admin rights, use the Jellyfin admin user you set up earlier.

5.0.1. 2.8.1 Authentik settings

  1. Open the Authentik Admin Interface
  2. Go to Applications->Providers and click Create
  3. Select OAuth2/OpenID Provider and click Next
  4. Enter the following:
    • Name: Jellyseerr Provider
    • Authorization flow: implicit-consent
    • Client type: Confidential
    • Redirect URIs/Origins (RegEx): ^https://jellyseerr\.DOMAIN\.COM/login\?provider=authentik&callback=true.*
    • Subject mode: Based on the User's username
  5. Take note of your Client ID and Client Secret, you will need these in the SSO plugin setup in Jellyfin
  6. Click Finish
  7. Go to Applications->Applications and click Create
  8. Enter the following:
    • Name: Jellyseerr
    • Slug: jellyseerr
    • Provider: Jellyseerr Provider
  9. (Optional) If you want to suppress Jellyfin being listed in the Authentik User Interface set Launch URL to blank://blank
  10. Click Create

5.0.2. 2.8.2 Application settings

  1. When you first load the page you're met with the setup wizard, click Configure Jellyfin
  2. Enter:
    • Jellyfin URL: http://jellyfin:8096
    • Base URL: Leave blank
    • Email: Not related to Jellyfin, use whatever
    • Username: admin
    • Password: The password you set up for the Jellyfin admin user previously
  3. Click Sign in at the bottom
  4. Click Sync Libraries and toggle them on, click Continue at the bottom
  5. Radarr Settings:
    • Default Server: Check
    • Server Name: Radarr
    • Hostname: radarr
    • Port: 7878
    • API Key: Get from Radarr Settings->General
    • Click Test at the bottom
    • Quality Profile: Any
    • Root Folder: /data/movies
    • Enable Scan: Check
    • Tag Requests: Check
  6. Click Add Server at the bottom
  7. Sonarr Settings:
    • Default Server: Check
    • Server Name: Sonarr
    • Hostname: sonarr
    • Port: 8989
    • API Key: Get from Sonarr Settings->General
    • Click Test at the bottom
    • Quality Profile: Any
    • Root Folder: /data/tv
    • Season Folders: Check
    • Tag Requests: Check
  8. Click Finish Setup at the bottom
  9. Go to Settings->Users
  10. Uncheck Enable Local Sign-In and check Enable OpenID Connect Sign-In
  11. In the popup that appears click Add OpenID Connect Provider and fill out:
    • Provider Name: Authentik
    • Logo: https://cdn.jsdelivr.net/gh/selfhst/icons/svg/authentik.svg
    • Issuer URL: https://auth.DOMAIN.COM/application/o/jellyseerr
    • Client ID: Get from Authentik Provider
    • Client Secret: Get from Authentik Provider
    • Provider Slug: authentik
    • Scopes: email openid profile (it says Comma-separated but use spaces)
    • Allow New Users: Check
  12. Click Save Changes at the bottom, then close the Configure OpenID Connect window by clicking Close
  13. Finally go to the bottom and click Save Changes

5.1. Nextcloud

Authentik has a community integration for Nextcloud to allow user login and provisioning via Authentik.

5.1.1. Authentik settings

Make sure usernames are immutable by going to System->Settings in the Admin Interface and checking that Allow users to change username is OFF.

  1. Open the Authentik Admin Interface
  2. Go to Directory->Groups and click Create
  3. Create a group called nextcloud Admins, this will control which users are given admin permissions in Nextcloud
  4. Create a group called nextcloud Users, this will control which users are allowed to access Nextcloud (to prevent Nextcloud accounts from being provisioned for users who aren't supposed to have access)
  5. Go to Customization->Property Mappings and click Create
  6. Select Scope Mapping and click Next
  7. Set Name to Nextcloud Profile and Scope name to profile
  8. In Expression enter the following:
     # Extract all groups the user is a member of
     groups = [group.name for group in user.groups.all()]
    
     # Nextcloud admins must be members of a group called "admin".
     # This is static and cannot be changed.
     # We append a fictional "admin" group to the user's groups if they are a member of "nextcloud Admins" in authentik.
     # This group would only be visible in Nextcloud and does not exist in authentik.
     if "nextcloud Admins" in groups:
         groups = ["admin"]
     else:
         groups = []
    
     return {
         # Display name
         "name": request.user.name,
         "groups": groups,
         # To set a quota set the "nextcloud_quota" property in the user's attributes
         "quota": user.group_attributes().get("nextcloud_quota", None),
         # To connect an already existing user, set the "nextcloud_user_id" property in the
         # user's attributes to the username of the corresponding user on Nextcloud.
         # Uses the Authentik username if attribute is not set.
         "user_id": user.attributes.get("nextcloud_user_id", str(user.username)),
     }
    
  9. Click Finish
  10. Go to Applications->Providers and click Create
  11. Select OAuth2/OpenID Provider and click Next
  12. Enter the following:
    • Name: Nextcloud Provider
    • Authorization flow: implicit-consent
    • Client type: Confidential
    • Redirect URIs/Origins (RegEx): https://nc.DOMAIN.COM/apps/user_oidc/code (make sure you're using the correct path prefix)
  13. Under Advanced protocol settings->Scopes select:
    • authentik default OAuth Mapping: OpenID 'email'
    • authentik default OAuth Mapping: OpenID 'openid'
    • authentik default OAuth Mapping: OpenID 'profile'
    • Nextcloud Profile
  14. Make sure that Advanced protocol settings->Subject mode: Based on the User's username is selected
  15. Make sure that Include claims in id_token at the bottom is ON
  16. Take note of your Client ID and Client Secret, you will use this in the Nextcloud stage
  17. Go to Applications->Applications and click Create
  18. Enter the following:
    • Name: Nextcloud
    • Slug: nextcloud
    • Provider: Nextcloud Provider
  19. Click Create
  20. Click on the recently created application and go to the Policy / Group/ User Bindings tab
  21. Click Bind existing Policy / Group / User, select the Group option and then select the nextcloud Users group

To map an Authentik user to an existing Nextcloud account give the user an attribute like nextcloud_user_id: NEXTCLOUD_ACCOUNT_NAME. To give a user a quota limit give it an atrtibute like nextcloud_quota: 10 GB.

5.1.2. Application settings

  1. Log into the web UI using an admin account, click on the profile icon in the top-right and then click on Apps
  2. Select the Integration category to the left and look for OpenID Connect user backend, enable it
  3. Go to the top-right menu again and this time click Administration Settings
  4. In the left-side menu list click on OpenID Connect
  5. Click the plus sign under Registered Providers and enter the following:
    • Identifier: Authentik
    • Client ID: See the Authentik section
    • Client secret: See the Authentik section
    • Discovery endpoint: https://auth.DOMAIN.COM/application/o/nextcloud/.well-known/openid-configuration
    • Scope: openid email profile
    • User ID mapping: user_id
    • Quota mapping: quota
    • Groups mapping: groups (Requires Use group provisioning to be checked further down)
    • Display name mapping: name (Under Extra attributes mapping)
    • Email mapping: email (Under Extra attributes mapping)
    • Use unique user id: Turn this OFF

To make Authentik the default login method for Nextcloud go to your Nextcloud docker directory and run docker compose exec -u www-data nextcloud php occ config:app:set --value=0 user_oidc allow_multiple_user_backends.

5.2. Paperless

5.2.1. Authentik settings

  1. Open the Authentik Admin Interface
  2. Go to Applications->Providers and click Create
  3. Select OAuth2/OpenID Provider and click Next
  4. Enter the following:
    • Name Paperless Provider
    • Authorization flow: implicit-consent
    • Client type: Confidential
    • Redirect URIs/Origins: Strict - https://paperless.DOMAIN.COM/accounts/oidc/authentik/login/callback/
  5. Take note of Client ID and Client Secret, you will use these when setting up your .env file later
  6. Expand Advanced protocol settings and verify that the selected scopes are:
  • authentik default OAuth Mapping: OpenID 'email'
  • authentik default OAuth Mapping: OpenID 'openid'
  • authentik default OAuth Mapping: OpenID 'profile'
  1. Click Finish
  2. Go to Application->Applications and click Create
  3. Enter Name/Slug as Paperless/paperless and for Provider select the recently created Paperless Provider
  4. Click Create

5.2.2. Application settings

  1. qwfqwfg

5.3. Servarr

Authentik can be set up to contain the user//pass for the HTTP logins for the various Servarr apps and to forward credentials to the respective app after authentication via Authentik. This way you can keep authentication activated for each app but still only have to log in once when going through Authentik.

5.3.1. Traefik changes

  1. Go to your Traefik dir and open your dynamic_config.yml
  2. Create a middleware similar to the one in the general Traefik setup above but including the authorization header (this is required for Authentik to be able to forward the credentials):
    middlewares:
        authentik-auth-http:
            forwardAuth:
                # Match base url to authentik server container name
                address: http://authentik-server:9000/outpost.goauthentik.io/auth/traefik
                trustForwardHeader: true
                authResponseHeaders:
                    - X-authentik-username
                    - X-authentik-groups
                    - X-authentik-email
                    - X-authentik-name
                    - X-authentik-uid
                    - X-authentik-jwt
                    - X-authentik-meta-jwks
                    - X-authentik-meta-outpost
                    - X-authentik-meta-provider
                    - X-authentik-meta-app
                    - X-authentik-meta-version
                    - authorization
    
  3. Optionally create a middleware chain similar to above:
    middlewares:
        authentik-http:
            chain:
                middlewares:
                    - authentik-auth-http
                    - default-security-headers
    

For the services where you want to use the HTTP-Basic authentication forwarding via Authentik you need to replace the default authentik middleware chain with the authentik-http created above instead.

5.3.2. Authentik settings

  1. Open the Authentik Admin Interface
  2. Go to Directory->Groups and click Create
  3. Set a suitable name, e.g. Servarr Users
  4. Under Attributes input a list of usernames//passwords for the different Servarr apps, e.g.:
    • prowlarr_user: PROWLARR_USERNAME
    • prowlarr_password: PROWLARR_PASSWORD
    • sonarr_user: SONARR_USERNAME
    • sonarr_password: SONARR_PASSWORD
    • etc...
  5. Click Create
  6. Click on the recently created group, go to the Users tab and click Add existing user
  7. Click the plus sign, select the users you want to be able to access the Servarr apps, click Add and then Add again
  8. Go to Applications->Providers and click Create
  9. Select Proxy Provider and click Next
  10. Set a suitable name, e.g. Prowlarr Provider and select implicit-concent under Authorization flow
  11. Click Forward auth (single application)
  12. Set External host to the externally accessible address for the app, e.g. https://prowlarr.DOMAIN.COM
  13. Expand Authntication settings and make sure that both Intercept header authentication and Send HTTP-Basic Authentication are ON
  14. Set HTTP-Basic Username Key and HTTP-Basic Password Key to prowlarr_user and prowlarr_password respectively (matching the keys in the list set up above)
  15. Click Finish
  16. Repeat Provider creation for each individual app in your stack
  17. Go to Applications->Applications and click Create
  18. Set a suitable name, e.g. Prowlarr and the slug similarly to prowlarr
  19. Under Provider select the Prowlarr Provider created previously and click Create
  20. Repeat Application creation for each individual app in your stack
  21. Go to Applications->Outposts and open authentik Embedded Outpost for editing
  22. Under Applications select each application created previously and click > to add them to `Selected Applications
  23. Click Update
  24. The previously created providers should now be listed in the Providers tab for authentik Embedded Outpost

5.4. Synology NAS

Authentik has a community integration for Synology DSM to allow user login via Authentik.

5.4.1. Authentik settings

  1. Open the Authentik Admin Interface
  2. Go to Applications->Providers and click Create
  3. Select OAuth2/OpenID Provider and click Next
  4. Enter the following:
    • Name: Synology Provider
    • Authorization flow: implicit-consent
    • Client type: Confidential
    • Redirect URIs/Origins (RegEx): https://nas.DOMAIN.COM/#/signin (use whatever subdomain you set up in your Traefik dynamic_config.yml)
    • Subject mode: Based on the User's username
  5. Click Finish
  6. Go to Applications->Applications and click Create
  7. Enter Name//Slug as NAS//nas and select the recently created provider, click Create

5.4.2. Application settings

  1. Log in to DSM with an admin account
  2. Go to Control Panel->Domain/LDAP and click on the SSO Client tab
  3. Check the Enable OpenID Connect SSO service box and click the OpenID Connect SSO Settings button below it
  4. Enter the following:
    • Name: Authentik
    • Wellknown URL: https://auth.DOMAIN.COM/application/o/nas/.well-known/openid-configuration
    • Application ID: Client ID from the Synology Provider
    • Application Key: Client Secret from the Synology Provider
    • Redirect URL: https://nas.DOMAIN.COM/#/signin
    • Authorization scope: openid profile email
    • Username claim: preferred_username

Currently doesn't work properly with DSM <7.2 so TBC...

About

Identity Provider for use with Traefik reverse-proxy

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages