Search code examples
ruby-on-railsrubygemsgoogle-cloud-sqlapp-engine-flexible

How to connect to ssl enabled cloud sql instance with blazer ruby gem


I have a rails application which hosted in google cloud flex app engine. application uses ssl certificate to connect to cloud sql instance(mysql5.7) . It is successful for rails application to connect to ssl connection enabled cloud sql instance. database.yml config as follows.

development:
  adapter: mysql2
  database: databasename
  host: 10.2.224.3
  username: root
  password: password
  sslca: config/server-ca.pem
  sslkey: config/client-key.pem
  sslcert: config/client-cert.pem

But when I installed blazer gem into my application. https://github.com/ankane/blazer#mysql-1

Blazer could only use cloud sql's private ip address to connect cloud sql instance which allows insecure connection.blazer.yml config as follows

data_sources:
  my_source:
    url: mysql2://root:password@10.2.224.3:3306/databasename

When I enabled ssl in my cloud sql instance. Blazer cannot connect to my ssl enabled cloud sql instance and got "SSL connection error: Unable to get certificate" error message. config in blazer.yml as follows.

data_sources:
  my_source:
    url: mysql2://root:password@10.2.224.3:3306/databasename?config/sslca=server-ca.pem&config/sslcert=client-cert.pem&sslkey=config/client-key.pem

How to configure rails gem blazer's blazer.yml to make it connect to ssl enabled cloud sql mysql instance? Or I may ask when I installed my rails application into flex app engine. How can I find the path of my ssl certificate file in flex app engine. which located in rails's config folder.

Any advise would be appreciated.


Solution

  • In your DB URI, I see the following:

    ...?config/sslca=server-ca.pem&...
    

    I believe it should be:

    sslca=config/server-ca.pem