定義
updateUserコマンドを実行するデータベース上のユーザーのプロファイルを更新します。 フィールドを更新すると、ユーザーの 配列と 配列の更新を含め、前のフィールドの値 が 完全に置き換え
rolesauthenticationRestrictionsられます。Tip
In
mongosh, this command can also be run through thedb.changeUserPassword()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.警告
roles配列を更新すると、前の配列の値が完全に置き換えられます。 ユーザーの既存のロールすべてを置き換えずにロールを追加または排除するには、grantRolesToUserまたはrevokeRolesFromUserコマンドを使用します。ユーザーを更新するには、
updateUserフィールドと少なくとも 1 つの他のフィールド(writeConcern以外)を指定する必要があります。
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
重要
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
構文
コマンドは、次の構文を使用します。
db.runCommand( { updateUser: "<username>", pwd: passwordPrompt(), // Or "<cleartext password>" customData: { <any information> }, roles: [ { role: "<role>", db: "<database>" } | "<role>", ... ], authenticationRestrictions: [ { clientSource: ["<IP>" | "<CIDR range>", ...], serverAddress: ["<IP>", | "<CIDR range>", ...] }, ... ], mechanisms: [ "<scram-mechanism>", ... ], digestPassword: <boolean>, writeConcern: { <write concern> }, comment: <any> } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | タイプ | 説明 |
|---|---|---|
| string | 更新するユーザーの名前。 |
| string | 任意。ユーザーのパスワード。値は以下のいずれかになります。
|
| ドキュメント | 任意。任意の情報が含まれます。 |
| 配列 | 任意。ユーザーに付与されたロール。 |
| ドキュメント | 任意。 操作の 書込み保証( write concern ) のレベル。 詳しくは、 書込み保証(write concern) の仕様を参照してください。 |
| 配列 | 任意。サーバーがユーザーに強制する認証制限。ユーザーによるサーバー接続が許可される、またはサーバーがユーザーを受け入れることができる IP アドレス リストと CIDR 範囲を指定します。 |
| 配列 | 任意。特定の SCRAM メカニズムまたはユーザー認証情報のメカニズムです。 パスワードなしで mechanisms フィールドを更新する場合、ユーザーの現在のメカニズムのサブセットのみを指定でき、指定されたメカニズムの既存のユーザー認証情報のみが保持されます。 メカニズムに併せてパスワードを更新すると、ユーザーの新しい認証情報セットが保存されます。 有効な値は次のとおりです。
|
| ブール値 | 任意。サーバーまたはクライアントがパスワードをダイジェスト化するかどうかを示します。
|
| any | 任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。
コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。 |
ロール
rolesフィールドでは、組み込みロールとユーザー定義ロールの両方を指定できます。
To specify a role that exists in the same database where updateUser runs, you can either specify the role with the name of the role:
"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 での認証の詳細については、「自己管理型配置での認証 」を参照してください。
動作
警告
By default, updateUser sends all specified data to the MongoDB instance in cleartext, even if using passwordPrompt(). Use TLS transport encryption to protect communications between clients and the server, including the password sent by updateUser. For instructions on enabling TLS transport encryption, see Configure MongoDB Instances for TLS/SSL Encryption.
MongoDB では、クリアテキストのパスワードはストアされません。パスワードが脆弱になるのは、クライアントとサーバー間の転送時と、TLS 転送暗号化が有効になっていない場合のみです。
必要なアクセス権
ユーザーの roles 配列を更新するには、すべてのデータベースに対する revokeRole アクションを含むアクセス権が必要です。
ユーザーにロールを追加するには、ロールのデータベースに対して grantRole アクションが必要です。
別のユーザーの pwd フィールドまたは customData フィールドを変更するには、そのユーザーのデータベースに対してそれぞれ changePassword アクションと changeCustomData アクションが必要です。
自分のパスワードとカスタム データを変更するには、ユーザーのデータベースに対してそれぞれ changeOwnPassword および changeOwnCustomData アクションを付与する特権が必要です。
例
products データベースに次のユーザー情報を持つユーザー appClient01 がある場合:
{ "_id" : "products.appClient01", "userId" : UUID("c5d88855-3f1e-46cb-9c8b-269bef957986"), "user" : "appClient01", "db" : "products", "customData" : { "empID" : "12345", "badge" : "9156" }, "roles" : [ { "role" : "readWrite", "db" : "products" }, { "role" : "read", "db" : "inventory" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
The following updateUser command completely replaces the user's customData and roles data:
use products db.runCommand( { updateUser : "appClient01", customData : { employeeId : "0x3039" }, roles : [ { role : "read", db : "assets" } ] } )
products データベース内のユーザー appClient01 には現在、次のユーザー情報があります。
{ "_id" : "products.appClient01", "userId" : UUID("c5d88855-3f1e-46cb-9c8b-269bef957986"), "user" : "appClient01", "db" : "products", "customData" : { "employeeId" : "0x3039" }, "roles" : [ { "role" : "read", "db" : "assets" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }