### Initialize Go Module and Install Packages Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-go Initialize a new Go module for your project and install the necessary Azure SDK packages for Key Vault certificates and identity. ```bash go mod init quickstart-go-kvcerts go get github.com/Azure/azure-sdk-for-go/sdk/keyvault/azcertificates go get github.com/Azure/azure-sdk-for-go/sdk/azidentity ``` -------------------------------- ### Install Azure Identity Package Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-node Install the `@azure/identity` client library to handle authentication with Azure Key Vault. ```bash npm install @azure/identity ``` -------------------------------- ### Initialize Go Module and Install Packages Source: https://learn.microsoft.com/en-us/azure/key-vault/keys/quick-create-go Initialize a new Go module for your project and install the necessary Azure SDK packages for identity and Key Vault operations. ```bash go mod init quickstart-keys go get -u github.com/Azure/azure-sdk-for-go/sdk/azidentity go get -u github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys ``` -------------------------------- ### Initialize Go Module and Install Packages Source: https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-go Initialize a new Go module named 'kvSecrets' and install the necessary Azure SDK packages for Key Vault and identity authentication. ```bash go mod init kvSecrets go get -u github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets go get -u github.com/Azure/azure-sdk-for-go/sdk/azidentity ``` -------------------------------- ### Install Azure SDK Packages Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/quickstart-javascript Install the necessary Azure Identity and Key Vault Keys client libraries for your JavaScript project. ```bash npm install @azure/identity @azure/keyvault-keys ``` -------------------------------- ### Key Vault Request URL Examples Source: https://learn.microsoft.com/en-us/azure/key-vault/general/authentication-requests-and-responses Examples of URLs for various Key Vault operations including creating, importing, and getting keys, as well as signing digests. Ensure to replace `` with a valid version. ```http PUT /keys/TESTKEY?api-version= HTTP/1.1 ``` ```http POST /keys/IMPORTEDKEY/import?api-version= HTTP/1.1 ``` ```http GET /secrets/MYSECRET?api-version= HTTP/1.1 ``` ```http POST /keys/TESTKEY/sign?api-version= HTTP/1.1 ``` -------------------------------- ### Download logs for a specific month and year using PowerShell Source: https://learn.microsoft.com/en-us/azure/key-vault/general/howto-logging Download all logs for a specific month and year. This example shows how to get logs for January 2016. Adjust the year and month values as needed. ```powershell Get-AzStorageBlob -Container "insights-logs-auditevent" -Context $sa.Context -Blob '*/year=2016/m=01/*' ``` -------------------------------- ### Install Azure Key Vault keys client library Source: https://learn.microsoft.com/en-us/azure/key-vault/keys/javascript-developer-guide-get-started Install the Azure Key Vault keys client library for JavaScript using npm. ```bash npm install @azure/keyvault-keys ``` -------------------------------- ### Maven project generation output example Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-java This is an example of the console output when a Maven project is successfully generated. It confirms the project parameters and creation location. ```text [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Archetype: maven-archetype-quickstart:1.4 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: com.keyvault.certificates.quickstart [INFO] Parameter: artifactId, Value: akv-certificates-java [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: package, Value: com.keyvault.certificates.quickstart [INFO] Parameter: packageInPathFormat, Value: com/keyvault/quickstart [INFO] Parameter: package, Value: com.keyvault.certificates.quickstart [INFO] Parameter: groupId, Value: com.keyvault.certificates.quickstart [INFO] Parameter: artifactId, Value: akv-certificates-java [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Project created from Archetype in dir: /home/user/quickstarts/akv-certificates-java [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 38.124 s [INFO] Finished at: 2019-11-15T13:19:06-08:00 [INFO] ------------------------------------------------------------------------ ``` -------------------------------- ### Set up Python virtual environment on Windows Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/key-attestation Sets up a Python virtual environment named 'attestation' and installs required packages on Windows. ```bash python3 -m venv attestation attestation\Scripts\activate.bat pip3 install -r requirements.txt cd src/ ``` -------------------------------- ### Install Azure Identity package Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-python Install the Microsoft Entra identity library using pip. This package is required for authentication. ```bash pip install azure-identity ``` -------------------------------- ### Set up Python virtual environment on Linux Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/key-attestation Sets up a Python virtual environment named 'attestation' and installs required packages on Linux. ```bash python3 -m venv attestation source attestation/bin/activate pip3 install -r requirements.txt cd src/ ``` -------------------------------- ### Sample Console Output Source: https://learn.microsoft.com/en-us/azure/key-vault/keys/quick-create-net This is an example of the console output you can expect when running the application. ```console Creating a key in mykeyvault called 'myKey' ... done. Retrieving your key from mykeyvault. Your key version is '8532359bced24e4bb2525f2d2050738a'. Deleting your key from jl-kv ... done Purging your key from ... done. ``` -------------------------------- ### Example Resource List Output (Console) Source: https://learn.microsoft.com/en-us/azure/key-vault/secrets/tutorial-rotation Displays the expected output format when listing resources, showing Key Vault and SQL Server instances. ```console Name ResourceGroup Location Type Status ----------------------- -------------------- ---------- --------------------------------- -------- akvrotation-kv akvrotation eastus Microsoft.KeyVault/vaults akvrotation-sql akvrotation eastus Microsoft.Sql/servers akvrotation-sql/master akvrotation eastus Microsoft.Sql/servers/databases akvrotation-sql2 akvrotation eastus Microsoft.Sql/servers akvrotation-sql2/master akvrotation eastus Microsoft.Sql/servers/databases ``` -------------------------------- ### Install Azure Identity Package Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-net Install the Azure Identity client library, which is required for authenticating your application with Azure services. ```dotnetcli dotnet add package Azure.Identity ``` -------------------------------- ### Install Azure CLI extension Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-cli Install the necessary Azure CLI extension if prompted during the first use. This ensures you have the required tools for Key Vault management. ```bash az extension add --name keyvault ``` -------------------------------- ### Install Azure Key Vault Secrets client library Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-net-virtual-machine Install the Azure Key Vault Secrets client library for .NET to manage secrets. ```bash dotnet add package Azure.Security.KeyVault.Secrets ``` -------------------------------- ### Initial Setup for Private Link Connection using Azure CLI Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/private-link This snippet covers the initial setup required for integrating Managed HSM with Azure Private Link. It includes logging into Azure, setting the subscription, creating a resource group, registering the KeyVault provider, turning on the HSM firewall, creating a virtual network and subnet, disabling network policies, creating a private DNS zone, and linking it to the virtual network. ```azurecli az login # Login to Azure CLI az account set --subscription # Select your Azure Subscription az group create -n -l # Create a new Resource Group az provider register -n Microsoft.KeyVault # Register KeyVault as a provider az keyvault update-hsm --hsm-name -g --default-action deny # Turn on firewall az network vnet create -g -n --location # Create a Virtual Network # Create a Subnet az network vnet subnet create -g --vnet-name --name --address-prefixes # Disable Virtual Network Policies az network vnet subnet update --name --resource-group --vnet-name --disable-private-endpoint-network-policies true # Create a Private DNS Zone az network private-dns zone create --resource-group --name privatelink.managedhsm.azure.net # Link the Private DNS Zone to the Virtual Network az network private-dns link vnet create --resource-group --virtual-network --zone-name privatelink.managedhsm.azure.net --name --registration-enabled true ``` -------------------------------- ### Install Node.js on VM Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-javascript-virtual-machine Install Node.js version 20.x on the virtual machine using the NodeSource repository and apt-get. This is a prerequisite for running JavaScript applications. ```bash curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash - && \ sudo apt-get install -y nodejs ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/quickstart-python Set up a Python virtual environment to manage project dependencies. Activate it to ensure packages are installed locally. ```bash python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate ``` -------------------------------- ### Install Azure Key Vault Keys Package Source: https://learn.microsoft.com/en-us/azure/key-vault/keys/quick-create-net Add the Azure Key Vault key client library for .NET to your project. ```bash dotnet add package Azure.Security.KeyVault.Keys ``` -------------------------------- ### Install Azure Key Vault Secrets Client Library Source: https://learn.microsoft.com/en-us/azure/key-vault/secrets/javascript-developer-guide-get-started Install the Azure Key Vault secrets client library for JavaScript using npm. ```bash npm install @azure/keyvault-secrets ``` -------------------------------- ### Sample Output Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/quickstart-python This is an example of the expected output when the Python application successfully runs and interacts with Managed HSM. ```text Retrieving key 'myrsakey' from Managed HSM... Key retrieved. Key type: RSA-HSM Original text: Hello, Managed HSM! Encrypted (hex): 5a8f3b2c1d4e5f6a7b8c9d0e1f2a3b4c... Decrypted text: Hello, Managed HSM! Done! ``` -------------------------------- ### Install Azure Key Vault and Identity Packages Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-javascript-virtual-machine Install the necessary Azure SDK packages for Node.js: `@azure/keyvault-secrets` for interacting with Key Vault secrets and `@azure/identity` for authentication. ```bash npm install @azure/keyvault-secrets @azure/identity ``` -------------------------------- ### Get system-assigned identity output (Azure PowerShell) Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-net-virtual-machine This is the expected output format when a system-assigned identity is successfully assigned to a VM using Azure PowerShell. It displays the PrincipalId, which is the GUID of the system-assigned identity. ```powershell PrincipalId TenantId Type UserAssignedIdentities ----------- -------- ---- ---------------------- xxxxxxxx-xx-xxxxxx xxxxxxxx-xxxx-xxxx SystemAssigned ``` -------------------------------- ### Example multi-line secret content Source: https://learn.microsoft.com/en-us/azure/key-vault/secrets/multiline-secrets This is an example of the content for a multi-line secret stored in a text file. ```text This is my multi-line secret ``` -------------------------------- ### Example Resource List Output After Function App Deployment (Console) Source: https://learn.microsoft.com/en-us/azure/key-vault/secrets/tutorial-rotation Shows the expected resources after deploying the function app for SQL password rotation, including storage and function app details. ```console Name ResourceGroup Location Type Status ----------------------- -------------------- ---------- --------------------------------- -------- akvrotation-kv akvrotation eastus Microsoft.KeyVault/vaults akvrotation-sql akvrotation eastus Microsoft.Sql/servers akvrotation-sql/master akvrotation eastus Microsoft.Sql/servers/databases cfogyydrufs5wazfunctions akvrotation eastus Microsoft.Storage/storageAccounts akvrotation-fnapp akvrotation eastus Microsoft.Web/serverFarms akvrotation-fnapp akvrotation eastus Microsoft.Web/sites akvrotation-fnapp akvrotation eastus Microsoft.insights/components ``` -------------------------------- ### Create Project Folder and Navigate Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/quickstart-python Create a new directory for your project and change into it. This organizes your application files. ```bash mkdir mhsm-python-app && cd mhsm-python-app ``` -------------------------------- ### Create and Initialize Project Folder Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/quickstart-javascript Create a new directory for your project and navigate into it. Then, initialize the Node.js project using npm. ```bash mkdir mhsm-js-app && cd mhsm-js-app ``` ```bash npm init -y ``` -------------------------------- ### Install Azure Key Vault Certificates Package Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-node Install the `@azure/keyvault-certificates` package for Node.js to interact with Azure Key Vault certificates. ```bash npm install @azure/keyvault-certificates ``` -------------------------------- ### Create and Initialize Node.js App Directory Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-javascript-virtual-machine Create a new directory for your application, navigate into it, and initialize a new Node.js project using `npm init -y`. This sets up the `package.json` file. ```bash mkdir app && cd app && npm init -y ``` -------------------------------- ### Install Azure Key Vault Secrets Library Source: https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-python Install the `azure-keyvault-secrets` Python package using pip to interact with Azure Key Vault secrets. ```bash pip install azure-keyvault-secrets ``` -------------------------------- ### Initialize Node.js Project Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-node Initialize a new Node.js project with default settings using `npm init -y`. ```bash npm init -y ``` -------------------------------- ### Install Azure Key Vault and Identity Libraries Source: https://learn.microsoft.com/en-us/azure/key-vault/general/apps-api-keys-secrets Install the necessary Python libraries for Azure identity and Key Vault secrets management using pip. ```bash pip install azure-identity pip install azure-keyvault-secrets ``` -------------------------------- ### Navigate to the project directory Source: https://learn.microsoft.com/en-us/azure/key-vault/keys/quick-create-java Change your current directory to the root of the newly created Java project. ```bash cd akv-keys-java ``` -------------------------------- ### Create a new .NET console app Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-net-virtual-machine Create a new .NET console application and navigate into its directory. This sets up the basic project structure. ```bash dotnet new console -n keyvault-console-app cd keyvault-console-app dotnet run ``` -------------------------------- ### Run Go Application Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-go Execute the main Go application file using the 'go run' command. ```bash go run main.go ``` -------------------------------- ### Change directory Source: https://learn.microsoft.com/en-us/azure/key-vault/keys/javascript-developer-guide-get-started Navigate to your project folder. Replace `` with your actual folder name. ```bash cd ``` -------------------------------- ### Install Azure Key Vault Keys Package Source: https://learn.microsoft.com/en-us/azure/key-vault/keys/quick-create-python Install the `azure-keyvault-keys` Python package using pip. This package provides client functionality for Azure Key Vault keys. ```bash pip install azure-keyvault-keys ``` -------------------------------- ### Run the Node.js Application Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-node Execute the main application file using Node.js to initiate the certificate creation process. ```bash node index.js ``` -------------------------------- ### Get All Versions of a Key Source: https://learn.microsoft.com/en-us/azure/key-vault/keys/javascript-developer-guide-get-key Iterate through all versions of a key using `listPropertiesOfKeyVersions` to get their properties. To access the key's value for each version, use the version ID with the `getKey` method. ```javascript // Azure client libraries import { DefaultAzureCredential } from '@azure/identity'; import { KeyClient, } from '@azure/keyvault-keys'; // Authenticate to Azure Key Vault const credential = new DefaultAzureCredential(); const client = new KeyClient( `https://${process.env.AZURE_KEYVAULT_NAME}.vault.azure.net`, credential ); const name = `myRsaKey`; for await (const keyProperties of client.listPropertiesOfKeyVersions(name)) { const thisVersion = keyProperties.version; const { key } = await client.getKey(name, { version: thisVersion }); // do something with version's key value } ``` -------------------------------- ### Install Python Key Vault Libraries Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-python-virtual-machine Install the necessary Python libraries, `azure-keyvault-secrets` and `azure-identity`, on your Linux VM using pip3. These libraries are required for interacting with Azure Key Vault. ```Bash pip3 install azure-keyvault-secrets ``` ```Bash pip3 install azure-identity ``` -------------------------------- ### Create and navigate to a new .NET Core project directory Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-net-create-vault-azure-web-app Use these bash commands to create a new directory for your .NET Core application and change into it. ```Bash mkdir akvwebapp cd akvwebapp ``` -------------------------------- ### Install Azure Key Vault Certificates package Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-python Install the Key Vault certificate client library using pip. This package provides functionalities for managing Key Vault certificates. ```bash pip install azure-keyvault-certificates ``` -------------------------------- ### Initial Setup for Key Vault Private Link Source: https://learn.microsoft.com/en-us/azure/key-vault/general/private-link-service This snippet covers the initial Azure CLI commands required to set up resources for a private link connection to Key Vault. It includes creating resource groups, registering providers, creating the Key Vault, configuring its firewall, and setting up the virtual network and private DNS zone. ```azurecli az login # Login to Azure CLI az account set --subscription # Select your Azure Subscription az group create -n -l # Create a new Resource Group az provider register -n Microsoft.KeyVault # Register KeyVault as a provider az keyvault create -n -g -l --enable-rbac-authorization true --enable-purge-protection true # Create a Key Vault az keyvault update -n -g --default-action deny # Turn on Key Vault Firewall az network vnet create -g -n -location # Create a Virtual Network # Create a Subnet az network vnet subnet create -g --vnet-name --name --address-prefixes # Disable Virtual Network Policies az network vnet subnet update --name --resource-group --vnet-name --disable-private-endpoint-network-policies true # Create a Private DNS Zone az network private-dns zone create --resource-group --name privatelink.vaultcore.azure.net # Link the Private DNS Zone to the Virtual Network az network private-dns link vnet create --resource-group --virtual-network --zone-name privatelink.vaultcore.azure.net --name --registration-enabled true ``` -------------------------------- ### Install Azure Key Vault Packages Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/quickstart-python Install the required Python packages for Azure Identity and Azure Key Vault Keys using pip. Ensure you have these libraries to interact with Azure services. ```bash pip install azure-identity azure-keyvault-keys ``` -------------------------------- ### Get all versions of a secret with JavaScript Source: https://learn.microsoft.com/en-us/azure/key-vault/secrets/javascript-developer-guide-get-secret Iterate through all versions of a secret using `listPropertiesOfSecretVersions` to get their properties. Then, for each version, use `getSecret` with the specific version to retrieve its value. This allows you to collect all versions and their details. ```javascript const versions = []; for await (const secretProperties of client.listPropertiesOfSecretVersions( secretName )) { const { value } = await client.getSecret(secretName, { version: secretProperties?.version, }); versions.push({ name: secretName, version: secretProperties?.version, value: value, createdOn: secretProperties?.createdOn, }); } ``` -------------------------------- ### Create a new .NET console application Source: https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/quickstart-dotnet Create a new .NET console project using the `dotnet new console` command. This sets up the basic structure for your application. ```bash dotnet new console --name mhsm-console-app ``` -------------------------------- ### Initialize Git repository and commit changes Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-net-create-vault-azure-web-app Initialize a Git repository for your .NET Core project and make the first commit. Ensure the initial branch is named 'main'. ```Bash git init --initial-branch=main git add . git commit -m "first commit" ``` -------------------------------- ### Install Azure Key Vault Packages Source: https://learn.microsoft.com/en-us/azure/key-vault/general/tutorial-net-create-vault-azure-web-app Install the necessary Azure Identity and Azure Key Vault Secrets client libraries for .NET using the dotnet CLI. These packages are required for authenticating to Key Vault and retrieving secrets. ```console dotnet add package Azure.Identity dotnet add package Azure.Security.KeyVault.Secrets ``` -------------------------------- ### Create a Self-Signed Certificate with Policy Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-powershell Creates a self-signed certificate named 'ExampleCertificate' with a specified policy, including content type, subject name, issuer, validity period, and key reuse settings. This is for demonstration; use a trusted CA for production. ```powershell $Policy = New-AzKeyVaultCertificatePolicy -SecretContentType "application/x-pkcs12" -SubjectName "CN=" -IssuerName "Self" -ValidityInMonths 6 -ReuseKeyOnRenewal Add-AzKeyVaultCertificate -VaultName "" -Name "ExampleCertificate" -CertificatePolicy $Policy ``` -------------------------------- ### Get the created certificate object Source: https://learn.microsoft.com/en-us/azure/key-vault/certificates/quick-create-java Retrieves the final result of the certificate creation operation once it has completed. ```Java KeyVaultCertificate createdCertificate = certificatePoller.getFinalResult(); ```