vapor / redis

Vapor provider for RediStack
MIT License
458 stars 57 forks source link

Add support for TLS-backed connections to Redis #205

Closed iKenndac closed 1 year ago

iKenndac commented 1 year ago

This PR adds TLS support to the current stable release of vapor/redis (and the underlying RediStack 1.x). There are three behaviour changes (all additive):

This PR allows vapor/redis to be used with hosting services like Heroku, which (in certain configurations) require that you connect to Redis using TLS.

Ramifications on Future Versions

The logic for this PR was "borrowed" from this PR on RediStack: https://gitlab.com/swift-server-community/RediStack/-/merge_requests/160

I'm aware that work is being done in RediStack to add this "properly". However, I need to use TLS now and I'd like to stay on stable releases as much as possible. I'm aware there's already work on the main branch here for RediStack 2.x. This PR is branched from the 4.6.0 release — hopefully it can be merged into a new 4.x release to tide us over until 5.x comes along.

Example Usage

Here's how I'm using this addition in my Vapor app running on Heroku. Heroku self-signs its TLS certificates, so I need to turn off certificate verification:

guard let redisUrl = Environment.get("REDIS_TLS_URL") else { throw Abort(.expectationFailed) }

let poolOptions = RedisConfiguration.PoolOptions(minimumConnectionCount: 1, connectionRetryTimeout: .seconds(10))

var tlsConfig: TLSConfiguration = .makeClientConfiguration()
tlsConfig.certificateVerification = .none

var redisConfig = try RedisConfiguration(url: redisUrl, pool: poolOptions)
redisConfig.tlsConfiguration = tlsConfig
app.redis.configuration = redisConfig
gwynne commented 1 year ago

@0xTim Looks like a straightforward and clean addition of support for 1.x, once the conflicts are resolved.

iKenndac commented 1 year ago

Whoops, I saw those 5.0.0 alpha releases and thought they were on main, so I branched from 4.6.0. My bad — fixed now!

0xTim commented 1 year ago

Released in https://github.com/vapor/redis/releases/tag/4.7.0

iKenndac commented 1 year ago

Thank you! :heart: