jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
284 stars 64 forks source link

AWS auth not supported, configure libmongoc with ENABLE_MONGODB_AWS_AUTH=ON #238

Closed kevpfowler closed 2 years ago

kevpfowler commented 2 years ago

I am using mongolite with an app that runs on an AWS EC2 instance (running Ubuntu 20.04) and connects to an Atlas MongoDB cluster.

When using authMechanism=MONGODB-AWS, i.e. with a URL like:

mongodb+srv://mytestcluster-pl-0.xxxxx.mongodb.net/myDb?authMechanism=MONGODB-AWS

on connect I get back:

Error in value[[3L]](cond) : 
  sourceDirectory() failed to source '...my R file...': AWS auth not supported, configure libmongoc with ENABLE_MONGODB_AWS_AUTH=ON

When I install the mongolite package I see it builds the mongoc on the fly. Does mongolite build mongoc with ENABLE_MONGODB_AWS_AUTH=ON?

I have libssl-dev and libsasl2-dev installed. Is there something more I need in my environment so that mongolite builds with this setting?

jeroen commented 2 years ago

I didn't ship the ec2 authentication module with the R package yet. Is that really needed? I think you can just authenticate with mongodb atlas if you remove the authMechanism=MONGODB-AWS part from your url? (i'm using mongodb atlas in the unit tests as well...)

kevpfowler commented 2 years ago

I am using (or want to be using) the configured EC2 Instance IAM Role for authenticating to the Atlas cluster. This allows authenticating without including any passwords or aws secret access key material in the application (or managing env vars on each instance). This is considered a best practice for production deployments.

The only way for me to achieve this is if the driver supports MONGODB-AWS, which kicks in the magic glue in libmongoc.

jeroen commented 2 years ago

Can you test if things now work with mongolite 2.6.0 ?

kevpfowler commented 2 years ago

I just completed basic testing and yes, this does now work with 2.6.0. Thank you for the quick response!