skwpspace yan pritzker’s home on the web

skwpspace is Yan Pritzker's home on the web

Blog :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

Top Posts

planypus

I'm the founder of Planypus, the place to share your plans!

cohesiveft

Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!

flickr

smokingThe old man and the accordionBicycle 6x6Eva 6x6Shaffies 6x6Phone Booth Velvia 6x6WynnStar 6x6

Archives

Contact

Reach me at yan at pritzker.ws

Posted
29 August 2006 @ 12am

Tagged
RubyOnRails, software

Encrypted db passwords for Rails with database.yml and erb

Some people are upset that database.yml can expose passwords in plaintext. However, there is a pretty simple way to get encryption into database.yml. Because the database.yml file is actually run through an ERB interpreter by Rails, we can put code into our file:

##### database.yml #####
production:
  adapter: oci
  username: user
  password: <%= PROD_DB_PASSWORD.decrypt(PROD_KEYFILE) %>
  host: host/schema
####### local.rb #######
class String
  def decrypt(keyfile)
   #do some magic to apply the keyfile to the password
  end
end

That’s all there is to it! Simply plugin any key-based encryption routine in there. In my case we were using a triple des two way encryption that was actually done by an external Java program. I simply invoked the java interpeter using backticks and got the output which was my decrypted password.


4 Comments

Posted by
Nathan
26 September 2006 @ 1pm

If someone already had access to your database.yml file, wouldn’t they also conceivably have access to your key file and general encryption routine? If that is true, it seems like the encryption process would boil down to little more than simple obfuscation.


Posted by
yan
26 September 2006 @ 4pm

Nathan, in theory your keyfile should be readable only by a system user, as should your database.yml file. Assuming your intruder has already gained access to the files, it still means he has to understand how to invoke the decryption scheme, so it’s adding one more step to the breakin process. For example if your attacker didn’t understand Ruby he could still read the password out of your file, but if it’s encrypted now he has to go through the decryption step. It’s not foolproof but neither is the lock on the door to your house. It’s just there as a deterrent.


Posted by
ohthklyhad
17 September 2007 @ 8am


Posted by
sjvfwcrfnz
17 September 2007 @ 8am

poker chips ace jack


Leave a Comment

Consuming document literal SOAP webservices with Ruby and ROXML Rails request log filtering