skip to Main Content

I’m new to Azure. While exploring various services, I have a question.

Are the values stored in Azure App Configuration and Key Vault loaded and used not only in the backend API server but also in the frontend, such as mobile apps and websites?

This is a simple question, but I couldn’t find information about this use case in the Azure official documentation.

2

Answers


  1. This comes down to how you load and access the data in the KeyVault via your code or setup in Azure as mentioned by @juunas.

    So, you can load the KeyVault Secret in backend code using something like this:

    SecretClientOptions options = new SecretClientOptions()
    {
        Retry =
        {
            Delay= TimeSpan.FromSeconds(2),
            MaxDelay = TimeSpan.FromSeconds(16),
            MaxRetries = 5,
            Mode = RetryMode.Exponential
         }
    };
    var client = new SecretClient(new Uri("https://<your-unique-key-vault- 
    name>.vault.azure.net/"), new DefaultAzureCredential(),options);
    
    KeyVaultSecret secret = client.GetSecret("<mySecret>");
    
    string secretValue = secret.Value;
    

    Available Here

    Depending where you call this and what variable you save to will decide where available.

    For Frontend, for example Javascript (I am not a FrontEnd Developer) use something like this:

    const { SecretClient } = require("@azure/keyvault-secrets");
    const { DefaultAzureCredential } = require("@azure/identity");
    
    async function main() {
      // If you're using MSI, DefaultAzureCredential should "just work".
      // Otherwise, DefaultAzureCredential expects the following three 
      environment variables:
      // - AZURE_TENANT_ID: The tenant ID in Azure Active Directory
      // - AZURE_CLIENT_ID: The application (client) ID registered in the AAD tenant
      // - AZURE_CLIENT_SECRET: The client secret for the registered application
      const credential = new DefaultAzureCredential();
    
      const keyVaultName = process.env["KEY_VAULT_NAME"];
      if(!keyVaultName) throw new Error("KEY_VAULT_NAME is empty");
      const url = "https://" + keyVaultName + ".vault.azure.net";
    
      const client = new SecretClient(url, credential);
    
      // Create a secret
      // The secret can be a string of any kind. For example,
      // a multiline text block such as an RSA private key with newline characters,
      // or a stringified JSON object, like `JSON.stringify({ mySecret: 'MySecretValue'})`.
      const uniqueString = new Date().getTime();
      const secretName = `secret${uniqueString}`;
      const result = await client.setSecret(secretName, "MySecretValue");
      console.log("result: ", result);
    
      // Read the secret we created
      const secret = await client.getSecret(secretName);
      console.log("secret: ", secret);
    
      // Update the secret with different attributes
      const updatedSecret = await client.updateSecretProperties(secretName, result.properties.version, {
         enabled: false
      });
      console.log("updated secret: ", updatedSecret);
    
      // Delete the secret immediately without ability to restore or purge.
      await client.beginDeleteSecret(secretName);
     }
    
     main().catch((error) => {
       console.error("An error occurred:", error);
       process.exit(1);
     });
    

    Available here

    You can also add KeyVault data straight into the Azure WebApp appSettings by doing something like this in the configuration of you Web App.

    Add Link to Keyvault

    All these require correct setup of security and network access to the KeyVault for them to work.

    Login or Signup to reply.
  2. There are no problems using Azure App Configuration and Key Vault in backend applications.

    There are two major considerations for using Azure App Configuration and Key Vault in frontend/mobile/client applications.

    • How are you going to secure the connection and data?

      Any secrets you made available to client applications should be considered pubic.

    • How are you going to scale?

      Very often, the instances of client applications are multi-magnitude higher than the instances of backend applications. Azure App Configurate allows a request to retrieve 100 key-values and Key Vault allows a request to retrieve 1 secret. Nevertheless, your clients may be throttled if they send a massive number of requests at the same time.

    Here are some recommendations from Azure App Configuration about how to use the service for client applications:
    https://learn.microsoft.com/en-us/azure/azure-app-configuration/howto-best-practices#client-applications-in-app-configuration

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search