Authelia 部署

项目地址

https://www.authelia.com/

应用下载

  • 我使用 Lite Compose Bundle, 适合服务器暴露在公网的场景
  • 克隆项目并切换到最新版本的分支

    git clone https://github.com/authelia/authelia.git
    cd authelia  
    # 切到最新的版本,如果运行有问题,可以分步执行
    git checkout $(git describe --tags git rev-list --tags --max-count=1)

修改配置

在线手册中有一个 Set Variable Configuration 按钮,点击它后可设置真实参数,文档中的配置样本将以你的参数自动设置进去

  • 修改 examples/compose/lite 下的配置文件, 主要三个文件 compose.ymlconfiguration.ymlusers_database.yml

    docker 配置

  • compose.yml docker-compose 配置

    • 因为我使用 nginx 所以将 traefik 部分全部删除
    • 只留下 autheliaredis 部分
    • 时区改为上海 TZ: 'Asia/Shanghai'

    工作配置

  • authelia/configuration.yml 工作配置

    • 修改 identity_validation.reset_password.jwt_secret, 可使用命令 openssl rand -hex 64 生成
    • 修改 session.secret, 可使用命令 openssl rand -hex 64 生成
    • 修改 storage.encryption_key, 必须大于 20 个字符
    • 修改 notifier.smtp 相关配置,发邮件
    • 修改 access_control.rules 相关配置,添加需要保护的域名
    access_control:
      default_policy: 'deny' # 默认拒绝
      rules:
        - domain: '*.xapi.fun' # 指定域名规则, 可能会所有该域名下的子域名使用同一个 cookie, 一个登出,所有站点都登出
          policy: one_factor # one_factor:密码登录 two_factor:密码+两步验证码 bypass:直接通过 deny:拒绝

    用户配置

    我在工作配置中设置为使用文件系统 users_database.yml 设置用户信息

  • authelia/users_database.yml 用户的配置

    • 修改用户名称、密码与邮箱等信息
    • 生成密码 docker run --rm authelia/authelia:latest authelia crypto hash generate argon2 --password 'password'

    邮件发送配置

    邮件发送配置有点特别,我用的是 163.com 这里列一下

    # 通知配置 https://www.authelia.com/configuration/notifications/introduction/
    notifier:
    disable_startup_check: false # 启动的时候核验一下,建议开启
    # 邮件通知 https://www.authelia.com/configuration/notifications/smtp/
    smtp:
      username: 'xxx@163.com' # 身份验证用户名
      # This secret can also be set using the env variables AUTHELIA_NOTIFIER_SMTP_PASSWORD_FILE
      password: 'xxx' # 身份验证密码
      address: 'submissions://smtp.163.com:465' # smtp 服务器配置
      sender: 'authelia ' # 发件人名称
      disable_require_tls: false # 启动 tls
      startup_check_address: xxx@gmail.com # 启动时用来检测的邮件地址,不会真的发送邮件

接入 lldap

lldap 是一个轻量及的 ldap 协议提供商

部署手册:https://github.com/lldap/lldap/blob/8a803bfb11faa11e04b8eb36cbc39acbcde948f0/docs/install.md#with-docker

配置手册:https://github.com/lldap/lldap/blob/8a803bfb11faa11e04b8eb36cbc39acbcde948f0/example\_configs/authelia.md

authentication_backend:
  # Authelia 应该多久检查一次 LDAP 中是否有用户更新
  refresh_interval: '1m'
  ldap:
    implementation: 'lldap'
    # 格式为 [<scheme>://]<hostname>[:<port>]
    # LLDAP 的 ldap 端口是 3890,ldaps 端口是 6360
    address: 'ldap://lldap:3890'
    # 设置您在 LLDAP 中配置的 base dn
    base_dn: 'DC=xapi,DC=fun'
    # 绑定用户的用户名和密码。
    # "bind_user" 应为您创建的、拥有 "lldap_strict_readonly" 权限用于认证的用户名。不建议在此处使用实际的管理员账户。
    # 如果您正在配置 Authelia 以更改用户密码,则此处使用的账户需要拥有 "lldap_password_manager" 权限。
    user: 'UID=bind_user,OU=people,DC=xapi,DC=fun'
    # 密码也可以通过密钥方式设置:https://www.authelia.com/configuration/methods/secrets/。
    password: 'xxxxxxx'
    # 可选:如果您已启用 LDAPS,请设置 TLS
    # tls:
    #  skip_verify: false
    #  minimum_version: TLS1.2

  # 如果 "bind_user" 没有 "lldap_password_manager" 权限,请禁用 Authelia 的密码更改和重置功能。
  password_reset:
    disable: false
  password_change:
    disable: false

应用部署

- 将 `lite` 目录下的文件拷贝到服务器
- `docker compose up -d` 启

修改 authelia npm 配置

  • 创建一个反向代理指向 http://authelia:9091
  • 指定 SSL 证书
  • 在高级中指定配置 (注:如果配置有问题,不会有错误提示)

    # 相关手册:https://www.authelia.com/integration/proxies/nginx-proxy-manager/
    # /snippets/proxy.conf 为 可以从他们的手册中直接复制过来 :https://www.authelia.com/integration/proxies/nginx/#authelia-authrequestconf
    ​
    location / {
      include /data/nginx/snippets/proxy.conf;
      proxy_pass $forward_scheme://$server:$port;
    }
  • 访问首页显示登录页面

修改待应用 npm 配置

  • 创建一个反向代理指向应用
  • 指定 SSL 证书
  • 在高级中指定配置(注:如果配置有问题,不会有错误提示)

    ​
    # 相关手册:https://www.authelia.com/integration/proxies/nginx-proxy-manager/
    # /snippets/***.conf 为 可以从他们的手册中直接复制过来 :https://www.authelia.com/integration/proxies/nginx/#authelia-authrequestconf
    ​
    include /data/nginx/snippets/authelia-location.conf;
    ​
    location / {
      include /data/nginx/snippets/proxy.conf;
      include /data/nginx/snippets/websocket.conf;
      include /data/nginx/snippets/authelia-authrequest.conf;
      proxy_pass $forward_scheme://$server:$port;
    }
  • 访问资源页面,会显示 authelia 登录页面

‍文档链接

域名访问规则

NGINX Proxy Manager 设置

NGINX 设置(NPM中的设置从这里抄)

session 服务设置、cookies 名称、过期时间等

authelia 在线生成密码 (我还没有试过)

老苏的blog - 单点登录服务Authelia

上一篇
下一篇