kndndrj / nvim-dbee

Interactive database client for neovim
GNU General Public License v3.0
710 stars 48 forks source link

How do I add connections with secure secrets? #2

Closed cseickel closed 1 year ago

cseickel commented 1 year ago

This is kind of 3 parter:

  1. It's not clear how to add connections. I see from the help file that you can add connections from the setup config, I think that should be prominently displayed on the README because it's the first thing a new user will need to do.
  2. It would be really great if we could add connections interactively while it is running, with a user command and/or buffer local mapping on the sidebar.
  3. I don't see any way that I can configure a connection without storing the password in plain text.

It would be ideal if it could pull a password from pass on linux, and/or read them from environment variables. I use doppler a lot at work, so it would be convenient for me to just configure connections using environment variable substitution and then I can run nvim with doppler to get those variables. for example:

  connections = {
        -- example:
        -- {
        --   name = "example-pg",
        --   type = "postgres",
        --   url = "postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}",
        -- },

or maybe if you just have your own internal way of specifying placeholders for secrets, you can then add a separate section for secrets, like:

  connections = {
         example:
         {
           name = "example-pg",
           type = "postgres",
           url = "postgres://{{SECRET_USER}}:{{SECRET_PASSWORD}}host:5432/mydb",
           secrets: {
             user: { source="env", key="WORK_DB_USER" }, -- pull from environment variables
             password: { source="pass", key="work_db_password" } -- pull from `pass`
           }
         },
kndndrj commented 1 year ago

Hi @cseickel, thanks for the suggestions. All are valid points in my opinion.

  1. and 2. are pretty straight forward, whereas 3. would need a bit of thinking.

To add on top of 3.:

That's an approximate TODO for this issue, I would love to hear your thoughts about it.

Other than that I'll start working on that as soon as I have some extra time.

cseickel commented 1 year ago

I think we go with the first syntax option you mentioned (${{}}) and just inject env vars once connecting to the db. That would probably be enough for now.

I agree that seems like the simplest way to go about it, and users can do a lot to roll their own solutions that inject env variables. One thing that may trip you up there is if you are checking the variables from an external (go) process, will it see the same env variables that are in nvim's process? If not then it might not work out.

For # 3, on further thought it would probably be a maintenance nightmare. It might be simpler to just integrate your own secret storage with an encrypted file. I'm sure there are go libraries you can use, and the input could just be an interactive prompt if the password was not set in the config.

kndndrj commented 1 year ago

One thing that may trip you up there is if you are checking the variables from an external (go) process, will it see the same env variables that are in nvim's process? If not then it might not work out.

I thought about that, yeah - one can also have a plugin that messes with vim.env jn lua - so we would need to read env in lua in my opinion - I'd still like to test go first - it might even work.

I also thought about an encrypted file - sounds like a good Idea to me!

kndndrj commented 1 year ago

Hey, @cseickel I implemented some functionality we discussed here in this PR: #9.

I would appreciate if you look at it / try it out / give any kind of feedback whatsoever.

Thanks :D

kndndrj commented 1 year ago

closed with #9