Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować się zalogować lub zmienić katalog.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Azure Key Vault to usługa w chmurze, która zapewnia bezpieczny magazyn wpisów tajnych, takich jak klucze, hasła, certyfikaty i inne wpisy tajne. Ten przewodnik szybkiego startu koncentruje się na procesie wdrażania pliku Bicep w celu utworzenia magazynu kluczy i sekretu.
Bicep to język specyficzny dla domeny (DSL), który używa składni deklaratywnej do wdrażania zasobów platformy Azure. Zapewnia zwięzłą składnię, niezawodne bezpieczeństwo typów i obsługę ponownego użycia kodu. Bicep oferuje najlepsze środowisko tworzenia rozwiązań infrastruktury jako kodu na platformie Azure.
Wymagania wstępne
Jeśli nie masz subskrypcji Azure, przed rozpoczęciem utwórz darmowe konto.
Identyfikator obiektu użytkownika Entra firmy Microsoft jest wymagany przez szablon w celu skonfigurowania uprawnień. Poniższa procedura pobiera identyfikator obiektu (GUID).
Uruchom następujące polecenie Azure PowerShell lub Azure CLI, wybierając pozycję Wypróbuj, następnie wklej skrypt do okienka powłoki. Aby wkleić skrypt, kliknij prawym przyciskiem myszy powłokę, a następnie wybierz polecenie Wklej.
echo "Enter your email address that is used to sign in to Azure:" && read upn && az ad user show --id $upn --query "objectId" && echo "Press [ENTER] to continue ..."Zanotuj identyfikator obiektu. Potrzebujesz go w następnej sekcji tego przewodnika Szybki start.
Przejrzyj plik programu Bicep
Szablon użyty w tym szybkim starcie pochodzi z szablonów szybkiego startu platformy Azure.
@description('Specifies the name of the key vault.')
param keyVaultName string
@description('Specifies the Azure location where the key vault should be created.')
param location string = resourceGroup().location
@description('Specifies whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key vault.')
param enabledForDeployment bool = false
@description('Specifies whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys.')
param enabledForDiskEncryption bool = false
@description('Specifies whether Azure Resource Manager is permitted to retrieve secrets from the key vault.')
param enabledForTemplateDeployment bool = false
@description('Specifies the Azure Active Directory tenant ID that should be used for authenticating requests to the key vault. Get it by using Get-AzSubscription cmdlet.')
param tenantId string = subscription().tenantId
@description('Specifies the object ID of a user, service principal or security group in the Azure Active Directory tenant for the vault. The object ID must be unique for the list of access policies. Get it by using Get-AzADUser or Get-AzADServicePrincipal cmdlets.')
param objectId string
@description('Specifies the permissions to keys in the vault. Valid values are: all, encrypt, decrypt, wrapKey, unwrapKey, sign, verify, get, list, create, update, import, delete, backup, restore, recover, and purge.')
param keysPermissions array = [
'list'
]
@description('Specifies the permissions to secrets in the vault. Valid values are: all, get, list, set, delete, backup, restore, recover, and purge.')
param secretsPermissions array = [
'list'
]
@description('Specifies whether the key vault is a standard vault or a premium vault.')
@allowed([
'standard'
'premium'
])
param skuName string = 'standard'
@description('Specifies the name of the secret that you want to create.')
param secretName string
@description('Specifies the value of the secret that you want to create.')
@secure()
param secretValue string
resource kv 'Microsoft.KeyVault/vaults@2023-07-01' = {
name: keyVaultName
location: location
properties: {
enabledForDeployment: enabledForDeployment
enabledForDiskEncryption: enabledForDiskEncryption
enabledForTemplateDeployment: enabledForTemplateDeployment
tenantId: tenantId
enableSoftDelete: true
softDeleteRetentionInDays: 90
accessPolicies: [
{
objectId: objectId
tenantId: tenantId
permissions: {
keys: keysPermissions
secrets: secretsPermissions
}
}
]
sku: {
name: skuName
family: 'A'
}
networkAcls: {
defaultAction: 'Allow'
bypass: 'AzureServices'
}
}
}
resource secret 'Microsoft.KeyVault/vaults/secrets@2023-07-01' = {
parent: kv
name: secretName
properties: {
value: secretValue
}
}
output location string = location
output name string = kv.name
output resourceGroupName string = resourceGroup().name
output resourceId string = kv.id
Dwa zasoby platformy Azure są zdefiniowane w pliku Bicep:
- Microsoft.KeyVault/vaults: utwórz magazyn kluczy platformy Azure.
- Microsoft.KeyVault/vaults/secrets: utwórz sekret magazynu kluczy.
Wdróż plik Bicep
Zapisz plik Bicep jako main.bicep na komputerze lokalnym.
Wdróż plik Bicep przy użyciu interfejsu wiersza polecenia platformy Azure lub programu Azure PowerShell.
az group create --name exampleRG --location eastus az deployment group create --resource-group exampleRG --template-file main.bicep --parameters keyVaultName=<vault-name> objectId=<object-id>Uwaga / Notatka
Zastąp <vault-name> nazwą magazynu kluczy. Zastąp <identyfikator object-id> identyfikatorem obiektu użytkownika, jednostki usługi lub grupy zabezpieczeń w dzierżawie Microsoft Entra dla skarbca. Identyfikator obiektu musi być unikatowy dla listy zasad dostępu. Pobierz go przy użyciu poleceń cmdlet Get-AzADUser lub Get-AzADServicePrincipal.
Po zakończeniu wdrażania powinien zostać wyświetlony komunikat informujący o pomyślnym wdrożeniu.
Przeglądanie wdrożonych zasobów
Możesz użyć portalu Azure, aby sprawdzić magazyn kluczy i sekret, lub użyć następującego Azure CLI lub Azure PowerShell, aby wyświetlić utworzony sekret.
echo "Enter your key vault name:" &&
read keyVaultName &&
az keyvault secret list --vault-name $keyVaultName &&
echo "Press [ENTER] to continue ..."
Uprzątnij zasoby
Gdy grupa zasobów i jej zasoby nie będą już potrzebne, użyj witryny Azure Portal, interfejsu wiersza polecenia platformy Azure lub programu Azure PowerShell.
az group delete --name exampleRG
Dalsze kroki
W tym przewodniku szybkiego startu utworzono Key Vault oraz tajemnicę przy użyciu narzędzia Bicep, a następnie zweryfikowano wdrożenie. Aby dowiedzieć się więcej o usłudze Key Vault i usłudze Bicep, przejdź do poniższych artykułów.
- Przeczytaj omówienie usługi Azure Key Vault
- Dowiedz się więcej o Bicep
- Przegląd zabezpieczeń usługi Key Vault