Docs Menu
Docs Home
/
MongoDB ๋งค๋‰ด์–ผ
/ / / /

๋„ค์ดํ‹ฐ๋ธŒ LDAP๋ฅผ ํ†ตํ•ด ์ž์ฒด ๊ด€๋ฆฌํ˜• Active Directory๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌํ•˜๊ธฐ

์ด ํŽ˜์ด์ง€์˜ ๋‚ด์šฉ

  • ์ „์ œ ์กฐ๊ฑด
  • ๊ณ ๋ ค ์‚ฌํ•ญ
  • ์ ˆ์ฐจ

์ฐธ๊ณ 

MongoDB 8.0 ๋ถ€ํ„ฐ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค. LDAP ์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌ ๋Š” ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. LDAP ๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ MongoDB 8 ์˜ ์ˆ˜๋ช… ๊ธฐ๊ฐ„ ๋™์•ˆ ๋ณ€๊ฒฝ ์—†์ด ๊ณ„์† ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. LDAP ๋Š” ํ–ฅํ›„ ์ฃผ์š” ์ถœ์‹œํ•˜๋‹ค ์—์„œ ์ œ๊ฑฐ๋  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ LDAP ์‚ฌ์šฉ ์ค‘๋‹จ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

MongoDB Enterprise ๋Š” ํ”Œ๋žซํผ LDAP ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ†ตํ•ด Active Directory(AD)์™€ ๊ฐ™์€ ์ง€์ •๋œ LDAP(LDAP Directory Access Protocol) ์„œ๋น„์Šค์— ๋Œ€ํ•œ ํ”„๋ก์‹œ ์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌ ์š”์ฒญ์„ ์ง€์› ํ•ฉ๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ํ”Œ๋žซํผ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ†ตํ•ด AD(Active Directory) ์„œ๋ฒ„๋ฅผ ํ†ตํ•ด ์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋„๋ก MongoDB๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ 

libldap์— ์—ฐ๊ฒฐ๋œ MongoDB 4.2 ์—”ํ„ฐํ”„๋ผ์ด์ฆˆ ๋ฐ”์ด๋„ˆ๋ฆฌ์˜ ๊ฒฝ์šฐ(์˜ˆ: RHEL์—์„œ ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ), libldap์— ๋Œ€ํ•œ ์•ก์„ธ์Šค๊ฐ€ ๋™๊ธฐํ™”๋˜์–ด ์ผ๋ถ€ ์„ฑ๋Šฅ/์ง€์—ฐ ๋น„์šฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

0}์— ์—ฐ๊ฒฐ๋œ MongoDB 4.2 Enterprise ๋ฐ”์ด๋„ˆ๋ฆฌ์˜ libldap_r ๊ฒฝ์šฐ ์ด์ „ MongoDB ๋ฒ„์ „๊ณผ ๋™์ž‘์ด ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์ค‘์š”

๊ณ„์† ์ง„ํ–‰ํ•˜๊ธฐ ์ „์— ๋‹ค์Œ ์ฃผ์ œ๋ฅผ ์ฒ ์ €ํžˆ ์ˆ™์ง€ํ•ฉ๋‹ˆ๋‹ค.

  • LDAP ์ธ์ฆ

  • LDAP ์ธ์ฆ

  • ์•กํ‹ฐ๋ธŒ ๋””๋ ‰ํ† ๋ฆฌ

AD ์— ๋Œ€ํ•œ ์ „์ฒด ์„ค๋ช…์€ ์ด ํŠœํ† ๋ฆฌ์–ผ์˜ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฉ๋‹ˆ๋‹ค. ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” AD ์— ๋Œ€ํ•œ ์‚ฌ์ „ ์ง€์‹์ด ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

MongoDB๋Š” MongoDB ์„œ๋ฒ„์™€ AD ๊ฐ„์˜ ๋ฐ”์ธ๋”ฉ์— SASL ๋ฉ”์ปค๋‹ˆ์ฆ˜ ์‚ฌ์šฉ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. SASL, SASL ๋ฉ”์ปค๋‹ˆ์ฆ˜์— ๋Œ€ํ•œ ์ „์ฒด ์„ค๋ช… ๋˜๋Š” ํŠน์ • SASL ๋ฉ”์ปค๋‹ˆ์ฆ˜์— ๋Œ€ํ•œ ํŠน์ • AD ๊ตฌ์„ฑ ์š”๊ตฌ ์‚ฌํ•ญ์€ ์ด ํŠœํ† ๋ฆฌ์–ผ์˜ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฉ๋‹ˆ๋‹ค. ์ด ํŠœํ† ๋ฆฌ์–ผ์€ SASL ๋ฐ ๊ด€๋ จ ์ฃผ์ œ์— ๋Œ€ํ•œ ์‚ฌ์ „ ์ง€์‹์ด ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

ํด๋Ÿฌ์Šคํ„ฐ์— ๋Œ€ํ•œ LDAP ์ธ์ฆ ๋˜๋Š” ๊ถŒํ•œ์„ ์„ค์ •ํ•˜๋ ค๋ฉด ๋จผ์ € ๋‚ด๋ถ€ ๋ฉค๋ฒ„ ์ธ์ฆ์„ ๊ตฌ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” AD ์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌ๋ฅผ ์œ„ํ•ด MongoDB๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

์ž์ฒด MongoDB Server์—์„œ ์ด ์ ˆ์ฐจ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ ค๋ฉด ์ž์ฒด ํŠน์ • ์ธํ”„๋ผ, ํŠนํžˆ Active Directory ๊ตฌ์„ฑ, AD ์ฟผ๋ฆฌ ๊ตฌ์„ฑ ๋˜๋Š” ์‚ฌ์šฉ์ž ๊ด€๋ฆฌ์™€ ๊ด€๋ จํ•˜์—ฌ ์ง€์ •๋œ ์ ˆ์ฐจ๋ฅผ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ MongoDB๋Š” AD ์„œ๋ฒ„์— ๋ฐ”์ธ๋”ฉํ•  ๋•Œ TLS/SSL ์—ฐ๊ฒฐ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด์„œ๋Š” MongoDB Server์˜ ํ˜ธ์ŠคํŠธ๊ฐ€ AD ์„œ๋ฒ„์˜ ์ธ์ฆ ๊ธฐ๊ด€(CA) ์ธ์ฆ์„œ์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ํ•„์š”ํ•œ ํ˜ธ์ŠคํŠธ ๊ตฌ์„ฑ์— ๋Œ€ํ•œ ์ง€์นจ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ AD ์„œ๋ฒ„์˜ CA ์ธ์ฆ์„œ์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๊ณ  MongoDB ์„œ๋ฒ„์— ์ธ์ฆ์„œ ๋ณต์‚ฌ๋ณธ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

2} ์ธ์ฆ ์‚ฌ์šฉ์ž(Kerberos, LDAP ๋˜๋Š” x.509 ์‚ฌ์šฉ์ž)์™€ ํ•จ๊ป˜ ํด๋ผ์ด์–ธํŠธ ์„ธ์…˜ ๋ฐ ์ธ๊ณผ์  ์ผ๊ด€์„ฑ ๋ณด์žฅ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์‚ฌ์šฉ์ž ์ด๋ฆ„์ด 10KB๋ณด๋‹ค ํด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. $external

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ๋‹ค์Œ ์˜ˆ์ œ 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 ๊ถŒํ•œ ๋ถ€์—ฌ๋ฅผ ์œ„ํ•ด์„œ๋Š” ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์˜ ๋ชจ๋“  mongod ๋ฐ mongos๊ฐ€ ์ตœ์†Œํ•œ MongoDB 3.4.0 ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

1

TLS/SSL์„ ํ†ตํ•ด AD (AD) ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•˜๋ ค๋ฉด mongod ๋˜๋Š” mongos ์ด(๊ฐ€) AD ์„œ๋ฒ„์˜ ์ธ์ฆ ๊ธฐ๊ด€(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.transportSecurity๋ฅผ none์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

๊ฒฝ๊ณ 

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 ์‚ฌ์šฉ์ž๊ฐ€ ํ•œ ๋ช… ์ด์ƒ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ Active Directory ๊ทธ๋ฃน ์ด ์ฃผ์–ด์ง€๋ฉด ๋‹ค์Œ ์ž‘์—…์ด ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค.

  • 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 ์ง€์ •ํ•˜์„ธ์š”.

๋˜ํ•œ security.authorization ๋ฅผ enabled ๋กœ ์„ค์ •ํ•˜๊ณ  setParameter authenticationMechanisms ๋ฅผ PLAIN๋กœ ์„ค์ •ํ•˜์—ฌ LDAP ์ธ์ฆ์„ ์‚ฌ์šฉํ•˜๋„๋ก ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ

activedirectory.example.net ์— ์žˆ๋Š” AD ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•˜๋ ค๋ฉด ๊ตฌ์„ฑ ํŒŒ์ผ์— ๋‹ค์Œ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

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

์ฟผ๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ ค๋ฉด MongoDB๊ฐ€ AD ์„œ๋ฒ„์— ๋ฐ”์ธ๋”ฉ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ MongoDB๋Š” ๊ฐ„๋‹จํ•œ ์ธ์ฆ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ์‚ฌ์šฉํ•˜์—ฌ AD ์„œ๋ฒ„์— ์ž์ฒด์ ์œผ๋กœ ๋ฐ”์ธ๋”ฉํ•ฉ๋‹ˆ๋‹ค.

๋˜๋Š” ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ ๋‹ค์Œ ์„ค์ •์„ ๊ตฌ์„ฑํ•˜์—ฌ SASL ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ AD ์„œ๋ฒ„์— ๋ฐ”์ธ๋”ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • security.ldap.bind.method๋ฅผ sasl๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

  • security.ldap.bind.saslMechanisms, AD ์„œ๋ฒ„๊ฐ€ ์ง€์›ํ•˜๋Š” ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„๋œ SASL ๋ฉ”์ปค๋‹ˆ์ฆ˜ ๋ฌธ์ž์—ด์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ๊ธฐ๋ณธ๊ฐ’ simple LDAP ์ธ์ฆ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

6

MongoDB ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ security.ldap.authz.queryTemplate์„ RFC4516 ํ˜•์‹์˜ LDAP ์ฟผ๋ฆฌ URL ํ…œํ”Œ๋ฆฟ์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

ํ…œํ”Œ๋ฆฟ์—์„œ๋Š” ๋‹ค์Œ ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • {USER} ํ”Œ๋ ˆ์ด์Šคํ™€๋”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฆ๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ LDAP ์ฟผ๋ฆฌ URL๋กœ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • {PROVIDED_USER} ์ธ์ฆ ๋˜๋Š” LDAP ๋ณ€ํ™˜ ์ „์— ์ œ๊ณต๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์€ LDAP ์ฟผ๋ฆฌ๋กœ ๋Œ€์ฒดํ•˜๋Š” ์ž๋ฆฌ ํ‘œ์‹œ์ž์ž…๋‹ˆ๋‹ค.

์ฐธ๊ณ 

RFC4515 ์— ๋Œ€ํ•œ ์ „์ฒด ์„ค๋ช… , RFC4516 ๋˜๋Š” AD ์ฟผ๋ฆฌ๋Š” ์ด ํŠœํ† ๋ฆฌ์–ผ์˜ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฉ๋‹ˆ๋‹ค. ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ ์ œ๊ณตํ•˜๋Š” queryTemplate ๋Š” ์˜ˆ์‹œ์ผ ๋ฟ์ด๋ฉฐ ํŠน์ • AD ๋ฐฐํฌ์„œ๋ฒ„์—๋Š” ์ ์šฉ๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์‹œ

๋‹ค์Œ ์ฟผ๋ฆฌ ํ…œํ”Œ๋ฆฟ์€ ์žฌ๊ท€ ๊ทธ๋ฃน ๋ฉค๋ฒ„์‹ญ์— ๋”ฐ๋ผ {USER} ์„(๋ฅผ) ๋ฉค๋ฒ„๋กœ ๋‚˜์—ดํ•˜๋Š” ๋ชจ๋“  ๊ทธ๋ฃน์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ด LDAP ์ฟผ๋ฆฌ๋Š” ๊ทธ๋ฃน ๊ฐ์ฒด๊ฐ€ member ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ „์ฒด ์‚ฌ์šฉ์ž DN(๊ณ ์œ  ์ด๋ฆ„)์„ ์ €์žฅํ•˜์—ฌ ์‚ฌ์šฉ์ž ๋ฉค๋ฒ„์‹ญ์„ ์ถ”์ ํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. ์ฟผ๋ฆฌ์—๋Š” 1.2.840.113556.1.4.1941 LDAP_MATCHING_RULE_IN_CHAIN ์— ๋Œ€ํ•œ AD ํŠน์ • ์ผ์น˜ ๊ทœ์น™ OID ๊ฐ€ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. . ์ด ์ผ์น˜ ๊ทœ์น™์€ LDAP Atlas Search ํ•„ํ„ฐ์— ๋Œ€ํ•œ AD ํŠน์ • ํ™•์žฅ์ž…๋‹ˆ๋‹ค.

๊ฒฝ๊ณ 

AD ํฌ๋ฆฌ์ŠคํŠธ์— ๋งŽ์€ ์ˆ˜์˜ ๊ทธ๋ฃน์ด ํฌํ•จ๋œ ๊ฒฝ์šฐ ์žฌ๊ท€ member:1.2.840.113556.1.4.1941 ํ•„ํ„ฐํ•˜๋‹ค ๋กœ ์ธํ•ด ์„ฑ๋Šฅ์ด ํฌ๊ฒŒ ์ €ํ•˜๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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

MongoDB๋Š” ์ฟผ๋ฆฌ ํ…œํ”Œ๋ฆฟ์„ ์‚ฌ์šฉํ•˜์—ฌ {USER}๋ฅผ ์ธ์ฆ๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์œผ๋กœ ๋Œ€์ฒดํ•˜์—ฌ LDAP ์„œ๋ฒ„๋ฅผ ์ฟผ๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ์‚ฌ์šฉ์ž๊ฐ€ CN=sam,CN=Users,DC=dba,DC=example,DC=com ์œผ๋กœ ์ธ์ฆํ•ฉ๋‹ˆ๋‹ค. MongoDB๋Š” queryTemplate ๊ธฐ๋ฐ˜์œผ๋กœ LDAP ์ฟผ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , {USER} ํ† ํฐ์„ ์ธ์ฆ๋œ/๋ณ€ํ™˜๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์œผ๋กœ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค. Active Directory ์„œ๋ฒ„๋Š” ์‚ฌ์šฉ์ž๋ฅผ ๊ตฌ์„ฑ์›์œผ๋กœ ์ง์ ‘ ๋˜๋Š” ์ „์ด์ ์œผ๋กœ ๋‚˜์—ดํ•˜๋Š” ๋ชจ๋“  ๊ทธ๋ฃน์— ๋Œ€ํ•ด ์žฌ๊ท€์  ๊ทธ๋ฃน ์กฐํšŒ๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. AD์„œ๋ฒ„๋Š” Active Directory ๊ทธ๋ฃน ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋‹ค์Œ ๊ทธ๋ฃน์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

  • 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๋Š” ๋ฐ˜ํ™˜๋œ ๊ฐ ๊ทธ๋ฃน DN ์„ admin ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์—ญํ• ์— ๋งคํ•‘ํ•ฉ๋‹ˆ๋‹ค. ๋งคํ•‘๋œ ๊ฐ ๊ทธ๋ฃน DN ์— ๋Œ€ํ•ด admin ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ด๋ฆ„์ด ์ •ํ™•ํžˆ DN ๊ณผ ์ผ์น˜ํ•˜๋Š” ๊ธฐ์กด ์—ญํ• ์ด ์žˆ๋Š” ๊ฒฝ์šฐ MongoDB๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ํ•ด๋‹น ์—ญํ• ์— ํ• ๋‹น๋œ ์—ญํ•  ๋ฐ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค.

๋งค์นญ ๊ทœ์น™ LDAP_MATCHING_RULE_IN_CHAIN ์—์„œ๋Š” ์ธ์ฆ ์‚ฌ์šฉ์ž์˜ ์ „์ฒด ๊ณ ์œ  ์ด๋ฆ„ ์„ ์ œ๊ณตํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ๊ณผ ๊ฐ™์€ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ์ด๋ฆ„ ํ˜•์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฆํ•˜๋Š” user principal name ๊ฒฝ์šฐ ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“ค์–ด์˜ค๋Š” ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ DN ์œผ๋กœ ๋ณ€ํ™˜ํ•ด์•ผ security.ldap.userToDNMapping ํ•ฉ๋‹ˆ๋‹ค.

7

์‚ฌ์šฉ์ž๊ฐ€ ์ „์ฒด LDAP ๊ณ ์œ  ์ด๋ฆ„์ด ์•„๋‹Œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์œผ๋กœ ์ธ์ฆํ•˜๋Š” ๊ฒฝ์šฐ LDAP ์ธ์ฆ ๋˜๋Š” ๊ถŒํ•œ ๋ถ€์—ฌ๋ฅผ ์ง€์›ํ•˜๋„๋ก ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ๋ณ€ํ™˜ํ•ด์•ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. MongoDB๋Š” ์ธ์ฆ๊ณผ ๊ถŒํ•œ ๋ถ€์—ฌ ๋ชจ๋‘์— ๋ณ€ํ™˜๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

MongoDB ๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ ์„ค์ •ํ•˜์—ฌ userToDNMapping ์ธ์ฆ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์„ ์ง€์›ํ•˜๋Š” AD ๊ณ ์œ  queryTemplate ์ด๋ฆ„์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ

๊ตฌ์„ฑ๋œ queryTemplate ๊ฐ€ ์ฃผ์–ด์ง€๋ฉด ์‚ฌ์šฉ์ž๋Š” ์ „์ฒด LDAP ๊ณ ์œ  ์ด๋ฆ„์œผ๋กœ ์ธ์ฆํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ๋Œ€์‹  userPrincipalName ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฆํ•˜๋Š” ๊ฒฝ์šฐ ์ œ๊ณต๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์ „์ฒด LDAP DN์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋„๋ก ๋ณ€ํ™˜์„ ์ ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ userToDNMapping ๊ตฌ์„ฑ์€ match ์ •๊ทœ ํ‘œํ˜„์‹ ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ œ๊ณต๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์บก์ฒ˜ํ•ฉ๋‹ˆ๋‹ค. MongoDB๋Š” ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์ „์— ์บก์ฒ˜๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ldapQuery ์ฟผ๋ฆฌ ํ…œํ”Œ๋ฆฟ์— ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค.

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

Active Directory ์„œ๋ฒ„๋Š” ์ผ์น˜ํ•˜๋Š” userPrincipalName ๋ฅผ ๊ฐ€์ง„ ์‚ฌ์šฉ์ž ๊ฐ์ฒด์™€ ์—ฐ๊ฒฐ๋œ ์ „์ฒด LDAP ๊ณ ์œ  ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ MongoDB๋Š” ์ด ๋ณ€ํ™˜๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐฐํฌ์„œ๋ฒ„์™€ ์ผ์น˜ํ•˜๋„๋ก ์ง€์ •๋œ ์ƒ˜ํ”Œ ๊ตฌ์„ฑ์„ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ldapQuery ๊ธฐ๋ณธ ๊ณ ์œ  ์ด๋ฆ„ ์€ ์‚ฌ์šฉ์ž ์—”ํ„ฐํ‹ฐ๊ฐ€ ํฌํ•จ๋œ ๊ธฐ๋ณธ ๊ณ ์œ  ์ด๋ฆ„ ๊ณผ ์ผ์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. AD ๋ฐฐํฌ๋ฅผ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ ์ˆ˜์ •์ด ํ•„์š”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์‹œ

์‚ฌ์šฉ์ž๊ฐ€ alice@ENGINEERING.EXAMPLE.COM์œผ๋กœ ์ธ์ฆํ•ฉ๋‹ˆ๋‹ค. MongoDB๋Š” ๋จผ์ € userToDNMapping์— ์ง€์ •๋œ ๋ชจ๋“  ๋ณ€ํ™˜์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. MongoDB๋Š” ์ œ๊ณต๋œ ๊ตฌ์„ฑ์— ๋”ฐ๋ผ match ๋‹จ๊ณ„์—์„œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์บก์ฒ˜ํ•˜๊ณ  LDAP ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

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

๊ตฌ์„ฑ๋œ Active Directory ์‚ฌ์šฉ์ž ์— ๋”ฐ๋ผ AD ์„œ๋ฒ„๋Š” CN=alice,CN=Users,DC=engineering,DC=example,DC=com ๋ฅผ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ ๋‹ค์Œ MongoDB๋Š” queryTemplate์— ๊ตฌ์„ฑ๋œ LDAP ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ {USER} ํ† ํฐ์„ ๋ณ€ํ™˜๋œ ์‚ฌ์šฉ์ž ์ด๋ฆ„ CN=alice,CN=Users,DC=engineering,DC=example,DC=com์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

์ค‘์š”

userToDNMapping์˜ substitution ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ทธ๋ฃน ์ด๋ฆ„์„ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋Œ€์ฒด ๊ฒฐ๊ณผ๋Š” ๋ฐ˜๋“œ์‹œ RFC4514 ์ด์Šค์ผ€์ดํ”„๋œ ๋ฌธ์ž์—ด์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

8

MongoDB๋Š” AD ์„œ๋ฒ„์—์„œ ์ฟผ๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ ค๋ฉด ์ž๊ฒฉ ์ฆ๋ช…์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๊ตฌ์„ฑ ํŒŒ์ผ์—์„œ ๋‹ค์Œ ์„ค์ •์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

  • , AD ์„œ๋ฒ„์—์„œ ์ฟผ๋ฆฌ๋ฅผsecurity.ldap.bind.queryUser mongos ์ˆ˜ํ–‰ํ•˜๊ธฐ mongod ์œ„ํ•ด ๋˜๋Š” ๋ฐ”์ธ๋“œํ•˜๋Š” Active Directory ์‚ฌ์šฉ์ž๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

  • security.ldap.bind.queryPassword๋ฅผ ํ†ตํ•ด ์ง€์ •๋œ queryUser์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

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

Windows MongoDB Server์—์„œ๋Š” security.ldap.bind.useOSDefaults ๋ฅผ true ๋กœ ์„ค์ •ํ•˜์—ฌ queryUser ๋ฐ queryPassword ๋Œ€์‹  OS ์‚ฌ์šฉ์ž์˜ ์ž๊ฒฉ ์ฆ๋ช…์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

queryUser์—๋Š” MongoDB๋ฅผ ๋Œ€์‹ ํ•˜์—ฌ ๋ชจ๋“  LDAP ์ฟผ๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

9

๋ฐฐํฌ์— ํ•„์š”ํ•œ ์ถ”๊ฐ€ ๊ตฌ์„ฑ ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์›ํ•˜๋Š” storage.dbPath ๋ฅผ ์ง€์ •ํ•˜๊ฑฐ๋‚˜ ๊ธฐ๋ณธ net.port ๋ฒˆํ˜ธ๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

mongod ๋ฐ mongos ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋กœ์ปฌ ํ˜ธ์ŠคํŠธ์— ๋ฐ”์ธ๋”ฉ๋ฉ๋‹ˆ๋‹ค. ๋ฐฐํฌ ๊ตฌ์„ฑ์›์ด ๋‹ค๋ฅธ ํ˜ธ์ŠคํŠธ์—์„œ ์‹คํ–‰๋˜๊ฑฐ๋‚˜ ์›๊ฒฉ ํด๋ผ์ด์–ธํŠธ๋ฅผ ๋ฐฐํฌ์— ์—ฐ๊ฒฐํ•˜๋ ค๋Š” ๊ฒฝ์šฐ net.bindIp ์„ค์ •์„ ์ง€์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

10

์ด ์ ˆ์ฐจ ์ค‘์— ์ƒ์„ฑ๋œ ๊ตฌ์„ฑ ํŒŒ์ผ์˜ ๊ฒฝ๋กœ๋ฅผ ์ง€์ •ํ•˜์—ฌ --config ์˜ต์…˜์œผ๋กœ MongoDB ์„œ๋ฒ„๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ํ˜„์žฌ MongoDB ์„œ๋ฒ„๊ฐ€ ์‹คํ–‰ ์ค‘์ธ ๊ฒฝ์šฐ ์„œ๋ฒ„๋ฅผ ์ค‘์ง€ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ ์ ˆํ•œ ์ค€๋น„๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

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

Windows MongoDB ๋ฐฐํฌ์—์„œ๋Š” {7 mongod.exe ์„(๋ฅผ) ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค mongod

11

MongoDB ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•˜์—ฌ ์ง์ ‘ ๋˜๋Š” ์ „์ด์  ๊ทธ๋ฃน ๋ฉค๋ฒ„์‹ญ์ด userAdmin๊ณผ userAdminAnyDatabase๊ฐ€ ์žˆ๋Š” admin ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ MongoDB ์—ญํ•  ๋˜๋Š” ์ด์™€ ๋™๋“ฑํ•œ ๊ถŒํ•œ์ด ์žˆ๋Š” ์‚ฌ์šฉ์ž ์ง€์ • ์—ญํ• ์— ํ•ด๋‹นํ•˜๋Š” ์‚ฌ์šฉ์ž๋กœ ์ธ์ฆํ•ฉ๋‹ˆ๋‹ค.

mongosh๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ MongoDB ์„œ๋ฒ„์— ์ธ์ฆํ•˜๊ณ  ๋‹ค์Œ ์˜ต์…˜์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

  • --host ๋ฅผ MongoDB ์„œ๋ฒ„์˜ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์œผ๋กœ ์‚ฌ์šฉ

  • --port ๋ฅผ MongoDB ์„œ๋ฒ„์˜ ํฌํŠธ๋กœ ์‚ฌ์šฉ

  • --username ์‚ฌ์šฉ์ž์˜ ์‚ฌ์šฉ์ž ์ด๋ฆ„์—

  • --password ์‚ฌ์šฉ์ž์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ์—

  • --authenticationMechanism to 'PLAIN'

  • --authenticationDatabase to '$external'

์˜ˆ์‹œ

์ด ์ ˆ์ฐจ์˜ ์ด์ „ ๋‹จ๊ณ„์—์„œ๋Š” ํ•„์š”ํ•œ ๊ถŒํ•œ์œผ๋กœ admin ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ dn:CN=dba,CN=Users,DC=example,DC=com ์—ญํ• ์„ ๊ตฌ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ์—ญํ• ์€ AD ๊ทธ๋ฃน์— ํ•ด๋‹นํ•ฉ๋‹ˆ๋‹ค. ๊ตฌ์„ฑ๋œ AD ์‚ฌ์šฉ์ž ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ sam@dba.example.com ์‚ฌ์šฉ์ž๋กœ ์ธ์ฆํ•˜๊ณ  ํ•„์š”ํ•œ ๊ถŒํ•œ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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

-p ๋ช…๋ น์ค„ ์˜ต์…˜์— ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด mongosh(์ด)๊ฐ€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ฌป๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

Windows MongoDB ๋ฐฐํฌ์—์„œ๋Š”mongosh ๋Œ€์‹  mongo.exe ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค

๊ตฌ์„ฑ๋œ ํ™œ์„ฑํ™” ๋””๋ ‰ํ† ๋ฆฌ ์‚ฌ์šฉ์ž๊ฐ€ ์ฃผ์–ด์ง€๋ฉด ์‚ฌ์šฉ์ž๋Š” ์„ฑ๊ณต์ ์œผ๋กœ ์ธ์ฆ๋˜๊ณ  ์ ์ ˆํ•œ ๊ถŒํ•œ์„ ๋ฐ›์Šต๋‹ˆ๋‹ค.

์ฐธ๊ณ 

$external์ด ์•„๋‹Œ ๊ธฐ์กด ์‚ฌ์šฉ์ž๋กœ ์ธ์ฆํ•˜๋ ค๋ฉด --authenticationMechanism์„ SCRAM ์ธ์ฆ ๋ฉ”์ปค๋‹ˆ์ฆ˜(์ƒํ™ฉ์— ๋”ฐ๋ผ SCRAM-SHA-1 ๋˜๋Š” SCRAM-SHA-256)์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ ค๋ฉด MongoDB ์„œ๋ฒ„์˜ setParameter authenticationMechanisms์— SCRAM-SHA-1 ๋ฐ/๋˜๋Š” 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

$external ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๊ตฌ์„ฑ๋œ ์‚ฌ์šฉ์ž ๋กœ ๊ธฐ์กด ์„ค์น˜๋ฅผ ์—…๊ทธ๋ ˆ์ด๋“œํ•˜๋Š” ๊ฒฝ์šฐ AD ์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌ๋ฅผ ์œ„ํ•ด MongoDB๋ฅผ ๊ตฌ์„ฑํ•œ ํ›„ ๊ฐ ์‚ฌ์šฉ์ž๊ฐ€ ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋„๋ก ๋‹ค์Œ ์š”๊ตฌ ์‚ฌํ•ญ์„ ์ถฉ์กฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ์‚ฌ์šฉ์ž๋Š” 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_analytics ๋ฐ PrimaryApplication ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ read ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค.

์ค‘์š”

ํ•ด๋‹น AD ๊ทธ๋ฃน์˜ ์—ญํ• ์„ ๊ตฌ์„ฑํ•  ๋•Œ๋Š” ํ•ด๋‹น ๊ทธ๋ฃน์˜ ๋ฉค๋ฒ„์‹ญ์ด ์žˆ๋Š” ๋ชจ๋“  ์‚ฌ์šฉ์ž๊ฐ€ ํ• ๋‹น๋œ ์—ญํ• ๊ณผ ๊ถŒํ•œ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์„ ๊ธฐ์–ตํ•˜์„ธ์š”. ์ตœ์†Œ ๊ถŒํ•œ ์›์น™ ์ ์šฉ ๊ณ ๋ ค MongoDB ์—ญํ• , AD ๊ทธ๋ฃน ๋˜๋Š” ๊ทธ๋ฃน ๋ฉค๋ฒ„์‹ญ์„ ๊ตฌ์„ฑํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

$external ๊ฐ€ ์•„๋‹Œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์‚ฌ์šฉ์ž๊ฐ€ MongoDB์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ณ„์† ํ—ˆ์šฉํ•˜๋ ค๋ฉด SCRAM ์ธ์ฆ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ํฌํ•จํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค(์˜ˆ: SCRAM-SHA-1 ๋ฐ/๋˜๋Š” SCRAM-SHA-256)์„ setParameter authenticationMechanisms ๊ตฌ์„ฑ ์˜ต์…˜์— ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

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"

์ง€์ •๋œ ์ƒ˜ํ”Œ ๊ตฌ์„ฑ์„ Active Directory ์Šคํ‚ค๋งˆ, ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ ๋ฐ ๊ตฌ์„ฑ์— ๋งž๊ฒŒ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ฐฐํฌ์„œ๋ฒ„๋ฅผ ์œ„ํ•œ ์ถ”๊ฐ€ ๊ตฌ์„ฑ ํŒŒ์ผ ์˜ต์…˜ ์ด ํ•„์š”ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์—ญํ•  ๋ฐ ๊ถŒํ•œ ๊ตฌ์„ฑ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋‹ค์Œ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๋Œ์•„๊ฐ€๊ธฐ

OpenLDAP ์‚ฌ์šฉ

์ด ํŽ˜์ด์ง€์˜ ๋‚ด์šฉ