does rails postgres adapter support ssl?

前端 未结 5 888
温柔的废话
温柔的废话 2020-12-19 01:31

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 f

5条回答
  •  借酒劲吻你
    2020-12-19 02:10

    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:

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

    please also take a look at another stackoverflow discussion regarding that topic: Can ActiveRecord connect to PostgreSQL remotely and protect the DB password?

提交回复
热议问题