Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connecting using SSL (client.flag=2048) to a RDS DB freezes forever #227

Open
kforner opened this issue Jan 17, 2020 · 3 comments
Open

connecting using SSL (client.flag=2048) to a RDS DB freezes forever #227

kforner opened this issue Jan 17, 2020 · 3 comments

Comments

@kforner
Copy link

kforner commented Jan 17, 2020

cross-posted, cf r-dbi/RMariaDB#151

@kforner
Copy link
Author

kforner commented Jan 27, 2020

Hello,
Any comment on this ?
I spent a lot of time providing a complete reproducible example with the mysql server and clients configured...

@hafermoraes
Copy link

hafermoraes commented Mar 10, 2021

Hello,

To @kforner and all the other poor souls like me fighting to connect using SSL, I did finally manage to connect using the following strategy.

Before proceeding, update the DBI and RMariaDB libraries to the last version using the devtools from within R.

  1. obtain the file rds-combined-ca-bundle.pem here and save it to disk on your home directory.

  2. provide a configuration file named db.conf (or whatever name you prefer) on your home directory having the following content

[connection_name]
database=database_name
host=your_host_address
user=your_user_name
password=your_password
ssl_ca=/path/to/rds-combined-ca-bundle.pem
  1. connect to the database via DBI and RMariaDB from R:
## install.packages("devtools")
## devtools::install_github("r-dbi/DBI")
## devtools::install_github("r-dbi/RMariaDB")

library(DBI)
library(RMariaDB)

mydb <- dbConnect(
    RMariaDB::MariaDB() 
   ,default.file = '/path/to/db.conf'
   ,group = 'connection_name'
)
## test the connection
dbGetQuery(mydb,'show tables;')

Hope that helps.

Best regards,
Rafael R. de Moraes

@kforner
Copy link
Author

kforner commented Mar 11, 2021

for what it's worth, here's my connect function:

mysql_connect <- function(..., drv = MariaDB(), ssl = FALSE, ssl.ca = get_rds_ssl_certificates_bundle()) {
#mysql_connect <- function(..., drv = MariaDB()) {
  ### ... can be a list of params or a list of a list of params
  ### we make sure to always a list of params
  args <- list(...)
  if (length(args) == 1 && is.list(args[[1]])) args <- args[[1]]
  
  if (is.null(args$drv)) args$drv <- drv
  if (!is.null(args$ssl)) {
    ssl <- args$ssl
    args$ssl <- NULL
  }

  # dbConnect has a bug with a relative default.file
  if (!is.null(args$default.file)) {
    first_char <- substr(args$default.file, 1, 1)
    if (first_char != .Platform$file.sep) # relative path
      args$default.file <- paste0('.', .Platform$file.sep, args$default.file)
  }

  if (ssl) {
    if (is.null(args$ssl.ca)) args$ssl.ca <- ssl.ca
  }
  
  do.call(DBI::dbConnect, args)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants