template-monorepo/deploy/openldap/README.md

3.2 KiB
Raw Permalink Blame History

本機 OpenLDAPk6 / dev

make k6-upmake ldap-up 一併啟動的測試用 LDAP 目錄。ZITADEL 透過 LDAP IdP 連到這台伺服器Gateway 仍只走 OIDCprovider=ldap + LdapIdPID)。

Compose 定義在 docker-compose.yml,由主 deploy/docker-compose.yml include 進來。

啟動

# 方式 A只起 LDAP已有 ZITADEL 或其他服務時)
make ldap-up
make ldap-wait

# 方式 Bk6 全棧(含 Postgres + ZITADEL + OpenLDAP
make k6-up
make k6-wait          # 自動LDAP seed + ZITADEL LDAP IdP + OIDC App → k6.env

# 一鍵(含 Gateway 背景)
make dev-up

make ldap-test  # 確認 alice / bob 可查

make k6-wait 會執行 ldap-seed,並跑 deploy/zitadel/bootstrap_dev.py 自動建立 ZITADEL LDAP IdPOIDC Web App,把 ZITADEL_LDAP_IDP_ID / ZITADEL_OAUTH_CLIENT_* 寫入 deploy/zitadel/machinekey/k6.env不必再手動開 Console。

連線資訊

項目
主機(本機) localhost:389
主機ZITADEL 容器內) openldap:389
Base DN dc=gateway,dc=local
Bind DN cn=admin,dc=gateway,dc=local
Bind 密碼 admin
Users OU ou=people,dc=gateway,dc=local

測試帳號

uid 密碼 Email
alice Password1! alice@gateway.local
bob Password1! bob@gateway.local

登入 ZITADEL LDAP IdP 時,使用者名稱通常填 uid(例如 alice),不是 email。

在 ZITADEL Console 建立 LDAP IdP

  1. 開啟 http://localhost:8080/ui/consoleadminzitadel-admin@zitadel.localhost / Password1!
  2. Settings → Identity Providers → New → LDAPGeneric LDAP
  3. 建議欄位(名稱可自訂):
欄位 建議值
Servers ldap://openldap:389
StartTLS 關閉
Bind DN / Username cn=admin,dc=gateway,dc=local
Bind password admin
User base DN ou=people,dc=gateway,dc=local
User object class inetOrgPerson
User unique attribute uid
User filters / Login filter (&(objectClass=inetOrgPerson)(uid=%s))(uid=%s)
Email attribute mail
Display name attribute cn
Username attribute uid
  1. 儲存後複製 IdP ID,寫入 Gateway
# etc/gateway.k6.yaml 或 gateway.dev.yaml
Zitadel:
  OAuthClientID: "<你的 OIDC app client id>"
  OAuthClientSecret: "<secret>"
  LdapIdPID: "<zitadel-ldap-idp-id>"
  1. 重啟 Gateway前端登入頁點 使用 LDAP 登入,以 alice / Password1! 測試。

本機 ldapsearch選用

make ldap-test

# 或手動(需本機 openldap 客戶端brew install openldap
ldapsearch -x -H ldap://localhost:389 \
  -D "cn=admin,dc=gateway,dc=local" -w admin \
  -b "ou=people,dc=gateway,dc=local" "(uid=alice)" mail cn

重設資料

make k6-down   # 會刪除 openldap volume下次 k6-up 會重新 bootstrap LDIF

注意

  • 僅供本機開發;admin / Password1! 不可上線。
  • 若改過 LDIFmake ldap-seed 重灌(已存在的 entry 會略過);要完全重建請 make k6-down 後再 make k6-up