Skip to content

Commit 0fa1bb6

Browse files
author
Trent Nadeau
committed
Added SSL support
1 parent f0bf416 commit 0fa1bb6

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

lib/puppet/provider/mongodb.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def self.get_mongo_conf
4141
config_hash['bindip'] = config['net.bindIp']
4242
config_hash['port'] = config['net.port']
4343
config_hash['ipv6'] = config['net.ipv6']
44+
config_hash['ssl'] = config['net.ssl.mode']
45+
config_hash['sslcert'] = config['net.ssl.PEMKeyFile']
46+
config_hash['sslca'] = config['net.ssl.CAFile']
4447
config_hash['auth'] = config['security.authorization']
4548
config_hash['shardsvr'] = config['sharding.clusterRole']
4649
config_hash['confsvr'] = config['sharding.clusterRole']
@@ -53,6 +56,9 @@ def self.get_mongo_conf
5356
config_hash['bindip'] = config['bind_ip']
5457
config_hash['port'] = config['port']
5558
config_hash['ipv6'] = config['ipv6']
59+
config_hash['ssl'] = config['sslMode']
60+
config_hash['sslcert'] = config['sslPEMKeyFile']
61+
config_hash['sslca'] = config['sslCAFile']
5662
config_hash['auth'] = config['auth']
5763
config_hash['shardsvr'] = config['shardsvr']
5864
config_hash['confsvr'] = config['confsvr']
@@ -66,9 +72,28 @@ def self.ipv6_is_enabled(config=nil)
6672
config['ipv6']
6773
end
6874

75+
def self.ssl_is_enabled(config=nil)
76+
config ||= get_mongo_conf
77+
ssl_mode = config.fetch('ssl')
78+
ssl_mode.nil? ? false : ssl_mode != 'disabled'
79+
end
80+
6981
def self.mongo_cmd(db, host, cmd)
82+
config = get_mongo_conf
83+
7084
args = [db, '--quiet', '--host', host]
71-
args.push('--ipv6') if ipv6_is_enabled
85+
args.push('--ipv6') if ipv6_is_enabled(config)
86+
87+
if ssl_is_enabled(config)
88+
args.push('--ssl')
89+
args += ['--sslPEMKeyFile', config['sslcert']]
90+
91+
ssl_ca = config['sslca']
92+
unless ssl_ca.nil?
93+
args += ['--sslCAFile', ssl_ca]
94+
end
95+
end
96+
7297
args += ['--eval', cmd]
7398
mongo(args)
7499
end

manifests/server/config.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
# - $shardsvr
133133
# - $slowms
134134
# - $smallfiles
135+
# - $ssl
136+
# - $ssl_ca
137+
# - $ssl_key
135138
# - $syslog
136139
# - $verbose
137140
# - $verbositylevel

templates/mongodb.conf.2.6.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ net.maxIncomingConnections: <%= @maxconns %>
102102
<% if ! @nohttpinterface.nil? -%>
103103
net.http.enabled: <%= ! @nohttpinterface %>
104104
<% end -%>
105+
<% if @ssl -%>
106+
net.ssl.mode: requireSSL
107+
net.ssl.PEMKeyFile: <%= @ssl_key %>
108+
<% if @ssl_ca -%>
109+
net.ssl.CAFile: <%= @ssl_ca %>
110+
<% end -%>
111+
<% end -%>
105112

106113
#Replication
107114
<% if @replset -%>

0 commit comments

Comments
 (0)