@@ -286,59 +286,125 @@ To route a query to a :term:`cluster <sharded cluster>`,
286
286
Sharded Cluster Security Considerations
287
287
---------------------------------------
288
288
289
- .. note::
289
+ MongoDB controls access to :term:`sharded clusters <sharded cluster>`
290
+ through key files that store authentication information. The components
291
+ of sharded clusters use key files when authenticating to each other. You
292
+ create key files and then point your :program:`mongos` and
293
+ :program:`mongod` instances to the files, as described later in this
294
+ section.
295
+
296
+ In addition to the MongoDB security described in this section, you
297
+ should run your sharded clusters only in trusted networking environments
298
+ that control access to the cluster using network rules. Your networking
299
+ environments should use restrictions that ensure only known traffic
300
+ reaches your :program:`mongos` and :program:`mongod` instances.
301
+
302
+ This section describes authentication specific to sharded clusters. For
303
+ information on authentication across MongoDB, see
304
+ :ref:`security-authentication`.
305
+
306
+ Access Control Privileges in Sharded Clusters
307
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
308
+
309
+ In sharded clusters, MongoDB provides separate administrative privileges
310
+ for the sharded cluster and for each shard. Aside from that, the
311
+ available privileges are the same as for any MongoDB instance, as
312
+ described in :ref:`security-authentication`.
313
+
314
+ For sharded clusters, MongoDB provides these separate administrative privileges:
315
+
316
+ - Administrative privileges for the sharded cluster. These privileges
317
+ provide read-and-write access to the clusters's :term:`admin <admin
318
+ database>`, which lets the user run all administrative commands.
319
+ Administrative privileges also give the user read-and-write access to
320
+ all the cluster's databases.
321
+
322
+ The credentials for administrative privileges on the cluster reside on
323
+ the config servers. To receive admin access to the cluster, you must
324
+ authenticate a session while connected to a :program:`mongos` instance
325
+ using the admin database.
326
+
327
+ - Administrative privileges for an individual shard. A shard is a
328
+ :program:`mongod` instance for which sharding has been enabled. Each
329
+ shard has its own admin database that stores administrative
330
+ credentials and access for that shard only. These credentials are
331
+ *completely* distinct from the cluster-wide administrative
332
+ credentials.
333
+
334
+ As with all :program:`mongod` instances, MongoDB provides two types of
335
+ administrative privileges for a shard:
336
+
337
+ - Normal administrative privileges, which provide read-and-write
338
+ access to the admin database and access to all administrative
339
+ commands, and which provide read-and-write accees to all other
340
+ databases on that shard.
341
+
342
+ - Read-only administrative privileges, which provide read-only access
343
+ to the admin database and to all other databases on that shard.
344
+
345
+ Also, as with all :program:`mongod` instances, a MongoDB sharded cluster
346
+ provides the following non-administrative user privileges:
347
+
348
+ - Normal privileges, which provide read-and-write access to a specific
349
+ database. Users with normal privilege can add users to the database.
350
+
351
+ - Read-only privileges, which provide read-only access to a specific
352
+ database.
290
353
291
- You should always run all :program:`mongod` components in trusted
292
- networking environments that control access to the cluster using
293
- network rules and restrictions to ensure that only known traffic
294
- reaches your :program:`mongod` and :program:`mongos` instances.
354
+ For more information on privileges, see :ref:`security-authentication`.
295
355
296
- .. warning:: Limitations
356
+ Enable Authentication in a Sharded Cluster
357
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
297
358
298
- .. versionchanged:: 2.2
299
- Read only authentication is fully supported in shard
300
- clusters. Previously, in version 2.0, sharded clusters would not
301
- enforce read-only limitations.
359
+ .. versionadded:: 2.0
360
+ Support for authentication with sharded clusters.
302
361
303
- .. versionchanged:: 2.0
304
- Sharded clusters support authentication. Previously, in version
305
- 1.8, sharded clusters will not support authentication and access
306
- control. You must run your sharded systems in trusted
307
- environments .
362
+ To control access to a sharded cluster, you create key files and then
363
+ set the :setting:`keyFile` option on *all* components of the sharded
364
+ cluster (all :program:`mongos` instances, all config server
365
+ :program:`mongod` instances, and all shard :program:`mongod` instances). The content of
366
+ the key file is arbitrary but must be the same on all cluster members .
308
367
309
- To control access to a sharded cluster, you must set the
310
- :setting:`keyFile` option on all components of the sharded cluster. Use
311
- the :option:`--keyFile <mongos --keyFile>` run-time option or the
312
- :setting:`keyFile` configuration option for all :program:`mongos`,
313
- configuration instances, and shard :program:`mongod` instances.
368
+ To enable authentication, do the following:
314
369
315
- There are two classes of security credentials in a sharded cluster:
316
- credentials for "admin" users (i.e. for the :term:`admin database`) and
317
- credentials for all other databases. These credentials reside in
318
- different locations within the cluster and have different roles:
370
+ 1. Generate a key file to store authentication information, as described
371
+ in :ref:`generate-key-file`.
319
372
320
- - Admin database credentials reside on the config servers, to receive
321
- admin access to the cluster you *must* authenticate a session while
322
- connected to a :program:`mongos` instance using the :term:`admin
323
- database`.
373
+ #. On each component in the sharded cluster, enable authentication by
374
+ doing one of the following:
324
375
325
- - Each shard has its own :term:`admin database`, which stores
326
- administrative credentials and access for that shard only .
376
+ - In the configuration file, set the :setting:`keyFile` option to the
377
+ key file's path and then start the component .
327
378
328
- - Other database credentials reside on the *primary* shard for the
329
- database.
379
+ The following is an example :setting:`keyFile` option and path:
330
380
331
- This means that you *can* authenticate to these users and databases
332
- while connected directly to the *primary* shard for a database. You
333
- **cannot** authenticate to a database in a sharded cluster that is not
334
- the primary for that database. However, for clarity and consistency
335
- all interactions between the client and the database should use a
336
- :program:`mongos` instance.
381
+ .. code-block:: cfg
337
382
338
- .. note::
383
+ keyFile = /srv/mongodb/keyfile
384
+
385
+ - When starting the component, set :option:`--keyFile <mongos --keyFile>` option,
386
+ which is an option for both :program:`mongos` instances and
387
+ :program:`mongod` instances. Set the :option:`--keyFile <mongos --keyFile>`
388
+ to the key file's path.
389
+
390
+ .. note:: The :setting:`keyFile` setting implies :setting:`auth`, which
391
+ means in most cases you do not need to set :setting:`auth`.
392
+
393
+ #. Add the first administrative user and then add subsequent users. See
394
+ :ref:`control-access-add-users`.
395
+
396
+ Access a Sharded Cluster for which Authentication is Enabled
397
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
398
+
399
+ To access a sharded cluster as an authenticated admin user, see
400
+ :ref:`control-access-admin-access`.
401
+
402
+ To access a sharded cluster as an authenticated, non-admin user, see
403
+ either of the following:
404
+
405
+ - :dbcommand:`authenticate`
406
+
407
+ - :method:`db.auth()`
339
408
340
- Individual shards can store administrative credentials to their
341
- instance, which only permit access to a single shard. MongoDB
342
- stores these credentials in the shards' :term:`admin databases
343
- <admin database>` and these credentials are *completely* distinct
344
- from the cluster-wide administrative credentials.
409
+ To terminate an authenticated session, see the :dbcommand:`logout`
410
+ command.
0 commit comments