Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid DNS due to spaces in logged in username #6

Closed
alexparadigm5416 opened this issue Jun 20, 2024 · 1 comment
Closed

Invalid DNS due to spaces in logged in username #6

alexparadigm5416 opened this issue Jun 20, 2024 · 1 comment

Comments

@alexparadigm5416
Copy link

alexparadigm5416 commented Jun 20, 2024

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
  1. Observe the error: cli.azure.cli.core.azclierror: Fail to connect to postgresql. invalid dsn: missing "=" after "Team" in connection info string
  2. 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)
  3. Repeat steps 1 and 2
  4. Observe that the connection was created without errors
@brycechen1849
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants