Skip to content

Commit 21a7f85

Browse files
committed
DOCS-8909: x509 auth from command line
1 parent b56ece7 commit 21a7f85

File tree

1 file changed

+187
-90
lines changed

1 file changed

+187
-90
lines changed

source/tutorial/configure-x509-client-authentication.txt

Lines changed: 187 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@ Use x.509 Certificates to Authenticate Clients
1010
:depth: 1
1111
:class: singlecol
1212

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
1814

1915
.. note::
2016

2117
.. include:: /includes/fact-tls-1.0.rst
2218

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.
2425

26+
.. seealso::
2527

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`.
2931

3032
Prerequisites
3133
-------------
@@ -40,6 +42,8 @@ Certificate Authority
4042

4143
.. include:: /includes/fact-ssl-certificate-authorities.rst
4244

45+
.. include:: /includes/warning-x509-requires-sslCAfile.rst
46+
4347
.. _x509-client-authentication:
4448

4549
Client x.509 Certificate
@@ -53,67 +57,106 @@ Client x.509 Certificate
5357

5458
.. include:: /includes/extracts/x509-certificate-client.rst
5559

56-
Procedures
57-
----------
60+
MongoDB Deployment Configured for x.509
61+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5862

59-
Configure Replica Set/Sharded Cluster
60-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63+
.. tabs::
6164

65+
tabs:
6266

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: |
6770

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:
7075

71-
- For :term:`sharded cluster` deployments, this includes all
72-
:binary:`~bin.mongod` and :binary:`~bin.mongos` instances.
76+
.. code-block:: sh
7377

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>
7579

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
7881

79-
.. note::
82+
The x.509 configuration requires:
8083

81-
.. include:: /includes/extracts/default-bind-ip-security-command-line.rst
84+
.. list-table::
85+
:header-rows: 1
86+
:widths: 25 75
8287

83-
Use Command-line Options
84-
````````````````````````
88+
* - Option
89+
- Notes
8590

86-
You can configure the MongoDB server from the command line, e.g.:
91+
* - :option:`--clusterAuthMode <mongod --clusterAuthMode>`.
8792

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.
8994

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.
9196

92-
.. include:: /includes/extracts/default-bind-ip-security-additional-command-line.rst
97+
* - :option:`--sslMode <mongod --sslMode>`
9398

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>
95128

129+
.. include:: /includes/extracts/default-bind-ip-security-additional-config-file.rst
96130

97-
Use Configuration File
98-
``````````````````````
131+
The x.509 configuration requires:
99132

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
102136

103-
.. code-block:: yaml
137+
* - Option
138+
- Notes
104139

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`
112141

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.
114143

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+
----------
117160

118161
.. _addX509SubjectUser:
119162

@@ -154,36 +197,23 @@ client certificate to authenticate more than one MongoDB user.
154197
#. Add the ``RFC2253`` compliant value of the ``subject`` as a user.
155198
Omit spaces as needed.
156199

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:
161203

162204
.. code-block:: javascript
163205

164206
db.getSiblingDB("$external").runCommand(
165207
{
166208
createUser: "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry",
167209
roles: [
168-
{ role: 'readWrite', db: 'test' },
169-
{ role: 'userAdminAnyDatabase', db: 'admin' }
170-
],
210+
{ role: "readWrite", db: "test" },
211+
{ role: "userAdminAnyDatabase", db: "admin" }
212+
],
171213
writeConcern: { w: "majority" , wtimeout: 5000 }
172214
}
173215
)
174216

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-
187217
See :doc:`/tutorial/manage-users-and-roles` for details on adding a user
188218
with roles.
189219

@@ -192,34 +222,101 @@ with roles.
192222
Authenticate with a x.509 Certificate
193223
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194224

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::
198226

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.
203230

204-
For example, if using the :binary:`~bin.mongo` shell,
231+
.. tabs::
205232

206-
1. Connect :binary:`~bin.mongo` shell to the :binary:`~bin.mongod` set up for
207-
TLS/SSL:
233+
tabs:
208234

209-
.. code-block:: sh
235+
- id: connect
236+
name: Connect with Authentication
237+
content: |
210238

211-
mongo --ssl --sslPEMKeyFile <path to CA signed client PEM file> --sslCAFile <path to root CA PEM file>
239+
To authenticate during connection:
212240

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
217242

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
219244

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

Comments
 (0)