views:

206

answers:

1

i'm trying to configure a rails app to remotely connect to a postgres db. i've noticed that the connection adapters for mysql have options that specify the required info for setting up an ssl connection, but there is no equivalent options for the postgres/pg adapter.

after googling around, i haven't been able to find anything either (only connecting via an ssh tunnel).

so simply, is trying to get the rails postgres adapter to connect over ssl a dead end?

thanks. any help or direction is appreciated.

-h

+1  A: 

reading the rubyonrails api of the PostgreSQLAdapter i would just answer your question with NO http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter.html

but: there are three different postgresql gems out there:

  1. postgres (written in C, discontinued)
  2. pg (written in C, best maintained)
  3. postgres-pr (pure ruby implementation, active maintained)

the gem "pg" seems to allow SSL connection (at least when taking a look at the sources). this seems to be documented nowhere but it looks like it works (redmine confirms this here: http://www.redmine.org/wiki/1/RedmineInstall ).

so i suggest you might want to take a look on how the database.yml is configured with MYSQL and also try that out with the pg gem. also make sure that you compiled postgresql with SSL support. see http://www.williambharding.com/blog/rails/guide-to-setup-rails-with-mysql-ssl/

if that all does not work, maybe you can try to monkey-patch the database connection from rails and add connection_parameters to the ssl connection. here is the information from the source from ruby-pg:

<var>sslmode=mode</var> : how to treat SSL(string) (one of disable, allow, prefer, require)

please also take a look at another stackoverflow discussion regarding that topic: http://stackoverflow.com/questions/753759/can-activerecord-connect-to-postgresql-remotely-and-protect-the-db-password

z3cko