This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource existingStorageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' existing = { | |
name: storageAccountName | |
} | |
resource existingWebApp 'Microsoft.Web/sites@2020-09-01' existing = { | |
name: webAppName | |
} | |
resource siteConfig 'Microsoft.Web/sites/config@2023-12-01' = { | |
parent: existingWebApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource siteConfig 'Microsoft.Web/sites/config@2023-12-01' = { | |
parent: existingWebApp | |
name: 'web' | |
properties: { | |
ipSecurityRestrictions: [ | |
{ | |
ipAddress: 'AzureFrontDoor.Backend' | |
action: 'Allow' | |
tag: 'ServiceTag' | |
priority: 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Key Vault with RBAC authorization mode | |
resource existingKeyVault 'Microsoft.KeyVault/vaults@2024-04-01-preview' = { | |
name: keyVaultName | |
} | |
// Creating a Key Vault RBAC roles mapping for more intuitive assignments | |
var roleIdMapping = { | |
'Key Vault Administrator': '00482a5a-887f-4fb3-b363-3b7fe8e74483' | |
'Key Vault Certificates Officer': 'a4417e6f-fecd-4de8-b567-7b0420556985' | |
'Key Vault Crypto Officer': '14b46e9e-c2b7-41b4-b07b-48a6ebf60603' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource appSettings 'Microsoft.Web/sites/config@2023-12-01' = { | |
parent: existingWebApp | |
name: 'appsettings' | |
properties: { | |
// ... redacted | |
database__connection__host: existingMySQLServer.properties.fullyQualifiedDomainName | |
database__connection__user: databaseLogin | |
database__connection__password: '@Microsoft.KeyVault(SecretUri=${databasePasswordSecretUri})' | |
database__connection__database: databaseName | |
// The public SSL certificate used by Azure Database for MySQL - Flexible Server (https://dl.cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"KeyVault": { | |
"vaultUri": "https://kv-4zdnwe1wgbwdp.vault.azure.net", // Your Key Vault URI | |
"credential": "managedidentity" // Using the system-assigned managed identity of your Azure Arc-enabled server | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"KeyVault": { | |
"vaultUri": "https://kv-4zdnwe1wgbwdp.vault.azure.net" // Your Key Vault URI | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"KeyVault": { | |
"vaultUri": "https://kv-4zdnwe1wgbwdp.vault.azure.net", // Your Key Vault URI | |
"tenantId": "3f5ed419-0e1b-4f47-8f94-a5b9fa4f298e", // Your Azure tenant ID | |
"clientId": "76a95e90-ec2c-4d59-b92b-9c5b8316cff4", // Your app registration in the tenant | |
"clientCertificate": "5378d04cd9a86a6cde595478d664cc9e2f755d4b", // That should be your unique certificate thumbprint | |
"clientCertificateStoreLocation": "LocalMachine" // The certificate store name, which should be 'CurrentUser' or 'LocalMachine' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extracts from a sample .NET Worker Service project | |
// You can add your target Azure resources in the Program.cs file using the 'AddAzureClients' method and extension methods from corresponding Azure services client libraries | |
// ... | |
var builder = Host.CreateApplicationBuilder(args); | |
builder.Services.AddAzureClients(clientBuilder => clientBuilder.AddSecretClient(builder.Configuration.GetSection("KeyVault"))); | |
// ... | |
// Then you can 'inject' your Azure client into the Worker object (the Worker.cs file) and use them in your task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Azure.Identity; | |
using Azure.Security.KeyVault.Secrets; | |
var keyVaultName = Environment.GetEnvironmentVariable("KEY_VAULT_NAME"); // Getting the Key Vault name from an environment variable | |
if (keyVaultName is not null) // Checking if the environment variable is set | |
{ | |
Console.WriteLine($"Key Vault name: {keyVaultName}"); | |
var keyVaultUri = "https://" + keyVaultName + ".vault.azure.net"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Security.Cryptography; | |
using System.Security.Cryptography.X509Certificates; | |
using Azure.Identity; | |
using Azure.Security.KeyVault.Secrets; | |
string keyVaultName = "kv-4zdnwe1wgbwdp"; // The name of the Key Vault you want to access | |
var keyVaultUri = "https://" + keyVaultName + ".vault.azure.net"; // The Key Vault URI | |
string tenantId = "3f5ed419-0e1b-4f47-8f94-a5b9fa4f298e"; // Your Azure tenant ID | |
string clientId = "76a95e90-ec2c-4d59-b92b-9c5b8316cff4"; // Your app registration in the tenant | |
string certificateThumbprint = "5378d04cd9a86a6cde595478d664cc9e2f755d4b"; // That should be your unique certificate thumbprint |
NewerOlder