-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathdb.getRoles.txt
201 lines (149 loc) · 4.62 KB
/
db.getRoles.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
=============
db.getRoles()
=============
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol
Definition
----------
.. |getRoleMethod| replace:: ``db.getRoles()``
.. method:: db.getRoles()
Returns information for all the roles in the database on which the command
runs. The method can be run with or without an argument.
If run without an argument, :method:`db.getRoles()` returns inheritance
information for the database's :ref:`user-defined <user-defined-roles>`
roles.
To return more information, pass the :method:`db.getRoles()` a
document with the following fields:
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Field
- Type
- Description
* - ``rolesInfo``
- integer
- Set this field to ``1`` to retrieve all user-defined roles.
* - ``showAuthenticationRestrictions``
- boolean
- .. include:: /includes/fact-show-auth-restrictions-description.rst
* - ``showBuiltinRoles``
- boolean
- Optional. Set this field to true to display :ref:`built-in
roles <built-in-roles>` as well as user-defined roles.
* - ``showPrivileges``
- boolean
- Optional. Set this field to ``true`` to show role privileges,
including both privileges inherited from other roles and
privileges defined directly. By default, the command returns
only the roles from which this role inherits privileges and
does not return specific privileges.
:method:`db.getRoles()` wraps the :dbcommand:`rolesInfo` command.
Compatibility
-------------
This method is available in deployments hosted in the following
environments:
.. include:: /includes/fact-environments-no-atlas-support.rst
.. include:: /includes/fact-environments-onprem-only.rst
Required Access
---------------
.. include:: /includes/access-roles-info.rst
Examples
--------
The examples in this section show how to use ``db.getRoles`` to:
- :ref:`db-getRoles-example-return-built-in-roles`
- :ref:`db-getRoles-example-auth-restrictions`
.. _db-getRoles-example-return-built-in-roles:
Show Role Privileges and Built-In Roles
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following operation returns all the roles on the ``products``
database, including role privileges and built-in roles:
.. code-block:: javascript
use products
db.getRoles(
{
rolesInfo: 1,
showPrivileges: true,
showBuiltinRoles: true
}
)
Example output (shortened for readability):
.. code-block:: javascript
:copyable: false
{
roles: [
{
role: 'dbOwner',
db: 'products',
isBuiltin: true,
roles: [],
inheritedRoles: [],
privileges: [
{
resource: { db: 'products', collection: '' },
actions: [
'analyze',
'bypassDocumentValidation',
'changeCustomData',
...
]
},
{
resource: { db: 'products', collection: 'system.profile' },
actions: [
'changeStream',
'collStats',
'convertToCapped',
...
]
}
],
inheritedPrivileges: [
{
resource: { db: 'products', collection: '' },
actions: [
'analyze',
'bypassDocumentValidation',
'changeCustomData',
...
]
}
]
},
...
]
}
.. _db-getRoles-example-auth-restrictions:
Show Authentication Restrictions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following operation returns role inheritance information and
authentication restrictions for all :ref:`user-defined roles
<user-defined-roles>` on the ``product`` database:
.. code-block:: javascript
use products
db.getRoles( { rolesInfo: 1, showAuthenticationRestrictions: true } )
Example output:
.. code-block:: javascript
:copyable: false
{
roles: [
{
_id: 'products.associate',
role: 'associate',
db: 'products',
roles: [ { role: 'readWrite', db: 'products' } ],
authenticationRestrictions: [
[ { clientSource: [ '198.51.100.0' ] } ]
],
isBuiltin: false,
inheritedRoles: [ { role: 'readWrite', db: 'products' } ],
inheritedAuthenticationRestrictions: [
[ { clientSource: [ '198.51.100.0' ] } ]
]
}
],
ok: 1
}