クイックスタート: Azure SDK for Java を使って Azure Managed CCF リソースを作成する
Azure Managed CCF (Managed CCF) は、機密性の高いアプリケーションをデプロイするための、高度なセキュリティで保護された新しいサービスです。 Azure Managed CCF の詳細については、「Azure Managed Confidential Consortium Framework の概要」を参照してください。
Azure サブスクリプションをお持ちでない場合は、開始する前に Azure 無料アカウントを作成してください。
API リファレンス ドキュメント | ライブラリのソース コード | パッケージ (Maven 中央リポジトリ)
前提条件
- Azure サブスクリプション - 無料アカウントを作成します。
- Azure SDK for Java でサポートされている Java Development Kit (JDK) バージョン。
- Windows または Linux を実行しているコンピューターでの OpenSSL。
セットアップ
このクイックスタートでは、Azure ID ライブラリを Azure CLI または Azure PowerShell と共に使用して、Azure サービスに対するユーザーの認証を行います。 開発者は、Windows または Linux.o Code を実行しているコンピューターで Visual Studio または Visual Studi- OpenSSL を使用して、呼び出しを認証することもできます。 詳細については、Azure ID クライアント ライブラリを使用したクライアントの認証に関するページを参照してください。
Azure へのサインイン
Azure CLI az login コマンドまたは Azure PowerShell Connect-AzAccount コマンドレットを使用して Azure にサインインします。
az login
CLI または PowerShell で既定のブラウザーを開くことができる場合、ブラウザが開き、Azure サインイン ページが読み込まれます。 そうでない場合は、https://aka.ms/devicelogin を開き、ターミナルに表示されている認証コードを入力します。
メッセージが表示されたら、ブラウザーでアカウントの資格情報を使用してサインインします。
依存関係をインストールする
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-confidentialledger</artifactId>
<version>1.0.0-beta.3</version>
</dependency>
リソース グループを作成する
リソース グループとは、Azure リソースのデプロイと管理に使用する論理コンテナーです。 Azure PowerShell の New-AzResourceGroup コマンドレットを使って、myResourceGroup という名前のリソース グループを southcentralus の場所に作成します。
New-AzResourceGroup -Name "myResourceGroup" -Location "SouthCentralUS"
リソース プロバイダーの登録
リソースを作成する前に、Azure Managed CCF リソースの種類をサブスクリプションに登録する必要があります。
az feature registration create --namespace Microsoft.ConfidentialLedger --name ManagedCCF
az provider register --namespace Microsoft.ConfidentialLedger
メンバーの作成
メンバーのキーの組を生成します。 下記のコマンドが完了すると、メンバーの公開キーが member0_cert.pem
に保存され、秘密キーが member0_privk.pem
に保存されます。
openssl ecparam -out "member0_privk.pem" -name "secp384r1" -genkey
openssl req -new -key "member0_privk.pem" -x509 -nodes -days 365 -out "member0_cert.pem" -"sha384" -subj=/CN="member0"
Java アプリケーションを作成する
Azure SDK for Java ライブラリ (azure-resourcemanager-confidentialledger) を使うと、Managed CCF リソースに対する操作 (作成や削除、サブスクリプションに関連付けられたリソースの一覧表示、特定のリソースの詳細の表示など) を行うことができます。 次のコードでは、Managed CCF リソースのプロパティを作成して表示します。
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.profile.AzureProfile;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.confidentialledger.ConfidentialLedgerManager;
import com.azure.resourcemanager.confidentialledger.fluent.models.ManagedCcfInner;
import com.azure.resourcemanager.confidentialledger.models.DeploymentType;
import com.azure.resourcemanager.confidentialledger.models.LanguageRuntime;
import com.azure.resourcemanager.confidentialledger.models.ManagedCcfProperties;
import com.azure.resourcemanager.confidentialledger.models.MemberIdentityCertificate;
import java.util.*;
public class AzureJavaSdkClient {
public static void main(String[] args) {
try {
AzureProfile profile = new AzureProfile("<tenant id>","<subscription id>", AzureEnvironment.AZURE);
ConfidentialLedgerManager manager = ConfidentialLedgerManager.authenticate(new DefaultAzureCredentialBuilder().build(), profile);
MemberIdentityCertificate member0 = new MemberIdentityCertificate()
.withCertificate("-----BEGIN CERTIFICATE-----\nMIIBvjCCAUSgAwIBAgIUA0YHcPpUCtd...0Yet/xU4G0d71ZtULNWo\n-----END CERTIFICATE-----")
.withTags(Map.of("Dept", "IT"));
List<MemberIdentityCertificate> members = new ArrayList<MemberIdentityCertificate>();
members.add(member0);
DeploymentType deployment = new DeploymentType().withAppSourceUri("").withLanguageRuntime(LanguageRuntime.JS);
ManagedCcfProperties properties = new ManagedCcfProperties()
.withDeploymentType(deployment)
.withNodeCount(5)
.withMemberIdentityCertificates(members);
ManagedCcfInner inner = new ManagedCcfInner().withProperties(properties).withLocation("southcentralus");
// Send Create request
manager.serviceClient().getManagedCcfs().create("myResourceGroup", "confidentialbillingapp", inner);
// Print the Managed CCF resource properties
ManagedCcfInner app = manager.serviceClient().getManagedCcfs().getByResourceGroup("myResourceGroup", "confidentialbillingapp");
printAppInfo(app);
// Delete the resource
manager.serviceClient().getManagedCcfs().delete("myResourceGroup", "confidentialbillingapp");
} catch (ManagementException ex) {
// The x-ms-correlation-request-id is located in the Header
System.out.println(ex.getResponse().getHeaders().toString());
System.out.println(ex);
}
}
private static void printAppInfo(ManagedCcfInner app) {
System.out.println("App Name: " + app.name());
System.out.println("App Id: " + app.id());
System.out.println("App Location: " + app.location());
System.out.println("App type: " + app.type());
System.out.println("App Properties Uri: " + app.properties().appUri());
System.out.println("App Properties Language Runtime: " + app.properties().deploymentType().languageRuntime());
System.out.println("App Properties Source Uri: " + app.properties().deploymentType().appSourceUri());
System.out.println("App Properties NodeCount: " + app.properties().nodeCount());
System.out.println("App Properties Identity Uri: " + app.properties().identityServiceUri());
System.out.println("App Properties Cert 0: " + app.properties().memberIdentityCertificates().get(0).certificate());
System.out.println("App Properties Cert tags: " + app.properties().memberIdentityCertificates().get(0).tags());
}
}
リソースをクリーンアップする
他の Managed CCF の記事には、このクイックスタートに基づいているものがあります。 後続のクイックスタートおよびチュートリアルを引き続き実行する場合は、これらのリソースをそのまま残しておくことをお勧めします。
それ以外の場合は、この記事で作成したリソースの操作が完了したら、Azure CLI の az group delete コマンドを使って、リソース グループとそれに含まれるすべてのリソースを削除します。
az group delete --resource-group myResourceGroup
次のステップ
このクイック スタートでは、Azure SDK for Java を使用してマネージド CCF リソースを作成しました。 Azure Managed CCF の詳細と、これをアプリケーションと統合する方法については、続けて以下の記事を参照してください。