External Authentication with Percona
Server for MongoDB and
MongoDB Enterprise
Jason Terpko
DBA @ Rackspace/ObjectRocket
linkedin.com/in/jterpko
1
Background
www.objectrocket.com
2
Overview
www.objectrocket.com
3
o Percona Server For MongoDB
o MongoDB Enterprise
o SASL and LDAP
o Kerberos and Active Directory
o Ops Manager
Percona Server For MongoDB
www.objectrocket.com
4
An enhanced free open source replacement for MongoDB Community Server
+ SASL Authentication
+ More Engine Options
+ Hot Backup
+ Auditing
All MongoDB 3.4 Community Features
External
Authentication
www.objectrocket.com
5
o LDAP
o SASL
o Authentication
Centralized Authentication
www.objectrocket.com
6
LDAP (Lightweight Directory Access Protocol) and Microsoft Active Directory
# extended LDIF
...
dn: uid=jason,ou=dba,dc=data,dc=com
...
cn: jasonuid: jason
uidNumber: 9999
gidNumber: 100
...
userPassword:: <secret>
# extended LDIF
...
dn: CN=Jason,OU=Users,DC=data,DC=com
...
cn: Jason
memberOf: CN=dba,OU=Mongo,DC=data,DC=com
...
sAMAccountName: jason
userPrincipalName: jason@data.com
OpenLDAP Active Directory
SASL Authentication
www.objectrocket.com
7
PLAIN Auth
Init SASL
SASL Auth
Yes/No Yes/No
YesYes
OK
Mongos / Server Configuration
www.objectrocket.com
8
/etc/sysconfig/saslauthd
SOCKETDIR=/run/saslauthd
MECH=ldap
FLAGS="-O /etc/saslauthd.conf"
/etc/mongos.conf
security:
keyFile: /etc/mongo.key
setParameter:
authenticationMechanisms: PLAIN,SCRAM-SHA-1
*LDAP Already Configured
Mongos / Server Configuration
www.objectrocket.com
9
/etc/saslauthd.conf
ldap_servers: ldap://127.0.0.1:389
ldap_search_base: dc=data,dc=com
ldap_filter: (uid=%u)
ldap_bind_dn: uid=bind,ou=People,dc=data,dc=com
ldap_password: <secret>
/etc/sasl2/mongodb.conf
pwcheck_method: saslauthd
saslauthd_path: /var/run/saslauthd/mux
log_level: 1
mech_list: plain
*LDAP Already Configured
Authentication
www.objectrocket.com
10
db.getSiblingDB("$external").createUser({user : 'jason', roles: [ {role : "readWrite", db: 'prod'} ] });
db.getSiblingDB("$external").auth({mechanism: "PLAIN", "user": "jason", "pwd": ”secret", "digestPassword": false });
HelloWorld.py
from pymongo import MongoClient
# MongoDB Connection URI and Establish Connection
uri = "mongodb://jason:terpko@localhost:27018/prod?authMechanism=PLAIN&authSource=$external”
client = MongoClient(uri)
…
MongoDB Enterprise
www.objectrocket.com
11
o Kerberos
o Authentication
o Authorization
o Ops Manager
MongoDB Enterprise Advance
www.objectrocket.com
12
An enterprise replacement for MongoDB Community Server
All MongoDB 3.4 Community Features
+ Ops Manager
+ Optional Engines
+ Enhanced Security
+ Additional Software
Enterprise
Authentication and
Authorization
www.objectrocket.com
13
o Kerberos Authentication
o LDAP Authorization
Kerberos Authentication
www.objectrocket.com
14
TGT request
Ticket
GSSAPI
OKCache
Validate
OK
Kerberos
www.objectrocket.com
15
A session ticket that authenticates a client to Kerberos enabled host and services.
# klist krb5cc_12345
Ticket cache: FILE:krb5cc_12345
Default principal: jason@DATA.COM
Valid starting Expires Service principal
01/01/2017 05:28:34 01/01/2017 17:28:34 krbtgt/DATA.COM@DATA.COM
renew until 01/08/2017 05:28:34
User Ticket Cache:
*Active Directory Configured
**Client Kerberos Configured
Service Principle
www.objectrocket.com
16
env KRB5_KTNAME=<path to keytab file> mongod -f /etc/mongod.conf
Starting MongoD with Kerberos
Service Principle
# klist
Ticket cache: FILE:krb5cc_0
…
Valid starting Expires Service principal
01/01/2017 05:28:34 01/01/2017 17:28:34 mongodb/server1.data.com@DATA.COM
renew until 01/08/2017 05:28:34
Mongod Configuration (security.)
www.objectrocket.com
17
security:
authorization: enabled
keyFile: /etc/mongo.key
ldap:
authz:
queryTemplate: DC=DATA,DC=COM??sub?(&(objectClass=group)(member:1.2.840.113556.1.4.1941:={USER}))
bind:
method: simple
queryPassword: <secret>
queryUser: bind@data.com
servers: ldap.data.com:636
transportSecurity: tls
userToDNMapping: '[{match : "(.+)",ldapQuery:"DC=DATA,DC=COM??sub?(userPrincipalName={0})"}]'
setParameter:
authenticationMechanisms: GSSAPI
/etc/mongod.conf
Mongod Configuration (security.)
www.objectrocket.com
18
security:
authorization: enabled
keyFile: /etc/mongo.key
ldap:
authz:
queryTemplate: DC=DATA,DC=COM??sub?(&(objectClass=group)(member:1.2.840.113556.1.4.1941:={USER}))
bind:
method: simple
queryPassword: <secret>
queryUser: bind@data.com
servers: ldap.data.com:636
transportSecurity: tls
userToDNMapping: '[{match : "(.+)",ldapQuery:"DC=DATA,DC=COM??sub?(userPrincipalName={0})"}]'
setParameter:
authenticationMechanisms: GSSAPI
/etc/mongod.conf
Mongod Configuration (security.)
www.objectrocket.com
19
security:
authorization: enabled
keyFile: /etc/mongo.key
ldap:
authz:
queryTemplate: DC=DATA,DC=COM??sub?(&(objectClass=group)(member:1.2.840.113556.1.4.1941:={USER}))
bind:
method: simple
queryPassword: <secret>
queryUser: bind@data.com
servers: ldap.data.com:636
transportSecurity: tls
userToDNMapping: '[{match : "(.+)",ldapQuery:"DC=DATA,DC=COM??sub?(userPrincipalName={0})"}]'
setParameter:
authenticationMechanisms: GSSAPI
/etc/mongod.conf
LDAP Authorization
www.objectrocket.com
20
Cache
Authz request
LDAP Query memberOf
Authorized
Client Authentication
www.objectrocket.com
21
db.getSiblingDB("admin").createRole( { role: "CN=dba,DC=data,DC=com", privileges: [], roles: [
"userAdminAnyDatabase", "readWriteAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin" ] });
db.getSiblingDB("$external").auth({mechanism: "GSSAPI", "user": "jason@DATA.COM" });
HelloWorld.py
from pymongo import MongoClient
# MongoDB Connection URI and Establish Connection
uri="mongodb://jason%40DATA.COM@server1.data.com:27017,.../?replicaSet=rs1&authMechanism=GSSAPI&ssl=true”
client=MongoClient(uri)
…
Ops Manager
www.objectrocket.com
22
Alternatively manage your deployment with Ops Manager.
Questions?
www.objectrocket.com
23
www.objectrocket.com
24
We’re Hiring!
Looking to join a dynamic & innovative
team?
https://www.objectrocket.com/careers
Reach out to us directly at careers@objectrocket.com
Thank you!
Address:
100 Congress Ave
Suite 400
Austin, TX 78701
Support:
1-800-961-4454
Sales:
1-888-440-3242
www.objectrocket.com
25

MongoDB - External Authentication