Skip to content

Commit 7885290

Browse files
Bob GrabarSam Kleinman
authored andcommitted
DOCS-2404 convert user admin tutorial to new steps format
Signed-off-by: Sam Kleinman <[email protected]>
1 parent 63f6218 commit 7885290

File tree

4 files changed

+74
-84
lines changed

4 files changed

+74
-84
lines changed

source/includes/access-create-user.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A user must have :authaction:`createUser` :ref:`action
1+
A user must have the :authaction:`createUser` :ref:`action
22
<security-user-actions>` on a database to create a new user on that
33
database.
44

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
source:
2+
file: steps-add-admin-user.yaml
3+
ref: connect-with-appropriate-privileges
4+
---
5+
source:
6+
file: steps-add-admin-user.yaml
7+
ref: verify-privileges
8+
---
9+
title: Create the User Administrator
10+
stepnum: 3
11+
ref: create-user-admin
12+
pre: |
13+
Add the user and assign the :authrole:`userAdmin` role or
14+
:authrole:`userAdminAnyDatabase` role, and only that role.
15+
action:
16+
pre: |
17+
The following example creates the user ``recordsUserAdmin`` on the
18+
``records`` database:
19+
language: javascript
20+
code: |
21+
db.createUser(
22+
{
23+
user: "recordsUserAdmin",
24+
pwd: "password",
25+
roles:
26+
[
27+
{
28+
role: "userAdmin",
29+
db: "records"
30+
}
31+
]
32+
}
33+
)
34+
...

source/reference/built-in-roles.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ single-database equivalents:
433433

434434
The :authrole:`userAdminAnyDatabase` role does not restrict the permissions
435435
that a user can grant. As a result, :authrole:`userAdminAnyDatabase` users
436-
can grant privileges themselves privileges in excess of their current
436+
can grant themselves privileges in excess of their current
437437
privileges and even can grant themselves *all privileges*, even though the
438438
role does not explicitly authorize privileges beyond user administration.
439439
This role is effectively a MongoDB system :ref:`superuser <superuser>`.

source/tutorial/add-user-administrator.txt

Lines changed: 38 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,40 @@ Create a User Administrator
44

55
.. default-domain:: mongodb
66

7-
In a MongoDB deployment, users with either the
8-
:authrole:`userAdmin` or :authrole:`userAdminAnyDatabase` roles are
9-
*effective* administrative "superusers". Users
10-
with either of these roles can create and modify any other users and can
11-
assign them any privileges. The user also can grant *itself* any
12-
privileges. In production deployments, this user should have *no other
13-
roles* and should only administer users and privileges.
14-
15-
This should be the first user created for a MongoDB deployment. This
16-
user can then create all other users in the system.
17-
18-
.. important:: The :authrole:`userAdminAnyDatabase` user can grant
19-
itself and any other user full access to the entire MongoDB
20-
instance. The credentials to log in as this user should be
21-
carefully controlled.
22-
23-
Users with the :authrole:`userAdmin` and
24-
:authrole:`userAdminAnyDatabase` privileges are not the same as the
25-
UNIX ``root`` superuser in that this role confers **no additional
26-
access** beyond user administration. These users cannot perform
27-
administrative operations or read or write data without first
28-
conferring themselves with additional permissions.
29-
30-
The :authrole:`userAdmin` allows a user the ability to gain
31-
:authrole:`userAdminAnyDatabase`, and so for the ``admin`` database
32-
**only** these roles are effectively the same.
33-
34-
Create a User Administrator
35-
---------------------------
36-
37-
1. Connect to the :program:`mongod` or :program:`mongos` by either:
38-
39-
- Authenticating as an existing user with the :authrole:`userAdmin`
40-
or :authrole:`userAdminAnyDatabase` role.
41-
42-
- Authenticating using the :ref:`localhost exception
43-
<localhost-exception>`. When creating the first user in a
44-
deployment, you must authenticate using the :ref:`localhost exception
45-
<localhost-exception>`.
46-
47-
#. Switch to the ``admin`` database:
48-
49-
.. code-block:: javascript
50-
51-
db = db.getSiblingDB('admin')
52-
53-
#. Add the user with either the :authrole:`userAdmin` role or
54-
:authrole:`userAdminAnyDatabase` role, and only that role, by issuing
55-
a command similar to the following, where ``<username>`` is the
56-
username and ``<password>`` is the password:
57-
58-
.. code-block:: javascript
59-
60-
db.addUser( { user: "<username>",
61-
pwd: "<password>",
62-
roles: [ "userAdminAnyDatabase" ] } )
63-
64-
To authenticate as this user, you must authenticate against the
65-
``admin`` database.
7+
Overview
8+
--------
9+
10+
The user administrator creates users and creates and assigns roles. The
11+
user administrator can grant any privilege in the database and can create
12+
new ones. In a MongoDB deployment, create the user administrator as the
13+
first user. Then let this user create all other users.
14+
15+
To support creation of user administrators, MongoDB provides the
16+
:authrole:`userAdmin` and :authrole:`userAdminAnyDatabase` roles, both of
17+
which grant :ref:`actions <security-user-actions>` specific to user and
18+
role management and confer no additional privileges, in keeping with the
19+
policy of :term:`least privilege`.
20+
21+
Carefully control these roles. A user with either of these roles can grant
22+
*itself* additional privileges. Specifically, a user with the
23+
:authrole:`userAdmin` role can grant itself any privilege in the database.
24+
A user assigned either the :authrole:`userAdmin` role on the ``admin``
25+
database or the :authrole:`userAdminAnyDatabase` can grant itself any
26+
privilege *in the system*.
6627

6728
.. _localhost-exception:
6829

69-
Authenticate with Full Administrative Access via Localhost
70-
----------------------------------------------------------
30+
Localhost Exception
31+
-------------------
7132

72-
If there are no users for the ``admin`` database, you can connect with
73-
full administrative access via the localhost interface. This bypass
74-
exists to support bootstrapping new deployments. This approach is
75-
useful, for example, if you want to run :program:`mongod` or
76-
:program:`mongos` with authentication before creating your first user.
33+
The localhost exception lets you connect *with* administrative access to an
34+
authentication-enabled :program:`mongod` or :program:`mongos` prior to
35+
creating your first user on the ``admin`` database. The exception applies *if*
36+
there are no users on the ``admin`` database. The bypass exists to support
37+
bootstrapping new deployments.
7738

78-
To authenticate via localhost, connect to the :program:`mongod` or
79-
:program:`mongos` from a client running on the same system. Your
80-
connection will have full administrative access.
39+
To use the exception, connect to the :program:`mongod` or :program:`mongos`
40+
from a client running on the same system.
8141

8242
To disable the localhost bypass, set the
8343
:parameter:`enableLocalhostAuthBypass` parameter using
@@ -87,20 +47,16 @@ To disable the localhost bypass, set the
8747

8848
mongod --setParameter enableLocalhostAuthBypass=0
8949

90-
.. note::
50+
Prerequisites
51+
-------------
9152

92-
For versions of MongoDB 2.2 prior to 2.2.4, if :program:`mongos` is
93-
running with :setting:`keyFile`, then all users connecting over the
94-
localhost interface must authenticate, even if there aren't any users
95-
in the ``admin`` database. Connections on localhost are not correctly
96-
granted full access on sharded systems that run those versions.
53+
.. include:: /includes/access-create-user.rst
9754

98-
MongoDB 2.2.4 resolves this issue.
55+
A user with either the :authrole:`userAdmin` or
56+
:authrole:`userAdminAnyDatabase` role, or authenticated using the
57+
:ref:`localhost exception <localhost-exception>`, has those privileges.
9958

100-
.. note::
59+
Procedure
60+
---------
10161

102-
In version 2.2, you cannot add the first user to a sharded cluster
103-
using the ``localhost`` connection. If you are running a 2.2
104-
sharded cluster and want to enable authentication, you must deploy
105-
the cluster and add the first user to the ``admin`` database before
106-
restarting the cluster to run with :setting:`keyFile`.
62+
.. include:: /includes/steps/add-user-administrator.rst

0 commit comments

Comments
 (0)