共用方式為


快速入門:使用適用於 Java 的 Azure SDK 建立 Azure 受控 CCF 資源

Azure 受控 CCF (受控 CCF) 是一項新的高度安全服務,用於部署機密應用程式。 如需 Azure 受控 CCF 的詳細資訊,請參閱 關於 Azure 受控機密聯盟架構

如果您沒有 Azure 帳戶,請先建立 免費帳戶 ,再開始。

API 參考文件 | 程式庫原始碼 | 套件 (maven 中央儲存庫)

先決條件

設定

本快速入門會使用 Azure 身分識別程式庫,以及 Azure CLI 或 Azure PowerShell,向 Azure 服務驗證使用者。 開發人員還可以在運行 Windows 或 Linux Code 的計算機上使用 Visual Studio 來驗證他們的呼叫。 如需詳細資訊,請參閱 使用 Azure 身分識別用戶端程式庫驗證用戶端

登入 Azure

使用 Azure CLI az login 命令或 Azure PowerShell Connect-AzAccount Cmdlet 登入 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 Cmdlet 在 southcentralus 位置建立名為 myResourceGroup 的資源群組。

New-AzResourceGroup -Name "myResourceGroup" -Location "SouthCentralUS"

註冊資源提供者

建立資源之前,必須先在訂用帳戶中註冊 Azure 受控 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 應用程式

適用於 Java 的 Azure SDK 程式庫 (azure-resourcemanager-confidentialledger) 允許對受控 CCF 資源進行作業,例如建立和刪除、列出與訂用帳戶相關聯的資源,以及檢視特定資源的詳細資料。 下列程式碼片段會建立並檢視受控 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());
    }
}

清理資源

其他受控 CCF 文章可以建立在此快速入門之上。 如果您打算繼續使用後續的快速入門和教學課程,您可能想要保留這些資源。

否則,當您完成本文中建立的資源時,請使用 Azure CLI az group delete 命令來刪除資源群組及其所有包含的資源。

az group delete --resource-group myResourceGroup

後續步驟

在本快速入門中,您已使用適用於 Java 的 Azure SDK 建立受控 CCF 資源。 若要深入瞭解 Azure 受控 CCF 以及如何將它與您的應用程式整合,請繼續閱讀下列文章: