How to setup a Web App with a Docker Compose file and safely use secrets from the Azure key vault.

Staffan Hedström 25 Reputation points
2023-11-13T15:19:22.4633333+00:00

Hello!

I want to create an Azure Web App with a docker compose file.

The compose file will at least contain a database (mssql) and an ASP.NET app.

The compose file will look something like

version: '3.4'
services:
  db:
    image: mcr.microsoft.com/mssql/server
    environment:
      DB_USER: ${DB_USER}
      DB_PASSWORD: ${DB_PASSWORD}
  api:
    image: myacr-image
    depends_on:
      - db

I am wondering how I can safely set this up and import db_user and db_password from an azure key vault into this docker compose file.

Note: This would be part of our dev environment so we are ok with having the database as docker image here.

Thanks!

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,960 questions
0 comments No comments
{count} votes

Accepted answer
  1. Boris Von Dahle 3,221 Reputation points
    2023-11-13T20:54:48.7433333+00:00

    Hello,

    For your Web App to safely use secret from the key vault, you will need to use a managed identity.

    After enabling the managed identity, you'll need to give this identity the necessary permissions on the key vault to get the secrets .

    Instead of pulling them from environment variables as is standard in many Docker setups, you should modify your application code to fetch these credentials directly from the Key Vault at runtime using Azure's SDKs, which provide methods to interact with the Key Vault.

    Since your application now gets these values from the Key Vault, there's no need to mention them in the Docker Compose file, enhancing your app's security.

    Hope this helps

    If you found this answer helpful, please consider marking it as accepted so that other users can easily find this topic.

    Regards


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.