does rails postgres adapter support ssl?

前端 未结 5 885
温柔的废话
温柔的废话 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:20

    In late 2012, things seem to have changed. Although documentation is still sparse, the pg gem seems to auto-negotiate SSL, and the jdbc drivers can be coerced to use SSL.

    My app is a hybrid MRI-jRuby app, that accesses heroku-postgres, a cloud postgresql server that requires SSL.

    # Gemfile.lock
    pg (0.14.1)
    
    activerecord-jdbc-adapter (1.2.2.1)
    activerecord-jdbcpostgresql-adapter (1.2.2.1)
    jdbc-postgres (9.1.901)
    

    The pg gem, seemed to auto-negotiate SSL. However, the JDBC adapter did not. MRI connected with a typical database.yml (no mention of ssl), but JDBC threw:

    (FATAL: no pg_hba.conf entry for host "xx.xx.xx.xx", user "username", database "database", SSL off)
    

    I eventually tried specifying the connection details in JDBC-URL format, and the connection succeeded:

    # jruby database.yml
    production:
      adapter: jdbcpostgresql
      url: jdbc:postgresql://host/database?user=user&password=password&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
    

    (sslfactory may not be needed for all setups)

提交回复
热议问题