設定プロバイダーを用いた機密情報の外部化 - Amazon Managed Streaming for Apache Kafka

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

設定プロバイダーを用いた機密情報の外部化

この例は、オープンソースの設定プロバイダーを使用して Amazon MSK Connect の機密情報を外部化する方法を示しています。設定プロバイダーを使用すると、コネクタまたはワーカー設定でプレーンテキストの代わりに変数を指定でき、コネクタで実行されているワーカーは実行時にこれらの変数を解決します。これにより、認証情報やその他のシークレットがプレーンテキストで保存されるのを防ぐことができます。この例の設定プロバイダーは、 AWS Secrets Manager、Amazon S3、および Systems Manager (SSM) からの設定パラメータの取得をサポートしています。ステップ 2 では、設定するサービスの機密情報の保存と取得をセットアップする方法を確認できます。

ステップ 1: カスタムプラグインを作成して S3 にアップロードする

カスタムプラグインを作成するには、ローカルマシンで次のコマンド msk-config-provider を実行して、コネクタと を含む zip ファイルを作成します。

ターミナルウィンドウと Debezium をコネクタとして使用してカスタムプラグインを作成するには

AWS CLI を使用して、 AWS S3 バケットへのアクセスを許可する認証情報を持つスーパーユーザーとしてコマンドを実行します。 AWS CLI のインストールとセットアップの詳細については、 ユーザーガイドの「 AWS CLI の開始方法AWS Command Line Interface 」を参照してください。Amazon S3 で AWS CLI を使用する方法については、「 ユーザーガイド」の「 CLI で Amazon S3 AWS を使用するAWS Command Line Interface 」を参照してください。

  1. ターミナルウィンドウで、以下のコマンドを使用して custom-plugin という名前のフォルダをワークスペースに作成します。

    mkdir custom-plugin && cd custom-plugin
  2. 次のコマンドを使用して、Debezium サイトから MySQL コネクタプラグインの最新の安定版リリースをダウンロードします。

    wget https://repo1.maven.org/maven2/io/debezium/debezium-connectormysql/ 2.2.0.Final/debezium-connector-mysql-2.2.0.Final-plugin.tar.gz

    次のコマンドを使用して、ダウンロードした gzip ファイルを custom-plugin フォルダに解凍します。

    tar xzf debezium-connector-mysql-2.2.0.Final-plugin.tar.gz
  3. 次のコマンドを使用して、MSK 設定プロバイダーの zip ファイルをダウンロードします。

    wget https://github.com/aws-samples/msk-config-providers/releases/download/r0.1.0/msk-config-providers-0.1.0-with-dependencies.zip

    次のコマンドを使用して、ダウンロードした zip ファイルを custom-plugin フォルダに解凍します。

    unzip msk-config-providers-0.1.0-with-dependencies.zip
  4. 上記のステップで取得した MSK 設定プロバイダーとカスタムコネクタの内容を、custom-plugin.zip という名前を付けた単一のファイルに圧縮します。

    zip -r ../custom-plugin.zip *
  5. このファイルを後で参照できるように S3 にアップロードします。

    aws s3 cp ../custom-plugin.zip s3:<S3_URI_BUCKET_LOCATION>
  6. Amazon MSK コンソールの [MSK Connect] セクションで [カスタムプラグイン] を選択し、次に [カスタムプラグインの作成] を選択して s3:<S3_URI_BUCKET_LOCATION> S3 バケットを参照し、アップロードしたカスタムプラグインの ZIP ファイルを選択します。

  7. プラグイン名には debezium-custom-plugin と入力します。オプションで説明を入力し、[カスタムプラグインの作成] を選択します。

ステップ 2: さまざまなプロバイダーのパラメータとアクセス許可を設定する

次の 3 つのサービスでパラメータ値を設定できます。

  • Secrets Manager

  • Systems Manager Parameter Store

  • S3 - Simple Storage Service

以下のタブのいずれかを選択すると、そのサービスのパラメータと関連するアクセス許可の設定方法が表示されます。

Configure in Secrets Manager
Secrets Manager でパラメータ値を設定するには
  1. Secrets Manager コンソールを開きます。

  2. 認証情報またはシークレットを保存する新しいシークレットを作成します。手順については、「 ユーザーガイド」の「 AWS Secrets Manager シークレットの作成 AWS Secrets Manager 」を参照してください。

  3. シークレットの ARN をコピーします。

  4. 以下のサンプルポリシーの Secrets Manager のアクセス許可をサービス実行ロールに追加します。<arn:aws:secretsmanager:us-east-1:123456789000:secret:MySecret-1234> をシークレットの ARN に置き換えます。

  5. ワーカー設定とコネクタの指示を追加します。

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "secretsmanager:GetResourcePolicy", "secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret", "secretsmanager:ListSecretVersionIds" ], "Resource": [ "<arn:aws:secretsmanager:us-east-1:123456789000:secret:MySecret-1234>" ] } ] }
  6. Secrets Manager 設定プロバイダーを使用するには、ステップ 3 のワーカー設定テキストボックスに次のコード行をコピーします。

    # define name of config provider: config.providers = secretsmanager # provide implementation classes for secrets manager: config.providers.secretsmanager.class = com.amazonaws.kafka.config.providers.SecretsManagerConfigProvider # configure a config provider (if it needs additional initialization), for example you can provide a region where the secrets or parameters are located: config.providers.secretsmanager.param.region = us-east-1
  7. Secrets Manager 設定プロバイダーで、ステップ 4 のコネクタ設定にある次のコード行をコピーします。

    #Example implementation for secrets manager variable database.hostname=${secretsmanager:MSKAuroraDBCredentials:username} database.password=${secretsmanager:MSKAuroraDBCredentials:password}

上記のステップは、他の設定プロバイダーでも使用できます。

Configure in Systems Manager Parameter Store
Systems Manager のパラメータストアでパラメータ値を設定するには
  1. Systems Manager コンソールを開きます。

  2. ナビゲーションペインで、[パラメータストア] を選択します。

  3. Systems Manager に保存する新しいパラメータを作成します。手順については、「 ユーザーガイド」の「Systems Manager パラメータの作成 (コンソール) AWS Systems Manager 」を参照してください。

  4. パラメータの ARN をコピーします。

  5. 以下のサンプルポリシーの Secrets Manager のアクセス許可をサービス実行ロールに追加します。<arn:aws:ssm:us-east-1:123456789000:parameter/MyParameterName> をパラメータの ARN に置き換えます。

    { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "ssm:GetParameterHistory", "ssm:GetParametersByPath", "ssm:GetParameters", "ssm:GetParameter" ], "Resource": "arn:aws:ssm:us-east-1:123456789000:parameter/MyParameterName" } ] }
  6. パラメータストア設定プロバイダーを使用するには、ステップ 3 のワーカー設定テキストボックスに次のコード行をコピーします。

    # define name of config provider: config.providers = ssm # provide implementation classes for parameter store: config.providers.ssm.class = com.amazonaws.kafka.config.providers.SsmParamStoreConfigProvider # configure a config provider (if it needs additional initialization), for example you can provide a region where the secrets or parameters are located: config.providers.ssm.param.region = us-east-1
  7. パラメータストア設定プロバイダーで、ステップ 5 のコネクタ設定にある次のコード行をコピーします。

    #Example implementation for parameter store variable schema.history.internal.kafka.bootstrap.servers=${ssm::MSKBootstrapServerAddress}

    上記の 2 つのステップを他の設定プロバイダーにバンドルすることもできます。

Configure in Amazon S3
Amazon S3 のオブジェクト/ファイルを設定するには
  1. Amazon S3 コンソールを開きます。

  2. オブジェクトを S3 のバケットにアップロードします。手順については、「オブジェクトのアップロード」を参照してください。

  3. オブジェクトの ARN をコピーします。

  4. 以下のサンプルポリシーの Amazon S3 オブジェクト読み取りアクセス許可をサービス実行ロールに追加します。<arn:aws:s3:::MY_S3_BUCKET/path/to/custom-plugin.zip> をオブジェクトの ARN に置き換えます。

    { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": "s3:GetObject", "Resource": "<arn:aws:s3:::MY_S3_BUCKET/path/to/custom-plugin.zip>" } ] }
  5. Amazon S3 設定プロバイダーを使用するには、ステップ 3 のワーカー設定テキストボックスに次のコード行をコピーします。

    # define name of config provider: config.providers = s3import # provide implementation classes for S3: config.providers.s3import.class = com.amazonaws.kafka.config.providers.S3ImportConfigProvider
  6. Amazon S3 設定プロバイダーで、次のコード行をステップ 4 のコネクタ設定にコピーします。

    #Example implementation for S3 object database.ssl.truststore.location = ${s3import:us-west-2:my_cert_bucket/path/to/trustore_unique_filename.jks}

    上記の 2 つのステップを他の設定プロバイダーにバンドルすることもできます。

ステップ 3: 設定プロバイダーに関する情報を使用してカスタムワーカー設定を作成する

  1. [Amazon MSK Connect] セクションで [ワーカー設定] を選択します。

  2. [ワーカー設定の作成] を選択します。

  3. [ワーカー設定名] テキストボックスに SourceDebeziumCustomConfig を入力します。説明はオプションです。

  4. 必要なプロバイダーに基づいて関連する設定コードをコピーし、[ワーカー設定] テキストボックスに貼り付けます。

  5. 3 つのプロバイダーすべてのワーカー設定の例を以下に示します。

    key.converter=org.apache.kafka.connect.storage.StringConverter key.converter.schemas.enable=false value.converter=org.apache.kafka.connect.json.JsonConverter value.converter.schemas.enable=false offset.storage.topic=offsets_my_debezium_source_connector # define names of config providers: config.providers=secretsmanager,ssm,s3import # provide implementation classes for each provider: config.providers.secretsmanager.class = com.amazonaws.kafka.config.providers.SecretsManagerConfigProvider config.providers.ssm.class = com.amazonaws.kafka.config.providers.SsmParamStoreConfigProvider config.providers.s3import.class = com.amazonaws.kafka.config.providers.S3ImportConfigProvider # configure a config provider (if it needs additional initialization), for example you can provide a region where the secrets or parameters are located: config.providers.secretsmanager.param.region = us-east-1 config.providers.ssm.param.region = us-east-1
  6. [ワーカー設定の作成] をクリックします。

ステップ 4: コネクタを作成する

  1. Create a new connector」の手順に従って新しいコネクタを作成します。

  2. ステップ 1: カスタムプラグインを作成して S3 にアップロードする で S3 バケットにアップロードした custom-plugin.zip ファイルをカスタムプラグインのソースとして選択します。

  3. 必要なプロバイダーに基づいて関連する設定コードをコピーし、[コネクタの設定] フィールドに貼り付けます。

  4. 3 つのプロバイダーすべてのコネクタ設定の例を以下に示します。

    #Example implementation for parameter store variable schema.history.internal.kafka.bootstrap.servers=${ssm::MSKBootstrapServerAddress} #Example implementation for secrets manager variable database.hostname=${secretsmanager:MSKAuroraDBCredentials:username} database.password=${secretsmanager:MSKAuroraDBCredentials:password} #Example implementation for Amazon S3 file/object database.ssl.truststore.location = ${s3import:us-west-2:my_cert_bucket/path/to/trustore_unique_filename.jks}
  5. 「カスタム設定を使用する」を選択し、「ワーカー設定」ドロップダウンSourceDebeziumCustomConfigから選択します。

  6. Create connector」の残りの手順に従います。

考慮事項

Amazon MSK Connect で MSK 設定プロバイダーを使用する際には、次の点を考慮してください。

  • 設定プロバイダーを使用するときは、IAM サービス実行ロールに適切なアクセス許可を割り当てます。

  • ワーカー設定で設定プロバイダーを定義し、コネクタ設定でその実装を定義します。

  • プラグインで機密設定値をシークレットとして定義していない場合、機密設定値がコネクタログに表示される可能性があります。Kafka Connect は、未定義の設定値を他のプレーンテキスト値と同じように扱います。詳細については、「シークレットがコネクタログに表示されないようにする」を参照してください。

  • デフォルトでは、コネクタが設定プロバイダーを使用するときに、MSK Connect はコネクタを頻繁に再起動します。この再起動動作を無効にするには、コネクタ設定で config.action.reload の値を none に設定します。