Skip to content

Commit b6796ab

Browse files
Merge pull request #250183 from xfz11/svc/postgres
{Service Connector}update postgresql passwordless tutorial
2 parents 8a21b49 + 1d52a3e commit b6796ab

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

articles/service-connector/includes/code-postgres-aad.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ For more information, see the following resources:
4444

4545
### [Spring](#tab/spring)
4646

47-
For a Spring application, if you create a connection with option `--client-type springboot`, Service Connector will set the properties `spring.datasource.azure.passwordless-enabled`, `spring.datasource.url`, and `spring.datasource.username` to Azure Spring Apps.
47+
For a Spring application, if you create a connection with option `--client-type springboot`, Service Connector sets the properties `spring.datasource.azure.passwordless-enabled`, `spring.datasource.url`, and `spring.datasource.username` to Azure Spring Apps.
4848

4949
Update your application following the tutorial [Bind an Azure Database for PostgreSQL to your application in Azure Spring Apps](../../spring-apps/how-to-bind-postgres.md#prepare-your-project). Remember to remove the `spring.datasource.password` configuration property if it was set before and add the correct dependencies,
5050

@@ -100,3 +100,21 @@ For other languages, you can use the connection string and username that Service
100100

101101
For more code samples, see [Connect to Azure databases from App Service without secrets using a managed identity](/azure/app-service/tutorial-connect-msi-azure-database?tabs=postgresql#3-modify-your-code).
102102

103+
104+
---
105+
106+
Next, if you have created tables and sequences in PostgreSQL flexible server, you need to connect as database owner and grant permission to `aad username` that's created by Service Connector. Get the user name from connection string or configuration set by Service Connector, it should look like `aad_<connection name>`. If you use Portal, click the expand button next to `Service Type` column and get the value. If you use Azure CLI, check `configurations` in output of CLI command.
107+
108+
Then, execute the query to grant permission
109+
110+
```azure-cli
111+
az extension add --name rdbms-connect
112+
113+
az postgres flexible-server execute -n <postgres server name> -u <owner username> -p "<owner password>" -d <database> --querytext "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO \"<aad username>\";GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO \"<aad username>\";"
114+
```
115+
The `<owner username>` and `<owner password>` is the owner of existing table that can grant permission to others. `<aad username>` is the user created by Service Connector. Replace them with the actual value.
116+
117+
You can validate the result with the command:
118+
```azure-cli
119+
az postgres flexible-server execute -n <postgres server name> -u <owner username> -p "<owner password>" -d <database> --querytext "SELECT distinct(table_name) FROM information_schema.table_privileges WHERE grantee='<aad username>' AND table_schema='public';" --output table
120+
```

0 commit comments

Comments
 (0)