本文最后更新于 2025年4月14日 凌晨
authelia使用说明
authelia 是一个专门用于应用程序和用户安全的 2FA 和 SSO 认证服务器。可以集成到反向代理服务,为其提供身份验证。
相对其他认证服务更加轻量,高效。有扩展性,支持多因素认证,单点登录,权限管理。
Authelia 使用会话 cookie 来授权用户访问各种受保护的网站。配置会话 cookie 行为为请求的域提供授权。
authelia官方文档配置
Host: authelia
Port: 9091
TLS: true
Domain: example.com
Subdomains: auth
authelia安装
可以使用docker compose
启动,配置文件如下:
1 2 3 4 5 6 7 8 9 10
| --- services: authelia: container_name: authelia image: authelia/authelia:latest restart: unless-stopped ports: - 9091:9091 volumes: - './config:/config'
|
首次启动后config
目录下会生成默认配置文件,可以进行修改。
配置文件configuration.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| --- server: address: 'tcp://0.0.0.0:9091/'
log: level: 'info'
identity_validation: reset_password: jwt_secret: 'a_very_important_secret'
authentication_backend: file: path: '/config/users_database.yml'
access_control: default_policy: 'deny' rules: - domain: 'public.example.com' policy: 'bypass' - domain: 'traefik.example.com' policy: 'one_factor' - domain: 'secure.example.com' policy: 'two_factor' - domain: 'private.example.com' domain_regex: '^(\d+\-)?priv-img\.example\.com$' policy: 'one_factor' networks: - 'internal' - '1.1.1.1' subject: - ['user:adam'] - ['user:fred'] - ['group:admins'] methods: - 'GET' - 'HEAD' resources: - '^/api.*' query: - - operator: 'present' key: 'secure' - operator: 'absent' key: 'insecure' - - operator: 'pattern' key: 'token' value: '^(abc123|zyx789)$' - operator: 'not pattern' key: 'random' value: '^(1|2)$'
session: secret: 'insecure_session_secret'
cookies: - name: 'authelia_session' domain: 'example.com' authelia_url: 'https://authelia.example.com' expiration: '1 hour' inactivity: '5 minutes'
regulation: max_retries: 3 find_time: '2 minutes' ban_time: '5 minutes'
storage: encryption_key: 'a_very_important_secret' local: path: '/config/db.sqlite3'
notifier: filesystem: filename: '/config/notification.txt'
identity_providers: oidc: hmac_secret: 'this_is_a_secret_abc123abc123abc' claims_policies: legacy_claims: id_token: - 'email' - 'email_verified' - 'preferred_username' - 'name' jwks: - key_id: 'example' key: | -----BEGIN RSA PRIVATE KEY----- ... -----END RSA PRIVATE KEY----- clients: - client_id: 'unique-client-identifier' client_name: 'Alist' client_secret: '$pbkdf2-sha512$310000$c8p78n7pUMln0jzvd4aK4Q$JNRBzwAo0ek5qKn50cFzzvE9RXV88h1wJn5KGiHrD0YKtZaR/nCb2CJPOsKaPK0hjf.9yHxzQGZziziccp6Yng' claims_policy: "legacy_claims" authorization_policy: 'one_factor' redirect_uris: - 'https://alist.example.com/api/auth/sso_callback?method=get_sso_id' - 'https://alist.example.com/api/auth/sso_callback?method=sso_get_token' scopes: - 'openid' - 'profile' - 'email' token_endpoint_auth_method: 'client_secret_basic' - client_id: 'unique-client-identifier' client_name: 'Portainer' client_secret: '$pbkdf2-sha512$310000$c8p78n7pUMln0jzvd4aK4Q$JNRBzwAo0ek5qKn50cFzzvE9RXV88h1wJn5KGiHrD0YKtZaR/nCb2CJPOsKaPK0hjf.9yHxzQGZziziccp6Yng' authorization_policy: 'one_factor' redirect_uris: - 'https://portainer/' scopes: - 'openid' - 'profile' - 'groups' - 'email' token_endpoint_auth_method: 'client_secret_post' - client_id: 'test' client_secret: 'test' claims_policy: "legacy_claims" authorization_policy: 'one_factor' redirect_uris: - 'https://psteniusubi.github.io/oidc-tester/authorization-code-flow.html' scopes: - 'openid' - 'profile' - 'email' token_endpoint_auth_method: 'client_secret_post'
|
身份验证
users_database.yaml
内容,多个用户配置多个key。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| ---
users: authelia: disabled: false displayname: 'Authelia User' password: '$6$rounds=50000$BpLnfgDsc2WD8F2q$Zis.ixdg9s/UOJYrs56b5QEZFiZECu0qZVNsIYxBaNJ7ucIL.nlxVCT5tqh8KHG8X4tlwCFm5r6NTOZZ5qRFN/' email: 'authelia@authelia.com' groups: - 'admins' - 'dev'
|
配置双因子认证
账号密码首次登录后,页面提示使用配置新的认证方式,支持duo、totp、webauthn。
argon2id格式密码
1
| docker run --rm -it authelia/authelia:latest authelia crypto hash generate argon2
|
hash格式密码
1
| docker run --rm authelia/authelia:latest authelia crypto hash generate argon2 --random --random.length 64 --random.charset alphanumeric
|
64位随机密码生成
1: Authelia
1
| docker run --rm authelia/authelia:latest authelia crypto rand --length 64 --charset alphanumeric
|
2: Openssl
- Linux
1 2
| LENGTH=64 tr -cd '[:alnum:]' < /dev/urandom | fold -w "${LENGTH}" | head -n 1 | tr -d '\n' ; echo
|
RSA秘钥生成
- Authelia
1
| docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd)":/keys authelia/authelia:latest authelia crypto certificate rsa generate --common-name example.com --directory /keys
|
- Openssl
1
| openssl req -x509 -nodes -newkey rsa:2048 -keyout private.pem -out public.crt -sha256 -days 365 -subj '/CN=example.com'
|
Alist SSO 配置
- 管理页面开启SSO
- 配置SSO:
单点登录平台: OIDC
单点登录客户端ID: client-id
单点登录客户端机密: client-secret
Sso oidc 用户名键: preferred_username
单点登录组织名称: Authelia
单点登录应用名称: Alist
单点登录端点名称: https://authelia.example.com
- 个人资料绑定单点登录
portainer SSO 配置
- Settings -> Authentication -> OAuth -> Custom
- 配置SSO
Client ID: portainer
Client Secret: insecure_secret
Authorization URL: https://auth.example.com/api/oidc/authorization
Access Token URL: https://auth.example.com/api/oidc/token
Resource URL: https://auth.example.com/api/oidc/userinfo
Redirect URL: https://portainer.example.com
User Identifier: preferred_username
Scopes: openid profile groups email
Auth Style: In Params
nginx配置方法
https://www.authelia.com/integration/proxies/nginx/
参考文档
- Authelia configuration
- Authelia openid-connect