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

belt is failing when special characters exist in password #440

Closed
Charmatzis opened this issue Apr 8, 2024 · 2 comments · Fixed by #441 or #442
Closed

belt is failing when special characters exist in password #440

Charmatzis opened this issue Apr 8, 2024 · 2 comments · Fixed by #441 or #442

Comments

@Charmatzis
Copy link

When in the config file include special characters in the password like # then the belt commands fail with the message

...
  File "/usr/local/lib/python3.11/site-packages/asyncpg/connect_utils.py", line 229, in _parse_hostlist
    hostlist_ports.append(int(hostspec_port))
                          ^^^^^^^^^^^^^^^^^^

ValueError: invalid literal for int() with base 10: 'h'

I tried to escape special characters e.g replacing # with h%23A in config file.
Then commands like belt setup or belt check-pkeys works...

But when we try to do
belt setup
fails with the message

Exception: Couldn't do ['psql', 'hostaddr=xx.x.xx.xxx port=5432 dbname=SOME_DB user=someuser password=h%23A', '-f', 'schemas/some-instance/some-cluster/no_invalid_constraints.sql'], got code 2.
  out: 
  err: psql: error: connection to server at "xx.x.xx.xxx", port 5432 failed: FATAL:  password authentication failed for user "someuser"
connection to server at "xx.x.xx.xxx", port 5432 failed: FATAL:  no pg_hba.conf entry for host "xx.x.xx.xx", user "someuser", database "SOME_DB", no encryption

Which means it tries to pass the password that has escaped the special characters.

@vjeeva
Copy link
Contributor

vjeeva commented Apr 8, 2024

Thanks for filing this issue @Charmatzis! Looks like it's a documented problem with asyncpg and how it consumes URIs for connections. encode/databases#145

Thankfully, the last comment in the issue shows how to work around the issue (using urllib.parse.quote). I've confirmed the issue is fixed in our integration testing, fixed it for all password rendering, and a release will be cut shortly!

Thanks for filing this issue and thanks for using our tool! We hope you are finding it useful!

@Charmatzis
Copy link
Author

@vjeeva I think still the have this issue with special characters.
If the password contains \ the config,json file breaks.
If we try to escape it by changing to \\ it fails the process until it is reached the step to execute using psql to apply the no_invalid_constraints_no_indexes.sql, because the password is different than the original one

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