Skip to content

Commit b98bae9

Browse files
authored
Merge pull request #85 from Azure-Samples/add-entra-auth
Docs on entra auth for pgadmin
2 parents 64a4c37 + 050ce2e commit b98bae9

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

docs/images/screenshot_pgadmin.png

185 KB
Loading

docs/using_entra_auth.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
To follow security best practices, this project is setup to use passwordless authentication with the Azure Database for PostgreSQL Flexible Server. This means that you can't connect to the database with a password, but instead need to use a token associated with a Microsoft Entra user. Locally, the user should be your own Azure account, whichever account was used to run `azd up`. In production, the user will be the managed identity assigned to the Azure Container App.
44

5-
## Using psql with Entra auth
5+
* [Using Entra auth with psql](#using-entra-auth-with-psql)
6+
* [Using Entra auth with pgAdmin](#using-entra-auth-with-pgadmin)
7+
8+
## Using Entra auth with psql
69

710
1. Make sure you are logged into the Azure Developer CLI with the same account that was used to run `azd up`.
811

@@ -45,3 +48,59 @@ To follow security best practices, this project is setup to use passwordless aut
4548
```
4649

4750
5. In psql, use `\d` to list the tables. When you `SELECT` from a table, select only the columns you're interested in, to avoid rendering the vector embeddings in the terminal.
51+
52+
## Using Entra auth with pgAdmin
53+
54+
1. Make sure you are logged into the Azure Developer CLI with the same account that was used to run `azd up`.
55+
56+
```shell
57+
azd auth login
58+
```
59+
60+
If you used a non-default tenant to run `azd up`, you may need to specify the tenant ID:
61+
62+
```shell
63+
azd auth login --tenant-id {tenant_id}
64+
```
65+
66+
2. Generate a token for the Azure Database for PostgreSQL Flexible Server.
67+
68+
```shell
69+
azd auth token --scope https://ossrdbms-aad.database.windows.net/.default --output json
70+
```
71+
72+
Once again, if you used a non-default tenant to run `azd up`, you may need to specify the tenant ID.
73+
74+
```shell
75+
azd auth token --scope https://ossrdbms-aad.database.windows.net/.default --tenant-id YOUR-TENANT-ID --output json
76+
```
77+
78+
This will output JSON with a token inside the "token" field. Copy the token.
79+
80+
3. Open pgAdmin and create a new server connection.
81+
82+
4. In the "General" tab, set the name to something memorable like "RAG PostgreSQL server".
83+
84+
5. In the "Connection" tab, set the host to the `POSTGRES_HOST` value from the current `azd` environment. Run:
85+
86+
```shell
87+
azd env get-value POSTGRES_HOST
88+
```
89+
90+
6. Set the database to the `POSTGRES_DATABASE` value from the current `azd` environment. Run:
91+
92+
```shell
93+
azd env get-value POSTGRES_DATABASE
94+
```
95+
96+
7. Set the username to the `POSTGRES_USERNAME` value from the current `azd` environment. Run:
97+
98+
```shell
99+
azd env get-value POSTGRES_USERNAME
100+
```
101+
102+
8. Set the password to the token you generated in step 2. You will need to refresh that password with a new token periodically (every few hours).
103+
104+
9. Now you should be able to connect to the database and view the tables and data.
105+
106+
![Screenshot of pgAdmin showing the tables in the database](images/screenshot_pgadmin.png)

0 commit comments

Comments
 (0)