The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

設定のシークレット

暗号化された設定値を使用して、機密性の高いパスワード、シークレット、トークン、キーを保護してください。

シークレット設定は、 ${handler::value} のように表現できます。 handler は、 value をデコードまたは復号化するための io.smallrye.config.SecretKeysHandler の名前です。

設定値の暗号化

設定値を暗号化し、後で復号化するには、以下のマネージド依存関係を追加します:

pom.xml
<dependency>
    <groupId>io.smallrye.config</groupId>
    <artifactId>smallrye-config-crypto</artifactId>
</dependency>

QuarkusのCLIコマンドを使用して、 新しい暗号化された値を追加するか、 application.properties の既存の値を暗号化します:

コマンドラインインタフェース
quarkus config set --encrypt --name=my.secret --value=1234

Quarkus CLIのインストール方法や使用方法については、 Quarkus CLIガイド を参照してください。

The configuration property my.secret will be added to application.properties with the value 1234 encrypted and encoded in Base64 and an expression ${aes-gcm-nopadding::}, with the required secret handler to decrypt the value. If it doesn’t exist, an encryption key is also generated and set into smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key.

my.secret=${aes-gcm-nopadding::DLTb_9zxThxeT5iAQqswEl5Dn1ju4FdM9hIyVip35t5V}

smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key=DDne5obnfH1RSeTg71xSZg
The default secret handler uses the AES/GCM/NoPadding algorithm and requires the expression ${aes-gcm-nopadding::value} to decrypt the value.

暗号化された設定の読み取り

Quarkus configuration system, will automatically decrypt the configuration value when looking up my.secret.

The encryption key used to encrypt the value must be the same used to decrypt the value and set into smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key.

class BusinessBean {
    @Inject
    SmallRyeConfig config;

    public void businessMethod() {
        ConfigValue mySecret = config.getConfigValue("my.secret");
        mySecret.getValue(); (1)
    }
}
1 Returns the value 1234.

キーストアへのシークレットの保存

暗号化された値を持つことは、平文の値よりも良いことですが、 application.properties で設定することは避けたいと思います。

Java KeyStoreは、ファイルベースの Vault として使用できます。 機密データをこの Vault にインポートし、Java SecretKey 値として安全に保存することができます。 KeyStore ConfigSource を使用するには、以下のマネージド依存関係を追加します:

<dependency>
    <groupId>io.smallrye.config</groupId>
    <artifactId>smallrye-config-source-keystore</artifactId>
</dependency>

KeyStoreの作成

次のコマンドは、単純なKeyStoreを作成します:

echo DLTb_9zxThxeT5iAQqswEl5Dn1ju4FdM9hIyVip35t5V | keytool -importpass -alias my.secret -keystore properties -storepass arealpassword -storetype PKCS12 -v

-alias my.secret オプションは、設定プロパティ名 my.secret を値 DLTb_9zxThxeT5iAQqswEl5Dn1ju4FdM9hIyVip35t5V と共にキーストアに格納します。 -storepass arealpassword は、キーストアにアクセスするために必要なパスワードです。

暗号鍵を安全に保管する必要もあります。鍵は他のシークレットと一緒に保存すべきではありません。 そのため、鍵用に別の KeyStore を作成することが出来ます:

echo DDne5obnfH1RSeTg71xSZg | keytool -importpass -alias smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key -keystore key -storepass anotherpassword -storetype PKCS12 -v

KeyStoreの使用

新しく作成した KeyStore を使用するには、以下の設定を application.properties に追加します:

smallrye.config.source.keystore."properties".path=properties (1)
smallrye.config.source.keystore."properties".password=arealpassword (2)
smallrye.config.source.keystore."properties".handler=aes-gcm-nopadding (3)

smallrye.config.source.keystore."key".path=key (4)
smallrye.config.source.keystore."key".password=anotherpassword (5)
1 secretsプロパティを持つ´KeyStore`へのパス
2 KeyStore のシークレットを抽出するための KeyStore パスワード
3 KeyStore シークレットを復号化する SecretKeyHandler
4 暗号化キーが格納されている´KeyStore`へのパス
5 暗号鍵を取り出すことが出来る KeyStore パスワード。

KeyStoreパスワードの保護

Quarkusがキーストアからシークレットを抽出できるようにするには、 application.propertiesKeyStore パスワードを指定する必要があります。 このキーストアのパスワードは機密性の高い値であるため、漏洩のリスクを最小限に抑え、保護する方法を検討する必要があります。

注意すべき重要な点として、権限のないユーザーも実際のキーストアにアクセスする必要があるため、このパスワードが漏れたとしても、キーストアに保存されている実際のシークレットが漏れるとは限らないということがあります。 キーストアファイルへのアクセスを限られたロールに制限し、そのロールの1つでQuarkusプロセスを実行させることで、グループ外の人がキーストアにアクセスしにくくなります。 キーストアパスワードは環境変数として設定できます。攻撃者がキーストアにアクセスできる時間を制限するために、このパスワードを定期的に変更する必要があります。