updateRole
定義
updateRole
Updates a user-defined role. The
updateRole
command must run on the role's database.Tip
mongosh
では、このコマンドはdb.updateRole()
ヘルパー メソッドを通じて実行することもできます。ヘルパー メソッドは
mongosh
ユーザーには便利ですが、データベースコマンドと同じレベルの情報は返されない可能性があります。 便宜上必要ない場合、または追加の戻りフィールドが必要な場合は、 データベースコマンドを使用します。An update to a field completely replaces the previous field's values. To grant or remove roles or privileges without replacing all values, use one or more of the following commands:
警告
An update to the
privileges
orroles
array completely replaces the previous array's values.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
重要
このコマンドは、M0、M2、M5、M10+、および Flex クラスターではサポートされていません。詳細については、「 サポートされていないコマンド 」を参照してください。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
To update a role, you must provide the privileges
array, roles
array, or both.
コマンドは、次の構文を使用します。
db.runCommand( { updateRole: "<role>", privileges: [ { resource: { <resource> }, actions: [ "<action>", ... ] }, ... ], roles: [ { role: "<role>", db: "<database>" } | "<role>", ... ], authenticationRestrictions: [ { clientSource: ["<IP>" | "<CIDR range>", ...], serverAddress: ["<IP>", ...] }, ... ] writeConcern: <write concern document>, comment: <any> } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | タイプ | 説明 |
---|---|---|
| string | The name of the user-defined role role to update. |
| 配列 | Optional. Required if you do not specify |
| 配列 | Optional. Required if you do not specify |
| 配列 | 任意。 The authentication restrictions the server enforces on the role. Specifies a list of IP addresses and CIDR ranges users granted this role are allowed to connect to and/or which they can connect from. |
| ドキュメント | 任意。 操作の 書込み保証( write concern ) のレベル。 詳しくは、 書込み保証(write concern) の仕様を参照してください。 |
| any | 任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。
コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。 |
ロール
roles
フィールドでは、組み込みロールとユーザー定義ロールの両方を指定できます。
updateRole
が実行されるのと同じデータベースに存在するロールを指定するには、ロールの名前を使用してロールを指定します。
"readWrite"
または、次のように、ドキュメントを使用してロールを指定することもできます。
{ role: "<role>", db: "<database>" }
別のデータベースに存在するロールを指定するには、 ドキュメントを使用してロールを指定します。
認証の制限
authenticationRestrictions
ドキュメントには、次のフィールドのみを含めることができます。 authenticationRestrictions
ドキュメントに認識されないフィールドが含まれている場合、サーバーはエラーをスローします。
フィールド名 | 値 | 説明 |
---|---|---|
| IP アドレスおよび/またはCIDR範囲の配列 | 存在する場合、サーバーはユーザーを認証する際に、クライアントの IP アドレスが指定されたリストに含まれているか、リスト内の CIDR 範囲に属していることを確認します。 クライアントの IP アドレスが存在しない場合、サーバーはユーザーを認証しません。 |
| IP アドレスおよび/またはCIDR範囲の配列 | クライアントが接続できる IP アドレスまたは CIDR 範囲のリスト。 存在する場合、サーバーはクライアントの接続が指定されたリスト内の IP アドレス経由で受け入れられたことを確認します。 認識されない IP アドレス経由で接続が受け入れられた場合、サーバーはユーザーを認証しません。 |
重要
ユーザーが互換性のない認証制限を持つ複数のロールを継承した場合、そのユーザーは使用できなくなります。
たとえば、ユーザーが、 clientSource
フィールドが["198.51.100.0"]
であるロールと、 clientSource
フィールドが["203.0.113.0"]
である別のロールを継承した場合、サーバーはユーザーを認証できません。
MongoDB での認証の詳細については、「自己管理型配置での認証 」を参照してください。
動作
A role's privileges apply to the database where the role is created. The
role can inherit privileges from other roles in its database. A role
created on the admin
database can include privileges that apply to all
databases or to the クラスター and can inherit
privileges from roles in other databases.
必要なアクセス権
You must have the revokeRole
アクション on all databases in order to update a role.
You must have the grantRole
アクション on the database of each role in the roles
array
to update the array.
You must have the grantRole
アクション on the database of each privilege
in the privileges
array to update the array. If a privilege's
resource spans databases, you must have grantRole
on the
admin
database. A privilege spans databases if the privilege is any of
the following:
a collection in all databases
all collections and all database
the
cluster
resource
You must have the setAuthenticationRestriction
アクション on the database of the target
role to update a role's authenticationRestrictions
document.
例
The following is an example of the updateRole
command that
updates the myClusterwideAdmin
role on the admin
database.
While the privileges
and the
roles
arrays are both optional, at least
one of the two is required:
db.adminCommand( { updateRole: "myClusterwideAdmin", privileges: [ { resource: { db: "", collection: "" }, actions: [ "find" , "update", "insert", "remove" ] } ], roles: [ { role: "dbAdminAnyDatabase", db: "admin" } ], writeConcern: { w: "majority" } } )
To view a role's privileges, use the rolesInfo
command.