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

Hide command line passwords from ps #355

Closed
joewalnes opened this issue Sep 17, 2015 · 5 comments
Closed

Hide command line passwords from ps #355

joewalnes opened this issue Sep 17, 2015 · 5 comments

Comments

@joewalnes
Copy link

It's super convenient to be able to run pgcli like this:

$ pgcli 'host=somehost user=someuser password=somepassword'
# or
$ pgcli postgresql://someuser:somepassword@somehost

However, it enables other users on the same system to see the password by running ps, top, etc.

Some other clients (like the regular mysql client) have a cunning way to hide this: http://unix.stackexchange.com/questions/88665/how-does-ps-know-to-hide-passwords

And there's a Python package that wraps this up to make it easy: https://github.com/dvarrazzo/py-setproctitle

Although neither of these are foolproof (there's a timing attack due to a small window of opportunity between the process being started and the args being modified), it can help reduce the attack vector.

@amjith
Copy link
Member

amjith commented Sep 18, 2015

Looks like you have a great solution to this. Would you be willing to take a stab at it and send a PR? I'll be happy to help in anyway possible.

@joewalnes
Copy link
Author

Sure! Looking at the code, I see two options for implementing this:

  • Option 1: In the main cli() function, read sys.argv and look for anything that looks like a connection string in the entire cmd line, and hide it. This is the quickest solution.
  • Option 2: Maybe this actual arg hiding should go inside the click library. Something like @click.argument('database', obscure=lambda arg: do_something(arg), ...). This will be useful to more people.

Thoughts?

@amjith
Copy link
Member

amjith commented Sep 20, 2015

That's a good observation. I think solution 1 is good for the short term and file an issue with click for the longer term solution.

You're right it'll be useful for others.

@jayzeng
Copy link
Contributor

jayzeng commented Sep 20, 2015

👍 on the feature, I (personally) don't see the need to make it a cli argument.

@amjith
Copy link
Member

amjith commented Nov 1, 2015

Fix released in 0.20.0.

Please upgrade:

pip install -U pgcli

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