Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
Azure Key Vault is een cloudservice die een beveiligd archief biedt voor geheimen, zoals sleutels, wachtwoorden, certificaten en andere geheimen. Deze quickstart richt zich op het deployen van een Bicep-bestand om een sleutelkluis en een geheim aan te maken.
Bicep is een domeinspecifieke taal (DSL) die declaratieve syntaxis gebruikt om Azure-resources te implementeren. Het biedt beknopte syntaxis, betrouwbare typeveiligheid en ondersteuning voor het hergebruik van code. Bicep biedt de beste ontwerpervaring voor uw infrastructuur als code-oplossingen in Azure.
Vereiste voorwaarden
Als je geen Azure-abonnement hebt, maak dan een gratis account aan voordat je begint.
Uw Microsoft Entra-gebruikersobject-id is nodig voor de sjabloon om machtigingen te configureren. Met de volgende procedure wordt de object-id (GUID) opgehaald.
Voer de volgende Azure PowerShell- of Azure CLI-opdracht uit door op Uitproberen te klikken, en plak vervolgens het script in het shell-venster. Plak het script door met de rechtermuisknop op de shell te klikken en Plakken te selecteren.
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 ..."Noteer de object-id. U hebt deze nodig in de volgende sectie van deze quickstart.
Het Bicep-bestand bekijken
De sjabloon die in deze quickstart wordt gebruikt, komt uit Azure-snelstartsjablonen.
@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
Er worden twee Azure-resources gedefinieerd in het Bicep-bestand:
- Microsoft.KeyVault/vaults: maak een Azure-sleutelkluis.
- Microsoft.KeyVault/vaults/secrets: maak een sleutelkluisgeheim.
Het Bicep-bestand implementeren
Sla het Bicep-bestand op als main.bicep op uw lokale computer.
Implementeer het Bicep-bestand met behulp van Azure CLI of 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>Opmerking
Vervang <kluisnaam> door de naam van de sleutelkluis. Vervang <object-ID> door de object-ID van een gebruiker, service-principal of beveiligingsgroep in de Microsoft Entra-tenant voor de kluis. De object-id moet uniek zijn voor de lijst met toegangsbeleidsregels. Haal deze op met behulp van de cmdlets Get-AzADUser of Get-AzADServicePrincipal.
Wanneer de implementatie is voltooid, ziet u een bericht waarin wordt aangegeven dat de implementatie is voltooid.
Geïmplementeerde middelen beoordelen
U kunt Azure Portal gebruiken om de sleutelkluis en het geheim te controleren, of het volgende Azure CLI- of Azure PowerShell-script gebruiken om het gemaakte geheim weer te geven.
echo "Enter your key vault name:" &&
read keyVaultName &&
az keyvault secret list --vault-name $keyVaultName &&
echo "Press [ENTER] to continue ..."
De hulpbronnen opschonen
Wanneer u deze niet meer nodig hebt, gebruikt u Azure Portal, Azure CLI of Azure PowerShell om de resourcegroep en de bijbehorende resources te verwijderen.
az group delete --name exampleRG
Volgende stappen
In deze quickstart hebt u een sleutelkluis en een geheim gemaakt met Bicep en vervolgens de implementatie gevalideerd. Ga verder met de onderstaande artikelen voor meer informatie over Key Vault en Bicep.
- Lees een Overzicht van Azure Key Vault
- Meer informatie over Bicep
- Bekijk de Key Vault beveiligingsoverzicht