JupyterHub 集成 Authentik OAuth 登录
2024-05-31
为 JupyterHub 配置统一身份认证,支持 OAuth2 和 LDAP 两种方式。
OAuth 认证(推荐)
使用 GenericOAuthenticator 实现 Authentik 登录。
values.yaml 配置
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
| hub: config: Authenticator: admin_users: - "admin" allow_all: true auto_login: true
GenericOAuthenticator: client_id: "your-client-id" client_secret: "your-client-secret" login_service: "OAuth" authorize_url: "https://authentik.example.com/application/o/authorize/" token_url: "https://authentik.example.com/application/o/token/" userdata_url: "https://authentik.example.com/application/o/userinfo/" oauth_callback_url: "https://jupyter.example.com/hub/oauth_callback" scope: - "openid" - "email" - "profile" username_claim: "sub"
JupyterHub: authenticator_class: "generic-oauth" admin_access: true
|
配置说明
| 配置项 |
说明 |
可选值 |
allow_all |
是否允许所有用户 |
true / false |
auto_login |
自动跳转登录 |
true / false |
username_claim |
用户名字段 |
sub / email / preferred_username |
oauth_callback_url |
回调地址 |
必须与 Authentik 配置一致 |
LDAP 认证(备选)
使用 LDAPAuthenticator 实现 LDAP 登录。
values.yaml 配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| hub: config: Authenticator: admin_users: - "admin" allow_all: true
LDAPAuthenticator: server_address: "ldap.example.com" use_ssl: true bind_dn_template: - "uid={username},ou=foo,ou=People,dc=example,dc=com" allowed_groups: [] escape_userdn: true lookup_dn: false
JupyterHub: authenticator_class: "ldapauthenticator.LDAPAuthenticator" admin_access: true
|
LDAP 配置说明
bind_dn_template: 用户 DN 模板,{username} 会被替换为实际用户名
allowed_groups: 限制可登录的 LDAP 组
escape_userdn: 转义用户名中的特殊字符,防止 LDAP 注入
并发配置
控制同时启动 Notebook 的数量:
1 2 3 4
| hub: concurrentSpawnLimit: 64 activeServerLimit: null allowNamedServers: false
|
参考文档
注意事项
- 回调地址 必须在 Authentik 的应用配置中添加
allow_all: true 会允许所有认证用户登录,生产环境建议配合 allowed_groups 限制
username_claim 选择 sub 可以避免用户名冲突
- OAuth 方式比 LDAP 更灵活,支持多种 SSO 平台