@@ -7,12 +7,14 @@ rolesInfo
7
7
.. contents:: On this page
8
8
:local:
9
9
:backlinks: none
10
- :depth: 1
10
+ :depth: 2
11
11
:class: singlecol
12
12
13
13
Definition
14
14
----------
15
15
16
+ .. |getRoleMethod| replace:: ``rolesInfo``
17
+
16
18
.. dbcommand:: rolesInfo
17
19
18
20
Returns inheritance and privilege information for specified roles,
@@ -32,8 +34,9 @@ The command has the following syntax:
32
34
db.runCommand(
33
35
{
34
36
rolesInfo: { role: <name>, db: <db> },
35
- showPrivileges : <Boolean>,
37
+ showAuthenticationRestrictions : <Boolean>,
36
38
showBuiltinRoles: <Boolean>,
39
+ showPrivileges: <Boolean>,
37
40
comment: <any>
38
41
}
39
42
)
@@ -55,20 +58,26 @@ The command takes the following fields:
55
58
- string, document, array, or integer
56
59
- The role(s) to return information about. For the syntax for specifying
57
60
roles, see :ref:`rolesinfo-behavior`.
58
-
59
- * - ``showPrivileges ``
61
+
62
+ * - ``showAuthenticationRestrictions ``
60
63
- 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
+
66
66
* - ``showBuiltinRoles``
67
67
- 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.
72
81
73
82
* - ``comment``
74
83
- any
@@ -193,6 +202,21 @@ Output
193
202
Examples
194
203
--------
195
204
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
+
196
220
View Information for a Single Role
197
221
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198
222
@@ -230,8 +254,10 @@ for the role ``associate`` defined on the ``products`` database:
230
254
}
231
255
)
232
256
233
- View Information for Several Roles
234
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
257
+ .. _rolesInfo-example-multiple-roles:
258
+
259
+ View Information for Multiple Roles
260
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235
261
236
262
The following command returns information for two roles on two different
237
263
databases:
@@ -261,6 +287,8 @@ The following returns *both* the role inheritance and the privileges:
261
287
}
262
288
)
263
289
290
+ .. _rolesInfo-example-user-defined-roles:
291
+
264
292
View All User-Defined Roles for a Database
265
293
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
266
294
@@ -277,6 +305,49 @@ privileges:
277
305
}
278
306
)
279
307
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
+
280
351
View All User-Defined and Built-In Roles for a Database
281
352
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282
353
@@ -291,3 +362,78 @@ runs, including both built-in and user-defined roles:
291
362
showBuiltinRoles: true
292
363
}
293
364
)
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