Docs Menu

네이티브 LDAP를 통해 자체 관리형 Active Directory를 사용하여 사용자 인증 및 권한 부여하기

이 페이지의 내용

참고

MongoDB 8.0 부터 시작됩니다. LDAP 인증 및 권한 부여 는 더 이상 사용되지 않습니다. LDAP 는 사용할 수 있으며 MongoDB 8 의 수명 기간 동안 변경 없이 계속 작동합니다. LDAP 는 향후 주요 출시하다 에서 제거될 예정입니다.

자세한 내용은 LDAP 사용 중단을 참조하세요.

MongoDB Enterprise provides support via platform LDAP libraries for proxy authentication and authorization requests to a specified Lightweight Directory Access Protocol (LDAP) service such as Active Directory (AD).

This tutorial describes how to configure MongoDB to perform authentication and authorization through an Active Directory (AD) server via the platform libraries.

참고

libldap (예: RHEL에서 실행되는 경우) 에 연결된 MongoDB 4.2 엔터프라이즈 바이너리의 경우 libldap 액세스가 동기화되므로 일부 성능/대기 시간 비용이 발생합니다.

0}에 연결된 MongoDB 4.2 Enterprise 바이너리의 libldap_r 경우 이전 MongoDB 버전과 동작이 변경되지 않습니다.

중요

Thoroughly familiarize yourself with the following subjects before proceeding:

AD에 대한 자세한 설명은 이 튜토리얼의 범위를 벗어납니다. 이 튜토리얼에서는 AD에 대한 사전 지식이 있다고 가정합니다.

MongoDB 는 MongoDB 서버 와 AD 간의 바인딩을 위해 SASL 메커니즘 사용을 지원합니다. SASL, SASL 메커니즘에 대한 전체 설명 또는 특정 SASL 메커니즘에 대한 특정 AD 구성 요구 사항은 이 튜토리얼의 범위를 벗어납니다. 이 튜토리얼은 SASL 및 관련 주제에 대한 사전 지식이 있다고 가정합니다.

You must configure internal member authentication before you can set up LDAP authentication or authorization for a cluster.

This tutorial explains configuring MongoDB for AD authentication and authorization.

To perform this procedure on your own MongoDB server, you must modify the given procedures with respect to your own specific infrastructure, especially Active Directory configurations, constructing AD queries, or managing users.

기본적으로 MongoDB는 AD 서버에 바인딩할 때 TLS/SSL 연결을 만듭니다. 이를 위해서는 AD 서버의 CA(인증 기관) 인증서에 액세스할 수 있도록 MongoDB 서버의 호스트를 구성해야 합니다.

이 튜토리얼에서는 필요한 호스트 구성에 대한 지침을 제공합니다.

이 튜토리얼에서는 사용자가 AD 서버의 CA 인증서에 액세스할 수 있고 MongoDB 서버에 인증서 복사본을 만들 수 있다고 가정합니다.

$external 인증 사용자(Kerberos, LDAP 또는 X.509 사용자)와 함께 클라이언트 세션 및 인과적 일관성 보장 을 사용하려면 사용자 이름이 10KB보다 클 수 없습니다.

이 튜토리얼에서는 다음 예시 AD 객체를 제공된 쿼리, 구성 및 출력의 기반으로 사용합니다. 각 객체 는 가능한 속성의 하위 집합만 표시합니다.

dn:CN=bob,CN=Users,DC=marketing,DC=example,DC=com
userPrincipalName: bob@marketing.example.com
memberOf: CN=marketing,CN=Users,DC=example,DC=com
dn:CN=alice,CN=Users,DC=engineering,DC=example,DC=com
userPrincipalName: alice@engineering.example.com
memberOf: CN=web,CN=Users,DC=example,DC=com
memberOf: CN=PrimaryApplication,CN=Users,DC=example,DC=com
dn:CN=sam,CN=Users,DC=dba,DC=example,DC=com
userPrincipalName: sam@dba.example.com
memberOf: CN=dba,CN=Users,DC=example,DC=com
memberOf: CN=PrimaryApplication,CN=Users,DC=example,DC=com
dn:CN=joe,CN=Users,DC=analytics,DC=example,DC=com
userPrincipalName: joe@analytics.example.com
memberof: CN=marketing,CN=Users,DC=example,DC=com
dn:CN=marketing,CN=Users,DC=example,DC=com
member:CN=bob,CN=Users,DC=marketing,DC=example,DC=com
member:CN=joe,CN=Users,DC=analytics,DC=example,DC=com
dn:CN=engineering,CN=Users,DC=example,DC=com
member:CN=web,CN=Users,DC=example,DC=com
member:CN=dba,CN=users,DC=example,DC=com
dn:CN=web,CN=Users,DC=example,DC=com
member:CN=alice,CN=Users,DC=engineering,DC=example,DC=com
dn:CN=dba,CN=Users,DC=example,DC=com
member:CN=sam,CN=Users,DC=dba,DC=example,DC=com
dn:CN=PrimaryApplication,CN=Users,DC=example,DC=com
member:CN=sam,CN=Users,DC=dba,DC=example,DC=com
member:CN=alice,CN=Users,DC=engineering,DC=example,DC=com

이 튜토리얼에서는 사용자 이름 과 비밀번호를 사용하여 AD 서버 에서 쿼리를 수행합니다. 제공된 자격 증명 에는 security.ldap.userToDNMapping 또는 security.ldap.authz.queryTemplate와 관련된 쿼리를 지원하기 위해 AD 서버 에 대한 충분한 권한이 있어야 합니다.

MongoDB LDAP 권한 부여를 받으려면 복제본 세트의 모든 mongod가 최소한 MongoDB 3.4.0 이상에 있어야 합니다.

MongoDB LDAP 권한 부여를 위해서는 샤딩된 클러스터의 모든 mongodmongos가 최소한 MongoDB 3.4.0 이상이어야 합니다.

1

TLS/SSL을 통해 AD (AD) 서버 에 연결하려면 mongod 또는 mongosAD 서버의 인증 기관(CA) 인증서에 액세스 이 필요합니다.

Linux에서는 ldap.conf 파일의 TLS_CACERT 또는 TLS_CACERTDIR 옵션을 통해 AD 서버의 CA 인증서를 지정합니다.

플랫폼의 패키지 관리자는 MongoDB Enterprise의 libldap 종속성을 설치하는 동안 ldap.conf 파일을 생성합니다. 구성 파일 또는 참조된 옵션에 대한 전체 문서를 확인하려면 ldap.conf를 참조하세요.

Microsoft Windows 에서 플랫폼의 자격 증명 관리 도구를 사용하여 AD 서버의 인증 기관(CA) 인증서를 로드합니다. 정확한 자격 증명 관리 도구는 Windows 버전에 따라 다릅니다. 이 도구를 사용하려면 사용 중인 Windows 버전에 대한 설명서를 참조하세요.

mongod 또는 mongos 이(가) AD CA 파일에 액세스 할 수 없는 경우, Active Directory 서버 에 대한 TLS/SSL 연결을 생성할 수 없습니다.

선택적으로 TLS/SSL을 비활성화하려면 security.ldap.transportSecuritynone으로 설정합니다.

경고

transportSecurity을(를) none(으)로 설정하면 MongoDB와 AD 서버 간에 사용자 자격 증명을 포함한 일반 텍스트 정보가 전송됩니다.

2

--host--port 옵션을 통해 mongosh(을)를 사용해 MongoDB 서버에 연결합니다.

mongosh --host <hostname> --port <port>

현재 MongoDB 서버가 인증을 시행하는 경우 userAdmin 또는 userAdminAnyDatabase에서 제공하는 것과 같은 역할 관리 권한이 있는 사용자로 admin 데이터베이스에 인증해야 합니다. MongoDB 서버의 구성된 인증 메커니즘에 적합한 --authenticationMechanism을 포함하세요.

mongosh --host <hostname> --port <port> --username <user> --password <pass> --authenticationDatabase="admin" --authenticationMechanism="<mechanism>"

참고

Windows MongoDB 배포 서버의 경우 mongosh(을)를 mongo.exe(으)로 바꿔야 합니다.

3

AD 를 사용하여 MongoDB 사용자를 관리 하려면 userAdmin 또는 userAdminAnyDatabase 에서제공하는 역할과 같이 역할을 생성하고 관리 할 수 있는 admin 데이터베이스 에 역할 을 하나 이상 생성해야 합니다.

역할 이름은 AD 그룹의 고유 이름과 정확히 일치해야 합니다. 그룹에는 최소한 한 명의 AD 사용자가 구성원으로 있어야 합니다.

Given the available Active Directory groups,the following operation:

  • AD 그룹 CN=dba,CN=Users,DC=example,DC=com 에 해당하는 역할 생성합니다.

  • admin 데이터베이스에서 userAdminAnyDatabase 역할을 할당합니다.

var admin = db.getSiblingDB("admin")
admin.createRole(
{
role: "CN=dba,CN=Users,DC=example,DC=com",
privileges: [],
roles: [ "userAdminAnyDatabase" ]
}
)

사용자가 사용자 관리자 권한을 가져야 하는 각 데이터베이스에 userAdmin 역할을 부여할 수도 있습니다. 이러한 역할은 역할 생성 및 관리에 필요한 권한을 제공합니다.

중요

MongoDB 역할, AD 그룹 또는 그룹 멤버십을 구성할 때는 최소 권한 원칙을 적용하는 것이 좋습니다.

4

MongoDB 구성 파일은 파일 확장자가 .conf인 일반 텍스트 YAML 파일입니다.

  • 기존 MongoDB 배포를 업그레이드하는 경우 현재 구성 파일을 복사하고 해당 복사본에서 작업하세요.

  • (Linux만 해당) 신규 배포이 플랫폼의 패키지 관리자를 사용하여 MongoDB Enterprise를 설치한 경우, 설치에는 /etc/mongod.conf 기본값 구성 파일이 포함됩니다. 해당 기본값 구성 파일을 사용하거나 해당 파일의 복사본을 만들어 작업할 수 있습니다.

  • 해당 파일이 없는 경우 확장자가 .conf인 빈 파일을 만들고 새 구성 파일에서 작업합니다.

5

MongoDB 구성 파일에서 security.ldap.servers을(를) AD 서버의 호스트 및 포트로 설정합니다. AD 인프라에 복제 목적으로 여러 AD 서버가 포함된 경우 서버의 호스트 및 포트를 쉼표로 구분된 목록으로 security.ldap.servers에 지정하세요.

You must also enable LDAP authentication by setting security.authorization to enabled and setParameter authenticationMechanisms to PLAIN

예시

activedirectory.example.net 위치에 있는 AD 서버에 연결하려면 구성 파일에 다음을 포함시키세요.

security:
authorization: "enabled"
ldap:
servers: "activedirectory.example.net"
setParameter:
authenticationMechanisms: 'PLAIN'

쿼리를 수행하려면 MongoDB 가 AD 서버 에 바인딩되어야 합니다. 기본값 으로 MongoDB 는 간단한 인증 메커니즘 을 사용하여 AD 서버 에 자신을 바인딩합니다.

또는 SASL을(를) 사용하여 AD 서버에 바인딩하도록 구성 파일에서 다음 설정을 구성할 수 있습니다.

이 튜토리얼에서는 기본값 simple LDAP 인증 메커니즘을 사용합니다.

6

MongoDB 구성 파일에서 security.ldap.authz.queryTemplateRFC4516 형식의 LDAP 쿼리 URL 템플릿으로 설정합니다.

템플릿에서는 다음 중 하나를 사용할 수 있습니다.

  • {USER} placeholder to substitute the authenticated username into the LDAP query URL.

  • {PROVIDED_USER} placeholder to substitute the supplied username, i.e. before either authentication or LDAP transformation, into the LDAP query.

참고

RFC4515 에 대한 전체 설명 , RFC4516 또는 AD 쿼리는 이 튜토리얼의 범위를 벗어납니다. 이 튜토리얼에서 제공하는 queryTemplate 는 예시 일 뿐이며, 특정 AD 배포서버 서버에는 적용되지 않을 수 있습니다.

예시

다음 쿼리 템플릿은 재귀 그룹 멤버 자격에 따라 {USER} 멤버로 나열하는 모든 그룹을 반환합니다. 이 LDAP 쿼리는 그룹 개체가 member 속성을 사용하여 전체 사용자 고유 이름(DN)을 저장하여 사용자 멤버십을 추적한다고 가정합니다. 쿼리에는 LDAP_MATCHING_RULE_IN_CHAIN에 대한 AD 관련 일치 규칙 OID 1.2.840.113556.1.4.1941이(가) 포함됩니다. 이 일치 규칙은 LDAP 검색 필터의 AD 전용 확장입니다.

경고

If the AD forest contains a large number of groups, the recursive member:1.2.840.113556.1.4.1941 filter can lead to significant performance degradation.

security:
ldap:
authz:
queryTemplate:
"DC=example,DC=com??sub?(&(objectClass=group)(member:1.2.840.113556.1.4.1941:={USER}))"

MongoDB는 쿼리 템플릿을 사용하여 {USER}를 인증된 사용자 이름으로 대체하여 LDAP 서버를 쿼리합니다.

For example, a user authenticates as CN=sam,CN=Users,DC=dba,DC=example,DC=com. MongoDB creates an LDAP query based on the queryTemplate, substituting the {USER} token with the authenticated/transfored username. The Active Directory server performs a recursive group lookup for any group that either directly or transitively lists the user as a member. Based on the Active Directory groups, the AD server returns the following groups:

  • CN=dba,CN=Users,DC=example,DC=com

  • CN=engineering,CN=Users,DC=example,DC=com

  • CN=PrimaryApplication,CN=Users,DC=example,DC=com

MongoDB는 반환된 각 그룹 DNadmin 데이터베이스의 역할에 매핑합니다. 매핑된 각 그룹 DN 에 대해 admin 데이터베이스에 이름이 정확히 DN과 일치하는 기존 역할이 있는 경우 MongoDB는 사용자에게 해당 역할에 할당된 역할 및 권한을 부여합니다.

The matching rule LDAP_MATCHING_RULE_IN_CHAIN requires providing the full DN of the authenticating user. If users authenticate using a different username format, such as their user principal name, you must transform the incoming usernames into DNs using security.ldap.userToDNMapping.

7

If your users authenticate with a username that is not a full LDAP DN, you may need to transform the username to support LDAP authentication or authorization. MongoDB uses the transformed username for both authentication and authorization.

MongoDB 구성 파일 에서 를 userToDNMapping 설정하다 하여 인증 사용자가 제공한 사용자 이름 을 를 지원 하는 AD DN으로 queryTemplate 변환합니다.

예시

Given the configured queryTemplate, users must authenticate with their full LDAP DN. If users instead authenticate using their userPrincipalName, then a transformation must be applied to convert the provided username to a full LDAP DN.

다음 userToDNMapping 구성은 match 정규 표현식 필터를 사용하여 제공된 사용자 이름을 캡처합니다. MongoDB는 쿼리를 실행하기 전에 캡처된 사용자 이름을 ldapQuery 쿼리 템플릿에 삽입합니다.

security:
ldap:
userToDNMapping:
'[
{
match : "(.+)",
ldapQuery: "DC=example,DC=com??sub?(userPrincipalName={0})"
}
]'

The Active Directory server returns the full LDAP DN associated to the user object with a matching userPrincipalName. MongoDB can then use this transformed username for authentication and authorization.

배포에 맞게 주어진 샘플 구성을 수정해야 합니다. 예를 들어 ldapQuery 기본 DN은 사용자 엔티티가 포함된 기본 DN과 일치해야 합니다. AD 배포를 지원하려면 다른 수정이 필요할 수 있습니다.

예시

사용자가 alice@ENGINEERING.EXAMPLE.COM으로 인증합니다. MongoDB는 먼저 userToDNMapping에 지정된 모든 변환을 적용합니다. MongoDB는 제공된 구성에 따라 match 단계에서 사용자 이름을 캡처하고 LDAP 쿼리를 실행합니다.

DC=example,DC=com??sub?(userPrincipalName=alice@ENGINEERING.EXAMPLE.COM)

Based on the configured Active Directory users, the AD server should return CN=alice,CN=Users,DC=engineering,DC=example,DC=com.

그런 다음 MongoDB는 queryTemplate에 구성된 LDAP 쿼리를 실행하여 {USER} 토큰을 변환된 사용자 이름 CN=alice,CN=Users,DC=engineering,DC=example,DC=com으로 바꿉니다.

중요

userToDNMappingsubstitution 매개 변수를 사용하여 그룹 이름을 변환하는 경우 대체 결과는 반드시 RFC4514 이스케이프된 문자열이어야 합니다.

8

MongoDB는 AD 서버에서 쿼리를 수행하기 위해 자격 증명이 필요합니다.

구성 파일에서 다음 설정을 구성합니다.

security:
ldap:
bind:
queryUser: "mongodbadmin@dba.example.com"
queryPassword: "secret123"

Windows MongoDB 서버에서는 security.ldap.bind.useOSDefaultstrue 로 설정하다 하여 queryUserqueryPassword 대신 OS 사용자의 자격 증명 을 사용할 수 있습니다.

queryUser에는 MongoDB를 대신하여 모든 LDAP 쿼리를 수행할 수 있는 권한이 있어야 합니다.

9

Add any additional configuration options required for your deployment. For example, you can specify your desired storage.dbPath or change the default net.port number.

mongodmongos 는 기본적으로 로컬 호스트에 바인딩됩니다. 배포 구성원이 다른 호스트에서 실행되거나 원격 클라이언트를 배포에 연결하려는 경우 net.bindIp 설정을 지정해야 합니다.

10

이 절차 중에 생성된 구성 파일의 경로를 지정하여 --config 옵션으로 MongoDB 서버를 시작합니다. 현재 MongoDB 서버가 실행 중인 경우 서버를 중지할 수 있도록 적절한 준비를 합니다.

mongod --config <path-to-config-file>

Windows MongoDB deployments must use mongod.exe instead of mongod.

11

MongoDB 서버에 연결하여 직접 또는 전이적 그룹 멤버십이 userAdminuserAdminAnyDatabase가 있는 admin 데이터베이스의 MongoDB 역할 또는 이와 동등한 권한이 있는 사용자 지정 역할에 해당하는 사용자로 인증합니다.

mongosh를 사용하여 MongoDB 서버에 인증하고 다음 옵션을 설정합니다.

예시

Previously in this procedure, you configured the dn:CN=dba,CN=Users,DC=example,DC=com role on the admin database with the required permissions. This role corresponds to an AD group. Based on the configured AD users, you can authenticate as the user sam@dba.example.com and receive the required permissions.

mongosh --username sam@DBA.EXAMPLE.COM --password --authenticationMechanism 'PLAIN' --authenticationDatabase '$external' --host <hostname> --port <port>

-p 명령줄 옵션에 비밀번호를 지정하지 않으면 mongosh(이)가 비밀번호를 묻는 메시지를 표시합니다.

Windows MongoDB 배포는 mongosh 대신 mongo.exe(을)를 사용해야 합니다.

구성된 활성화 디렉토리 사용자가 주어지면 사용자는 성공적으로 인증되고 적절한 권한을 받습니다.

참고

If you want to authenticate as an existing non-$external user, set --authenticationMechanism to SCRAM authentication mechanism (e.g. SCRAM-SHA-1 or SCRAM-SHA-256 as appropriate). This requires that the MongoDB server's setParameter authenticationMechanisms includes SCRAM-SHA-1 and/or SCRAM-SHA-256.

12

MongoDB 권한 부여 에 사용하려는 AD 서버 의 각 그룹 에 대해 MongoDB 서버의 admin 데이터베이스 에 일치하는 역할 을 만들어야 합니다.

예시

다음 작업은 AD 그룹 DN CN=PrimaryApplication,CN=Users,DC=example,DC=com 의 이름을 딴 역할 생성하고 해당 그룹 에 적절한 역할과 권한을 할당합니다.

db.getSiblingDB("admin").createRole(
{
role: "CN=PrimaryApplication,CN=Users,DC=example,DC=com",
privileges: [],
roles: [
{ role: "readWrite", db: "PrimaryApplication" }
]
}
)

구성된 Active Directory 그룹이 주어지면 MongoDB는 sam@DBA.EXAMPLE.COM 또는 alice@ENGINEERING.EXAMPLE.COM 중 하나로 인증하는 사용자에게 PrimaryApplication 데이터베이스의readWrite 역할을 부여합니다.

참고

admin 데이터베이스에서 역할을 관리하려면 admin, userAdminAnyDatabase에서 userAdmin을 가진 사용자로 인증되었거나 동등한 권한이 있는 사용자 지정 역할이 켜져 있어야 합니다.

13

If upgrading an existing installation with users configured on the $external database, you must meet the following requirements for each user to ensure access after configuring MongoDB for AD authentication and authorization:

  • 사용자는 AD 서버 에 해당 사용자 객체 가 있습니다.

  • 사용자는 AD 서버 에서 적절한 그룹의 멤버십을 가지고 있습니다.

  • MongoDB에는 인증된 사용자가 권한을 유지할 수 있도록 사용자의 AD 그룹 이름을 딴 admin 데이터베이스의 역할이 포함되어 있습니다.

예시

$external 데이터베이스에 다음 사용자가 있습니다.

{
user : "joe@ANALYTICS.EXAMPLE.COM",
roles: [
{ role : "read", db : "web_analytics" },
{ role : "read", db : "PrimaryApplication" }
]
}

사용자가 AD 그룹 CN=marketing,CN=Users,DC=example,DC=com에 속한다고 가정하면 다음 작업을 수행하면 적절한 권한이 있는 일치하는 역할이 생성됩니다.

db.getSiblingDB("admin").createRole(
{
role: "CN=marketing,CN=Users,DC=example,DC=com",
privileges: [],
roles: [
{ role: "read", db: "web_analytics" }
{ role: "read", db: "PrimaryApplication" }
]
}
)

구성된 queryTemplate에 따라 MongoDB는 CN=marketing,CN=Users,DC=example,DC=com 그룹에 직접 또는 전이 멤버십이 있는 모든 사용자에게 web_analyticsPrimaryApplication 데이터베이스에서 read 작업을 수행할 수 있는 권한을 부여합니다.

중요

해당 AD 그룹에 대한 역할을 구성할 때 해당 그룹의 구성원 자격이 있는 모든 사용자는 할당된 역할 및 권한을 받을 수 있다는 점을 기억하세요. MongoDB 역할, AD 그룹 또는 그룹 구성원 자격을 구성할 때는 최소 권한 원칙을 적용하는 것이 좋습니다.

If you want to continue allowing users on non-$external databases to access MongoDB, you must include SCRAM authentication mechanism (e.g. SCRAM-SHA-1 and/or SCRAM-SHA-256) in the setParameter authenticationMechanisms configuration option. For example:

setParameter:
authenticationMechanisms: "PLAIN,SCRAM-SHA-1,SCRAM-SHA-256"

또는 위의 절차에 따라$external 가 아닌 사용자를 AD 로 전환합니다.

이 절차를 수행하면 다음 구성 파일이 생성됩니다.

security:
authorization: "enabled"
ldap:
servers: "activedirectory.example.net"
bind:
queryUser: "mongodbadmin@dba.example.com"
queryPassword: "secret123"
userToDNMapping:
'[
{
match: "(.+)",
ldapQuery: "DC=example,DC=com??sub?(userPrincipalName={0})"
}
]'
authz:
queryTemplate: "DC=example,DC=com??sub?(&(objectClass=group)(member:1.2.840.113556.1.4.1941:={USER}))"
setParameter:
authenticationMechanisms: "PLAIN"

The given sample configuration requires modification to match your Active Directory schema, directory structure, and configuration. You may also require additional configuration file options for your deployment.

역할 및 권한 구성에 대한 자세한 내용은 다음을 참조하세요.

이 페이지의 내용