AWS KMSでの暗号化
AWS KMSでシークレットマネージャー接続の詳細情報を保護

Keeperシークレットマネージャーは、AWS KMSと統合することで、Keeperシークレットマネージャーの構成ファイルを暗号化できます。この統合により、マシン上の接続情報を保護しながら、すべてのシークレット認証情報に対してKeeperのゼロ知識暗号化を活用できます。
機能
AWS KMS を使用して、Keeperシークレットマネージャーの構成ファイルを暗号化および復号化
シークレットマネージャーの接続情報への不正アクセスを防止
わずかなコード変更で即座に保護を実現。すべてのKeeperシークレットマネージャーSDK機能と互換性あり
前提条件
Java 11以降をサポート
セットアップ
1. モジュールのインストール
GradleまたはMavenを使用してプロジェクトをセットアップ
Gradle
repositories {
mavenCentral()
}
dependencies {
implementation("com.keepersecurity.secrets-manager:aws:1.0.0")
implementation("com.keepersecurity.secrets-manager:core:17.0.0")
implementation ("software.amazon.awssdk:kms:2.20.28")
implementation ("software.amazon.awssdk:auth:2.20.28")
implementation("com.fasterxml.jackson.core:jackson-databind:2.18.2")
implementation("com.fasterxml.jackson.core:jackson-core:2.18.2")
implementation("com.google.code.gson:gson:2.12.1")
implementation("org.slf4j:slf4j-api:1.7.32"){
exclude("org.slf4j:slf4j-log4j12")
}
implementation("ch.qos.logback:logback-classic:1.2.6")
implementation("ch.qos.logback:logback-core:1.2.6")
implementation("org.bouncycastle:bc-fips:1.0.2.4")
}
Maven
<!-- KMS-core -->
<dependency>
<groupId>com.keepersecurity.secrets-manager</groupId>
<artifactId>aws</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.keepersecurity.secrets-manager</groupId>
<artifactId>core</artifactId>
<version>17.0.0</version>
</dependency>
<!-- aws-kms -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>kms</artifactId>
<version>2.20.28</version>
</dependency>
<!-- aws-auth -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>auth</artifactId>
<version>2.20.28</version>
</dependency>
<!--gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.12.1</version>
</dependency>
<!--jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.18.2</version>
</dependency>
<!--jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.18.2</version>
</dependency>
<!-- slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<scope>runtime</scope>
</dependency>
<!-- logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
<scope>compile</scope>
</dependency>
<!-- logback-core -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.6</version>
<scope>compile</scope>
</dependency>
<!-- bc-fips -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bc-fips</artifactId>
<version>1.0.2.4</version>
</dependency>
2. AWS接続を構成
デフォルトでは、boto3ライブラリは、aws configure
コマンドを使用したAWS CLIで既定の接続セッション設定を利用します。 接続の詳細情報を指定したい場合は、~/.aws/config
と~/.aws/credentials
にある2つの設定ファイルを手動で編集できます。
または、AwsSessionConfig
データクラスを使用し、aws_access_key_id
変数、aws_secret_access_key
変数、aws_session_token
変数を使用して、設定の変数をアクセスキーとして明示的に指定することもできます。
3. AWS KMSストレージをコードに追加
AWS接続の構成が完了すると、KSM構成ファイルの暗号化・復号に使用するキーを連携を通じて取得できます。また、シークレットマネージャーSDKに対して、KMSをストレージとして利用するよう指定する必要があります。
指定された接続認証情報の使用
この操作を行うには、SecretsManager
コンストラクタで、AwsKeyValueStorage
をシークレットマネージャーのストレージとして使用します。
このストレージには、AWSキーID、AwsSessionConfig
、AWS KMSによって暗号化されるシークレットマネージャー構成ファイルの名前が必要となります。
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
import com.keepersecurity.secretmanager.aws.kms.AwsKeyValueStorage;
import com.keepersecurity.secretmanager.aws.kms.AwsSessionConfig;
import com.keepersecurity.secretsManager.core.InMemoryStorage;
import com.keepersecurity.secretsManager.core.SecretsManager;
import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import static com.keepersecurity.secretsManager.core.SecretsManager.initializeStorage;
import software.amazon.awssdk.regions.Region;
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
class Test {
public static void main(String args[]){
String keyId = "<Key ID>";
String awsAccessKeyId = "<AWS Access ID>";
String awsSecretAccessKey = "<AWS Secret>";
String oneTimeToken = "[One Time Token]";
Region region = Region.<cloud-region>;
String profile = null OR "DEFAULT"; //set profile (ex. DEFUALT/UAT/PROD) if ~/.aws/config is set
String configFileLocation = "client_config_test.json";
try{
//set AWS configuration, It can be null if profile is set for aws credentials
AwsSessionConfig sessionConfig = new AwsSessionConfig(awsAccessKeyId, awsSecretAccessKey);
//Get Storage
AwsKeyValueStorage awskvstorage = new AwsKeyValueStorage(keyId, configFileLocation, profile, null, region);
initializeStorage(awskvstorage, oneTimeToken);
SecretsManagerOptions options = new SecretsManagerOptions(awskvstorage);
//getSecrets(OPTIONS);
}catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
デフォルトの接続を使用
この操作を行うには、SecretsManager
コンストラクタで、AwsKeyValueStorage
をシークレットマネージャーのストレージとして使用します。
このストレージには、AWSキーID、AwsSessionConfig
、AWS KMSによって暗号化されるシークレットマネージャー構成ファイルの名前が必要となります。
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
import com.keepersecurity.secretmanager.aws.kms.AwsKeyValueStorage;
import com.keepersecurity.secretmanager.aws.kms.AwsSessionConfig;
import com.keepersecurity.secretsManager.core.InMemoryStorage;
import com.keepersecurity.secretsManager.core.SecretsManager;
import com.keepersecurity.secretsManager.core.SecretsManagerOptions;
import static com.keepersecurity.secretsManager.core.SecretsManager.initializeStorage;
import software.amazon.awssdk.regions.Region;
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
class Test {
public static void main(String args[]){
String keyId = "<Key ID>";
String awsAccessKeyId = "<AWS Access ID>";
String awsSecretAccessKey = "<AWS Secret>";
String oneTimeToken = "[One Time Token]";
Region region = Region.<cloud-region>;
String profile = null OR "DEFAULT"; //set profile (ex. DEFUALT/UAT/PROD) if ~/.aws/config is set
String configFileLocation = "client_config_test.json";
try{
//set AWS configuration, It can be null if profile is set for aws credentials
AwsSessionConfig sessionConfig = new AwsSessionConfig(awsAccessKeyId, awsSecretAccessKey);
//Get Storage
AwsKeyValueStorage awskvstorage = new AwsKeyValueStorage(keyId, configFileLocation, profile, sessionConfig, region);
initializeStorage(awskvstorage, oneTimeToken);
SecretsManagerOptions options = new SecretsManagerOptions(awskvstorage);
//getSecrets(OPTIONS);
}catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
AWS KMS連携の使用
セットアップが完了すると、シークレットマネージャーとAWS KMSの連携により、シークレットマネージャーPython SDKのすべての機能が利用できるようになります。 実行時に構成ファイルの復号化を管理するには、コードからAWS KMS APIにアクセスできなければなりません。
追加オプション
キーの変更
構成の暗号化に使用するキーは変更できます。以下はその変更に必要なコードの例となります。
String newkeyId = "<New-Key-ID>";
AwsKeyValueStorage awskvstorage = new AwsKeyValueStorage(keyId, configFileLocation, profile, sessionConfig, region);
awskvstorage.changeKey(newkeyId)
構成の復号化
現在の実装を別のクラウド環境へ移行する場合や、生の認証情報を取得したい場合には、構成ファイルを復号できます。この関数はブール値を受け取り、true
に設定すると復号された構成をファイルに保存し、false
の場合は復号済みの構成内容のみを返します。
AwsKeyValueStorage awskvstorage = new AwsKeyValueStorage(keyId, configFileLocation, profile, sessionConfig, region);
awskvstorage.decryptConfig(true) // Set true as a parameter to extract plaintext and save config as a plaintext.
//OR
awskvstorage.decryptConfig(false); // Set false as a parameter to extract only plaintext.
KSM統合機能を使用する準備ができました。
最終更新