Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| services:authelia [2024/08/27 12:08] – created willy | services:authelia [2024/09/18 13:56] (current) – willy | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | https:// | + | ====== Authelia |
| - | https://github.com/authelia/ | + | [[https://www.authelia.com/|Authelia]] is an open-source authentication and authorization server and portal fulfilling the identity and access management (IAM) role of information security in providing multi-factor authentication and single sign-on (SSO) for your applications via a web portal. It acts as a companion for common reverse proxies. |
| + | This is **not** simple stuff and it require some understanding of what you are doing: just copy-pasting configurations and finger-crossing will **not** work and only //lead to frustration.// | ||
| + | |||
| + | I strongly suggest you read the very good [[https:// | ||
| + | |||
| + | ===== Installation ===== | ||
| + | |||
| + | First of all, your NGINX must be compiled with **auth_request** module, but if you followed my NGINX guide ([[selfhost: | ||
| + | |||
| + | While Authelia support docker images, there is really **no** reason to use a container since it's a single executable that you can simply download and start. So let's install on bare-metal! | ||
| + | |||
| + | As usual, let's create a dedicated user: | ||
| + | <code bash> | ||
| useradd -m authelia | useradd -m authelia | ||
| + | </ | ||
| + | in this case, you should let the home folder be under the **/ | ||
| + | |||
| + | Now it's time to download the latest release from [[https:// | ||
| + | <code bash> | ||
| su - authelia | su - authelia | ||
| + | wget https:// | ||
| + | mkdir bin config db logs | ||
| + | cd bin | ||
| + | tar xvf ../ | ||
| + | </ | ||
| + | ===== Configuration ===== | ||
| - | wget https://github.com/ | + | You need to copy the provided example configuration and edit to your needs: |
| + | <code bash> | ||
| + | cp bin/config-example.yml configuration.yml | ||
| + | </code> | ||
| - | mkdir bin | + | As an example, here is my configuration.yml, |
| - | cd bin | + | <file - configuration.yml> |
| - | tar xvf ../authelia-v4.38.10-linux-amd64.tar.gz | + | --- |
| - | cd .. | + | theme: ' |
| + | server: | ||
| + | address: ' | ||
| + | endpoints: | ||
| + | <<< | ||
| + | log: | ||
| + | <<< | ||
| + | telemetry: | ||
| + | metrics: | ||
| + | enabled: false | ||
| + | totp: | ||
| + | disable: false | ||
| + | webauthn: | ||
| + | disable: false | ||
| + | identity_validation: | ||
| + | reset_password: | ||
| + | jwt_secret: '<<< | ||
| + | authentication_backend: | ||
| + | <<< | ||
| + | password_policy: | ||
| + | standard: | ||
| + | enabled: false | ||
| + | min_length: 8 | ||
| + | max_length: 0 | ||
| + | require_uppercase: | ||
| + | require_lowercase: | ||
| + | require_number: | ||
| + | require_special: | ||
| + | zxcvbn: | ||
| + | enabled: false | ||
| + | min_score: 3 | ||
| + | privacy_policy: | ||
| + | enabled: false | ||
| + | require_user_acceptance: | ||
| + | policy_url: '' | ||
| + | access_control: | ||
| + | <<< | ||
| + | session: | ||
| + | secret: '<<< | ||
| + | cookies: | ||
| + | | ||
| + | domain: ' | ||
| + | authelia_url: | ||
| + | | ||
| + | name: ' | ||
| + | same_site: ' | ||
| + | inactivity: ' | ||
| + | expiration: ' | ||
| + | remember_me: | ||
| - | creare file configuration.yml (vedi esempio) | + | storage: |
| + | <<< | ||
| - | mkdir config db logs | + | notifier: |
| + | <<< | ||
| - | lancia authelia | + | identity_providers: |
| + | oidc: | ||
| + | <<< | ||
| + | ... | ||
| + | </ | ||
| + | This file has a few assumptions, | ||
| - | NGINX auth_request | ||
| - | www-servers/ | + | === Access Control === |
| - | crea file org.gardiol/ | + | This section is used to define how to access domains, and with which policy. I use single factor at this time, so: |
| - | crea file org.gardiol/ | + | < |
| - | crea org.gardiol/ | + | access_control: |
| - | crea org.gardiol/authelia_authrequest.conf (file) | + | default_policy: |
| + | rules: | ||
| + | - domain: '*.mydomain.com' | ||
| + | | ||
| + | </code> | ||
| - | configura ogni subdomain auth | + | === Authentication Backend === |
| + | I choose to store passwords and users in a yaml text file, for my few users this is perfect and simple enough: | ||
| + | < | ||
| + | password_reset: | ||
| + | disable: false | ||
| + | file: | ||
| + | path: '/ | ||
| + | watch: true | ||
| + | </ | ||
| - | Creazione passwords: | + | See below on how to add/create users. |
| - | ./authelia-linux-amd64 crypto hash generate --help | + | |
| + | === Storage === | ||
| + | Due to my very limited use case (less than 10 users) i am using SQLite3 as storage backend: | ||
| + | < | ||
| + | storage: | ||
| + | encryption_key: | ||
| + | local: | ||
| + | path: '/ | ||
| + | </ | ||
| + | === Notifier === | ||
| + | |||
| + | Authelia support both on-flie notifier, which is pretty simple to setup, or email based notifier. While email requires you to setup a dedicated email address for Authelia, it will allow users to reset their password without your actions, which might be desirable. | ||
| + | |||
| + | File based, simple, notifier: | ||
| + | < | ||
| + | notifier: | ||
| + | disable_startup_check: | ||
| + | filesystem: # Using email notifier is probably better: TBD | ||
| + | filename: '/ | ||
| + | </ | ||
| + | |||
| + | SMTP / email notifier: | ||
| + | < | ||
| + | notifier: | ||
| + | disable_startup_check: | ||
| + | smtp: | ||
| + | address: ' | ||
| + | username: ' | ||
| + | password: '<<< | ||
| + | sender: ' | ||
| + | </ | ||
| + | |||
| + | Note the **disable_startup_check**: | ||
| + | |||
| + | === Endpoints === | ||
| + | |||
| + | Please note the **endpoints** configuration below: i have created two different endpoints: | ||
| + | * standard: which will be used by all supported services | ||
| + | * basic: which will be needed by some protocols like WebDAV and such | ||
| + | |||
| + | < | ||
| + | endpoints: | ||
| + | authz: | ||
| + | normal: | ||
| + | implementation: | ||
| + | authn_strategies: | ||
| + | - name: ' | ||
| + | basic: | ||
| + | implementation: | ||
| + | authn_strategies: | ||
| + | - name: ' | ||
| + | schemes: | ||
| + | - ' | ||
| + | </ | ||
| + | |||
| + | This is **different** from the stock authelia configuration files and **requires** one important change to the NGINX snippets below, which i will point out. Do not forget to edit the snippets where indicated. | ||
| + | |||
| + | === Log === | ||
| + | |||
| + | Moving logging to a separate file, remember to // | ||
| + | < | ||
| + | log: | ||
| + | level: ' | ||
| + | format: ' | ||
| + | file_path: '/ | ||
| + | </ | ||
| + | |||
| + | For the log file, you need to create and set permissions to **/ | ||
| + | <code bash> | ||
| + | mkdir / | ||
| + | chown authelia: | ||
| + | chmod 750 / | ||
| + | </ | ||
| + | |||
| + | === OIDC Provider === | ||
| + | |||
| + | Setting up Authelia as OIDC Provider is useful to support services that support this protocol, like Jellyfin. See [[https:// | ||
| + | |||
| + | Add the following section to your configuration.yml: | ||
| + | < | ||
| + | identity_providers: | ||
| + | oidc: | ||
| + | hmac_secret: | ||
| + | jwks: | ||
| + | - key_id: ' | ||
| + | use: ' | ||
| + | key: | | ||
| + | -----BEGIN PRIVATE KEY----- | ||
| + | ... <<< | ||
| + | -----END PRIVATE KEY----- | ||
| + | enable_client_debug_messages: | ||
| + | minimum_parameter_entropy: | ||
| + | enforce_pkce: | ||
| + | enable_pkce_plain_challenge: | ||
| + | enable_jwt_access_token_stateless_introspection: | ||
| + | discovery_signed_response_alg: | ||
| + | discovery_signed_response_key_id: | ||
| + | require_pushed_authorization_requests: | ||
| + | authorization_policies: | ||
| + | policy_name: | ||
| + | default_policy: | ||
| + | rules: | ||
| + | - policy: ' | ||
| + | subject: ' | ||
| + | lifespans: | ||
| + | access_token: | ||
| + | authorize_code: | ||
| + | id_token: ' | ||
| + | refresh_token: | ||
| + | cors: | ||
| + | endpoints: | ||
| + | - ' | ||
| + | - ' | ||
| + | - ' | ||
| + | - ' | ||
| + | allowed_origins: | ||
| + | - ' | ||
| + | allowed_origins_from_client_redirect_uris: | ||
| + | </ | ||
| + | |||
| + | To generate **hmac_secret** use the following command: | ||
| + | <code bash> | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | To generate the **PRIVATE KEY** use the following command: | ||
| + | <code bash> | ||
| + | openssl genrsa -out private.pem 4096 && cat private.pem | ||
| + | </ | ||
| + | You can delete the generated files afterward. | ||
| + | |||
| + | === OIDC Client === | ||
| + | |||
| + | Each OIDC client must have it's own section in the Authelia configuration file. See [[https:// | ||
| + | |||
| + | < | ||
| + | identity_providers: | ||
| + | oidc: | ||
| + | << omissis, see OIDC Providers above >> | ||
| + | clients: | ||
| + | - client_id: ' <<< | ||
| + | client_name: | ||
| + | client_secret: | ||
| + | public: false | ||
| + | authorization_policy: | ||
| + | require_pkce: | ||
| + | pkce_challenge_method: | ||
| + | redirect_uris: | ||
| + | - ' | ||
| + | scopes: | ||
| + | - ' | ||
| + | - ' | ||
| + | - ' | ||
| + | userinfo_signed_response_alg: | ||
| + | token_endpoint_auth_method: | ||
| + | </ | ||
| + | |||
| + | To generate the **client_id**: | ||
| + | <code bash> | ||
| + | ./ | ||
| + | </ | ||
| + | |||
| + | To generate **client_secret**: | ||
| + | <code bash> | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | === Customization === | ||
| + | |||
| + | If you want to customize the look & feel of the login dialog, you can replace the logo and the favicon. | ||
| + | |||
| + | In your configuration path add the line: | ||
| + | < | ||
| + | server: | ||
| + | asset_path: '/ | ||
| + | </ | ||
| + | |||
| + | and drop in that folder two files: | ||
| + | * favicon.ico (must be an ico) | ||
| + | * logo.png (must be a png) | ||
| + | |||
| + | === Logout === | ||
| + | |||
| + | You can logout by going to the URL **https:// | ||
| + | |||
| + | |||
| + | ==== NGINX support files ==== | ||
| + | |||
| + | From this point onward, always refer to [[https:// | ||
| + | |||
| + | This is the associated NGINX config file **/ | ||
| + | <file - login.conf> | ||
| + | server { | ||
| + | server_name login.mydomain.com; | ||
| + | listen 443 ssl; | ||
| + | listen 8443 ssl; | ||
| + | http2 on; | ||
| + | |||
| + | access_log / | ||
| + | error_log / | ||
| + | |||
| + | location / { | ||
| + | include com.mydomain/ | ||
| + | proxy_pass http:// | ||
| + | } | ||
| + | |||
| + | location = /api/verify { | ||
| + | proxy_pass http:// | ||
| + | } | ||
| + | |||
| + | location /api/authz/ { | ||
| + | proxy_pass http:// | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | In addition to this one, you need also che following specific NGINX config files: | ||
| + | * The **/ | ||
| + | * The **/ | ||
| + | * The **/ | ||
| + | * The **/ | ||
| + | * The **/ | ||
| + | |||
| + | Now, you need to edit the **authelia_location.conf** and replace the first line to match the __standard endpoint__ defined above: | ||
| + | < | ||
| + | set $upstream_authelia http:// | ||
| + | </ | ||
| + | |||
| + | And, similarly, you need to edit the **authelia_location-basic.conf** and replace the first line to match the __basic endpoint__ defined above: | ||
| + | < | ||
| + | set $upstream_authelia http:// | ||
| + | </ | ||
| + | |||
| + | I have added the specific endpoints (normal / basic) to the URL.. | ||
| + | |||
| + | |||
| + | ===== Enable Authelia in NGINX ===== | ||
| + | |||
| + | Well, you can enable Authelia support in any subdomain you want by simply adding the following three lines to your NGINX configurations: | ||
| + | < | ||
| + | # The following goes in the server section: | ||
| + | include " | ||
| + | # The following two can go either in specific location section, or directly in the server section to protect ALL locations: | ||
| + | include " | ||
| + | include " | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Adding and editing users ===== | ||
| + | |||
| + | Since i choose file based storage, adding and editing users is a simple matter of editing the following text file **/ | ||
| + | <file - users_database.yml>> | ||
| + | # yamllint disable rule: | ||
| + | --- | ||
| + | ############################################################### | ||
| + | # Users Database | ||
| + | ############################################################### | ||
| + | |||
| + | # This file can be used if you do not have an LDAP set up. | ||
| + | |||
| + | users: | ||
| + | myuser: | ||
| + | disabled: false | ||
| + | displayname: | ||
| + | password: " << see below >>" | ||
| + | email: myuser@mydomain.com | ||
| + | groups: | ||
| + | - admins | ||
| + | - dev | ||
| + | ... | ||
| + | # yamllint enable rule: | ||
| + | </ | ||
| + | |||
| + | To create passwords, you can use the Authelia binary itself: | ||
| + | <code bash> | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | then copy & paste the password hash inside the above yaml file. Authelia should pickup autmatically the change without the need to reload. | ||
| + | |||
| + | I will be working on an automatic synchronization between **/ | ||
| + | |||
| + | |||
| + | ===== Autostart ===== | ||
| + | |||
| + | Create the following file as **/ | ||
| <file - authelia> | <file - authelia> | ||
| # | # | ||
| Line 55: | Line 431: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | Make it executable, and enable on boot: | ||
| + | <code bash> | ||
| + | chmod +x / | ||
| + | rc-update add authelia default | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Update ===== | ||
| + | |||
| + | Download a new binary, replace old, restart service! | ||
| + | |||