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

feat: add tls and acl options to redis configuration #403

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions common/redispool/redis_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package redispool

import (
"context"
"crypto/tls"
"errors"
"fmt"
"math"
Expand Down Expand Up @@ -94,6 +95,7 @@ type Resp struct {
// Config redis pool configuration
type Config struct {
KvAddr string `json:"kvAddr"`
KvUser string `json:"kvUser"`
KvPasswd string `json:"kvPasswd"`
MaxIdle int `json:"maxIdle"`
IdleTimeout commontime.Duration `json:"idleTimeout"`
Expand All @@ -104,6 +106,7 @@ type Config struct {
MaxRetry int `json:"maxRetry"`
MinBatchCount int `json:"minBatchCount"`
WaitTime commontime.Duration `json:"waitTime"`
WithTLS bool `json:"withTLS"`
}

// DefaultConfig redis pool configuration with default values
Expand All @@ -126,8 +129,8 @@ func (c *Config) Validate() error {
if len(c.KvAddr) == 0 {
return errors.New("kvAddr is empty")
}
if len(c.KvPasswd) == 0 {
return errors.New("KvPasswd is empty")
if len(c.KvUser) > 0 && len(c.KvPasswd) == 0 { // password is required only when ACL's user is given
return errors.New("kvPasswd is empty")
}
if c.MaxIdle <= 0 {
return errors.New("maxIdle is empty")
Expand Down Expand Up @@ -163,8 +166,9 @@ type Pool struct {

// NewPool init a redis connection pool instance
func NewPool(ctx context.Context, config *Config, statis plugin.Statis) *Pool {
redisClient := redis.NewClient(&redis.Options{
redisOptions := &redis.Options{
Addr: config.KvAddr,
Username: config.KvUser,
Password: config.KvPasswd,
MaxRetries: -1,
DialTimeout: time.Duration(config.ConnectTimeout),
Expand All @@ -173,7 +177,14 @@ func NewPool(ctx context.Context, config *Config, statis plugin.Statis) *Pool {
PoolSize: config.MaxIdle,
MinIdleConns: config.MaxIdle,
IdleTimeout: time.Duration(config.IdleTimeout),
})
}
if config.WithTLS {
redisOptions.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
}

redisClient := redis.NewClient(redisOptions)
pool := &Pool{
config: config,
ctx: ctx,
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ apiVersion: v1
appVersion: "1.0"
description: A Helm chart for polaris
name: polaris
version: 0.0.1
version: 0.0.2
maintainers:
- name: trezhang
6 changes: 6 additions & 0 deletions deploy/helm/templates/polaris-server-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,18 @@ data:
- name: heartbeatRedis
option:
kvAddr: {{ .Values.polaris.storage.redis.address }}
{{- if .Values.polaris.storage.redis.user }}
kvUser: {{ .Values.polaris.storage.redis.user }}
{{- end }}
{{- if .Values.polaris.storage.redis.password }}
kvPasswd: {{ .Values.polaris.storage.redis.password }}
{{- end }}
maxIdle: 200
idleTimeout: 120s
connectTimeout: 200ms
msgTimeout: 200ms
concurrency: 200
withTLS: {{ .Values.polaris.storage.redis.withTLS | default false }}
{{- else }}
- name: heartbeatMemory
{{- end }}
Expand Down
4 changes: 3 additions & 1 deletion deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ polaris:
password: polaris@123456
redis:
address: localhost:6379
password: polaris@123456
user: polaris # ACL user from redis v6.0, remove it if ACL is not available
password: polaris@123456 # AUTH password below redis v6.0, or ACL password from redis v6.0
withTLS: false

service:
type: LoadBalancer
Expand Down
2 changes: 2 additions & 0 deletions deploy/standalone/k8s/02-polaris-server-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,14 @@ data:
# - name: heartbeatRedis
# option:
# kvAddr: ##REDIS_ADDR##
# kvUser: ##REDIS_USER#
# kvPasswd: ##REDIS_PWD##
# maxIdle: 200
# idleTimeout: 120s
# connectTimeout: 200ms
# msgTimeout: 200ms
# concurrency: 200
# withTLS: false
# 缓存配置
cache:
open: true
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/emicklei/go-restful v2.15.0+incompatible
github.com/envoyproxy/go-control-plane v0.10.1
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
github.com/go-redis/redis/v8 v8.11.4
github.com/go-redis/redis/v8 v8.11.5
github.com/go-sql-driver/mysql v1.6.0
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg=
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
Expand Down Expand Up @@ -171,7 +171,6 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand All @@ -189,6 +188,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
Expand Down Expand Up @@ -284,12 +284,16 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ=
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
2 changes: 2 additions & 0 deletions polaris-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,14 @@ healthcheck:
# - name: heartbeatRedis
# option:
# kvAddr: ##REDIS_ADDR##
# kvUser: ##REDIS_USER#
# kvPasswd: ##REDIS_PWD##
# maxIdle: 200
# idleTimeout: 120s
# connectTimeout: 200ms
# msgTimeout: 200ms
# concurrency: 200
# withTLS: false
# 配置中心模块启动配置
config:
# 是否启动配置模块
Expand Down
2 changes: 2 additions & 0 deletions test/discover/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ healthcheck:
# - name: heartbeatRedis
# option:
# kvAddr: ##REDIS_ADDR##
# kvUser: ##REDIS_USER#
# kvPasswd: ##REDIS_PWD##
# maxIdle: 200
# idleTimeout: 120s
# connectTimeout: 200ms
# msgTimeout: 200ms
# concurrency: 200
# withTLS: false
# 缓存配置
cache:
open: true
Expand Down