@@ -10,22 +10,24 @@ Use x.509 Certificates to Authenticate Clients
10
10
:depth: 1
11
11
:class: singlecol
12
12
13
- MongoDB supports x.509 certificate authentication for use with a secure
14
- :doc:`TLS/SSL connection </tutorial/configure-ssl>`. The x.509 client
15
- authentication allows :ref:`clients to authenticate to servers with
16
- certificates <x509-client-authentication>` rather than with a username and
17
- password.
13
+ .. |binary| replace:: MongoDB
18
14
19
15
.. note::
20
16
21
17
.. include:: /includes/fact-tls-1.0.rst
22
18
23
- .. |binary| replace:: MongoDB
19
+ MongoDB supports x.509 certificate authentication for use with a secure
20
+ :doc:`TLS/SSL connection </tutorial/configure-ssl>`. The x.509 client
21
+ authentication allows :ref:`clients to authenticate to servers with
22
+ certificates <x509-client-authentication>` rather than with a username
23
+ and password. The following tutorial outlines the steps to use x.509
24
+ for client authentication.
24
25
26
+ .. seealso::
25
27
26
- To use x.509 authentication for the internal authentication of replica
27
- set/sharded cluster members, see
28
- :doc:`configure-x509-member-authentication`.
28
+ To use x.509 authentication for the internal authentication of
29
+ replica set/sharded cluster members, see
30
+ :doc:`configure-x509-member-authentication`.
29
31
30
32
Prerequisites
31
33
-------------
@@ -40,6 +42,8 @@ Certificate Authority
40
42
41
43
.. include:: /includes/fact-ssl-certificate-authorities.rst
42
44
45
+ .. include:: /includes/warning-x509-requires-sslCAfile.rst
46
+
43
47
.. _x509-client-authentication:
44
48
45
49
Client x.509 Certificate
@@ -53,67 +57,106 @@ Client x.509 Certificate
53
57
54
58
.. include:: /includes/extracts/x509-certificate-client.rst
55
59
56
- Procedures
57
- ----------
60
+ MongoDB Deployment Configured for x.509
61
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
62
59
- Configure Replica Set/Sharded Cluster
60
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63
+ .. tabs::
61
64
65
+ tabs:
62
66
63
- Outside of rolling upgrade procedures, every component of a :term:`replica
64
- set` or :term:`sharded cluster` should use the same
65
- ``--clusterAuthMode`` setting to ensure it can securely connect to all
66
- other components in the deployment:
67
+ - id: cmdline
68
+ name: Command-Options
69
+ content: |
67
70
68
- - For :term:`replica set` deployments, this includes all
69
- :binary:`~bin.mongod` members of the replica set.
71
+ You can configure :binary:`~bin.mongod`/:binary:`~bin.mongos`
72
+ for x.509 authentication from the command-line. For example,
73
+ if running a replica set, each member would include the
74
+ following options:
70
75
71
- - For :term:`sharded cluster` deployments, this includes all
72
- :binary:`~bin.mongod` and :binary:`~bin.mongos` instances.
76
+ .. code-block:: sh
73
77
74
- .. note::
78
+ mongod --clusterAuthMode x509 --sslMode requireSSL --sslPEMKeyFile <path to TLS/SSL certificate and key PEM file> --sslCAFile <path to root CA PEM file> --replSet <name> --bind_ip <hostnames>
75
79
76
- If you are configuring a standalone :binary:`~bin.mongod`, omit the
77
- ``--clusterAuthMode`` option.
80
+ .. include:: /includes/extracts/default-bind-ip-security-additional-command-line.rst
78
81
79
- .. note: :
82
+ The x.509 configuration requires :
80
83
81
- .. include:: /includes/extracts/default-bind-ip-security-command-line.rst
84
+ .. list-table::
85
+ :header-rows: 1
86
+ :widths: 25 75
82
87
83
- Use Command-line Options
84
- ````````````````````````
88
+ * - Option
89
+ - Notes
85
90
86
- You can configure the MongoDB server from the command line, e.g.:
91
+ * - :option:`--clusterAuthMode <mongod --clusterAuthMode>`.
87
92
88
- .. code-block:: sh
93
+ - If the deployment is a replica set or a sharded cluster, specify ``x509`` for all members of the replica set/sharded cluter.
89
94
90
- mongod --clusterAuthMode x509 --sslMode requireSSL --sslPEMKeyFile <path to TLS/SSL certificate and key PEM file> --sslCAFile <path to root CA PEM file>
95
+ Omit for standalone.
91
96
92
- .. include:: /includes/extracts/default-bind-ip-security-additional-command-line.rst
97
+ * - :option:`--sslMode <mongod --sslMode>`
93
98
94
- .. include:: /includes/warning-x509-requires-sslCAfile.rst
99
+ - Specify ``requireSSL``.
100
+
101
+ * - :option:`--sslPEMKeyFile <mongo --sslPEMKeyFile>`
102
+ - The instance's x.509 certificate.
103
+
104
+ * - :option:`--sslCAFile <mongo --sslCAFile>`
105
+
106
+ - Certificate Authority file to verify the certificate
107
+ presented to the instance.
108
+
109
+ - id: cfg
110
+ name: Configuration File
111
+ content: |
112
+
113
+ You can configure :binary:`~bin.mongod`/:binary:`~bin.mongos`
114
+ for x.509 authentication in the :doc:`configuration file
115
+ </reference/configuration-options>`. For example, if running
116
+ a replica set, each member would include the following
117
+ options:
118
+
119
+ .. code-block:: yaml
120
+
121
+ security:
122
+ clusterAuthMode: x509
123
+ net:
124
+ ssl:
125
+ mode: requireSSL
126
+ PEMKeyFile: <path to TLS/SSL certificate and key PEM file>
127
+ CAFile: <path to root CA PEM file>
95
128
129
+ .. include:: /includes/extracts/default-bind-ip-security-additional-config-file.rst
96
130
97
- Use Configuration File
98
- ``````````````````````
131
+ The x.509 configuration requires:
99
132
100
- You may also specify these options in the :doc:`configuration file
101
- </reference/configuration-options>`:
133
+ .. list-table::
134
+ :header-rows: 1
135
+ :widths: 25 75
102
136
103
- .. code-block:: yaml
137
+ * - Option
138
+ - Notes
104
139
105
- security:
106
- clusterAuthMode: x509
107
- net:
108
- ssl:
109
- mode: requireSSL
110
- PEMKeyFile: <path to TLS/SSL certificate and key PEM file>
111
- CAFile: <path to root CA PEM file>
140
+ * - :setting:`security.clusterAuthMode`
112
141
113
- .. include:: /includes/extracts/default-bind-ip-security-additional-config-file.rst
142
+ - If the deployment is a replica set or a sharded cluster, specify ``x509`` for all members of the replica set/sharded cluter.
114
143
115
- For v2.4 older configuration file format, see the :v2.4:`2.4 Manual
116
- </reference/configuration-options>`.
144
+ Omit for standalone.
145
+
146
+ * - :setting:`net.ssl.mode`
147
+
148
+ - Specify ``requireSSL``.
149
+
150
+ * - :setting:`net.ssl.PEMKeyFile`
151
+ - The instance's x.509 certificate.
152
+
153
+ * - :setting:`net.ssl.CAFile`
154
+
155
+ - Certificate Authority file to verify the certificate
156
+ presented to the instance.
157
+
158
+ Procedures
159
+ ----------
117
160
118
161
.. _addX509SubjectUser:
119
162
@@ -154,36 +197,23 @@ client certificate to authenticate more than one MongoDB user.
154
197
#. Add the ``RFC2253`` compliant value of the ``subject`` as a user.
155
198
Omit spaces as needed.
156
199
157
- For example, in the :binary:`~bin.mongo` shell, to add the user with
158
- both the ``readWrite`` role in the ``test`` database and the
159
- ``userAdminAnyDatabase`` role which is defined only in the ``admin``
160
- database:
200
+ For example, the following adds a user and grants the user
201
+ :authrole:`readWrite` role in the ``test`` database and the
202
+ :authrole:`userAdminAnyDatabase` role:
161
203
162
204
.. code-block:: javascript
163
205
164
206
db.getSiblingDB("$external").runCommand(
165
207
{
166
208
createUser: "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry",
167
209
roles: [
168
- { role: ' readWrite' , db: ' test' },
169
- { role: ' userAdminAnyDatabase' , db: ' admin' }
170
- ],
210
+ { role: " readWrite" , db: " test" },
211
+ { role: " userAdminAnyDatabase" , db: " admin" }
212
+ ],
171
213
writeConcern: { w: "majority" , wtimeout: 5000 }
172
214
}
173
215
)
174
216
175
- In the above example, to add the user with the ``readWrite`` role in
176
- the ``test`` database, the role specification document specified
177
- ``'test'`` in the ``db`` field. To add ``userAdminAnyDatabase``
178
- role for the user, the above example specified ``'admin'`` in the
179
- ``db`` field.
180
-
181
- .. note::
182
- Some roles are defined only in the ``admin`` database, including:
183
- ``clusterAdmin``, ``readAnyDatabase``, ``readWriteAnyDatabase``,
184
- ``dbAdminAnyDatabase``, and ``userAdminAnyDatabase``. To add a
185
- user with these roles, specify ``'admin'`` in the ``db``.
186
-
187
217
See :doc:`/tutorial/manage-users-and-roles` for details on adding a user
188
218
with roles.
189
219
@@ -192,34 +222,101 @@ with roles.
192
222
Authenticate with a x.509 Certificate
193
223
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194
224
195
- To authenticate with a client certificate, you must first add a MongoDB
196
- user that corresponds to the client certificate. See
197
- :ref:`addX509SubjectUser`.
225
+ .. container::
198
226
199
- To authenticate, use the :method:`db.auth()` method in the
200
- ``$external`` database, specifying ``"MONGODB-X509"`` for the
201
- ``mechanism`` field, and the :ref:`user that corresponds to the client
202
- certificate <addX509SubjectUser>` for the ``user`` field.
227
+ After you have :ref:`added the x.509 client certificate subject as a
228
+ corresponding MongoDB user <addX509SubjectUser>`, you can
229
+ authenticate with the client certificate.
203
230
204
- For example, if using the :binary:`~bin.mongo` shell,
231
+ .. tabs::
205
232
206
- 1. Connect :binary:`~bin.mongo` shell to the :binary:`~bin.mongod` set up for
207
- TLS/SSL:
233
+ tabs:
208
234
209
- .. code-block:: sh
235
+ - id: connect
236
+ name: Connect with Authentication
237
+ content: |
210
238
211
- mongo --ssl --sslPEMKeyFile <path to CA signed client PEM file> --sslCAFile <path to root CA PEM file>
239
+ To authenticate during connection:
212
240
213
- #. To perform the authentication, use the :method:`db.auth()` method in
214
- the ``$external`` database. For the ``mechanism`` field, specify
215
- ``"MONGODB-X509"``, and for the ``user`` field, specify the user, or
216
- the ``subject``, that corresponds to the client certificate.
241
+ .. code-block:: sh
217
242
218
- .. code-block:: javascript
243
+ mongo --ssl --sslPEMKeyFile <path to CA signed client PEM file> --sslCAFile <path to root CA PEM file> –-authenticationDatabase '$external' -–authenticationMechanism MONGODB-X509
219
244
220
- db.getSiblingDB("$external").auth(
221
- {
222
- mechanism: "MONGODB-X509",
223
- user: "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry"
224
- }
225
- )
245
+ .. list-table::
246
+ :header-rows: 1
247
+ :widths: 30 70
248
+
249
+ * - Option
250
+ - Notes
251
+
252
+ * - :option:`--ssl <mongo --ssl>`
253
+ -
254
+
255
+ * - :option:`--sslPEMKeyFile <mongo --sslPEMKeyFile>`
256
+ - Client's x.509 file.
257
+
258
+ * - :option:`--sslCAFile <mongo --sslCAFile>`
259
+
260
+ - Certificate Authority file to verify the
261
+ certificate presented by
262
+ :binary:`~bin.mongod`/:binary:`~bin.mongos`
263
+ instance.
264
+
265
+ * - :option:`--authenticationDatabase <mongo --authenticationDatabase>`
266
+ - Specify ``'$external'``.
267
+
268
+ * - :option:`--authenticationMechanism <mongo --authenticationMechanism>`
269
+ - Specify ``MONGODB-X509``.
270
+
271
+ - id: authafter
272
+ name: Authenticate after Connection
273
+ content: |
274
+
275
+ You can connect without authentication and use the
276
+ :method:`db.auth()` method to authenticate after
277
+ connection.
278
+
279
+ For example, if using the :binary:`~bin.mongo` shell,
280
+
281
+ 1. Connect :binary:`~bin.mongo` shell to the :binary:`~bin.mongod` set up for
282
+ TLS/SSL:
283
+
284
+ .. code-block:: sh
285
+
286
+ mongo --ssl --sslPEMKeyFile <path to CA signed client PEM file> --sslCAFile <path to root CA PEM file>
287
+
288
+ .. list-table::
289
+ :header-rows: 1
290
+ :widths: 25 75
291
+
292
+ * - Option
293
+ - Notes
294
+
295
+ * - :option:`--ssl <mongo --ssl>`
296
+ -
297
+
298
+ * - :option:`--sslPEMKeyFile <mongo --sslPEMKeyFile>`
299
+ - Client's x.509 file.
300
+
301
+ * - :option:`--sslCAFile <mongo --sslCAFile>`
302
+
303
+ - Certificate Authority file to verify the
304
+ certificate presented by
305
+ :binary:`~bin.mongod`/:binary:`~bin.mongos`
306
+ instance.
307
+
308
+ #. To perform the authentication, use the :method:`db.auth()` method in
309
+ the ``$external`` database. For the ``mechanism``
310
+ field, specify ``"MONGODB-X509"``, and for the
311
+ ``user`` field, specify the :ref:`user that
312
+ corresponds to the client certificate
313
+ <addX509SubjectUser>` .
314
+
315
+ .. code-block:: javascript
316
+
317
+ db.getSiblingDB("$external").auth(
318
+ {
319
+ mechanism: "MONGODB-X509",
320
+ user: "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry"
321
+ }
322
+ )
0 commit comments