You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Integrate Azure Key Vault Certificates into Sample Projects (#36)
* add Azure Key Vault integration and connection string management
* fix variable name typo and update SQL connection string to use Azure Key Vault
* work in progress
* Update Key Vault secret names in deploy and validate scripts
* Integrate Azure Key Vault for SQL connection string management in web app
* work in progress
* add missing logger
* work in progress
* Integrate Azure Key Vault for certificate management and validation in web app
* add validate cert
* refactor SQL connection handling
* update README
Copy file name to clipboardExpand all lines: samples/web-app-sql-database/python/README.md
+9-2Lines changed: 9 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Azure Web App with Azure SQL Database and Azure Key Vault
2
2
3
-
This sample demonstrates a Python Flask single-page web application called *Vacation Planner* hosted on an [Azure Web App](https://learn.microsoft.com/en-us/azure/app-service/overview). The app runs on an Azure App Service Plan and stores activity data in an `activities` table within the `sampledb` database on an [Azure SQL Database](https://learn.microsoft.com/en-us/azure/azure-sql/database/) instance. The connection string of the SQL database is stored as a secret in [Azure Key Vault](https://learn.microsoft.com/en-us/azure/key-vault/general/overview).
3
+
This sample demonstrates a Python Flask single-page web application called *Vacation Planner* hosted on an [Azure Web App](https://learn.microsoft.com/en-us/azure/app-service/overview). The app runs on an Azure App Service Plan and stores activity data in an `activities` table within the `sampledb` database on an [Azure SQL Database](https://learn.microsoft.com/en-us/azure/azure-sql/database/) instance. The connection string of the SQL database is stored as a secret in [Azure Key Vault](https://learn.microsoft.com/en-us/azure/key-vault/general/overview). The application also retrieves its certificate from Key Vault to serve traffic over HTTPS.
4
4
5
5
6
6
## Architecture
@@ -12,7 +12,7 @@ The following diagram illustrates the architecture of the solution:
12
12
-**Azure Web App**: Hosts the Python Flask application
13
13
-**Azure App Service Plan**: Provides compute resources for the web app
14
14
-**Azure SQL Database**: Stores activity data in a relational table
15
-
-**Azure Key Vault**: Stores the database connection string
15
+
-**Azure Key Vault**: Stores the database connection string and the certificate used to secure HTTPS traffic
16
16
17
17
## Prerequisites
18
18
@@ -43,6 +43,13 @@ The Vacation Planner Web App supports two common approaches for accessing Azure
43
43
44
44
This flexibility allows the app to run securely in Azure or in emulated environments like [LocalStack for Azure](https://azure.localstack.cloud/). The client code supports both authentication modes using [`ClientSecretCredential`](https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.clientsecretcredential?view=azure-python) or [`DefaultAzureCredential`](https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python) from the Azure SDK.
45
45
46
+
## Azure Key Vault Integration
47
+
The application integrates with Azure Key Vault for managing secrets and certificates:
48
+
49
+
Secrets: The SQL connection string is stored as a secret in Key Vault. At runtime, the app retrieves it using the Azure Key Vault Secrets SDK. This is configured via the KEY_VAULT_NAME and SECRET_NAME environment variables.
50
+
51
+
Certificates: A self-signed certificate is created in Key Vault during deployment. The app exposes a GET /api/certificate endpoint that retrieves the certificate using the Azure Key Vault Certificates SDK and returns its name, confirming the integration works. This is configured via the KEYVAULT_URI and CERT_NAME environment variables.
52
+
46
53
## Deployment
47
54
48
55
Set up the Azure emulator using the LocalStack for Azure Docker image. Before starting, ensure you have a valid `LOCALSTACK_AUTH_TOKEN` to access the Azure emulator. Refer to the [Auth Token guide](https://docs.localstack.cloud/getting-started/auth-token/?__hstc=108988063.8aad2b1a7229945859f4d9b9bb71e05d.1743148429561.1758793541854.1758810151462.32&__hssc=108988063.3.1758810151462&__hsfp=3945774529) to obtain your Auth Token and set it in the `LOCALSTACK_AUTH_TOKEN` environment variable. The Azure Docker image is available on the [LocalStack Docker Hub](https://hub.docker.com/r/localstack/localstack-azure-alpha). To pull the image, execute:
0 commit comments