Skip to content

Commit 0da3e96

Browse files
author
Cephas Lin
committed
change tip location & rewrite connectivity overview
1 parent 707a2f0 commit 0da3e96

File tree

2 files changed

+57
-54
lines changed

2 files changed

+57
-54
lines changed

articles/app-service/tutorial-connect-overview.md

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,86 @@
11
---
22
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.
44
author: cephalin
55
ms.author: cephalin
6-
7-
ms.topic: tutorial
8-
ms.date: 01/16/2023
6+
ms.topic: article
7+
ms.date: 07/06/2024
98
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.
1010
---
11-
# Securely connect to Azure services and databases from Azure App Service
11+
# Secure connectivity to Azure services and databases from Azure App Service
1212

1313
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.
1414

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 migration 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.
16+
1517
|Connection method|When to use|
1618
|--|--|
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.|
20-
21-
## Connect using secrets
19+
|[Connect using an app identity](#connect-using-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.|
2222

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.
23+
## Connect with an app identity
2424

25-
### Use secrets in app settings
25+
If your app already uses a single set of credentials to access a downstream Azure service, you can very 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.
2626

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.
27+
The following image demonstrates the following an App Service connecting to other Azure services:
2828

29-
Examples of using application secrets to connect to a database:
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.
3032

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)
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.":::
3834

39-
### Use secrets from Key Vault
35+
## Connect on behalf of the signed-in user
4036

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.
37+
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 this signed-in user to any downstream service. For example:
4238

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.
39+
- In SQL database, run a query that returns confidential data that the signed-in user is authorized to read.
40+
- Retrieve personal data or take actions as the signed-in user in Microsoft Graph.
4941

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:
42+
The following image demonstrates an application securely accessing an SQL database on behalf of the signed-in user.
5143

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.":::
44+
:::image type="content" source="./media/tutorial-connect-app-access-sql-database-as-user-dotnet/architecture.png" alt-text="Architecture diagram for tutorial scenario.":::
5345

46+
Some common scenarios are:
47+
- [Connect to Microsoft Graph on behalf of the user](scenario-secure-app-access-microsoft-graph-as-user.md)
48+
- [Connect to an SQL database on behalf the user](tutorial-connect-app-access-sql-database-as-user-dotnet.md)
49+
- [Connect to another App Service app on behalf of the user](tutorial-auth-aad.md)
50+
- [Flow the signed-in user through multiple layers of downstream services](tutorial-connect-app-app-graph-javascript.md)
5451

55-
## Connect using the app identity
52+
## Connect using secrets
5653

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.
54+
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.
5855

59-
The following image demonstrates the following an App Service connecting to other Azure services:
56+
### Use secrets from Key Vault
6057

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.
58+
[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.
6459

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.":::
60+
Benefits of managed identities integrated with Key Vault include:
61+
- Access to the key vault secret is restricted to the app.
62+
- 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.
63+
- No code change is required if your application code already accesses connection secrets with app settings.
64+
- Key Vault provides monitoring and auditing of who accessed secrets.
65+
- Rotation of key vault secrets requires no changes in App Service.
6666

67-
## Connect as the authenticated user
67+
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:
6868

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.
69+
:::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.":::
7070

71-
The following image demonstrates an application securely accessing an SQL database on behalf of the signed-in user.
71+
### Use secrets in app settings
7272

73-
:::image type="content" source="./media/tutorial-connect-app-access-sql-database-as-user-dotnet/architecture.png" alt-text="Architecture diagram for tutorial scenario.":::
73+
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).
7474

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
75+
Examples of using application secrets to connect to a database:
8076

77+
- [ASP.NET Core with SQL DB](tutorial-dotnetcore-sqldb-app.md)
78+
- [ASP.NET with SQL DB](app-service-web-tutorial-dotnet-sqldatabase.md)
79+
- [PHP with MySQL](tutorial-php-mysql-app.md)
80+
- [Node.js with MongoDB](tutorial-nodejs-mongodb-app.md)
81+
- [Python with Postgres](tutorial-python-postgresql-app.md)
82+
- [Java with Spring Data](tutorial-java-spring-cosmosdb.md)
83+
- [Quarkus with Postgres](tutorial-java-quarkus-postgresql-app.md)
8184

8285
## Next steps
8386

articles/app-service/tutorial-dotnetcore-sqldb-app.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ Sign in to the [Azure portal](https://portal.azure.com/) and follow these steps
159159

160160
## 2. Verify connection strings
161161

162+
> [!TIP]
163+
> The default SQL database connection string uses SQL authentication. For more secure, passwordless authentication, see [How do I change the SQL Database connection to use a managed identity instead?](#how-do-i-change-the-sql-database-connection-to-use-a-managed-identity-instead)
164+
162165
The creation wizard generated connection strings for the SQL database and the Redis cache already. In this step, find the generated connection strings for later.
163166

164167
:::row:::
@@ -182,9 +185,6 @@ The creation wizard generated connection strings for the SQL database and the Re
182185
:::column-end:::
183186
:::row-end:::
184187

185-
> [!TIP]
186-
> The default SQL database connection string uses SQL authentication. For more secure, passwordless authentication, see [How do I change the SQL Database connection to use a managed identity instead?](#how-do-i-change-the-sql-database-connection-to-use-a-managed-identity-instead)
187-
188188
## 3. Deploy sample code
189189

190190
In this step, you configure GitHub deployment using GitHub Actions. It's just one of many ways to deploy to App Service, but also a great way to have continuous integration in your deployment process. By default, every `git push` to your GitHub repository kicks off the build and deploy action.
@@ -467,6 +467,9 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
467467

468468
## 3. Verify connection strings
469469

470+
> [!TIP]
471+
> The default SQL database connection string uses SQL authentication. For more secure, passwordless authentication, see [How do I change the SQL Database connection to use a managed identity instead?](#how-do-i-change-the-sql-database-connection-to-use-a-managed-identity-instead)
472+
470473
The AZD template you use generated the connectivity variables for you already as [app settings](configure-common.md#configure-app-settings) and outputs the them to the terminal for your convenience. App settings are one way to keep connection secrets out of your code repository.
471474

472475
1. In the AZD output, find the settings `AZURE_SQL_CONNECTIONSTRING` and `AZURE_REDIS_CONNECTIONSTRING`. To keep secrets safe, only the setting names are displayed. They look like this in the AZD output:
@@ -482,9 +485,6 @@ The AZD template you use generated the connectivity variables for you already as
482485

483486
1. For your convenience, the AZD template shows you the direct link to the app's app settings page. Find the link and open it in a new browser tab.
484487
485-
> [!TIP]
486-
> The default SQL database connection string uses SQL authentication. For more secure, passwordless authentication, see [How do I change the SQL Database connection to use a managed identity instead?](#how-do-i-change-the-sql-database-connection-to-use-a-managed-identity-instead)
487-
488488
Having issues? Check the [Troubleshooting section](#troubleshooting).
489489
490490
## 4. Modify sample code and redeploy
@@ -713,7 +713,7 @@ Your app should now have connectivity to the SQL database. For more information,
713713
> [!TIP]
714714
> **Don't want to enable public network connection?** You can skip `az sql server update --enable-public-network true` by running the commands from an [Azure cloud shell that's integrated with your virtual network](../cloud-shell/vnet/deployment.md) if you have the **Owner** role assignment on your subscription.
715715
>
716-
> To grant the identity the required access to the database that's secured by the virtual network, `az webapp connection create sql` needs direct connectivity to the database server.
716+
> To grant the identity the required access to the database that's secured by the virtual network, `az webapp connection create sql` needs direct connectivity with Entra ID authentication to the database server. By default, the Azure cloud shell doesn't have this access to the network-secured database.
717717
718718
### What can I do with GitHub Copilot in my codespace?
719719

0 commit comments

Comments
 (0)