Skip to content

Commit 8a46d83

Browse files
Merge pull request #217493 from KarlErickson/patch-1
edits: Support postgresql flexible server in Service Connector
2 parents ef1ebea + 7a09156 commit 8a46d83

File tree

3 files changed

+200
-22
lines changed

3 files changed

+200
-22
lines changed

articles/app-service/tutorial-java-tomcat-connect-managed-identity-postgresql-database.md

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ Run the following commands in your terminal to clone the sample repo and set up
3333

3434
```bash
3535
git clone https://github.com/Azure-Samples/Passwordless-Connections-for-Java-Apps
36-
cd Passwordless-Connections-for-Java-Apps/Tomcat/checklist/
36+
cd Passwordless-Connections-for-Java-Apps/Tomcat/
3737
```
3838

3939
## Create an Azure Postgres DB
4040

41-
Follow these steps to create an Azure Database for Postgres Single Server in your subscription. The Spring Boot app will connect to this database and store its data when running, persisting the application state no matter where you run the application.
41+
Follow these steps to create an Azure Database for Postgres in your subscription. The Spring Boot app will connect to this database and store its data when running, persisting the application state no matter where you run the application.
4242

4343
1. Sign into the Azure CLI, and optionally set your subscription if you have more than one connected to your login credentials.
4444

@@ -56,11 +56,32 @@ Follow these steps to create an Azure Database for Postgres Single Server in you
5656
az group create --name $RESOURCE_GROUP --location $LOCATION
5757
```
5858

59-
1. Create an Azure Postgres Database server. The server is created with an administrator account, but it won't be used as we'll use the Azure Active Directory (Azure AD) admin account to perform administrative tasks.
59+
1. Create an Azure Postgres Database server. The server is created with an administrator account, but it won't be used because we'll use the Azure Active Directory (Azure AD) admin account to perform administrative tasks.
60+
61+
### [Flexible Server](#tab/flexible)
62+
63+
```azurecli-interactive
64+
POSTGRESQL_ADMIN_USER=azureuser
65+
# PostgreSQL admin access rights won't be used because Azure AD authentication is leveraged to administer the database.
66+
POSTGRESQL_ADMIN_PASSWORD=<admin-password>
67+
POSTGRESQL_HOST=<postgresql-host-name>
68+
69+
# Create a PostgreSQL server.
70+
az postgres flexible-server create \
71+
--resource-group $RESOURCE_GROUP \
72+
--name $POSTGRESQL_HOST \
73+
--location $LOCATION \
74+
--admin-user $POSTGRESQL_ADMIN_USER \
75+
--admin-password $POSTGRESQL_ADMIN_PASSWORD \
76+
--public-network-access 0.0.0.0 \
77+
--sku-name Standard_D2s_v3
78+
```
79+
80+
### [Single Server](#tab/single)
6081

6182
```azurecli-interactive
6283
POSTGRESQL_ADMIN_USER=azureuser
63-
# PostgreSQL admin access rights won't be used as Azure AD authentication is leveraged to administer the database.
84+
# PostgreSQL admin access rights won't be used because Azure AD authentication is leveraged to administer the database.
6485
POSTGRESQL_ADMIN_PASSWORD=<admin-password>
6586
POSTGRESQL_HOST=<postgresql-host-name>
6687
@@ -77,6 +98,19 @@ Follow these steps to create an Azure Database for Postgres Single Server in you
7798

7899
1. Create a database for the application.
79100

101+
### [Flexible Server](#tab/flexible)
102+
103+
```azurecli-interactive
104+
DATABASE_NAME=checklist
105+
106+
az postgres flexible-server db create \
107+
--resource-group $RESOURCE_GROUP \
108+
--server-name $POSTGRESQL_HOST \
109+
--database-name $DATABASE_NAME
110+
```
111+
112+
### [Single Server](#tab/single)
113+
80114
```azurecli-interactive
81115
DATABASE_NAME=checklist
82116
@@ -90,17 +124,17 @@ Follow these steps to create an Azure Database for Postgres Single Server in you
90124

91125
Follow these steps to build a WAR file and deploy to Azure App Service on Tomcat using a WAR packaging.
92126

93-
The changes you made in *application.properties* also apply to the managed identity, so the only thing to do is to remove the existing application settings in App Service.
94-
95-
1. The sample app contains a *pom-war.xml* file that can generate the WAR file. Run the following command to build the app.
127+
1. The sample app contains a *pom.xml* file that can generate the WAR file. Run the following command to build the app.
96128

97129
```bash
98-
mvn clean package -f pom-war.xml
130+
mvn clean package -f pom.xml
99131
```
100132

101133
1. Create an Azure App Service resource on Linux using Tomcat 9.0.
102134

103135
```azurecli-interactive
136+
APPSERVICE_PLAN=<app-service-plan>
137+
APPSERVICE_NAME=<app-service-name>
104138
# Create an App Service plan
105139
az appservice plan create \
106140
--resource-group $RESOURCE_GROUP \
@@ -129,7 +163,25 @@ The changes you made in *application.properties* also apply to the managed ident
129163

130164
## Connect Postgres Database with identity connectivity
131165

132-
Next, connect your app to an Postgres Database Single Server with a system-assigned managed identity using Service Connector. To do this, run the [az webapp connection create](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres) command.
166+
Next, connect your app to a Postgres Database with a system-assigned managed identity using Service Connector.
167+
168+
### [Flexible Server](#tab/flexible)
169+
170+
To do this, run the [az webapp connection create](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres-flexible) command.
171+
172+
```azurecli-interactive
173+
az webapp connection create postgres-flexible \
174+
--resource-group $RESOURCE_GROUP \
175+
--name $APPSERVICE_NAME \
176+
--target-resource-group $RESOURCE_GROUP \
177+
--server $POSTGRESQL_HOST \
178+
--database $DATABASE_NAME \
179+
--system-identity
180+
```
181+
182+
### [Single Server](#tab/single)
183+
184+
To do this, run the [az webapp connection create](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres) command.
133185

134186
```azurecli-interactive
135187
az webapp connection create postgres \
@@ -141,6 +193,7 @@ az webapp connection create postgres \
141193
--system-identity
142194
```
143195

196+
---
144197
This command creates a connection between your web app and your PostgreSQL server, and manages authentication through a system-assigned managed identity.
145198

146199
## View sample web app

articles/container-apps/tutorial-java-quarkus-connect-managed-identity-postgresql-database.md

Lines changed: 117 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ The following example creates a resource group named `myResourceGroup` in the Ea
4545
az group create --name myResourceGroup --location eastus
4646
```
4747

48-
Create an Azure container registry instance using the [az acr create](/cli/azure/acr#az-acr-create) command. The registry name must be unique within Azure, and contain 5-50 alphanumeric characters. In the following example, `myContainerRegistry007` is used. Update this to a unique value.
48+
Create an Azure container registry instance using the [az acr create](/cli/azure/acr#az-acr-create) command. The registry name must be unique within Azure, contain 5-50 alphanumeric characters. All letters must be specified in lower case. In the following example, `mycontainerregistry007` is used. Update this to a unique value.
4949

5050
```azurecli
5151
az acr create \
5252
--resource-group myResourceGroup \
53-
--name myContainerRegistry007 \
53+
--name mycontainerregistry007 \
5454
--sku Basic
5555
```
5656

@@ -83,6 +83,69 @@ cd quarkus-quickstarts/hibernate-orm-panache-quickstart
8383

8484
Delete the existing content in *application.properties* and replace with the following to configure the database for dev, test, and production modes:
8585

86+
### [Flexible Server](#tab/flexible)
87+
88+
```properties
89+
quarkus.package.type=uber-jar
90+
91+
quarkus.hibernate-orm.database.generation=drop-and-create
92+
quarkus.datasource.db-kind=postgresql
93+
quarkus.datasource.jdbc.max-size=8
94+
quarkus.datasource.jdbc.min-size=2
95+
quarkus.hibernate-orm.log.sql=true
96+
quarkus.hibernate-orm.sql-load-script=import.sql
97+
quarkus.datasource.jdbc.acquisition-timeout = 10
98+
99+
%dev.quarkus.datasource.username=${AZURE_CLIENT_NAME}
100+
%dev.quarkus.datasource.jdbc.url=jdbc:postgresql://${DBHOST}.postgres.database.azure.com:5432/${DBNAME}?\
101+
authenticationPluginClassName=com.azure.identity.providers.postgresql.AzureIdentityPostgresqlAuthenticationPlugin\
102+
&sslmode=require\
103+
&azure.clientId=${AZURE_CLIENT_ID}\
104+
&azure.clientSecret=${AZURE_CLIENT_SECRET}\
105+
&azure.tenantId=${AZURE_TENANT_ID}
106+
107+
%prod.quarkus.datasource.username=${AZURE_MI_NAME}
108+
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://${DBHOST}.postgres.database.azure.com:5432/${DBNAME}?\
109+
authenticationPluginClassName=com.azure.identity.providers.postgresql.AzureIdentityPostgresqlAuthenticationPlugin\
110+
&sslmode=require
111+
112+
%dev.quarkus.class-loading.parent-first-artifacts=com.azure:azure-core::jar,\
113+
com.azure:azure-core-http-netty::jar,\
114+
io.projectreactor.netty:reactor-netty-core::jar,\
115+
io.projectreactor.netty:reactor-netty-http::jar,\
116+
io.netty:netty-resolver-dns::jar,\
117+
io.netty:netty-codec::jar,\
118+
io.netty:netty-codec-http::jar,\
119+
io.netty:netty-codec-http2::jar,\
120+
io.netty:netty-handler::jar,\
121+
io.netty:netty-resolver::jar,\
122+
io.netty:netty-common::jar,\
123+
io.netty:netty-transport::jar,\
124+
io.netty:netty-buffer::jar,\
125+
com.azure:azure-identity::jar,\
126+
com.azure:azure-identity-providers-core::jar,\
127+
com.azure:azure-identity-providers-jdbc-postgresql::jar,\
128+
com.fasterxml.jackson.core:jackson-core::jar,\
129+
com.fasterxml.jackson.core:jackson-annotations::jar,\
130+
com.fasterxml.jackson.core:jackson-databind::jar,\
131+
com.fasterxml.jackson.dataformat:jackson-dataformat-xml::jar,\
132+
com.fasterxml.jackson.datatype:jackson-datatype-jsr310::jar,\
133+
org.reactivestreams:reactive-streams::jar,\
134+
io.projectreactor:reactor-core::jar,\
135+
com.microsoft.azure:msal4j::jar,\
136+
com.microsoft.azure:msal4j-persistence-extension::jar,\
137+
org.codehaus.woodstox:stax2-api::jar,\
138+
com.fasterxml.woodstox:woodstox-core::jar,\
139+
com.nimbusds:oauth2-oidc-sdk::jar,\
140+
com.nimbusds:content-type::jar,\
141+
com.nimbusds:nimbus-jose-jwt::jar,\
142+
net.minidev:json-smart::jar,\
143+
net.minidev:accessors-smart::jar,\
144+
io.netty:netty-transport-native-unix-common::jar
145+
```
146+
147+
### [Single Server](#tab/single)
148+
86149
```properties
87150
quarkus.package.type=uber-jar
88151

@@ -146,11 +209,11 @@ cd quarkus-quickstarts/hibernate-orm-panache-quickstart
146209

147210
1. Build the container image.
148211

149-
Run the following command to build the Quarkus app image. You must tag it with the fully qualified name of your registry login server. The login server name is in the format *\<registry-name\>.azurecr.io* (must be all lowercase), for example, *myContainerRegistry007.azurecr.io*. Replace the name with your own registry name.
212+
Run the following command to build the Quarkus app image. You must tag it with the fully qualified name of your registry login server. The login server name is in the format *\<registry-name\>.azurecr.io* (must be all lowercase), for example, *mycontainerregistry007.azurecr.io*. Replace the name with your own registry name.
150213

151214
```bash
152215
mvnw quarkus:add-extension -Dextensions="container-image-jib"
153-
mvnw clean package -Pnative -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true -Dquarkus.container-image.registry=myContainerRegistry007 -Dquarkus.container-image.name=quarkus-postgres-passwordless-app -Dquarkus.container-image.tag=v1
216+
mvnw clean package -Pnative -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true -Dquarkus.container-image.registry=mycontainerregistry007 -Dquarkus.container-image.name=quarkus-postgres-passwordless-app -Dquarkus.container-image.tag=v1
154217
```
155218

156219
1. Log in to the registry.
@@ -165,10 +228,10 @@ cd quarkus-quickstarts/hibernate-orm-panache-quickstart
165228

166229
1. Push the image to the registry.
167230

168-
Use [docker push][docker-push] to push the image to the registry instance. Replace `myContainerRegistry007` with the login server name of your registry instance. This example creates the `quarkus-postgres-passwordless-app` repository, containing the `quarkus-postgres-passwordless-app:v1` image.
231+
Use [docker push][docker-push] to push the image to the registry instance. Replace `mycontainerregistry007` with the login server name of your registry instance. This example creates the `quarkus-postgres-passwordless-app` repository, containing the `quarkus-postgres-passwordless-app:v1` image.
169232

170233
```bash
171-
docker push myContainerRegistry007/quarkus-postgres-passwordless-app:v1
234+
docker push mycontainerregistry007/quarkus-postgres-passwordless-app:v1
172235
```
173236

174237
## 4. Create a Container App on Azure
@@ -190,7 +253,7 @@ cd quarkus-quickstarts/hibernate-orm-panache-quickstart
190253

191254
```azurecli
192255
CONTAINER_IMAGE_NAME=quarkus-postgres-passwordless-app:v1
193-
REGISTRY_SERVER=myContainerRegistry007
256+
REGISTRY_SERVER=mycontainerregistry007
194257
REGISTRY_USERNAME=<REGISTRY_USERNAME>
195258
REGISTRY_PASSWORD=<REGISTRY_PASSWORD>
196259
@@ -206,10 +269,28 @@ cd quarkus-quickstarts/hibernate-orm-panache-quickstart
206269

207270
## 5. Create and connect a PostgreSQL database with identity connectivity
208271

209-
Next, create a PostgreSQL Database Single Server and configure your container app to connect to a PostgreSQL Database with a system-assigned managed identity. The Quarkus app will connect to this database and store its data when running, persisting the application state no matter where you run the application.
272+
Next, create a PostgreSQL Database and configure your container app to connect to a PostgreSQL Database with a system-assigned managed identity. The Quarkus app will connect to this database and store its data when running, persisting the application state no matter where you run the application.
210273

211274
1. Create the database service.
212275

276+
### [Flexible Server](#tab/flexible)
277+
278+
```azurecli
279+
DB_SERVER_NAME='msdocs-quarkus-postgres-webapp-db'
280+
ADMIN_USERNAME='demoadmin'
281+
ADMIN_PASSWORD='<admin-password>'
282+
283+
az postgres flexible-server create \
284+
--resource-group $RESOURCE_GROUP \
285+
--name $DB_SERVER_NAME \
286+
--location $LOCATION \
287+
--admin-user $DB_USERNAME \
288+
--admin-password $DB_PASSWORD \
289+
--sku-name GP_Gen5_2
290+
```
291+
292+
### [Single Server](#tab/single)
293+
213294
```azurecli
214295
DB_SERVER_NAME='msdocs-quarkus-postgres-webapp-db'
215296
ADMIN_USERNAME='demoadmin'
@@ -224,6 +305,8 @@ Next, create a PostgreSQL Database Single Server and configure your container ap
224305
--sku-name GP_Gen5_2
225306
```
226307

308+
---
309+
227310
The following parameters are used in the above Azure CLI command:
228311

229312
* *resource-group* &rarr; Use the same resource group name in which you created the web app, for example `msdocs-quarkus-postgres-webapp-rg`.
@@ -240,6 +323,17 @@ Next, create a PostgreSQL Database Single Server and configure your container ap
240323

241324
1. Create a database named `fruits` within the PostgreSQL service with this command:
242325

326+
### [Flexible Server](#tab/flexible)
327+
328+
```azurecli
329+
az postgres flexible-server db create \
330+
--resource-group $RESOURCE_GROUP \
331+
--server-name $DB_SERVER_NAME \
332+
--database-name fruits
333+
```
334+
335+
### [Single Server](#tab/single)
336+
243337
```azurecli
244338
az postgres db create \
245339
--resource-group $RESOURCE_GROUP \
@@ -249,6 +343,20 @@ Next, create a PostgreSQL Database Single Server and configure your container ap
249343

250344
1. Connect the database to the container app with a system-assigned managed identity, using the connection command.
251345

346+
### [Flexible Server](#tab/flexible)
347+
348+
```azurecli
349+
az containerapp connection create postgres-flexible \
350+
--resource-group $RESOURCE_GROUP \
351+
--name my-container-app \
352+
--target-resource-group $RESOURCE_GROUP \
353+
--server $DB_SERVER_NAME \
354+
--database fruits \
355+
--managed-identity
356+
```
357+
358+
### [Single Server](#tab/single)
359+
252360
```azurecli
253361
az containerapp connection create postgres \
254362
--resource-group $RESOURCE_GROUP \
@@ -276,4 +384,4 @@ When the new webpage shows your list of fruits, your app is connecting to the da
276384
Learn more about running Java apps on Azure in the developer guide.
277385

278386
> [!div class="nextstepaction"]
279-
> [Azure for Java Developers](/java/azure/)
387+
> [Azure for Java Developers](/java/azure/)

articles/spring-apps/how-to-bind-postgres.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,36 @@ Use the following steps to bind your app.
7070
--secret name=$USERNAME secret=$PASSWORD
7171
```
7272

73-
### [Using a passwordless connection with a managed identity](#tab/Passwordless)
73+
### [Using a passwordless connection with a managed identity for flexible server](#tab/Passwordlessflex)
7474

75-
Configure Azure Spring Apps to connect to the PostgreSQL Database Single Server with a system-assigned managed identity using the `az spring connection create` command.
75+
Configure Azure Spring Apps to connect to the PostgreSQL Database with a system-assigned managed identity using the `az spring connection create` command.
76+
77+
```azurecli
78+
az spring connection create postgres-flexible \
79+
--resource-group $SPRING_APP_RESOURCE_GROUP \
80+
--service $Spring_APP_SERVICE_NAME \
81+
--app $APP_NAME \
82+
--deployment $DEPLOYMENT_NAME \
83+
--target-resource-group $POSTGRES_RESOURCE_GROUP \
84+
--server $POSTGRES_SERVER_NAME \
85+
--database $DATABASE_NAME \
86+
--system-identity
87+
```
88+
89+
### [Using a passwordless connection with a managed identity for single server](#tab/Passwordlesssingle)
90+
91+
Configure Azure Spring Apps to connect to the PostgreSQL Database with a system-assigned managed identity using the `az spring connection create` command.
7692

7793
```azurecli
7894
az spring connection create postgres \
7995
--resource-group $SPRING_APP_RESOURCE_GROUP \
8096
--service $Spring_APP_SERVICE_NAME \
81-
--app $APP_NAME --deployment $DEPLOYMENT_NAME \
97+
--app $APP_NAME \
98+
--deployment $DEPLOYMENT_NAME \
8299
--target-resource-group $POSTGRES_RESOURCE_GROUP \
83100
--server $POSTGRES_SERVER_NAME \
84101
--database $DATABASE_NAME \
85-
--system-assigned-identity
102+
--system-identity
86103
```
87104

88105
---

0 commit comments

Comments
 (0)