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

Unable to connect using password with special characters #232

Closed
german-muzquiz opened this issue May 13, 2024 · 15 comments
Closed

Unable to connect using password with special characters #232

german-muzquiz opened this issue May 13, 2024 · 15 comments
Labels
bug Something isn't working

Comments

@german-muzquiz
Copy link

I'm unable to establish a connection to a postgres database hosted in AWS RDS that has the special character $ as part of the password. The error I'm getting is ...The password that was provided for the role postgres is wrong....

I tried escaping the $ symbol using %24 with no success, and I'm able to establish the connection using raw vim-dadbod with the escaped password.

The url that I'm using is postgresql://postgres:[REDACTED]@127.0.0.1:5432

@kristijanhusak
Copy link
Owner

Does it happen only with AWS RDS or also with a local database?
How are you adding a connection, through the "Add connections", env variable, vim variable, or something else?
It works for me locally when I connect to a docker db.

Is the URL you provided just an example how the URL looks? It points to localhost, and you are mentioning that there is an issue with RDS.

@german-muzquiz
Copy link
Author

  • It also happens with a local database launched with docker
  • I'm adding the connection through the "Add connections" option in the sidebar
  • The url is exactly what I use besides the actual password, I'm opening a local SSH tunnel to connect to the target AWS RDS postgres instance because it runs in a private subnet
  • The special characters in the password are $ and also +, vim-dadbod works by escaping only $

I'm just starting with the plugin so I didn't know there were other means for providing the connection, I'll take a look to see if those work

@kristijanhusak
Copy link
Owner

I'm assuming that SSH tunnel is the issue. Did you try using https://github.com/pbogut/vim-dadbod-ssh ?

@german-muzquiz
Copy link
Author

Actually I use AWS session manager to establish the tunnel because the bastion server is not public, so is not an actual SSH connection but rather a command like this:

aws ssm start-session --target ${INSTANCE_ID} --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters "{\"portNumber\":[\"${PORT}\"],\"localPortNumber\":[\"${L_PORT}\"],\"host\":[\"${HOST}\"]}"

However I wonder why it also fails for local postgres launched with docker

@kristijanhusak
Copy link
Owner

Does everything work locally or on RDS when there is no $ in the password?
Also, what system are you using?

@german-muzquiz
Copy link
Author

Confirmed that it works locally when there is no $ in the password. I cannot change the RDS password though.

Vim version:

~/code % vim --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Apr 18 2024 20:05:12)
macOS version - arm64
Included patches: 1-350
Compiled by Homebrew

@kristijanhusak
Copy link
Owner

Can you try applying this patch to your local vim-dadbod-ui installation and try it again?

diff --git a/autoload/db_ui.vim b/autoload/db_ui.vim
index d944db7..419fd29 100644
--- a/autoload/db_ui.vim
+++ b/autoload/db_ui.vim
@@ -422,7 +422,7 @@ endfunction
 " we don't want to do.
 function db_ui#resolve(url) abort
   let parsed_url = db#url#parse(a:url)
-  let ignored_resolve_schemes = ['ssh']
+  let ignored_resolve_schemes = ['ssh', 'postgres', 'postgresql']
 
   if index(ignored_resolve_schemes, get(parsed_url, 'scheme', '')) > -1
     return a:url

If you added a connection through "Add connection", delete and re-add it.

@german-muzquiz
Copy link
Author

Cool, after adding that patch I was able to connect using the escaped password with $

@kristijanhusak kristijanhusak added the bug Something isn't working label May 14, 2024
@kristijanhusak
Copy link
Owner

Ok, thanks for testing it. I'll fix it and let you know to give it another test.

@kristijanhusak
Copy link
Owner

I pushed a change to master. Can you pull latest changes and see if it works?

@wstewarttennes
Copy link

wstewarttennes commented May 14, 2024

@kristijanhusak I am experiencing this issue as well with a # in the DB connection string -- I'm on the most recent pull and it's giving me this when running :DBUI:

Error executing Lua callback: .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: function db_ui#open[1]..<SNR>55_init[2]..4[25]..6[10]..7[35]..
17, line 6: Vim(if):E716: Key not present in Dictionary: "path !=? '/'"

@kristijanhusak
Copy link
Owner

@wstewarttennes in which part of db connection string? Did it work before this change? Does vim-dadbod directly work?

@wstewarttennes
Copy link

@kristijanhusak thanks for the quick reply, in the password field -- I have solved this by using %23 instead of the # symbol in the password string (this can fixed for other special characters in a similar matter). I believe this is also present in vim-dadbod directly (I was able to reproduce error using the :DB command). See this issue: tpope/vim-dadbod#103

@german-muzquiz
Copy link
Author

I confirm that the issue was fixed in the latest pull.

@kristijanhusak
Copy link
Owner

Ok great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants