|
| 1 | +--- |
| 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. |
| 4 | + |
| 5 | +ms.topic: tutorial |
| 6 | +ms.date: 01/26/2022 |
| 7 | +--- |
| 8 | +# Securely connect to Azure services and databases from Azure App Service |
| 9 | + |
| 10 | +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. |
| 11 | + |
| 12 | +|Connection method|When to use| |
| 13 | +|--|--| |
| 14 | +|[Direct connection from App Service managed identity](#connect-to-azure-services-with-managed-identity)|Dependent service [supports managed identity](/azure/active-directory/managed-identities-azure-resources/managed-identities-status)<br><br>* Best for enterprise-level security<br>* Connection to dependent service is secured with managed identity<br>* Large team or automated connection string and secret management<br>* Don't manage credentials manually.<br>* Credentials aren’t accessible to you.| |
| 15 | +|[Connect using Key Vault secrets from App Service managed identity](#connect-to-key-vault-with-managed-identity)|Dependent service doesn't support managed identity<br><br>* Best for enterprise-level security<br>* Connection includes non-Azure services such as GitHub, Twitter, Facebook, Google<br>* Large team or automated connection string and secret management<br>* Don't manage credentials manually.<br>* Credentials aren’t accessible to you.<br>* Manage connection information with environment variables.| |
| 16 | +|[Connect with app settings](#connect-with-app-settings)|* Best for small team or individual owner of Azure resources.<br>* Stage 1 of multi-stage migration to Azure<br>* Temporary or proof-of-concept applications<br>* Manually manage connection information with environment variables| |
| 17 | + |
| 18 | +## Connect to Azure services with managed identity |
| 19 | + |
| 20 | +Use [managed identity](/azure/active-directory/managed-identities-azure-resources/overview) to authenticate from one Azure resource, such as Azure app service, to another Azure resource whenever possible. This level of authentication lets Azure manage the authentication process, after the required setup is complete. Once the connection is set up, you won't need to manage the connection. |
| 21 | + |
| 22 | +Benefits of managed identity: |
| 23 | + |
| 24 | +* Automated credentials management |
| 25 | +* Many Azure services are included |
| 26 | +* No additional cost |
| 27 | +* No code changes |
| 28 | + |
| 29 | +:::image type="content" source="media/tutorial-connect-overview/when-use-managed-identities.png" alt-text="Image showing source and target resources for managed identity."::: |
| 30 | + |
| 31 | +Learn which [services](/azure/active-directory/managed-identities-azure-resources/managed-identities-status) are supported with managed identity and what [operations you can perform](/azure/active-directory/managed-identities-azure-resources/overview). |
| 32 | + |
| 33 | +### Example managed identity scenario |
| 34 | + |
| 35 | +The following image demonstrates the following an App Service connecting to other Azure services: |
| 36 | + |
| 37 | +* A: User visits Azure app service website. |
| 38 | +* B: Securely **connect from** App Service **to** another Azure service using managed identity. |
| 39 | +* C: Securely **connect from** App Service **to** Microsoft Graph. |
| 40 | + |
| 41 | +:::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."::: |
| 42 | + |
| 43 | +## Connect to Key Vault with managed identity |
| 44 | + |
| 45 | +When managed identity isn't supported for your app's dependent services, use Key Vault to store your secrets, and connect your app to Key Vault with a managed identity. |
| 46 | + |
| 47 | +Secrets include: |
| 48 | + |
| 49 | +|Secret|Example| |
| 50 | +|--|--| |
| 51 | +|Certificates|SSL certificates| |
| 52 | +|Keys and access tokens|Cognitive service API Key<br>GitHub personal access token<br>Twitter consumer keys and authentication tokens| |
| 53 | +|Connection strings|Database connection strings such as SQL server or MongoDB| |
| 54 | + |
| 55 | +:::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 Cognitive Services."::: |
| 56 | + |
| 57 | +Benefits of managed identity integrated with Key Vault include: |
| 58 | + |
| 59 | +* Connectivity to Key Vault is secured by managed identities |
| 60 | +* Access to the Key Vault is restricted to the app. 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. |
| 61 | +* No code change is required if your application code already accesses connection secrets with app settings. |
| 62 | +* Monitoring and auditing of who accessed secrets. |
| 63 | +* Rotation of connection information in Key Vault requires no changes in App Service. |
| 64 | + |
| 65 | +## Connect with app settings |
| 66 | + |
| 67 | +The App Service provides [App settings](configure-common.md?tabs=portal#configure-app-settings) to store connection strings, API keys, and other environment variables. While App Service does provide encryption for app settings, for enterprise-level security, consider other services to manage these types of secrets that provide additional benefits. |
| 68 | + |
| 69 | +**App settings** best used when: |
| 70 | + |
| 71 | +* Security of connection information is manual and limited to a few people |
| 72 | +* Web app is temporary, proof-of-concept, or in first migration stage to Azure |
| 73 | + |
| 74 | +**App Service** managed identity to another Azure service best when: |
| 75 | + |
| 76 | +* You don't need to manage Azure credentials. Credentials aren’t even accessible to you. |
| 77 | +* You can use managed identities to authenticate to any resource that supports Azure Active Directory authentication including your own applications. |
| 78 | +* Managed identities can be used without any additional cost. |
| 79 | + |
| 80 | +**Key Vault** integration from App Service with managed identity best used when: |
| 81 | + |
| 82 | +* Connectivity to Key Vault is secured by managed identities. |
| 83 | +* Access to the Key Vault is restricted to the app. 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. |
| 84 | +* No code change is required if your application code already accesses connection secrets with app settings. |
| 85 | +* Monitoring and auditing of who accessed secrets. |
| 86 | + |
| 87 | + |
| 88 | +## Next steps |
| 89 | + |
| 90 | +* Learn how to use App Service managed identity with: |
| 91 | + * [SQL server](tutorial-connect-msi-sql-database.md?tabs=windowsclient%2Cdotnet) |
| 92 | + * [Azure storage](scenario-secure-app-access-storage.md?tabs=azure-portal%2Cprogramming-language-csharp) |
| 93 | + * [Microsoft Graph](scenario-secure-app-access-microsoft-graph-as-app.md?tabs=azure-powershell%2Cprogramming-language-csharp) |
0 commit comments