support Redis TLS Connection (#482)

* Add TLS for Redis connection

* Update to add tls flag
This commit is contained in:
Alex Beattie
2022-03-02 22:17:29 -08:00
committed by GitHub
parent 7a5b5dbc69
commit 96654e164a
3 changed files with 37 additions and 8 deletions
+1
View File
@@ -110,6 +110,7 @@ type RedisConfig struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
DB int `yaml:"db"`
UseTLS bool `yaml:"use_tls"`
}
type RoomConfig struct {
+20 -6
View File
@@ -17,6 +17,7 @@ import (
"github.com/livekit/protocol/webhook"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
"crypto/tls"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/routing"
@@ -106,12 +107,25 @@ func createRedisClient(conf *config.Config) (*redis.Client, error) {
}
logger.Infow("using multi-node routing via redis", "addr", conf.Redis.Address)
rc := redis.NewClient(&redis.Options{
Addr: conf.Redis.Address,
Username: conf.Redis.Username,
Password: conf.Redis.Password,
DB: conf.Redis.DB,
})
rcOptions := &redis.Options{
Addr: conf.Redis.Address,
Username: conf.Redis.Username,
Password: conf.Redis.Password,
DB: conf.Redis.DB,
}
if conf.Redis.UseTLS {
rcOptions = &redis.Options{
Addr: conf.Redis.Address,
Username: conf.Redis.Username,
Password: conf.Redis.Password,
DB: conf.Redis.DB,
TLSConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
},
}
}
rc := redis.NewClient(rcOptions)
if err := rc.Ping(context.Background()).Err(); err != nil {
err = errors.Wrap(err, "unable to connect to redis")
return nil, err
+16 -2
View File
@@ -8,6 +8,7 @@ package service
import (
"context"
"crypto/tls"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/livekit/livekit-server/pkg/config"
@@ -126,12 +127,25 @@ func createRedisClient(conf *config.Config) (*redis.Client, error) {
return nil, nil
}
logger.Infow("using multi-node routing via redis", "addr", conf.Redis.Address)
rc := redis.NewClient(&redis.Options{
rcOptions := &redis.Options{
Addr: conf.Redis.Address,
Username: conf.Redis.Username,
Password: conf.Redis.Password,
DB: conf.Redis.DB,
})
}
if conf.Redis.UseTLS {
rcOptions = &redis.Options{
Addr: conf.Redis.Address,
Username: conf.Redis.Username,
Password: conf.Redis.Password,
DB: conf.Redis.DB,
TLSConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
},
}
}
rc := redis.NewClient(rcOptions)
if err := rc.Ping(context.Background()).Err(); err != nil {
err = errors.Wrap(err, "unable to connect to redis")
return nil, err