Azure 托管 CCF(托管 CCF)是一项用于部署机密应用程序的新且高度安全的服务。 有关 Azure 托管 CCF 的详细信息,请参阅 “关于 Azure 托管机密联盟框架”。
如果没有 Azure 帐户,请在开始之前创建 一个免费帐户 。
API 参考文档 | 库源代码 | 包 (maven 中央存储库)
先决条件
- Azure 订阅 - 免费创建一个订阅。
- 适用于 Java 的 Azure SDK 支持的 Java 开发工具包 (JDK) 版本。
- 在运行 Windows 或 Linux 的计算机上 OpenSSL。
设置
本快速入门使用 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 应用程序
Azure SDK for Java 库(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 以及如何将其与应用程序集成,请继续阅读以下文章: