|
1 | 1 | ---
|
2 | 2 | title: 'Securely connect to Azure resources'
|
3 |
| -description: Your app service may need to connect to other Azure services such as a database, storage, or another app. This overview recommends the more secure method for connecting. |
| 3 | +description: Shows you how to connect to other Azure services such as a database, storage, or another app. This overview recommends the more secure method for connecting. |
4 | 4 | author: cephalin
|
5 | 5 | ms.author: cephalin
|
6 |
| - |
7 |
| -ms.topic: tutorial |
8 |
| -ms.date: 01/16/2023 |
| 6 | +ms.topic: article |
| 7 | +ms.date: 07/06/2024 |
9 | 8 | ms.custom: AppServiceConnectivity
|
| 9 | +#customer intent: As a developer, I want to learn how to securely connect to Azure resources from Azure App Service so that I can protect sensitive data and ensure secure communication. |
10 | 10 | ---
|
11 |
| -# Securely connect to Azure services and databases from Azure App Service |
| 11 | +# Secure connectivity to Azure services and databases from Azure App Service |
| 12 | + |
| 13 | +Your app service might need to connect to other Azure services such as a database, storage, or another app. This overview recommends different methods for connecting and when to use them. |
12 | 14 |
|
13 |
| -Your app service may need to connect to other Azure services such as a database, storage, or another app. This overview recommends different methods for connecting and when to use them. |
| 15 | +Today, the decision for a connectivity approach is closely related to secrets management. The common pattern of using connection secrets in connection strings, such as username and password, secret key, etc. is no longer considered the most secure approach for connectivity. The risk is even higher today because threat actors regularly crawl public GitHub repositories for accidentally committed connection secrets. For cloud applications, the best secrets management is to have no secrets at all. When you migrate to Azure App Service, your app might start with secrets-based connectivity, and App Service lets you keep secrets securely. However, Azure can help secure your app's back-end connectivity through Microsoft Entra authentication, which eliminates secrets altogether in your app. |
14 | 16 |
|
15 | 17 | |Connection method|When to use|
|
16 | 18 | |--|--|
|
17 |
| -|[Connect using the app identity](#connect-using-the-app-identity)|* You want to connect to a resource without an authenticated user present or using the app identity.<br>* You don't need to manage credentials, keys, or secrets, or the credentials aren’t even accessible to you.<br>* You can use managed identities to manage credentials for you.<br>* A Microsoft Entra identity is required to access the Azure resource. For example, services such as Microsoft Graph or Azure management SDKs.| |
18 |
| -|[Connect as the authenticated user](#connect-as-the-authenticated-user)| * You want to access a resource and perform some action as the signed-in user.| |
19 |
| -|[Connect using secrets](#connect-using-secrets)|* You need secrets to be passed to your app as environment variables.<br>* You want to connect to non-Azure services such as GitHub, Twitter, Facebook, or Google.<br>* The downstream resource doesn't support Microsoft Entra authentication. <br>* The downstream resource requires a connection string or key or secret of some sort.| |
| 19 | +|[Connect with an app identity](#connect-with-an-app-identity)|* You want to remove credentials, keys, or secrets completely from your application.<br/>* The downstream Azure service supports Microsoft Entra authentication, such as Microsoft Graph.<br/>* The downstream resource doesn't need to know the current signed-in user or doesn't need granular authorization of the current signed-in user.| |
| 20 | +|[Connect on behalf of the signed-in user](#connect-on-behalf-of-the-signed-in-user)| * The app must access a downstream resource on behalf of the signed-in user.<br/>* The downstream Azure service supports Microsoft Entra authentication, such as Microsoft Graph.<br/>* The downstream resource must perform granular authorization of the current signed-in user.| |
| 21 | +|[Connect using secrets](#connect-using-secrets)|* The downstream resource requires connection secrets.<br/>* Your app connects to non-Azure services, such as an on-premises database server.<br/>* The downstream Azure service doesn't support Microsoft Entra authentication yet.| |
20 | 22 |
|
21 |
| -## Connect using secrets |
| 23 | +## Connect with an app identity |
22 | 24 |
|
23 |
| -There are two recommended ways to use secrets in your app: using secrets stored in Azure Key Vault or secrets in App Service application settings. |
| 25 | +If your app already uses a single set of credentials to access a downstream Azure service, you can quickly convert the connection to use an app identity instead. A [managed identity](overview-managed-identity.md) from Microsoft Entra ID lets App Service access resources without secrets, and you can manage its access through role-based access control (RBAC). A managed identity can connect to any Azure resource that supports Microsoft Entra authentication, and the authentication takes place with short-lived tokens. |
24 | 26 |
|
25 |
| -### Use secrets in app settings |
| 27 | +The following image demonstrates the following an App Service connecting to other Azure services: |
26 | 28 |
|
27 |
| -Some apps access secrets using environment variables. Traditionally, App Service [app settings](configure-common.md) have been used to store connection strings, API keys, and other environment variables. These secrets are injected into your application code as environment variables at app startup. App settings are always encrypted when stored (encrypted-at-rest). If you also want access policies and audit history for your secrets, consider putting them in Azure Key Vault and using [Key Vault references](app-service-key-vault-references.md) in your app settings. |
| 29 | +* A: User visits Azure app service website. |
| 30 | +* B: Securely **connect from** App Service **to** another Azure service using a managed identity. |
| 31 | +* C: Securely **connect from** App Service **to** Microsoft Graph using a managed identity. |
| 32 | + |
| 33 | +:::image type="content" source="media/scenario-secure-app-overview/web-app.svg" alt-text="Diagram showing managed identity accessing a resource with or without the user's identity."::: |
28 | 34 |
|
29 | 35 | Examples of using application secrets to connect to a database:
|
30 | 36 |
|
31 |
| -- [ASP.NET Core with SQL DB](tutorial-dotnetcore-sqldb-app.md) |
32 |
| -- [ASP.NET with SQL DB](app-service-web-tutorial-dotnet-sqldatabase.md) |
33 |
| -- [PHP with MySQL](tutorial-php-mysql-app.md) |
34 |
| -- [Node.js with MongoDB](tutorial-nodejs-mongodb-app.md) |
35 |
| -- [Python with Postgres](tutorial-python-postgresql-app.md) |
36 |
| -- [Java with Spring Data](tutorial-java-spring-cosmosdb.md) |
37 |
| -- [Quarkus with Postgres](tutorial-java-quarkus-postgresql-app.md) |
| 37 | +- [Tutorial: Connect to Azure databases from App Service without secrets using a managed identity](tutorial-connect-msi-azure-database.md) |
| 38 | +- [Tutorial: Connect to SQL Database from .NET App Service without secrets using a managed identity](tutorial-connect-msi-sql-database.md) |
| 39 | +- [Tutorial: Connect to a PostgreSQL Database from Java Tomcat App Service without secrets using a managed identity](tutorial-java-tomcat-connect-managed-identity-postgresql-database.md) |
38 | 40 |
|
39 |
| -### Use secrets from Key Vault |
| 41 | +## Connect on behalf of the signed-in user |
40 | 42 |
|
41 |
| -[Azure Key Vault](app-service-key-vault-references.md) can be used to securely store secrets and keys, monitor access and use of secrets, and simplify administration of application secrets. If your app's downstream service doesn't support Microsoft Entra authentication or requires a connection string or key, use Key Vault to store your secrets and connect your app to Key Vault with a managed identity and retrieve the secrets. |
| 43 | +Your app might need to connect to a downstream service on behalf of the signed-in user. App Service lets you easily authenticate users using the most common identity providers (see [Authentication and authorization in Azure App Service and Azure Functions](overview-authentication-authorization.md)). If you use the Microsoft provider (Microsoft Entra authentication), you can then flow the signed-in user to any downstream service. For example: |
42 | 44 |
|
43 |
| -Benefits of managed identities integrated with Key Vault include: |
44 |
| -- Access to the Key Vault is restricted to the app. |
45 |
| -- App contributors, such as administrators, may have complete control of the App Service resources, and at the same time have no access to the Key Vault secrets. |
46 |
| -- No code change is required if your application code already accesses connection secrets with app settings. |
47 |
| -- Key Vault provides monitoring and auditing of who accessed secrets. |
48 |
| -- Rotation of connection information in Key Vault requires no changes in App Service. |
| 45 | +- Run a database query that returns confidential data that the signed-in user is authorized to read. |
| 46 | +- Retrieve personal data or take actions as the signed-in user in Microsoft Graph. |
49 | 47 |
|
50 |
| -The following image demonstrates App Service connecting to Key Vault using a managed identity and then accessing an Azure service using secrets stored i Key Vault: |
| 48 | +The following image demonstrates an application securely accessing an SQL database on behalf of the signed-in user. |
51 | 49 |
|
52 |
| -:::image type="content" source="media/tutorial-connect-overview/app-service-connect-key-vault-managed-identity.png" alt-text="Image showing app service using a secret stored in Key Vault and managed with Managed identity to connect to Azure AI services."::: |
| 50 | +:::image type="content" source="./media/tutorial-connect-app-access-sql-database-as-user-dotnet/architecture.png" alt-text="Architecture diagram for tutorial scenario."::: |
53 | 51 |
|
| 52 | +Some common scenarios are: |
| 53 | +- [Connect to Microsoft Graph on behalf of the user](scenario-secure-app-access-microsoft-graph-as-user.md) |
| 54 | +- [Connect to an SQL database on behalf the user](tutorial-connect-app-access-sql-database-as-user-dotnet.md) |
| 55 | +- [Connect to another App Service app on behalf of the user](tutorial-auth-aad.md) |
| 56 | +- [Flow the signed-in user through multiple layers of downstream services](tutorial-connect-app-app-graph-javascript.md) |
54 | 57 |
|
55 |
| -## Connect using the app identity |
| 58 | +## Connect using secrets |
56 | 59 |
|
57 |
| -In some cases, your app needs to access data under the identity of the app itself or without a signed-in user present. A [managed identity](overview-managed-identity.md) from Microsoft Entra ID allows App Service to access resources through role-based access control (RBAC), without requiring app credentials. A managed identity can connect to any resource that supports Microsoft Entra authentication. After assigning a managed identity to your web app, Azure takes care of the creation and distribution of a certificate. You don't have to worry about managing secrets or app credentials. |
| 60 | +There are two recommended ways to use secrets in your app: using secrets stored in Azure Key Vault or secrets in App Service app settings. |
58 | 61 |
|
59 |
| -The following image demonstrates the following an App Service connecting to other Azure services: |
| 62 | +### Use secrets from Key Vault |
60 | 63 |
|
61 |
| -* A: User visits Azure app service website. |
62 |
| -* B: Securely **connect from** App Service **to** another Azure service using a managed identity. |
63 |
| -* C: Securely **connect from** App Service **to** Microsoft Graph using a managed identity. |
| 64 | +[Azure Key Vault](app-service-key-vault-references.md) can be used to securely store secrets and keys, monitor access and use of secrets, and simplify administration of application secrets. If the downstream service doesn't support Microsoft Entra authentication or requires a connection string or key, use Key Vault to store your secrets and connect your app to Key Vault with a managed identity and retrieve the secrets. Your app can access they key vault secrets as [Key Vault references](app-service-key-vault-references.md) in the app settings. |
64 | 65 |
|
65 |
| -:::image type="content" source="media/scenario-secure-app-overview/web-app.svg" alt-text="Diagram showing managed identity accessing a resource with or without the user's identity."::: |
| 66 | +Benefits of managed identities integrated with Key Vault include: |
| 67 | +- Access to the key vault secret is restricted to the app. |
| 68 | +- App contributors, such as administrators, might have complete control of the App Service resources, and at the same time have no access to the key vault secrets. |
| 69 | +- No code change is required if your application code already accesses connection secrets with app settings. |
| 70 | +- Key Vault provides monitoring and auditing of who accessed secrets. |
| 71 | +- Rotation of key vault secrets requires no changes in App Service. |
66 | 72 |
|
67 |
| -## Connect as the authenticated user |
| 73 | +The following image demonstrates App Service connecting to Key Vault using a managed identity and then accessing an Azure service using secrets stored in Key Vault: |
68 | 74 |
|
69 |
| -In some cases, your app needs to connect to a resource and perform some action that only the signed-in user can do. Grant delegated permissions to your app to connect to resources using the identity of the signed-in user. |
| 75 | +:::image type="content" source="media/tutorial-connect-overview/app-service-connect-key-vault-managed-identity.png" alt-text="Diagram showing app service using a secret stored in Key Vault and managed with Managed identity to connect to Azure AI services."::: |
70 | 76 |
|
71 |
| -The following image demonstrates an application securely accessing an SQL database on behalf of the signed-in user. |
| 77 | +### Use secrets in app settings |
72 | 78 |
|
73 |
| -:::image type="content" source="./media/tutorial-connect-app-access-sql-database-as-user-dotnet/architecture.png" alt-text="Architecture diagram for tutorial scenario."::: |
| 79 | +For apps that connect to services using secrets (such as usernames, passwords, and API keys), App Service can store them securely in [app settings](configure-common.md). These secrets are injected into your application code as environment variables at app startup. App settings are always encrypted when stored (encrypted-at-rest). For more advanced secrets management, such as secrets rotation, access policies, and audit history, try [using Key Vault](#use-secrets-from-key-vault). |
74 | 80 |
|
75 |
| -Some common scenarios are: |
76 |
| -- [Connect to Microsoft Graph](scenario-secure-app-access-microsoft-graph-as-user.md) as the user |
77 |
| -- [Connect to an SQL database](tutorial-connect-app-access-sql-database-as-user-dotnet.md) as the user |
78 |
| -- [Connect to another App Service app](tutorial-auth-aad.md) as the user |
79 |
| -- [Connect to another App Service app and then a downstream service](tutorial-connect-app-app-graph-javascript.md) as the user |
| 81 | +Examples of using application secrets to connect to a database: |
80 | 82 |
|
| 83 | +- [Tutorial: Deploy an ASP.NET Core and Azure SQL Database app to Azure App Service](tutorial-dotnetcore-sqldb-app.md) |
| 84 | +- [Tutorial: Deploy an ASP.NET app to Azure with Azure SQL Database](app-service-web-tutorial-dotnet-sqldatabase.md) |
| 85 | +- [Tutorial: Deploy a PHP, MySQL, and Redis app to Azure App Service](tutorial-php-mysql-app.md) |
| 86 | +- [Deploy a Node.js + MongoDB web app to Azure](tutorial-nodejs-mongodb-app.md) |
| 87 | +- [Deploy a Python (Django or Flask) web app with PostgreSQL in Azure](tutorial-python-postgresql-app.md) |
| 88 | +- [Tutorial: Build a Tomcat web app with Azure App Service on Linux and MySQL](tutorial-java-tomcat-mysql-app.md) |
| 89 | +- [Tutorial: Build a Java Spring Boot web app with Azure App Service on Linux and Azure Cosmos DB](tutorial-java-spring-cosmosdb.md) |
| 90 | +- [Tutorial: Build a Quarkus web app with Azure App Service on Linux and PostgreSQL](tutorial-java-quarkus-postgresql-app.md) |
81 | 91 |
|
82 | 92 | ## Next steps
|
83 | 93 |
|
|
0 commit comments