support Redis TLS Connection (#482)
* Add TLS for Redis connection * Update to add tls flag
This commit is contained in:
@@ -110,6 +110,7 @@ type RedisConfig struct {
|
|||||||
Username string `yaml:"username"`
|
Username string `yaml:"username"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
DB int `yaml:"db"`
|
DB int `yaml:"db"`
|
||||||
|
UseTLS bool `yaml:"use_tls"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RoomConfig struct {
|
type RoomConfig struct {
|
||||||
|
|||||||
+16
-2
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/livekit/protocol/webhook"
|
"github.com/livekit/protocol/webhook"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
"crypto/tls"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
"github.com/livekit/livekit-server/pkg/routing"
|
"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)
|
logger.Infow("using multi-node routing via redis", "addr", conf.Redis.Address)
|
||||||
rc := redis.NewClient(&redis.Options{
|
rcOptions := &redis.Options{
|
||||||
Addr: conf.Redis.Address,
|
Addr: conf.Redis.Address,
|
||||||
Username: conf.Redis.Username,
|
Username: conf.Redis.Username,
|
||||||
Password: conf.Redis.Password,
|
Password: conf.Redis.Password,
|
||||||
DB: conf.Redis.DB,
|
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 {
|
if err := rc.Ping(context.Background()).Err(); err != nil {
|
||||||
err = errors.Wrap(err, "unable to connect to redis")
|
err = errors.Wrap(err, "unable to connect to redis")
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
+16
-2
@@ -8,6 +8,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
@@ -126,12 +127,25 @@ func createRedisClient(conf *config.Config) (*redis.Client, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
logger.Infow("using multi-node routing via redis", "addr", conf.Redis.Address)
|
logger.Infow("using multi-node routing via redis", "addr", conf.Redis.Address)
|
||||||
rc := redis.NewClient(&redis.Options{
|
rcOptions := &redis.Options{
|
||||||
Addr: conf.Redis.Address,
|
Addr: conf.Redis.Address,
|
||||||
Username: conf.Redis.Username,
|
Username: conf.Redis.Username,
|
||||||
Password: conf.Redis.Password,
|
Password: conf.Redis.Password,
|
||||||
DB: conf.Redis.DB,
|
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 {
|
if err := rc.Ping(context.Background()).Err(); err != nil {
|
||||||
err = errors.Wrap(err, "unable to connect to redis")
|
err = errors.Wrap(err, "unable to connect to redis")
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user