OSGi 設定への秘密情報のマッピング

OSGi サービスで秘密鍵の値を公開するには、OSGi 秘密鍵設定値を使用して、OSGi 設定にマッピングします。 SecretsManager.getSecret() メソッドから秘密鍵の値を取得するキーとして OSGi プロパティ名を定義します。

AEM Maven プロジェクトの OSGi 設定ファイル /apps/example/osgiconfig/config/com.example.core.util.impl.SecretsManagerImpl.cfg.json で秘密鍵を定義します。 各プロパティは AEM で公開される秘密鍵を表し、値は Cloud Manager 経由で設定されます。 キーは、SecretsManager サービスから秘密鍵の値の取得に使用される OSGi プロパティ名です。

{
    "api.key": "$[secret:api_key]",
    "service.password": "$[secret:service_password]"
}

また、共有秘密鍵マネージャー OSGi サービスを使用する代わりに、秘密鍵を使用する特定のサービスの OSGi 設定に秘密鍵を直接含めることもできます。 このアプローチは、秘密鍵が単一の OSGi サービスでのみ必要であり、複数のサービス間で共有されない場合に役立ちます。 この場合、秘密鍵の値は、特定のサービス用の OSGi 設定ファイルで定義され、@Activate メソッドを通じてサービスの Java コードでアクセスされます。

秘密鍵の使用

秘密鍵は、Sling モデルや別の OSGi サービスなど、様々な方法で OSGi サービスから使用できます。 両方から秘密鍵を使用する方法の例を以下に示します。

Sling モデルから

Sling モデルは、多くの場合、AEM サイトコンポーネントのビジネスロジックを提供します。 SecretsManager OSGi サービスは、@OsgiService 注釈を通じて使用でき、Sling モデル内で使用して秘密鍵の値を取得できます。

import com.example.core.util.SecretsManager;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.OsgiService;

@Model(
    adaptables = {SlingHttpServletRequest.class, Resource.class},
    adapters = {ExampleDatabaseModel.class}
)
public class ExampleDatabaseModelImpl implements ExampleDatabaseModel {

    @OsgiService
    SecretsManager secretsManager;

    @Override
    public String doWork() {
        final String secret = secretsManager.getSecret("api.key");
        // Do work with secret
    }
}

OSGi サービスから

OSGi サービスは、多くの場合、Sling モデル、ワークフローなどの AEM サービス、またはその他のカスタム OSGi サービスで使用される、AEM 内で再利用可能なビジネスロジックを公開します。 SecretsManager OSGi サービスは、@Reference 注釈を通じて使用でき、OSGi サービス内で使用して秘密鍵の値を取得できます。

import com.example.core.util.SecretsManager;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component
public class ExampleSecretConsumerImpl implements ExampleSecretConsumer {

    @Reference
    SecretsManager secretsManager;

    public void doWork() {
        final String secret = secretsManager.getSecret("service.password");
        // Do work with the secret
    }
}

Cloud Manager での秘密鍵の設定

OSGi サービスと設定が整ったら、最後の手順として Cloud Manager でシークレット値を設定します。

秘密鍵の値は、Cloud Manager API 経由で設定することも、より一般的には Cloud Manager UI 経由で設定することもできます。 Cloud Manager UI 経由で秘密変数を適用するには:

Cloud Manager の秘密鍵の設定

  1. Adobe Cloud Manager にログインします。

  2. シークレットを設定する AEM プログラムと環境を選択します。

  3. 環境の詳細表示で、「設定」タブを選択します。

  4. 「追加」を選択します。

  5. 環境設定ダイアログで、次の操作を実行します。

    • OSGi 設定で参照される秘密鍵の変数名(例:api_key)を入力します。
    • 秘密鍵の値を入力します。
    • シークレットを適用する AEM サービスを選択します。
    • タイプとして「秘密鍵」を選択します。
  6. 「追加」を選択して、秘密鍵を保持します。

  7. 必要な数のシークレットを追加します。 完了したら、「保存」を選択して、変更を AEM 環境に直ちに適用します。

秘密情報に Cloud Manager 設定を使用すると、様々な環境やサービスに異なる値を適用し、AEM アプリケーションを再デプロイせずに秘密情報をローテーションできるというメリットがあります。

Ask AI

Not sure where to start?
Ask me anything about Adobe products.

Type your question or pick a suggestion below.

Use of this AI chatbot is subject to Adobe's Privacy Policy. Don't share sensitive data. AI responses are not your Content, may be inaccurate, and any offers provided are non-binding. Generative AI Terms.