Azure / ServiceConnector

Questions, feedback and samples for Service Connector service.
MIT License
1 stars 3 forks source link

Invalid DNS due to spaces in logged in username #6

Closed alexparadigm5416 closed 2 days ago

alexparadigm5416 commented 2 weeks ago

Extension and version: serviceconnector-passwordless v2.0.3

What is the command being used: az webapp connection create postgres-flexible

What is the error: cli.azext_serviceconnector_passwordless._credential_free: Fail to connect to postgresql. invalid dsn: missing "=" after "Team" in connection info string

Why is this happening: The logged in service principal is named "Some Team Pipeline SPN", because the user name is not properly quoted when passed as part of the connection string in _credential_free.py at line 830, when it tries to connect using conn = psycopg2.connect(conn_string) at line 798, it does not know how to parse the connection string.

Reproduction Steps:

  1. Run: az login --service-principal --username "$azlogin" --password "$clientDeploySecret" --tenant "$tenantId" where azlogin is the client id of a service principal with the username "Some Team Pipeline" or equivalent. The important part is the spaces
  2. Run:
    az webapp connection create postgres-flexible \
    --connection $dbConnectionName \
    --resource-group $resourceGroupName \
    --subscription $deploySubscription \
    --name $apiName \
    --target-resource-group $resourceGroupName \
    --server $dbServer \
    --database $dbName \
    --user-identity client-id=$identityId subs-id=$deploySubscription \
    --client-type java \
    --yes
  3. Observe the error: cli.azure.cli.core.azclierror: Fail to connect to postgresql. invalid dsn: missing "=" after "Team" in connection info string
  4. Go to the _credential_free.py located at /root/.azure/cliextensions/serviceconnector-passwordless/azext_serviceconnector_passwordless/_credential_free.py and modify the get_connection_string function to wrap the username in singlequotes. IE: conn_string = "host={} user='{}' dbname=postgres password={} sslmode=require".format(self.host, self.admin_username, password)
  5. Repeat steps 1 and 2
  6. Observe that the connection was created without errors
brycechen1849 commented 1 week ago

Thanks @alexparadigm5416 for feedback. We are looking into the issue.