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

When using rediss:/ URLs, auto-configure tls.servername #948

Closed
paulmelnikow opened this issue Aug 20, 2019 · 2 comments
Closed

When using rediss:/ URLs, auto-configure tls.servername #948

paulmelnikow opened this issue Aug 20, 2019 · 2 comments

Comments

@paulmelnikow
Copy link
Contributor

As mentioned at #939 (comment), using ioredis (or node-redis) with Compose.io's Let's Encrypt certificates generates an SSL error:

Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (_tls_wrap.js:1049:34)
    at TLSSocket.emit (events.js:182:13)
    at TLSSocket.EventEmitter.emit (domain.js:442:20)
    at TLSSocket._finishInit (_tls_wrap.js:631:8) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'

Disabling strict SSL is a workaround, though the correct solution is to pass the servername option to TLS.connect, which tells the client which TLS certificate to use.

I found the solution in this article: https://www.compose.com/articles/ssl-connections-arrive-for-redis-on-compose/

It doesn't do an awesome job of explaining the cause, though I think the reason is that there are more than one certificates being used on the same IP address.

My code looks like this:

const options =
  this.url && this.url.startsWith('rediss:')
    ? {
        //  https://www.compose.com/articles/ssl-connections-arrive-for-redis-on-compose/
        tls: { servername: new URL(this.url).hostname },
      }
    : undefined
this.redis = new Redis(this.url, options)

I'd be happy to open a PR if this default behavior would be welcome!

@monkbroc
Copy link
Contributor

From the issue comment

Probably this should set tls: true only when tls is not already present in the options.

I submitted PR #939 so I'm happy to submit another PR to correct this issue. In retrospect, I should have added a test to ensure that custom tls options would not be overwritten by the default.

Compose.io's Let's Encrypt certificates generates an SSL error

My use case was Redis through AWS Elasticache. I didn't run into issues with the server name. Thanks for documenting this issue so clearly.

If changing the behavior that rediss:// sets { tls: true } to rediss:// sets the { tls: { servername } works for both AWS and Compose then I agree that making that the default behavior of ioredis would benefit everyone.

ioredis-robot pushed a commit that referenced this issue Aug 27, 2019
## [4.14.1](v4.14.0...v4.14.1) (2019-08-27)

### Bug Fixes

* don’t clobber passed-in tls options with rediss:/ URLs ([#949](#949)) ([ceefcfa](ceefcfa)), closes [#942](#942) [#940](#940) [#950](#950) [#948](#948)
@stale
Copy link

stale bot commented Sep 20, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs, but feel free to re-open a closed issue if needed.

@stale stale bot added the wontfix label Sep 20, 2019
@stale stale bot closed this as completed Sep 27, 2019
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

Successfully merging a pull request may close this issue.

2 participants