@@ -7,12 +7,14 @@ rolesInfo
77.. contents:: On this page
88 :local:
99 :backlinks: none
10- :depth: 1
10+ :depth: 2
1111 :class: singlecol
1212
1313Definition
1414----------
1515
16+ .. |getRoleMethod| replace:: ``rolesInfo``
17+
1618.. dbcommand:: rolesInfo
1719
1820 Returns inheritance and privilege information for specified roles,
@@ -32,8 +34,9 @@ The command has the following syntax:
3234 db.runCommand(
3335 {
3436 rolesInfo: { role: <name>, db: <db> },
35- showPrivileges : <Boolean>,
37+ showAuthenticationRestrictions : <Boolean>,
3638 showBuiltinRoles: <Boolean>,
39+ showPrivileges: <Boolean>,
3740 comment: <any>
3841 }
3942 )
@@ -55,20 +58,26 @@ The command takes the following fields:
5558 - string, document, array, or integer
5659 - The role(s) to return information about. For the syntax for specifying
5760 roles, see :ref:`rolesinfo-behavior`.
58-
59- * - ``showPrivileges ``
61+
62+ * - ``showAuthenticationRestrictions ``
6063 - boolean
61- - Optional. Set the field to ``true`` to show role privileges, including both privileges
62- inherited from other roles and privileges defined directly. By default, the
63- command returns only the roles from which this role inherits privileges and
64- does not return specific privileges.
65-
64+ - .. include:: /includes/fact-show-auth-restrictions-description.rst
65+
6666 * - ``showBuiltinRoles``
6767 - boolean
68- - Optional. When the ``rolesInfo`` field is set to ``1``, set ``showBuiltinRoles`` to
69- ``true`` to include :ref:`built-in roles <built-in-roles>` in the output.
70- By default this field is set to ``false``, and the output for ``rolesInfo:
71- 1`` displays only :ref:`user-defined roles <user-defined-roles>`.
68+ - Optional. When the ``rolesInfo`` field is set to ``1``, set
69+ ``showBuiltinRoles`` to ``true`` to include :ref:`built-in roles
70+ <built-in-roles>` in the output. By default, this field is set to
71+ ``false``, and the output for ``rolesInfo: 1`` displays only
72+ :ref:`user-defined roles <user-defined-roles>`.
73+
74+ * - ``showPrivileges``
75+ - boolean
76+ - Optional. Set the field to ``true`` to show role privileges,
77+ including both privileges inherited from other roles and
78+ privileges defined directly. By default, the command returns only
79+ the roles from which this role inherits privileges and does not
80+ return specific privileges.
7281
7382 * - ``comment``
7483 - any
@@ -193,6 +202,21 @@ Output
193202Examples
194203--------
195204
205+ The examples in this section show how to use the ``rolesInfo`` command
206+ to:
207+
208+ - :ref:`rolesInfo-example-single-role`
209+
210+ - :ref:`rolesInfo-example-multiple-roles`
211+
212+ - :ref:`rolesInfo-example-user-defined-roles`
213+
214+ - :ref:`rolesInfo-example-user-defined-and-built-in-roles`
215+
216+ - :ref:`rolesInfo-example-auth-restrictions`
217+
218+ .. _rolesInfo-example-single-role:
219+
196220View Information for a Single Role
197221~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198222
@@ -230,8 +254,10 @@ for the role ``associate`` defined on the ``products`` database:
230254 }
231255 )
232256
233- View Information for Several Roles
234- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
257+ .. _rolesInfo-example-multiple-roles:
258+
259+ View Information for Multiple Roles
260+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235261
236262The following command returns information for two roles on two different
237263databases:
@@ -261,6 +287,8 @@ The following returns *both* the role inheritance and the privileges:
261287 }
262288 )
263289
290+ .. _rolesInfo-example-user-defined-roles:
291+
264292View All User-Defined Roles for a Database
265293~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
266294
@@ -277,6 +305,49 @@ privileges:
277305 }
278306 )
279307
308+ Example output (shortened for readability):
309+
310+ .. code-block:: javascript
311+ :copyable: false
312+
313+ {
314+ roles: [
315+ {
316+ _id: 'products.associate',
317+ role: 'associate',
318+ db: 'products',
319+ privileges: [
320+ {
321+ resource: { db: 'products', collection: '' },
322+ actions: [ 'bypassDocumentValidation' ]
323+ }
324+ ],
325+ roles: [ { role: 'readWrite', db: 'products' } ],
326+ isBuiltin: false,
327+ inheritedRoles: [ { role: 'readWrite', db: 'products' } ],
328+ inheritedPrivileges: [
329+ {
330+ resource: { db: 'products', collection: '' },
331+ actions: [ 'bypassDocumentValidation' ]
332+ },
333+ {
334+ resource: { db: 'products', collection: '' },
335+ actions: [
336+ 'changeStream',
337+ 'collStats',
338+ 'compactStructuredEncryptionData',
339+ ...
340+ ]
341+ },
342+ ...
343+ ]
344+ }
345+ ],
346+ ok: 1
347+ }
348+
349+ .. _rolesInfo-example-user-defined-and-built-in-roles:
350+
280351View All User-Defined and Built-In Roles for a Database
281352~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282353
@@ -291,3 +362,78 @@ runs, including both built-in and user-defined roles:
291362 showBuiltinRoles: true
292363 }
293364 )
365+
366+ Example output (shortened for readability):
367+
368+ .. code-block:: javascript
369+ :copyable: false
370+
371+ {
372+ roles: [
373+ {
374+ role: 'enableSharding',
375+ db: 'products',
376+ isBuiltin: true,
377+ roles: [],
378+ inheritedRoles: []
379+ },
380+ {
381+ role: 'userAdmin',
382+ db: 'products',
383+ isBuiltin: true,
384+ roles: [],
385+ inheritedRoles: []
386+ },
387+ {
388+ role: 'read',
389+ db: 'products',
390+ isBuiltin: true,
391+ roles: [],
392+ inheritedRoles: []
393+ },
394+ ...
395+ ],
396+ ok: 1
397+ }
398+
399+ .. _rolesInfo-example-auth-restrictions:
400+
401+ View Authentication Restrictions for Roles
402+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
403+
404+ The following operation returns all user-defined roles on the
405+ ``products`` database and includes authentication restrictions:
406+
407+ .. code-block:: javascript
408+
409+ db.runCommand(
410+ {
411+ rolesInfo: 1,
412+ showAuthenticationRestrictions: true
413+ }
414+ )
415+
416+ Example output:
417+
418+ .. code-block:: javascript
419+ :copyable: false
420+
421+ {
422+ roles: [
423+ {
424+ _id: 'products.associate',
425+ role: 'associate',
426+ db: 'products',
427+ roles: [ { role: 'readWrite', db: 'products' } ],
428+ authenticationRestrictions: [
429+ [ { clientSource: [ '198.51.100.0' ] } ]
430+ ],
431+ isBuiltin: false,
432+ inheritedRoles: [ { role: 'readWrite', db: 'products' } ],
433+ inheritedAuthenticationRestrictions: [
434+ [ { clientSource: [ '198.51.100.0' ] } ]
435+ ]
436+ }
437+ ],
438+ ok: 1
439+ }
0 commit comments