Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit 4ffe1d5

Browse files
Merge pull request #4 from stone-payments/feat/security-ldap
Adjusted ldap configurations
2 parents 89c8fba + 667734c commit 4ffe1d5

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ mongodb_processmanagement_fork: false # Fork server process
7878
# Disable or enable security. Possible values: 'disabled', 'enabled'
7979
mongodb_security_authorization: "disabled"
8080
mongodb_security_keyfile: /etc/mongodb-keyfile # Specify path to keyfile with password for inter-process authentication
81-
mongodb_active_directory_role: "" # Create role root to active directory integration
81+
mongodb_active_directory_role: # Create role root to active directory integration
82+
- role_name: "CN=sysadmin,OU=grants,OU=Groups,OU=base,DC=mycompany,DC=com,DC=br"
83+
role_permission: "root"
8284

8385
## storage Options
8486
mongodb_storage_dbpath: /data/mongodb # Directory for datafiles
@@ -149,16 +151,18 @@ mongodb_replication_oplogsize: 1024 # specifies a maximum size in megabytes for
149151
# Configure setParameter option.
150152
# Example :
151153
mongodb_set_parameters:
152-
{
153-
"enableLocalhostAuthBypass": "true",
154-
"authenticationMechanisms": "SCRAM-SHA-1,MONGODB-CR",
155-
}
154+
enableLocalhostAuthBypass: "true"
155+
authenticationMechanisms: "SCRAM-SHA-1,MONGODB-CR"
156156

157157
## Extend config with arbitrary values
158158
# Example :
159159
mongodb_config:
160160
replication:
161-
- "enableMajorityReadConcern: false"
161+
enableMajorityReadConcern: "false"
162+
auditLog:
163+
destination: "file"
164+
format: "JSON"
165+
path: "/var/log/mongodb/audit.json"
162166

163167
# MMS Agent
164168
mongodb_mms_agent_pkg: https://cloud.mongodb.com/download/agent/monitoring/mongodb-mms-monitoring-agent_7.2.0.488-1_amd64.ubuntu1604.deb

tasks/auth_initialization.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,27 @@
8181
- name: Check if Active Directory Role already exists
8282
command: >
8383
mongo --quiet {{ '--ssl --host ' + mongodb_net_ssl_host if mongodb_net_ssl_mode == 'requireSSL' else '' }} -u {{ mongodb_root_user_name }} \
84-
-p {{ mongodb_root_user_password }} --port {{ mongodb_net_port }} --eval 'db.getSiblingDB("admin").getRole( "{{ mongodb_active_directory_role }}" )'
84+
-p {{ mongodb_root_user_password }} --port {{ mongodb_net_port }} --eval 'db.getSiblingDB("admin").getRole( "{{ item.role_name }}" )'
8585
register: mongodb_role_ad_check
86-
changed_when: false
86+
changed_when: mongodb_role_ad_check.stdout == 'null'
8787
check_mode: no
8888
ignore_errors: true
8989
no_log: true
90+
loop: "{{ mongodb_active_directory_role }}"
9091
when: mongodb_active_directory_role | length > 0
9192

9293
- name: Create MongoDB Active Directory Role
9394
command: >
9495
mongo --quiet {{ '--ssl --host ' + mongodb_net_ssl_host if mongodb_net_ssl_mode == 'requireSSL' else '' }} -u {{ mongodb_root_user_name }} \
9596
-p {{ mongodb_root_user_password }} --port {{ mongodb_net_port }} \
96-
--eval 'db.getSiblingDB("admin").createRole({ role:"{{ mongodb_active_directory_role }}",privileges:[], roles:["root"] })'
97+
--eval 'db.getSiblingDB("admin").createRole({ role:"{{ item.role_name }}",privileges:[], roles:["{{ item.role_permission }}"] })'
9798
check_mode: no
99+
ignore_errors: true
98100
no_log: true
101+
loop: "{{ mongodb_active_directory_role }}"
99102
when:
100103
- mongodb_active_directory_role | length > 0
101-
- mongodb_role_ad_check.stdout == "null"
104+
- mongodb_role_ad_check.changed
102105

103106
always:
104107
- name: Move back mongod.conf

templates/mongod.conf.j2

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,27 @@ security:
8282
javascriptEnabled: {{ mongodb_security_javascript_enabled | to_nice_json }}
8383
{% if mongodb_config['security'] is defined and mongodb_config['security'] is iterable -%}
8484
{% for item in mongodb_config['security'] -%}
85+
{% if item == 'ldap' -%}
86+
ldap:
87+
transportSecurity: "{{ mongodb_config['security']['ldap'].transportSecurity }}"
88+
servers: "{{ mongodb_config['security']['ldap'].servers }}"
89+
bind:
90+
queryUser: "{{ mongodb_config['security']['ldap'].bind.queryUser }}"
91+
queryPassword: "{{ mongodb_config['security']['ldap'].bind.queryPassword }}"
92+
authz:
93+
queryTemplate: "{{ mongodb_config['security']['ldap'].authz.queryTemplate }}"
94+
userToDNMapping:
95+
{{ mongodb_config['security']['ldap'].userToDNMapping }}
96+
{% else -%}
97+
{% if mongodb_config['security'][item] is mapping -%}
8598
{{ item }}:
8699
{% for key, value in mongodb_config['security'][item].items() %}
87100
{{ key }}: {{ value | to_nice_json }}
88101
{% endfor -%}
102+
{% else -%}
103+
{{ item }}: {{ mongodb_config['security'][item] | to_nice_json }}
104+
{% endif -%}
105+
{% endif -%}
89106
{% endfor %}
90107
{% endif %}
91108

0 commit comments

Comments
 (0)