{"id":2031,"date":"2024-08-04T21:17:02","date_gmt":"2024-08-05T01:17:02","guid":{"rendered":"https:\/\/enterpriseadmins.org\/blog\/?p=2031"},"modified":"2024-08-04T21:17:02","modified_gmt":"2024-08-05T01:17:02","slug":"monitoring-mongodb-enterprise-using-ldap-authentication","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/virtualization\/monitoring-mongodb-enterprise-using-ldap-authentication\/","title":{"rendered":"Monitoring MongoDB Enterprise using LDAP Authentication"},"content":{"rendered":"\n<p>I had a recent need to dig into MongoDB monitoring with Aria Operations.  In those posts, I used a preconfigured Bitnami MongoDB virtual appliance.  This virtual appliance used MongoDB Community Edition.  As a follow-up, I was looking into if it were possible to use an active directory user for monitoring instead of the local user from the previous post.  <\/p>\n\n\n\n<p>Looking into this question, I learned that it is possible&#8230; but there are a few requirements.  This post will explain how to configure MongoDB to use an active directory user account for authentication, specifically for the Aria Operations management pack.  <\/p>\n\n\n\n<p>MongoDB has a community edition, which was installed in my previous appliance.  If we look at the &#8216;ldap&#8217; configuration options documented here: <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/configuration-options\/\">https:\/\/www.mongodb.com\/docs\/manual\/reference\/configuration-options\/<\/a>, we&#8217;ll notice that those settings say &#8220;Available in MongoDB Enterprise only.&#8221;<\/p>\n\n\n\n<p>The MongoDB folks have some really good documentation on installing <code>mongodb-enterprise<\/code> available here: <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/tutorial\/install-mongodb-enterprise-on-ubuntu\/#std-label-install-mdb-enterprise-ubuntu\">https:\/\/www.mongodb.com\/docs\/manual\/tutorial\/install-mongodb-enterprise-on-ubuntu\/#std-label-install-mdb-enterprise-ubuntu<\/a>.  I choose the Ubuntu version of this document as I already had Ubuntu template VMs available in my lab.  The installation went very smooth, I&#8217;ll include the commands I ran below as a quick reference.  I had already <code>su -<\/code> and was running as root, so I didn&#8217;t require he <code>sudo<\/code> from the above example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get install gnupg curl\n# no change, these packages already in image\n\ncurl -fsSL https:\/\/pgp.mongodb.com\/server-7.0.asc | \\\n   gpg -o \/usr\/share\/keyrings\/mongodb-server-7.0.gpg \\\n   --dearmor\n\necho \"deb &#91; arch=amd64,arm64 signed-by=\/usr\/share\/keyrings\/mongodb-server-7.0.gpg ] http:\/\/repo.mongodb.com\/apt\/ubuntu focal\/mongodb-enterprise\/7.0 multiverse\" | tee \/etc\/apt\/sources.list.d\/mongodb-enterprise-7.0.list\n\napt-get update\n\napt-get install -y mongodb-enterprise\n\nps --no-headers -o comm 1\n# returns systemd\n\nsudo systemctl start mongod<\/code><\/pre>\n\n\n\n<p>With a working MongoDB Enterprise installation, I was able to start configuring LDAP\/Active Directory authentication.  MongoDB docs discuss using groups only to delegate roles, so I created two objects in Active Directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Group: CN=LAB MongoDB Ent Monitoring,OU=LAB Service Accounts,DC=lab,DC=enterpriseadmins,DC=org\nUser: CN=svc-mgdbeops,OU=LAB Service Accounts,DC=lab,DC=enterpriseadmins,DC=org<\/code><\/pre>\n\n\n\n<p>This directory has an existing service account used for generic binds. I&#8217;m going to re-use this account:\u00a0<code>CN=svc-ldapbind,OU=LAB Service Accounts,DC=lab,DC=enterpriseadmins,DC=org<\/code>. In the real world the MongoDB admins would likely have their own service account for this purpose, or perhaps create a unique account per environment.<\/p>\n\n\n\n<p>The first step is to grant my group limited access to the instance.  I&#8217;ve also decided to create a local <code>root<\/code> user to use for administration, if needed.  We&#8217;ll do all this using the <code>mongosh<\/code> command directly on the appliance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mongosh # no credentials were required\n\nvar admin = db.getSiblingDB(\"admin\")\n\n# create a root user to have, just in case\nadmin.createUser(\n   {\n       user: \"root\", \n       pwd: \"VMware1!\", \n       roles:&#91;\"root\"]\n   })\n# returns: { ok: 1 }\n\n# give our AD service account limited access\nadmin.createRole(\n    {\n        role: \"CN=LAB MongoDB Ent Monitoring,OU=LAB Service Accounts,DC=lab,DC=enterpriseadmins,DC=org\",\n        roles: &#91; { role: \"clusterMonitor\", db: \"admin\" } ]\n    }\n)\n# returns: { ok: 1 }<\/code><\/pre>\n\n\n\n<p>With our permissions delegated, we now need to update our <code>\/etc\/mongod.conf<\/code> to make it aware of our directory.  We&#8217;ll make to edits to this default file.  First, in the <code>network interfaces<\/code> section, we&#8217;ll change the entry that binds to localhost only to allow binding to all IPs.  I left the previous configuration as a comment, so I could revert back easily if needed.  The change looks like this in my config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># network interfaces\nnet:\n  port: 27017\n  bindIpAll: true\n  #bindIp: 127.0.0.1 <\/code><\/pre>\n\n\n\n<p>We&#8217;ll continue to the end of the file.  I do not have <code>security:<\/code> or <code>setParameter:<\/code> sections, so I will create them:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>security:\n   authorization: \"enabled\"\n   ldap:\n      servers: \"core-control-21.lab.enterpriseadmins.org:389\"\n      bind:\n         queryUser: \"CN=svc-ldapbind,OU=LAB Service Accounts,DC=lab,DC=enterpriseadmins,DC=org\"\n         queryPassword: \"VMware1!\"\n      transportSecurity: \"none\"\n      authz:\n         queryTemplate: \"{USER}?memberOf?base\"\n      validateLDAPServerConfig: true\nsetParameter:\n   authenticationMechanisms: \"PLAIN\"<\/code><\/pre>\n\n\n\n<p>MongoDB documentation has additional configuration options for <code>userToDNMapping<\/code>, but I&#8217;m not using those and opting instead to just pass the distinguished name as the user name.<\/p>\n\n\n\n<p>With the configuraiton file update, I restarted the mongod service and confirmed that it was running with the following syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart mongod.service\nsudo systemctl status mongod.service<\/code><\/pre>\n\n\n\n<p>Finally, in Aria Operations I was able to configure the adapter instance to use this LDAP credential.  For the adapter name, I entered the short host name of the monitored server, and for the host attribute I used the fully qualified domain name.  When creating the credential, I entered my user distinguished name, as well as selected &#8216;LDAP SASL&#8217; for the type of authentication.  I&#8217;ve included a screenshot below for reference:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/08\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"503\" height=\"400\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/08\/image.png\" alt=\"\" class=\"wp-image-2035\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/08\/image.png 503w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/08\/image-300x239.png 300w\" sizes=\"auto, (max-width: 503px) 100vw, 503px\" \/><\/a><\/figure>\n\n\n\n<p>With these properties configured, I was able to create the configuration of the adapter instance.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/08\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"523\" height=\"205\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/08\/image-1.png\" alt=\"\" class=\"wp-image-2036\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/08\/image-1.png 523w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/08\/image-1-300x118.png 300w\" sizes=\"auto, (max-width: 523px) 100vw, 523px\" \/><\/a><\/figure>\n\n\n\n<p>After a few minutes, the dashboards begin populating with the <code>mongod<\/code> information.  <\/p>\n\n\n\n<p>Hopefully this post helps with configuration of MongoDB Enterprise LDAP authentication. <\/p>\n\n\n\n<p><strong>Previous MongoDB posts:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/creating-a-mongodb-replica-set\/\">https:\/\/enterpriseadmins.org\/blog\/scripting\/creating-a-mongodb-replica-set\/<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/enterpriseadmins.org\/blog\/virtualization\/optimizing-operations-aria-operations-management-pack-for-mongodb\/\">https:\/\/enterpriseadmins.org\/blog\/virtualization\/optimizing-operations-aria-operations-management-pack-for-mongodb\/<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/enterpriseadmins.org\/blog\/virtualization\/mongodb-test-data-for-performance-monitoring\/\">https:\/\/enterpriseadmins.org\/blog\/virtualization\/mongodb-test-data-for-performance-monitoring\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I had a recent need to dig into MongoDB monitoring with Aria Operations. In those posts, I used a preconfigured Bitnami MongoDB virtual appliance. This virtual appliance used MongoDB Community Edition. As a follow-up, I was looking into if it &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/virtualization\/monitoring-mongodb-enterprise-using-ldap-authentication\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9,4],"tags":[],"class_list":["post-2031","post","type-post","status-publish","format-standard","hentry","category-lab-infrastructure","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=2031"}],"version-history":[{"count":3,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2031\/revisions"}],"predecessor-version":[{"id":2037,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2031\/revisions\/2037"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=2031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=2031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=2031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}