Azure / CloudShell

Container Image for Azure Cloud Shell (https://azure.microsoft.com/en-us/features/cloud-shell/)
https://shell.azure.com
MIT License
251 stars 103 forks source link

[BUG] psql cli on web fails when FSPG with AAD is used #440

Open srdjanrilak-ms opened 2 months ago

srdjanrilak-ms commented 2 months ago

To Reproduce

If one creates an instance of PostgreSQL service (FSPG) with AAD enabled and tries to connect to it on Portal using bash as a shell and AAD login, the console will show an error and psql will not be connected.

It looks like the bash command for psql does not use escape characters correctly.

The generated command fails, but if I run very similar one with different escaping, it works. Screenshot shows the command that fails. The one that works is following psql "host=entera-test-2.postgres.database.azure.com port=5432 dbname=postgres user=srdjanrilak@microsoft.com password='$(az account get-access-token --resource-type oss-rdbms --output tsv --query accessToken)' sslmode=require"

image

Observed Behavior

Already described in the previous section.

Expected behavior

The psql tool should be connected to the database on the startup.

Is this specific to Cloud Shell?

Running the correct command outside the cloud shell works fine.

Interface information

I access cloud shell with Edge browser on Windows Server 2022. Used bash on web.

mbifeld commented 2 months ago

@surajssd Could this be connected to the mysql installing the server version rather than client version? Unlikely but surprised we're not seeing issues for escape characters not working outside of psql

surajssd commented 1 month ago

So this issue was before we removed the mysql package.

Also I think this can be broken down into two steps to see if it works:

export PS_PASS="$(az account get-access-token --resource-type oss-rdbms --output tsv --query accessToken)"
psql "host=entera-test-2.postgres.database.azure.com port=5432 dbname=postgres user=srdjanrilak@microsoft.com password=${PS_PASS} sslmode=require"

My hunch is that the sub-query which gets password is not being evaluated but is getting interpreted as a string.

mbifeld commented 1 month ago

@srdjanrilak-ms has the above recommendation worked for you?