DMS MongoDB エンドポイント設定の平文パスワード

DMS の MongoDB 接続用パスワードをテンプレートやパラメータの既定値に含めないでください。

説明

MongoDbSettings.Password には MongoDB アカウントのパスワードを既定値なしで渡します。!Ref を使っても、パラメータの Default に書いた値はテンプレートに残ります。

想定される影響

値が漏えいすると、ソースに接続できる人に移行用アカウントの権限で MongoDB のデータを読まれるおそれがあります。

対処方法

パスワードを直接渡す場合は NoEcho: true を指定し、ログや出力には残さないでください。Secrets Manager を使う場合はユーザー名、パスワード、サーバー、ポートを省き、MongoDbSettings に SecretsManagerSecretId と SecretsManagerAccessRoleArn を指定します。漏えいした場合は MongoDB でパスワードを変更し、DMS の認証情報を更新して接続を確認します。

例

どちらの例も既存ユーザーを admin データベースで認証します。ソースサーバーとユーザー名を指定し、現在のパスワードを MasterMongoDBPassword で渡します。このパラメータを変更しても MongoDB のアカウント自体のパスワードは変わりません。

変更前

yaml
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  MongoDBServer:
    Type: String
  ParentMasterUsername:
    Type: String
  MasterMongoDBPassword:
    Type: String
    Default: "as@3djdkDjskjs73!!"
Resources:
  NewAmpApp1:
    Type: AWS::DMS::Endpoint
    Properties:
      EngineName: mongodb
      EndpointType: source
      SslMode: require
      MongoDbSettings:
        AuthType: password
        AuthSource: admin
        Password: !Ref MasterMongoDBPassword
        Port: 27017
        ServerName: !Ref MongoDBServer
        Username: !Ref ParentMasterUsername

変更後

yaml
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  MongoDBServer:
    Type: String
  ParentMasterUsername:
    Type: String
  MasterMongoDBPassword:
    Type: String
    NoEcho: true
Resources:
  NewAmpApp1:
    Type: AWS::DMS::Endpoint
    Properties:
      EngineName: mongodb
      EndpointType: source
      SslMode: require
      MongoDbSettings:
        AuthType: password
        AuthSource: admin
        Password: !Ref MasterMongoDBPassword
        Port: 27017
        ServerName: !Ref MongoDBServer
        Username: !Ref ParentMasterUsername

参考資料