Skip to content

Commit

Permalink
Don't provide the password with dbconsole unless explicitly opted in.
Browse files Browse the repository at this point in the history
Some operating system configurations allow other users to view your process list
or environmental variables.  This option should not be used on shared hosts.

http://dev.mysql.com/doc/refman/5.0/en/password-security.html
http://www.postgresql.org/docs/8.3/static/libpq-envars.html
  • Loading branch information
NZKoz committed May 31, 2008
1 parent 4e4bcb4 commit 0abf0da
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions railties/lib/commands/dbconsole.rb
Expand Up @@ -2,8 +2,13 @@
require 'yaml'
require 'optparse'

include_password = false

OptionParser.new do |opt|
opt.banner = "Usage: dbconsole [environment]"
opt.banner = "Usage: dbconsole [options] [environment]"
opt.on("-p", "--include-password", "Automatically provide the database from database.yml") do |v|
include_password = true
end
opt.parse!(ARGV)
abort opt.to_s unless (0..1).include?(ARGV.size)
end
Expand Down Expand Up @@ -31,10 +36,13 @@ def find_cmd(*commands)
'port' => '--port',
'socket' => '--socket',
'username' => '--user',
'password' => '--password',
'encoding' => '--default-character-set'
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact

if config['password'] && include_password
args << "--password=#{config['password']}"
end

args << config['database']

exec(find_cmd('mysql5', 'mysql'), *args)
Expand All @@ -43,7 +51,7 @@ def find_cmd(*commands)
ENV['PGUSER'] = config["username"] if config["username"]
ENV['PGHOST'] = config["host"] if config["host"]
ENV['PGPORT'] = config["port"].to_s if config["port"]
ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
ENV['PGPASSWORD'] = config["password"].to_s if config["password"] && include_password
exec(find_cmd('psql'), config["database"])

when "sqlite"
Expand Down

3 comments on commit 0abf0da

@drothlis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage string should read “Automatically provide the password from database.yml”

@drothlis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Usage string fixed on docrails:
http://github.com/lifo/docrails/commit/43334d63844da05f2cde53c4f77c829e582163be )

@akostadinov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is wrong to disable automatically providing of password. Instead the way password is provided might be fixed by using a properly protected temporary options file given the issue is env variables and command line arguments.

$ man mysql
...
           You can use an option file to avoid giving the password
           on the command line.
...

Relying on individual people to obtain and supply password securely to the remote host only clears rails from responsibility but opens up more opportunity for error because we humans are not that reliable.

Please sign in to comment.