Skip to content

Commit 64a4c37

Browse files
authored
Merge pull request #84 from Azure-Samples/add-entra-auth
Add entra auth
2 parents cf7e799 + 8c565c2 commit 64a4c37

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

.github/workflows/app-tests.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@ name: App Tests
33
on:
44
push:
55
branches: [ main ]
6+
paths-ignore:
7+
- "**.md"
8+
- ".azdo/**"
9+
- ".devcontainer/**"
10+
- ".github/**"
611
pull_request:
712
branches: [ main ]
13+
paths-ignore:
14+
- "**.md"
15+
- ".azdo/**"
16+
- ".devcontainer/**"
17+
- ".github/**"
818
workflow_dispatch:
919

1020
permissions:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Further documentation is available in the `docs/` folder:
204204
* [Understanding the RAG flow](docs/rag_flow.md)
205205
* [Customizing the data](docs/customize_data.md)
206206
* [Deploying with existing resources](docs/deploy_existing.md)
207+
* [Using Entra auth with PostgreSQL tools](docs/using_entra_auth.md)
207208
* [Monitoring with Azure Monitor](docs/monitoring.md)
208209
* [Load testing](docs/loadtesting.md)
209210

docs/using_entra_auth.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Using Entra auth with PostgreSQL tools
2+
3+
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.
4+
5+
## Using psql with Entra auth
6+
7+
1. Make sure you are logged into the Azure Developer CLI with the same account that was used to run `azd up`.
8+
9+
```shell
10+
azd auth login
11+
```
12+
13+
If you used a non-default tenant to run `azd up`, you may need to specify the tenant ID:
14+
15+
```shell
16+
azd auth login --tenant-id {tenant_id}
17+
```
18+
19+
2. Generate a token for the Azure Database for PostgreSQL Flexible Server.
20+
21+
```shell
22+
azd auth token --scope https://ossrdbms-aad.database.windows.net/.default --output json
23+
```
24+
25+
Once again, if you used a non-default tenant to run `azd up`, you may need to specify the tenant ID.
26+
27+
```shell
28+
azd auth token --scope https://ossrdbms-aad.database.windows.net/.default --tenant-id YOUR-TENANT-ID --output json
29+
```
30+
31+
This will output JSON with a token inside the "token" field. Copy the token.
32+
33+
3. Set the `PGPASSWORD` environment variable to the token.
34+
35+
```shell
36+
export PGPASSWORD={token}
37+
```
38+
39+
If you are using a different shell, you may need to use a different syntax to set the environment variable.
40+
41+
4. Connect to the database with `psql`, using the `POSTGRES_HOST`, `POSTGRES_USERNAME`, and `POSTGRES_DATABASE` values from the current `azd` environment.
42+
43+
```shell
44+
psql -h $(azd env get-value POSTGRES_HOST) -U $(azd env get-value POSTGRES_USERNAME) -d $(azd env get-value POSTGRES_DATABASE) -p 5432
45+
```
46+
47+
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.

0 commit comments

Comments
 (0)