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

Difficulty when connect using TLS/SSL and verify client certificate #4900

Closed
CallMeLaNN opened this issue Jan 16, 2017 · 2 comments
Closed
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@CallMeLaNN
Copy link

CallMeLaNN commented Jan 16, 2017

NodeJs: 6.9.1
Mongoose version: 4.4.19
MongoDb NodeJs driver version: 2.1.19
A quick checking inside the connection.js in master branch seems similar between mine one and the latest one.

I have difficulty to configure Mongoose to connect using TLS/SSL and verify server & client certificate but then I manage to figure it out. So something can be improved or at least this page helps the others to configure the same options.

  1. Documentation for options.auth is not enough in Connections. Maybe I was wrong but I can't find example like this.
    My problem is I unable to explicitly define authMechanism. Following MongoDb NodeJs native driver authMechanism is simply ignored by Mongoose.
    In the Connections documentation, it just describe options for authentication while in the source code it point to the options for authentication (see http://mongodb.github.com/node-mongodb-native/api-generated/db.html#authenticate). This URI is good to be included in the documentation since I don't have any idea how to construct the options.auth without checking the source code.
    Apparently options.auth.authMechanism is the way to go.

  2. Simply follow the MongoDb NodeJs native driver URI pattern does not work.

    • authMechanism in query string is ignored. Maybe Mongoose can add this?
    • user in the URL mongodb://user:password@server:27017/db is not possible for this case
      • The user coming from x.509 certificate subject compatible with RFC2253 should be encoded because it contain comma.
        If I leave it as is, it will throw MongoError: no valid seed servers in list because of the comma but if I encode it, it will keep encoded until the MongoDb server complain There is no x.509 client certificate matching the user because encoded user does not match with un-encoded one.
      • Muri should decode the user. Mongoose internally use Muri to parse the user but Muri does not decode it.
      • While fixing this might introduce breaking changes (we don't know if it will be double decoding), it is good to note the user and password in URI does not support special character and also do not specify user in URL for client certificate.

Finally it only works this way:

var conn = mongoose.createConnection("mongodb://server:27017/db", {
    user: "CN=nodejs-api.server.com,OU=IT,O=Org,L=City,ST=State,C=MY",
    auth: { authMechanism: "MONGODB-X509" },
    server: {
        ssl: true
        sslValidate: true
        sslCA: ...
        sslCert: ...
        sslKey: ...
        sslPass: ...
    }
});
@sobafuchs
Copy link
Contributor

sobafuchs commented Jan 16, 2017

Regarding 1, we could probably include an example of using options.auth in the docs.

For 2, aheckmann/muri#9 resolves this no?

And I would probably agree that the docs should list special characters in the uri string, even though that's more of a mongo thing than it is mongoose's issue. That's a simple docs change though

@sobafuchs sobafuchs added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Jan 16, 2017
@sobafuchs sobafuchs added this to the 4.7.8 milestone Jan 16, 2017
@vkarpov15
Copy link
Collaborator

Upgraded to latest muri in this commit: 596572e will be released in 4.7.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

No branches or pull requests

3 participants