Bagikan melalui


Mulai cepat: Membuat sumber daya Azure Managed CCF menggunakan Azure SDK untuk .NET

Azure Managed CCF (Managed CCF) adalah layanan baru dan sangat aman untuk menyebarkan aplikasi rahasia. Untuk informasi selengkapnya tentang CCF Terkelola, dan misalnya kasus penggunaan, lihat Tentang Azure Managed Confidential Consortium Framework.

Dalam mulai cepat ini, Anda mempelajari cara membuat sumber daya CCF Terkelola menggunakan pustaka manajemen klien .NET.

Jika Anda tidak memiliki Langganan Azure, buat Akun gratis Azure sebelum memulai.

Dokumentasi referensi API | Kode sumber pustaka | Paket (NuGet)

Prasyarat

Penyiapan

Buat aplikasi konsol .NET baru

  1. Di shell perintah, jalankan perintah berikut untuk membuat proyek bernama managedccf-app:

    dotnet new console --name managedccf-app
    
  2. Ubah ke direktori managedccf-app yang baru dibuat, dan jalankan perintah berikut untuk membangun proyek:

    dotnet build
    

    Output build tidak boleh berisi peringatan atau kesalahan.

    Build succeeded.
     0 Warning(s)
     0 Error(s)
    

Pasang paket

Instal pustaka klien Azure Managed CCF untuk .NET dengan NuGet:

dotnet add package Azure.ResourceManager.ConfidentialLedger --version 1.1.0-beta.2

Untuk mulai cepat ini, Anda juga perlu menginstal pustaka klien Azure SDK untuk Azure Identity:

dotnet add package Azure.Identity

Buat grup sumber daya

Grup sumber daya adalah kontainer logis yang disebarkan dan dikelola oleh sumber daya Azure. Gunakan cmdlet Azure PowerShell New-AzResourceGroup untuk membuat grup sumber daya bernama myResourceGroup di lokasi southcentralus.

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

Mendaftarkan penyedia sumber

Jenis sumber daya Azure Managed CCF harus didaftarkan dalam langganan sebelum membuat sumber daya.

az feature registration create --namespace Microsoft.ConfidentialLedger --name ManagedCCF

az provider register --namespace Microsoft.ConfidentialLedger

Membuat anggota

Buat pasangan kunci untuk anggota. Setelah perintah berikut selesai, kunci umum anggota disimpan dan member0_cert.pem kunci privat disimpan di 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"

Membuat aplikasi .NET

Menggunakan pustaka klien bidang manajemen

Azure SDK untuk .NET (azure/arm-confidentialledger) memungkinkan operasi pada sumber daya CCF Terkelola, seperti pembuatan dan penghapusan, mencantumkan sumber daya yang terkait dengan langganan, dan melihat detail sumber daya tertentu. Bagian kode berikut membuat dan melihat properti sumber daya CCF Terkelola.

Tambahkan arahan berikut di bagian atas Program.cs:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.ConfidentialLedger;
using Azure.ResourceManager.ConfidentialLedger.Models;
using Azure.ResourceManager.Resources;

Mengautentikasi dan membuat klien

Dalam mulai cepat ini, pengguna yang masuk digunakan untuk mengautentikasi ke Azure Managed CCF, yang merupakan metode pilihan untuk pengembangan lokal. Contoh ini menggunakan kelas 'DefaultAzureCredential()' dari Azure Identity Library, yang memungkinkan untuk menggunakan kode yang sama di berbagai lingkungan dengan opsi yang berbeda untuk memberikan identitas.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();

Buat klien Azure Resource Manager dan autentikasi menggunakan kredensial token.

// authenticate your client
ArmClient client = new ArmClient(cred);

Membuat sumber daya CCF Terkelola

// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "0000000-0000-0000-0000-000000000001";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);

// get the collection of this ManagedCcfResource
ManagedCcfCollection collection = resourceGroupResource.GetManagedCcfs();

// invoke the operation
string appName = "confidentialbillingapp";
ManagedCcfData data = new ManagedCcfData(new AzureLocation("SouthCentralUS"))
{
    Properties = new ManagedCcfProperties()
    {
        MemberIdentityCertificates =
        {
            new ConfidentialLedgerMemberIdentityCertificate()
            {
                Certificate = "-----BEGIN CERTIFICATE-----MIIBsjCCATigA...LjYAGDSGi7NJnSkA-----END CERTIFICATE-----",
                Encryptionkey = "",
                Tags = BinaryData.FromObjectAsJson(new Dictionary<string, object>()
                {
                    ["additionalProps1"] = "additional properties"
                }),
            }
        },
        DeploymentType = new ConfidentialLedgerDeploymentType()
        {
            LanguageRuntime = ConfidentialLedgerLanguageRuntime.JS,
            AppSourceUri = new Uri(""),
        },
        NodeCount = 3,
    },
    Tags =
    {
        ["additionalProps1"] = "additional properties",
    },
};

ArmOperation<ManagedCcfResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, appName, data);
ManagedCcfResource result = lro.Value;

// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedCcfData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");

Menampilkan properti sumber daya CCF Terkelola

Bagian kode berikut mengambil sumber daya CCF Terkelola dan mencetak propertinya.

// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "0000000-0000-0000-0000-000000000001";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);

// get the collection of this ManagedCcfResource
ManagedCcfCollection collection = resourceGroupResource.GetManagedCcfs();

// invoke the operation
string appName = "confidentialbillingapp";
ManagedCcfResource result = await collection.GetAsync(appName);

// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ManagedCcfData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");

Mencantumkan sumber daya CCF Terkelola dalam Grup Sumber Daya

Bagian kode berikut mengambil sumber daya CCF Terkelola dalam grup sumber daya.

// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "0000000-0000-0000-0000-000000000001";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);

// get the collection of this ManagedCcfResource
ManagedCcfCollection collection = resourceGroupResource.GetManagedCcfs();

// invoke the operation and iterate over the result
await foreach (ManagedCcfResource item in collection.GetAllAsync())
{
    // the variable item is a resource, you could call other operations on this instance as well
    // but just for demo, we get its data from this resource instance
    ManagedCcfData resourceData = item.Data;
    // for demo we just print out the id
    Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

Console.WriteLine($"Succeeded");

Mencantumkan sumber daya CCF Terkelola dalam langganan

Bagian kode berikut mengambil sumber daya CCF Terkelola dalam langganan.

// this example assumes you already have this SubscriptionResource created on azure
// for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource
string subscriptionId = "0000000-0000-0000-0000-000000000001";
ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId);
SubscriptionResource subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId);

// invoke the operation and iterate over the result
await foreach (ManagedCcfResource item in subscriptionResource.GetManagedCcfsAsync())
{
    // the variable item is a resource, you could call other operations on this instance as well
    // but just for demo, we get its data from this resource instance
    ManagedCcfData resourceData = item.Data;
    // for demo we just print out the id
    Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

Console.WriteLine($"Succeeded");

Membersihkan sumber daya

Artikel CCF Terkelola lainnya dapat dibuat berdasarkan mulai cepat ini. Jika Anda berencana untuk terus bekerja dengan mulai cepat dan tutorial berikutnya, Anda mungkin ingin meninggalkan sumber daya ini di tempat.

Jika tidak, setelah Anda selesai dengan sumber daya yang dibuat dalam artikel ini, gunakan perintah az group delete Azure CLI untuk menghapus grup sumber daya dan semua sumber daya yang terkandung.

az group delete --resource-group myResourceGroup

Langkah berikutnya

Dalam mulai cepat ini, Anda membuat sumber daya CCF Terkelola dengan menggunakan Azure Python SDK untuk Confidential Ledger. Untuk mempelajari selengkapnya tentang Azure Managed CCF dan cara mengintegrasikannya dengan aplikasi Anda, lanjutkan ke artikel berikut: