Skip to content

assign a user a role #1372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/includes/access-grant-user-role.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To grant a role, a user must have access that includes the
:authaction:`grantAnyRole` action on the relevant database.
3 changes: 1 addition & 2 deletions source/reference/command/grantRolesToUser.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ Definition
Required Access
---------------

To grant a role, a user must have access that includes the
:authaction:`grantAnyRole` action on the relevant database.
.. include:: /includes/access-grant-user-role.rst

Example
-------
Expand Down
51 changes: 51 additions & 0 deletions source/tutorial/assign-a-user-a-role.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
====================
Assign a User a Role
====================

.. default-domain:: mongodb

Overview
--------

Assign a user a role to give the user access to resources according to the
operational needs of the deployment.

Prerequisites
-------------

.. include:: /includes/access-grant-user-role.rst

Procedure
---------

Identify the Privileges to Assign
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Identify the :doc:`privileges </reference/user-privileges>` to make
available to the user. Privileges are combinations of database resources
and :ref:`actions <security-user-actions>`.

Identify the Role with Those Privileges
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Determine whether an existing role contains those privileges, and only
those privileges. If such a role does not exist, see the :docs:`procedure
for creating a role </tutorial/define-roles>`.

Grant the Role to the User
~~~~~~~~~~~~~~~~~~~~~~~~~~

Grant the role using the :dbcommand:`grantRolesToUser` command. For
example, to grant the user ``Alice`` the :authrole:`read` role on the
``stock`` database, run the following.

.. code-block:: javascript

db.runCommand( { grantRolesToUser: "Alice",
roles: [
{ role: "read", db: "stock"},
],
} )

The :dbcommand:`grantRolesToUser` command adds role to ``Alice``'s
existing roles.