本主題將說明如何設定 MongoDB,以便與 Managed Service for Microsoft Active Directory 整合。以下程序已通過 MongoDB Enterprise 4.0 和 4.2 版的驗證。
事前準備
設定 MongoDB 前,請建立受管理的 Microsoft AD 網域。
部署 MongoDB
首先,將 MongoDB 部署至 Google Cloud。為確保與 Active Directory 相容,請務必安裝支援 LDAP 驗證的 MongoDB 版本,例如 MongoDB Enterprise 版。您可以在 Compute Engine 執行個體上安裝 MongoDB,也可以在 Google Kubernetes Engine 上部署 MongoDB。
在 Compute Engine 執行個體上
如要在 Compute Engine 執行個體上以獨立套件形式安裝 MongoDB,請完成 MongoDB Enterprise 安裝程序中的步驟。
在 Google Kubernetes Engine 容器中
如要在 Google Kubernetes Engine 容器上部署 MongoDB,請完成下列步驟:
- 完成「在 Kubernetes 中使用 StatefulSets 執行 MongoDB 資料庫」程式碼研究室課程。
- 前往
./mongo-k8s-sidecar/example/StatefulSet/
目錄。 - 開啟「
mongo-statefulset.yaml
」 - 以
image: path to gcr
取代image: mongo
設定驗證
接著,請設定驗證機制。受管理的 Microsoft AD 可做為 LDAP 後端,用於驗證。您可以選擇 LDAP 或 Kerberos。
如要設定驗證,請使用設定值完成下列任一設定程序:
- 如要使用 LDAP 設定驗證,請完成 MongoDB LDAP 教學課程。
- 如要使用 Kerberos 設定驗證,請完成 MongoDB Kerberos 教學課程。
驗證設定值
請使用下列值設定驗證:
security.ldap.server
:使用設定期間為網域提供的 FQDN。security.ldap.userToDNMapping
:使用ldapQuery
中提供的網域網域名稱。- 範例:
ldapQuery: "DC=cloudad,DC=gke,DC=com??sub?(userPrincipalName={0})"
- 範例:
security.ldap.server.authz
:使用queryTemplate
中提供的網域名稱。- 範例:
queryTemplate: "DC=cloudad,DC=gke,DC=com??sub?(&(objectClass=group)(member:1.2.840.113556.1.4.1941:={USER}))"
- 範例:
security.ldap.transportSecurity
:設為none
可停用 TLS/SSL。
在受管理的 Microsoft AD 中,使用者會在 Cloud OU
下建立。您應為在 Cloud OU
下建立的資源和群組使用專屬名稱。舉例來說,如果是使用者 dba
,您應使用其別名 "CN=dba,OU=Cloud,DC=cloudad,DC=gke,DC=com"
。