Azure 機密總帳 (ACL) 可程式性
可程式性是機密總帳中的新功能,可讓客戶在與一般 Azure 機密總帳 (ACL) 交易相同的受信任計算基底 (TCB) 中執行自定義程式代碼。 在 TCB 中執行自訂程式代碼和交易的優點是,它會為自定義程式代碼及其所產生的交易提供相同的機密性和完整性保證。 可程式性也支援角色型 存取控制 (RBAC),透過在 ACL 中定義的自定義角色,並在程式碼中使用。
可透過程式設計啟用的幾個案例如下:
- 數據匯總和分析:敏感性資訊可以在 TCB 中進行分析,而且只能與專案關係人共用匯總資訊。
- 證明:證明之後,可以在 Azure 機密 ACI 和機密 VM 等機密計算供應專案上執行的工作負載共用 PII、信用分數和健康情況資訊等敏感性資訊
必要條件
- 訂用帳戶擁有者 - 只有具備 Azure 訂用帳戶「擁有者」權限的使用者,才能建立機密總帳。 先確認您有適當的存取權,再繼續進行本快速入門。
本教學課程假設您已建立機密總賬實例。 您可以使用 Azure 入口網站、Azure CLI 或 Azure PowerShell 來建立機密總帳。
開發和部署應用程式
應用程式是使用 TypeScript 開發,並匯總成 JavaScript 套件組合。 若要深入了解開發程式,請參閱 機密聯盟架構 (CCF) 檔。
重要
只有系統管理員用戶可以在機密總帳中部署應用程式及管理自定義 RBAC。 區段的其餘部分假設系統管理員會執行下列步驟。
下一節假設應用程式已準備好進行部署。 為了示範部署程式,我們會使用 azureconfidentialledger-app-samples 存放庫 (https://github.com/microsoft/azureconfidentialledger-app-samples) 提供的範例銀行應用程式。
注意
此應用程式示範如何透過部署在機密總賬實例上的 JavaScript 應用程式,實現常見的銀行使用案例,例如開立帳戶、存款和轉移資金。 它也示範如何使用自定義角色和 RBAC 來授權用戶動作。
登入 Azure
注意
機密總賬支援Microsoft現用的 Entra。 不需要再進行設定。 如果您的應用程式使用其他識別提供者所發出的 JWT,請連絡客戶支援,使其在機密總賬實例上設定。
取得Microsoft Entra 令牌,以向機密總賬實例進行驗證。
az login --use-device-code
az account get-access-token --resource https://confidential-ledger.azure.com
從命令輸出複製原始令牌值。
下載總賬身分識別
每個機密總賬實例都會與稱為服務憑證的憑證所代表的唯一身分識別相關聯。 必須建立實例的安全連線。 下載並儲存至 servicer_cert.pem。
注意
contoso
是機密總賬實例的名稱。 將它取代為您的實例名稱。
curl https://identity.confidential-ledger.core.azure.com/ledgerIdentity/contoso --silent | jq ' .ledgerTlsCertificate' | xargs echo -e > service_cert.pem
部署應用程式
呼叫 /app/userDefinedEndpoints 來部署JavaScript 應用程式套件組合。
apiVersion="2024-08-22-preview"
content_type_application_json="Content-Type: application/json"
bundle="/path/to/bundle.json"
authorization="Authorization: Bearer raw_token_value"
server_identity="--cacert service_cert.pem"
# Deploy the application
#
curl $server_identity -X PUT "https://contoso.confidential-ledger.azure.com/app/userDefinedEndpoints?api-version=$apiVersion" -H "$content_type_application_json" -H "$authorization" -d @$bundle
# View the application
#
curl $server_identity "https://contoso.confidential-ledger.azure.com/app/userDefinedEndpoints?api-version=$apiVersion" -H "$authorization"
建立自定義角色和使用者
銀行應用程式涉及兩個角色,即「經理」和「櫃員」。 我們會建立兩個角色和用戶來代表角色。
注意
使用者會以唯一的憑證表示。
注意
應用程式使用者可以指派內建角色,也就是系統管理員、參與者和讀者。 自定義角色區分大小寫,且內建角色不區分大小寫。 用戶可以指派多個角色。
apiVersion="2024-08-22-preview"
content_type_application_json="Content-Type: application/json"
content_type_merge_patch_json="Content-Type: application/merge-patch+json"
authorization="Authorization: Bearer raw_token_value"
curve="secp384r1"
server_identity="--cacert service_cert.pem"
# These actions must match (case-sensitive) the values defined in the application.
#
role_actions='{"roles":[{"role_name":"manager","role_actions":["/banking/accounts/post","/banking/accounts/put","/banking/accounts/get","/banking/accounts/patch"]},{"role_name":"teller","role_actions":["/banking/accounts/put","/banking/accounts/get","/banking/accounts/patch"]}]}'
# Create the roles.
#
curl $server_identity -X PUT "https://contoso.confidential-ledger.azure.com/app/roles?api-version=$apiVersion" -H "$content_type_application_json" -H "$authorization" -d $role_actions
# View the roles
#
curl $server_identity "https://contoso.confidential-ledger.azure.com/app/roles?api-version=$apiVersion" -H "$authorization"
# Create a certificate for the manager user.
#
openssl ecparam -out "manager_privk.pem" -name "$curve" -genkey
openssl req -new -key "manager_privk.pem" -x509 -nodes -days 365 -out "manager_cert.pem" -sha384 -subj=/CN="manager"
manager_cert_fingerprint=$(openssl x509 -in "manager_cert.pem" -noout -fingerprint -sha256 | cut -d "=" -f 2)
manager_user="{\"user_id\":\"$manager_cert_fingerprint\",\"assignedRoles\":[\"manager\"]}"
# Create a certificate for the teller user.
#
openssl ecparam -out "teller_privk.pem" -name "$curve" -genkey
openssl req -new -key "teller_privk.pem" -x509 -nodes -days 365 -out "teller_cert.pem" -sha384 -subj=/CN="teller"
teller_cert_fingerprint=$(openssl x509 -in "teller_cert.pem" -noout -fingerprint -sha256 | cut -d "=" -f 2)
teller_user="{\"user_id\":\"$teller_cert_fingerprint\",\"assignedRoles\":[\"teller\"]}"
# Create the manager user.
#
curl $server_identity -X PATCH "https://contoso.confidential-ledger.azure.com/app/ledgerUsers/$manager_cert_fingerprint?api-version=$apiVersion" -H "$content_type_merge_patch_json" -H "$authorization" -d $manager_user
# Create the teller user.
#
curl $server_identity -X PATCH "https://contoso.confidential-ledger.azure.com/app/ledgerUsers/$teller_cert_fingerprint?api-version=$apiVersion" -H "$content_type_merge_patch_json" -H "$authorization" -d $teller_user
# View the users
#
curl $server_identity "https://contoso.confidential-ledger.azure.com/app/ledgerUsers?api-version=$apiVersion" -H "$authorization"
更新執行時間群組態 (選擇性)
呼叫 /app/userDefinedEndpoints/runTimeOptions 端點,即可更新 JavaScript 運行時間組態。 為了示範,讓我們將運行時間上限設定為 2000 毫秒。
apiVersion="2024-08-22-preview"
content_type_merge_patch_json="Content-Type: application/merge-patch+json"
authorization="Authorization: Bearer raw_token_value"
runtime_options="{\"max_heap_bytes\":1024,\"max_stack_bytes\":1024,\"max_execution_time_ms\":2000,\"log_exception_details\":false,\"return_exception_details\":false,\"max_cached_interpreters\":1024}"
server_identity="--cacert service_cert.pem"
# Patch the runtime options
#
curl $server_identity -X PATCH "https://contoso.confidential-ledger.azure.com/app/userDefinedEndpoints/runTimeOptions?api-version=$apiVersion" -H "$content_type_merge_patch_json" -H "$authorization" -d $runtime_options
# View the runtime options
#
curl $server_identity "https://contoso.confidential-ledger.azure.com/app/userDefinedEndpoints/runTimeOptions?api-version=$apiVersion" -H "$authorization"
現在您已準備好呼叫應用程式端點並提交交易。
清除資源
此集合中的其他快速入門和教學課程會以本快速入門為基礎。 如果您打算繼續進行後續的快速入門和教學課程,您可以讓這些資源留在原處。
若不再需要,您可以使用 Azure CLI az group delete 命令來移除資源群組和所有相關資源:
az group delete --name "myResourceGroup"
下一步
在本教學課程中,您已將自定義 JavaScript 應用程式部署至機密總賬實例。 若要深入了解 Azure 機密總帳及如何與應用程式整合,請繼續閱讀下列文章。