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
# Use a managed identity to connect Azure SQL Database to an Azure Spring Apps app
12
+
# Use a managed identity to connect Azure SQL Database to an app deployed to Azure Spring Apps
13
13
14
14
> [!NOTE]
15
15
> Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.
This article shows you how to create a managed identity for an Azure Spring Apps app and use it to access Azure SQL Database.
21
+
This article shows you how to create a managed identity for an app deployed to Azure Spring Apps and use it to access Azure SQL Database.
22
22
23
23
[Azure SQL Database](https://azure.microsoft.com/services/sql-database/) is the intelligent, scalable, relational database service built for the cloud. It’s always up to date, with AI-powered and automated features that optimize performance and durability. Serverless compute and Hyperscale storage options automatically scale resources on demand, so you can focus on building new applications without worrying about storage size or resource management.
24
24
25
25
## Prerequisites
26
26
27
-
* Follow the [Spring Data JPA tutorial](/azure/developer/java/spring-framework/configure-spring-data-jpa-with-azure-sql-server) to provision an Azure SQL Database and get it work with a Java app locally
28
-
* Follow the [Azure Spring Apps system-assigned managed identity tutorial](./how-to-enable-system-assigned-managed-identity.md) to provision an Azure Spring Apps app with MI enabled
27
+
* An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
28
+
*[Azure CLI](/cli/azure/install-azure-cli) version 2.45.0 or higher.
29
+
* Follow the [Spring Data JPA tutorial](/azure/developer/java/spring-framework/configure-spring-data-jpa-with-azure-sql-server) to provision an Azure SQL Database and get it work with a Java app locally.
30
+
* Follow the [Azure Spring Apps system-assigned managed identity tutorial](./how-to-enable-system-assigned-managed-identity.md) to provision an app in Azure Spring Apps with managed identity enabled.
29
31
30
32
## Connect to Azure SQL Database with a managed identity
31
33
32
-
You can connect your application deployed to Azure Spring Apps to an Azure SQL Database with a managed identity by following manual steps or using [Service Connector](../service-connector/overview.md).
34
+
You can connect your application to an Azure SQL Database with a managed identity by following manual steps or using [Service Connector](../service-connector/overview.md).
33
35
34
36
### [Manual configuration](#tab/manual)
35
37
@@ -38,14 +40,14 @@ You can connect your application deployed to Azure Spring Apps to an Azure SQL D
38
40
Connect to your SQL server and run the following SQL query:
39
41
40
42
```sql
41
-
CREATE USER [<MIName>] FROM EXTERNAL PROVIDER;
42
-
ALTER ROLE db_datareader ADD MEMBER [<MIName>];
43
-
ALTER ROLE db_datawriter ADD MEMBER [<MIName>];
44
-
ALTER ROLE db_ddladmin ADD MEMBER [<MIName>];
43
+
CREATE USER [<managed-identity-name>] FROM EXTERNAL PROVIDER;
44
+
ALTER ROLE db_datareader ADD MEMBER [<managed-identity-name>];
45
+
ALTER ROLE db_datawriter ADD MEMBER [<managed-identity-name>];
46
+
ALTER ROLE db_ddladmin ADD MEMBER [<managed-identity-name>];
45
47
GO
46
48
```
47
49
48
-
The value of the `<MIName>` placeholder follows the rule `<service-instance-name>/apps/<app-name>`; for example: `myspringcloud/apps/sqldemo`. You can also query the MIName with Azure CLI:
50
+
The value of the `<managed-identity-name>` placeholder follows the rule `<service-instance-name>/apps/<app-name>`; for example: `myspringcloud/apps/sqldemo`. You can also use the following command to query the managed identity name with Azure CLI:
49
51
50
52
```azurecli
51
53
az ad sp show --id <identity-object-ID> --query displayName
Configure your app deployed to Azure Spring to connect to an SQL Database with a system-assigned managed identity using the `az spring connection create` command, as shown in the following example.
66
+
Configure your app deployed to Azure Spring Apps to connect to an Azure SQL Database with a system-assigned managed identity using the `az spring connection create` command, as shown in the following example.
65
67
66
-
> [!NOTE]
67
-
> These commands require [Azure CLI](/cli/azure/install-azure-cli) version 2.45.0 or higher.
68
-
69
-
1. Install the Service Connector passwordless extension for the Azure CLI.
68
+
1. Use the following command to install the Service Connector passwordless extension for the Azure CLI:
70
69
71
70
```azurecli
72
71
az extension add --name serviceconnector-passwordless --upgrade
73
72
```
74
73
75
-
1.Run the `az spring connection create`command, as shown in the following example.
74
+
1.Use the following command to connect to the database:
76
75
77
76
```azurecli
78
77
az spring connection create sql \
@@ -86,11 +85,28 @@ Configure your app deployed to Azure Spring to connect to an SQL Database with a
86
85
--system-identity
87
86
```
88
87
88
+
1. Use the following command to check the creation result:
89
+
90
+
```azurecli
91
+
CONNECTION_NAME=$(az spring connection list \
92
+
--resource-group $SPRING_APP_RESOURCE_GROUP \
93
+
--service $SPRING_APP_SERVICE_NAME \
94
+
--app $APP_NAME \
95
+
--query '[0].name' \
96
+
--output tsv)
97
+
98
+
az spring connection list-configuration \
99
+
--resource-group $SPRING_APP_RESOURCE_GROUP \
100
+
--service $SPRING_APP_SERVICE_NAME \
101
+
--app $APP_NAME \
102
+
--connection $CONNECTION_NAME
103
+
```
104
+
89
105
---
90
106
91
107
## Build and deploy the app to Azure Spring Apps
92
108
93
-
Rebuild the app and deploy it to the Azure Spring Apps provisioned in the second bullet point under Prerequisites. Now you have a Spring Boot application, authenticated by a managed identity, that uses JPA to store and retrieve data from an Azure SQL Database in Azure Spring Apps.
109
+
Rebuild the app and deploy it to the Azure Spring Apps provisioned in the second bullet point under Prerequisites. You now have a Spring Boot application authenticated by a managed identity that uses JPA to store and retrieve data from an Azure SQL Database in Azure Spring Apps.
Instead of manually configuring your Spring Boot applications, you can automatically bind select Azure services to your applications by using Azure Spring Apps. This article demonstrates how to bind your application to an Azure Cosmos DB database.
22
22
@@ -76,46 +76,50 @@ If you don't have a deployed Azure Spring Apps instance, follow the steps in the
76
76
77
77
### [Service Connector](#tab/Service-Connector)
78
78
79
-
1. Use the Azure CLI to configure your Spring app to connect to a Cosmos SQL Database with a system-assigned managed identity by using the `az spring connection create` command, as shown in the following example.
79
+
#### Use the Azure CLI
80
80
81
-
> [!NOTE]
82
-
> Updating Azure Cosmos DB database settings can take a few minutes to complete.
Use the following command to configure your Spring app to connect to a Cosmos SQL Database with a system-assigned managed identity:
95
82
96
-
> [!NOTE]
97
-
> If you're using [Service Connector](../service-connector/overview.md) for the first time, start by running the command `az provider register --namespace Microsoft.ServiceLinker` to register the Service Connector resource provider.
98
-
>
99
-
> If you're using Cosmos Cassandra, use a `--key_space` instead of `--database`.
83
+
> [!NOTE]
84
+
> Updating Azure Cosmos DB database settings can take a few minutes to complete.
> If you're using [Service Connector](../service-connector/overview.md) for the first time, start by running the command `az provider register --namespace Microsoft.ServiceLinker` to register the Service Connector resource provider.
100
+
>
101
+
> If you're using Cosmos Cassandra, use a `--key_space` instead of `--database`.
102
+
103
+
> [!TIP]
104
+
> Run the command `az spring connection list-support-types --output table` to get a list of supported target services and authentication methods for Azure Spring Apps. If the `az spring` command isn't recognized by the system, check that you have installed the required extension by running `az extension add --name spring`.
100
105
101
-
> [!TIP]
102
-
> Run the command `az spring connection list-support-types --output table` to get a list of supported target services and authentication methods for Azure Spring Apps. If the `az spring` command isn't recognized by the system, check that you have installed the required extension by running `az extension add --name spring`.
106
+
#### Use the Azure portal
103
107
104
-
1.Alternately, you can use the Azure portal to configure this connection by completing the following steps. The Azure portal provides the same capabilities as the Azure CLI and provides an interactive experience.
108
+
Alternately, you can use the Azure portal to configure this connection by completing the following steps. The Azure portal provides the same capabilities as the Azure CLI and provides an interactive experience.
105
109
106
-
1. Select your Azure Spring Apps instance in the Azure portal and select **Apps** from the navigation menu. Choose the app you want to connect and select **Service Connector** on the navigation menu.
110
+
1. Select your Azure Spring Apps instance in the Azure portal and select **Apps** from the navigation menu. Choose the app you want to connect and select **Service Connector** on the navigation menu.
107
111
108
-
1. Select **Create**.
112
+
1. Select **Create**.
109
113
110
-
1. On the **Basics** tab, for service type, select Cosmos DB, then choose a subscription. For API type, select Core (SQL), choose a Cosmos DB account, and a database. For client type, select Java, then select **Next: Authentication**. If you haven't created your database yet, see [Quickstart: Create an Azure Cosmos DB account, database, container, and items from the Azure portal](../cosmos-db/nosql/quickstart-portal.md).
114
+
1. On the **Basics** tab, for service type, select Cosmos DB, then choose a subscription. For API type, select Core (SQL), choose a Cosmos DB account, and a database. For client type, select Java, then select **Next: Authentication**. If you haven't created your database yet, see [Quickstart: Create an Azure Cosmos DB account, database, container, and items from the Azure portal](../cosmos-db/nosql/quickstart-portal.md).
111
115
112
-
1. On the **Authentication** tab, choose **Connection string**. Service Connector automatically retrieves the access key from your Cosmos DB account. Select **Next: Networking**.
116
+
1. On the **Authentication** tab, choose **Connection string**. Service Connector automatically retrieves the access key from your Cosmos DB account. Select **Next: Networking**.
113
117
114
-
1. On the **Networking** tab, select **Configure firewall rules to enable access to target service**, then select **Next: Review + Create**.
118
+
1. On the **Networking** tab, select **Configure firewall rules to enable access to target service**, then select **Next: Review + Create**.
115
119
116
-
1. On the **Review + Create** tab, wait for the validation to pass and then select **Create**. The creation can take a few minutes to complete.
120
+
1. On the **Review + Create** tab, wait for the validation to pass and then select **Create**. The creation can take a few minutes to complete.
117
121
118
-
1. Once the connection between your Spring apps and your Cosmos DB database has been generated, you can see it in the Service Connector page and select the unfold button to view the configured connection variables.
122
+
1. Once the connection between your Spring apps and your Cosmos DB database has been generated, you can see it in the Service Connector page and select the unfold button to view the configured connection variables.
119
123
120
124
### [Service Binding](#tab/Service-Binding)
121
125
@@ -152,7 +156,7 @@ Azure Cosmos DB has five different API types that support binding. The following
152
156
153
157
### [Terraform](#tab/Terraform)
154
158
155
-
The following Terraform script shows how to set up an Azure Spring Apps app with an Azure Cosmos DB account.
159
+
The following Terraform script shows how to set up an app deployed to Azure Spring Apps with an Azure Cosmos DB account.
0 commit comments