authentik实践之三、配置LDAP集成Showdoc 与 Jumpserver

官方文档

## 官方介绍文档
    https://docs.goauthentik.io/docs/add-secure-apps/providers/ldap/
    https://docs.goauthentik.io/docs/users-sources/sources/protocols/ldap/

## 引入一个独立容器 专门用于ldap

创建 ldap 专用对接用户 ldapservice,以及 ldap分组 ldapsearch

## 创建 ldap 专用对接用户 ldapservice,并设置密码

## 创建 ldap 分组 ldapsearch,并将 用户 ldapservice 加入该组

创建 ldap 认证的三个阶段

创建新的识别阶段:创建一个名为 ldap-identification-stage 的 Identification Stage
file

file
创建新的密码阶段:创建一个名为 ldap-authentication-password 的 Password Stage
file
file
创建新的用户登录阶段:创建一个名为 ldap-authentication-login 的 User Login Stage
file
file

创建 ldap 身份认证流程,并进行阶段绑定

1、创建流程
file
2、选择 ldap-authentication-flow 进行 阶段绑定
3、单击Bind Stage选择 ldap-identification-stage 并将顺序设置为10
file
4、单击Bind Stage选择 ldap-authentication-login 并将顺序设置为30
file
5、编辑 ldap-identification-stage
file
6、将密码阶段更改为 ldap-authentication-password
file

创建 ldap 应用程序 和 提供程序(ldap 对接 showdoc)

创建应用程序
file
创建提供程序
file
file
绑定用户或用户组
file

赋予 ldap 对接账户 ldapservice 搜索权限

file
file

创建 ldap 前哨(ldap Outposts)

file
file

## 用这个内容替换(注意:先用docker ps 看看容器名称,docker network ls 看看容器网络,是不是我下面的)
log_level: info
docker_labels: null
authentik_host: https://authentik-server-1:9443/
docker_network: authentik_default
container_image: null
docker_map_ports: true
refresh_interval: minutes=5
kubernetes_replicas: 1
kubernetes_namespace: default
authentik_host_browser: ""
object_naming_template: ak-outpost-%(name)s
authentik_host_insecure: true
kubernetes_json_patches: null
kubernetes_service_type: ClusterIP
kubernetes_image_pull_secrets: []
kubernetes_ingress_class_name: null
kubernetes_disabled_components: []
kubernetes_ingress_annotations: {}
kubernetes_ingress_secret_name: authentik-outpost-tls
kubernetes_httproute_annotations: {}
kubernetes_httproute_parent_refs: []

前哨创建完成后会生成一个docker容器
file

创建一个 authentik 用户 zhangsan,并将其加入 ldapsearch 组

## 创建用户,设置密码,加入ldapsearch组,后面会用该用户登录showdoc

file
用ldapsearch 命令测试 是否可以获取到ldap用户信息(Tips:正常应返回所有用户信息)

## 安装命令工具
    yum install -y openldap-clients
    apt install -y ldap-utils

## 查询语句
    # -w 给定密码,非交换式查询(注意: ldapservice 这个用户是有 search full 权限的,正常应该返回所有用户信息,若非如此 肯定有问题,既有可能是 提供程序处 是缓存查询,而非直接查询)
    ldapsearch -x -H ldap://192.168.60.24:389 \
        -D 'cn=ldapservice,ou=users,DC=ldap,DC=goauthentik,DC=io' \
        -b 'DC=ldap,DC=goauthentik,DC=io' \
        '(objectClass=user)' \
        -w <password>

    # -W 手动输入密码,交互式查询
    ldapsearch -x -H ldap://192.168.60.24:389 \
        -D 'cn=ldapservice,ou=users,DC=ldap,DC=goauthentik,DC=io' \
        -b 'DC=ldap,DC=goauthentik,DC=io' \
        '(objectClass=user)' \
        -W

file

执行 ldap 对接 showdoc

## 先获取 提供程序的 相关信息
    base dn: DC=ldap,DC=goauthentik,DC=io
    Bind DN: cn=ldapservice,ou=users,dc=ldap,dc=goauthentik,dc=io    # 就是你之前创建的专用账户 ldapservice
    bind password: xxxxx    # 就是bind dn 这个用户 ldapservice 在authentik的用户密码
    ldap name field: displayname    # showdoc 填写这个,才能正确展示 authentik 用户的显示名
    search filter:    # 搜索过滤规则,只同步ldapsearch 组的用户,并且排除 用户 ldapservice (你可以用uid,或者cn)
(&
  (objectClass=user)
  (memberOf=cn=ldapsearch,ou=groups,dc=ldap,dc=goauthentik,dc=io)
  (!(cn=ldapservice))
)

# 或者这样
(&
  (objectClass=user)
  (memberOf=cn=ldapsearch,ou=groups,dc=ldap,dc=goauthentik,dc=io)
  (!(uid=ldapservice))
)

file
file
file

创建 ldap 应用程序 和 提供程序(ldap 对接 jumpserver)

创建应用程序
file
创建提供程序
file
绑定用户或用户组
file
创建名为 jumpmserver的组,并将 ldapservice 和 zhangsan都放入该组
file
为 应用程序 授权jumpserver用户组
file
为 提供程序 授予 ldapservice 用户搜索查询权限
file
将 应用程序 添加到 ldap 前哨中
file
用ldapsearch 命令测试 是否可以获取到ldap用户信息(Tips:正常应返回所有用户信息)

## 查询语句(注意 这里的 dc=jumpserver,可以理解为找jumpserver 这个组的用户)
    # -w 给定密码,非交换式查询(注意: ldapservice 这个用户是有 search full 权限的,正常应该返回所有用户信息,若非如此 肯定有问题,既有可能是 提供程序处 是缓存查询,而非直接查询)
    ldapsearch -x -H ldap://192.168.60.24:389 \
        -D 'cn=ldapservice,ou=users,DC=jumpserver,DC=goauthentik,DC=io' \
        -b 'DC=jumpserver,DC=goauthentik,DC=io' \
        '(objectClass=user)' \
        -w <password>

    # -W 手动输入密码,交互式查询
    ldapsearch -x -H ldap://192.168.60.24:389 \
        -D 'cn=ldapservice,ou=users,DC=jumpserver,DC=goauthentik,DC=io' \
        -b 'DC=jumpserver,DC=goauthentik,DC=io' \
        '(objectClass=user)' \
        -W

## 这里示例仅 贴一个用户的数据
# zhangsan, users, jumpserver.goauthentik.io
dn: cn=zhangsan,ou=users,dc=jumpserver,dc=goauthentik,dc=io
ak-active: TRUE
ak-superuser: FALSE
cn: zhangsan
sAMAccountName: zhangsan
uid: 4483a4847a00f3c7f955a6e13c8ddfc23b514135ede6014ae09ce56dd218eb07
displayName:: 5byg5LiJ
uidNumber: 2007
gidNumber: 2007
memberOf: cn=ldapsearch,ou=groups,dc=jumpserver,dc=goauthentik,dc=io
memberOf: cn=jumpserver,ou=groups,dc=jumpserver,dc=goauthentik,dc=io  # 注意看这个
name:: 5byg5LiJ
mail: aaaaa@qq.coom
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: user
objectClass: posixAccount
objectClass: goauthentik.io/ldap/user
homeDirectory: /home/zhangsan
sn:: 5byg5LiJ

# search result
search: 2
result: 0 Success

执行 ldap 对接 jumpserver

## 先获取 提供程序的 相关信息
    链接信息: 可以用 ldap://xxxx:389   或者 ldps://xxx:636
    base dn: DC=jumpserver,DC=goauthentik,DC=io
    Bind DN: cn=ldapservice,ou=users,dc=jumpserver,dc=goauthentik,dc=io    # 就是你之前创建的专用账户 ldapservice
    bind password: xxxxx    # 就是bind dn 这个用户 ldapservice 在authentik的用户密码
    用户OU: ou=users,dc=jumpserver,dc=goauthentik,dc=io
    用户过滤器:    # 搜索过滤规则,只同步 jumpserver 组的用户,并且排除 用户 ldapservice (你可以用uid,或者cn)
(&
    (memberOf=cn=jumpserver,ou=groups,dc=jumpserver,dc=goauthentik,dc=io)
    (!(cn=ldapservice))
    (cn=%(user)s)
)
    # 或者这样
    (&(memberOf=cn=jumpserver,ou=groups,dc=jumpserver,dc=goauthentik,dc=io)(!(cn=ldapservice))(cn=%(user)s))

## 用户属性映射(用displayname 给name)
{
  "username": "cn",
  "name": "displayname",
  "email": "mail"
}

## 附、一份ldaps 交互认证的数据报文(有兴趣可以研究下)
    wget https://qiniu.wsfnk.com/bokefiles/ldaps.pcap

file
file

ldap 对接jumpserver 完成后,如何将本地老用户,改成ldap认证(按需修改)

## 用户登录方式是存放在 jumpserver 数据库,users_user 表,source 字段
    docker exec -it jms_mysql bash
    mysql -u root -p -h localhost
    USE jumpserver;
    SELECT id, username, source FROM users_user;

## 数据格式如下
MariaDB [jumpserver]> SELECT id, username,password,source FROM users_user;
+----------------------------------+-----------------------------------------------------+------------------------------------------------------------------------------------------+--------+
| id                               | username                                            | password                                                                                 | source |
+----------------------------------+-----------------------------------------------------+------------------------------------------------------------------------------------------+--------+
| 0e35c38aa1b347629e8f897566cea351 | [Tinker]-TEST-64VptAs                               |                                                                                          | local  |
| 228b35fd59e74037a71a9847ef637e2e | [Tinker]-JumpServer_RemoteAPP_win2019server-jK3WsaO |                                                                                          | local  |
| 22b99642e67947e58d5e16ee324c756e | [Celery]-localhost                                  |                                                                                          | local  |
| 31e263644a024ff7945b87d384d174b2 | admin                                               | pbkdf2_sha256$390000$FfLSes8jlCI5lmWvnHyxiL$lEF6JKC9uxqlp8cwOxywp14mqOStqtgZ6NHUh7fKD4g= | local  |
| 457f0ee368fc4e9688986f90bba485a9 | [Chen]-localhost-jms_chen-NQRjwDv                   |                                                                                          | local  |
| 4cf76169d5e146abbdf7f4955774c0ec | chenglong                                           | pbkdf2_sha256$390000$b7pFOG9d1dqQ65FofOPGTz$eb5lFjAViyB/dekEDUnohxxsqZ9l7UgcdDMcbFEzJ4E= | ldap   |
| 83aa006bcbb64c4ba15021fe7a71acdc | [Kael]-localhost-jms_kael-zxGGglT                   |                                                                                          | local  |
| 9432e866745947dc86615aff40d23047 | [Magnus]-localhost-jms_magnus-dYZrUOO               |                                                                                          | local  |
| aba4d3ecf6d64732b933aed58e1b86ae | [Core]-localhost                                    |                                                                                          | local  |
| d1d593388aba43129011491306645bb3 | [KoKo]-localhost-jms_koko-EznoRHj                   |                                                                                          | local  |
| db7b3e11a8b74c83b9ffeacd11ca68d8 | [Lion]-localhost-jms_lion-AGYqpCx                   |                                                                                          | local  |
| f6d6c16731234e7196b52b9a1dd7085a | zhangsan                                            | !70DjQieq9S9FJvFkXxeoUfEB306SmVd3kYSYxxaa                                                | ldap   |
+----------------------------------+-----------------------------------------------------+------------------------------------------------------------------------------------------+--------+

## 演示将chenglong 改成ldap认证
    ## 改chenglong 这个用户认证方式(可选值 local、ldap )
    UPDATE users_user SET source = 'ldap' WHERE username = 'chenglong';

    ## 改几个用户
    UPDATE users_user SET source = 'ldap' WHERE username IN ('alice', 'bob', 'charlie');

## 验证
MariaDB [jumpserver]> SELECT id, username, source FROM users_user;
+----------------------------------+-----------------------------------------------------+--------+
| id                               | username                                            | source |
+----------------------------------+-----------------------------------------------------+--------+
| 0e35c38aa1b347629e8f897566cea351 | [Tinker]-TEST-64VptAs                               | local  |
| 228b35fd59e74037a71a9847ef637e2e | [Tinker]-JumpServer_RemoteAPP_win2019server-jK3WsaO | local  |
| 22b99642e67947e58d5e16ee324c756e | [Celery]-localhost                                  | local  |
| 31e263644a024ff7945b87d384d174b2 | admin                                               | local  |
| 457f0ee368fc4e9688986f90bba485a9 | [Chen]-localhost-jms_chen-NQRjwDv                   | local  |
| 4cf76169d5e146abbdf7f4955774c0ec | chenglong                                           | ldap   |
| 83aa006bcbb64c4ba15021fe7a71acdc | [Kael]-localhost-jms_kael-zxGGglT                   | local  |
| 9432e866745947dc86615aff40d23047 | [Magnus]-localhost-jms_magnus-dYZrUOO               | local  |
| aba4d3ecf6d64732b933aed58e1b86ae | [Core]-localhost                                    | local  |
| d1d593388aba43129011491306645bb3 | [KoKo]-localhost-jms_koko-EznoRHj                   | local  |
| db7b3e11a8b74c83b9ffeacd11ca68d8 | [Lion]-localhost-jms_lion-AGYqpCx                   | local  |
| f6d6c16731234e7196b52b9a1dd7085a | zhangsan                                            | ldap   |
+----------------------------------+-----------------------------------------------------+--------+
12 rows in set (0.000 sec)

## 当你做完 这一步,你会惊奇的发现,chenglong 这个账户,你用本地密码可以登录,ldap那边的密码也可以登录
    # 原因:是jumpserver 匹配到用户后,先检查是否有本地密码,若有且成功,则登录
    # 解决办法, 、将chenglong 用户的密码字段设置为空,2、写一串复杂的垃圾数据 填充密码字段
    # 置空 单个用户的密码
    UPDATE users_user SET password = '' WHERE username = 'chenglong';

    # 置空 多个用户的密码
    UPDATE users_user SET password = '' WHERE IN ('alice', 'bob', 'charlie');

## 大功告成,测试用ldap密码可以登录
MariaDB [jumpserver]> SELECT id, username,password,source FROM users_user;
+----------------------------------+-----------------------------------------------------+------------------------------------------------------------------------------------------+--------+
| id                               | username                                            | password                                                                                 | source |
+----------------------------------+-----------------------------------------------------+------------------------------------------------------------------------------------------+--------+
| 0e35c38aa1b347629e8f897566cea351 | [Tinker]-TEST-64VptAs                               |                                                                                          | local  |
| 228b35fd59e74037a71a9847ef637e2e | [Tinker]-JumpServer_RemoteAPP_win2019server-jK3WsaO |                                                                                          | local  |
| 22b99642e67947e58d5e16ee324c756e | [Celery]-localhost                                  |                                                                                          | local  |
| 31e263644a024ff7945b87d384d174b2 | admin                                               | pbkdf2_sha256$39000$FfLSesxxlCI5lmWvnHyxiL$lEF6JKC9uDlW88cwssxywp14mqOStqtgZ6NHUxxfKDxx= | local  |
| 457f0ee368fc4e9688986f90bba485a9 | [Chen]-localhost-jms_chen-NQRjwDv                   |                                                                                          | local  |
| 4cf76169d5e146abbdf7f4955774c0ec | chenglong                                           |                                                                                          | ldap   |
| 83aa006bcbb64c4ba15021fe7a71acdc | [Kael]-localhost-jms_kael-zxGGglT                   |                                                                                          | local  |
| 9432e866745947dc86615aff40d23047 | [Magnus]-localhost-jms_magnus-dYZrUOO               |                                                                                          | local  |
| aba4d3ecf6d64732b933aed58e1b86ae | [Core]-localhost                                    |                                                                                          | local  |
| d1d593388aba43129011491306645bb3 | [KoKo]-localhost-jms_koko-EznoRHj                   |                                                                                          | local  |
| db7b3e11a8b74c83b9ffeacd11ca68d8 | [Lion]-localhost-jms_lion-AGYqpCx                   |                                                                                          | local  |
| f6d6c16731234e7196b52b9a1dd7085a | zhangsan                                            | !70DjQieq9S9FJvFkXYeiUfEB306Sxxd3kYSY49xx                                                | ldap   |
+----------------------------------+-----------------------------------------------------+------------------------------------------------------------------------------------------+--------+
声明:本文为原创,作者为 辣条①号,转载时请保留本声明及附带文章链接:https://boke.wsfnk.com/archives/1487.html
谢谢你请我吃辣条谢谢你请我吃辣条

如果文章对你有帮助,欢迎点击上方按钮打赏作者

最后编辑于:2025/6/5作者: 辣条①号

目标:网络规划设计师、系统工程师、ceph存储工程师、云计算工程师。 不负遇见,不谈亏欠!

暂无评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

arrow grin ! ? cool roll eek evil razz mrgreen smile oops lol mad twisted wink idea cry shock neutral sad ???

文章目录