Azure Key Vaultでの暗号化

Azure Key Vault キーでシークレットマネージャーの接続情報を保護

KeeperシークレットマネージャーとAzure Key Vaultと連携することで、構成ファイルを暗号化できます。この連携により、接続情報をローカル環境で保護しつつ、すべての機密認証情報に対してKeeperのゼロ知識暗号化を活用できます。

機能

  • Keeperシークレットマネージャーの構成ファイルをAzure Key Vaultで暗号化および復号化

  • シークレットマネージャー接続への不正アクセスを防止

  • 最小限のコード変更で即時に保護を実現。すべてのKeeperシークレットマネージャーSDK機能と連携

  • AzureのRSA非対称鍵に対応

要件

セットアップ

1. モジュールのインストール

GradleまたはMavenを使用してプロジェクトをセットアップ

Gradle

repositories {
  mavenCentral()
}

dependencies {
  implementation("com.keepersecurity.secrets-manager:azurekv:1.0.0")
  implementation("com.keepersecurity.secrets-manager:core:17.0.0")
  implementation("com.azure:azure-identity:1.15.0")
  implementation("com.azure:azure-security-keyvault-keys:4.9.2")
  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>azurekv</artifactId>
     <version>1.0.0</version>
</dependency>
<dependency>
     <groupId>com.keepersecurity.secrets-manager</groupId>
     <artifactId>core</artifactId>
     <version>17.0.0</version>
 </dependency>

 <!-- Azure-identity -->
   <dependency>
       <groupId>com.azure</groupId>
       <artifactId>azure-identity</artifactId>
       <version>1.15.0</version>
        <scope>compile</scope>
   </dependency>
  <!-- Azure-keyvault -->
   <dependency>
       <groupId>com.azure</groupId>
       <artifactId>azure-security-keyvault-keys</artifactId>
       <version>4.9.2</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. Azure Key Vaultの接続を構成

Azure Key Vaultインスタンスが利用可能であることを確認してください。Azure Key Vaultに接続するために必要な以下のパラメータが必要です。 AZURE_TENANT_ID: The Microsoft Entra tenant (directory) ID.

AZURE_CLIENT_ID: The client (application) ID of an App Registration in the tenant.

AZURE_CLIENT_SECRET: A client secret that was generated for the App Registration.

Azure Key Vault統合を使用するには、Azure Appディレクトリのアプリが必要です。

Azure Appディレクトリのアプリ登録および権限の詳細については、以下のAzureのドキュメントをご参照ください。

https://learn.microsoft.com/en-us/azure/key-vault/general/authentication

3. コードにAzure Key Vaultストレージを追加する

Azure接続が構成されたら、Azureキーを使用してKSM構成の暗号化/復号化を行うためにキーを取得できます。また、Secrets Manager SDKに対して、キー ボルトをストレージとして使用するよう指示する必要があります。

Azure Key Vault統合の使用

設定が完了すると、Secrets Manager Azure Key Vault統合はすべてのSecrets Manager SDK機能をサポートします。コードは、KSM構成ファイルの暗号化および復号化を管理するために、Azureキーにアクセスできる必要があります。 指定された接続認証情報の使用

この操作を行うには、AzureKeyValueStorageインスタンスを作成し、SecretManagerOptionsコンストラクタで使用します。

AzureKeyValueStorageは、azure_key_idazure_keyvault_URL、構成が含まれたシークレットマネージャー構成ファイルの名前を必要とします。

import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
import static com.keepersecurity.secretsManager.core.SecretsManager.initializeStorage;
import com.keepersecurity.secretmanager.azurekv.AzureKeyValueStorage;
import com.keepersecurity.secretmanager.azurekv.AzureSessionConfig;
import com.keepersecurity.secretsManager.core.SecretsManagerOptions;


class Test {
	public static void main(String args[]){
		String oneTimeToken = "[One_Time_Token]";
		String keyId = "https://<vault-name>.vault.azure.net/keys/<keyname>/<keyversion>";
		String configFileLocation="<KSM-client-config.json>";
		String azTenantId = "<azure-tenant-id>";
		String azClientId = "<azure-client-id>";
		String azClientSecret = "<azure-client-secret>";
		String keyVaultUrl = "https://<vault-name>.vault.azure.net/";
		Security.addProvider(new BouncyCastleFipsProvider());
		try{
			//set azure KV configuration, 
			AzureSessionConfig azConfig= new AzureSessionConfig(azTenantId, azClientId, azClientSecret, keyVaultUrl);
			//Get Storage 
			AzureKeyValueStorage azkvstorage =  AzureKeyValueStorage.getInternalStorage(keyId, configFileLocation, azConfig);
			initializeStorage(azkvstorage, oneTimeToken);
			SecretsManagerOptions options = new SecretsManagerOptions(azkvstorage);
			//getSecrets(options)
		}catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
}

追加オプション

キーの変更

KSM構成の暗号化に使用するキーを変更することも可能です。以下の例は、そのために必要なコードとなります。

// `changeKey(newKeyID)`メソッドは、新しいAzureキーでKSM構成ファイルを暗号化するために使用されます。
....
 String newKeyID = "https://<vault-name>.vault.azure.net/keys/<keyname>/<keyversion>";
 AzureKeyValueStorage azkvstorage =  AzureKeyValueStorage.getInternalStorage(keyId, configFileLocation, azConfig);
 boolean isChanged = azkvstorage.changeKey(newKeyID);	 // Change the key for encryption/decryption
....

構成の復号化

現在の実装を別のクラウド環境へ移行する場合や、生の認証情報を取得したい場合には、構成の復号が可能です。この関数はブール値を受け取り、trueに設定すると復号化された構成をファイルに保存し、falseの場合は復号化された構成を返します。

....
 AzureKeyValueStorage azkvstorage =  AzureKeyValueStorage.getInternalStorage(keyId, configFileLocation, azConfig);
 azkvstorage.decryptConfig(false); // falseをパラメータとして設定すると、プレーンテキストのみが抽出されます。
 //または
 azkvstorage.decryptConfig(true); //trueをパラメータとして設定すると、プレーンテキストを抽出し、構成をプレーンテキストとして保存します。
....

その他の例と機能については、KSM SDKのドキュメントをご参照ください。

最終更新