git.iko.soy/typeable/oauth2-proxy
on master help sign in
Add support for Redis with custom CA.
commit3f7ed36e4643c4ca78121c8292d1fdbfac040825 authorLukasz Leszczuk <lleszczuk@gmail.com> dateThu 7 Nov 2019, 11:04 (7 years ago) parentfef940d
3 files changed+29
main.go+2 pkg/apis/options/sessions.go+2 pkg/sessions/redis/redis_store.go+25
main.go+2
@@ -91,6 +91,8 @@ func main() {
9191 flagSet.String("redis-connection-url", "", "URL of redis server for redis session storage (eg: redis://HOST[:PORT])")
9292 flagSet.Bool("redis-use-sentinel", false, "Connect to redis via sentinels. Must set --redis-sentinel-master-name and --redis-sentinel-connection-urls to use this feature")
9393 flagSet.String("redis-sentinel-master-name", "", "Redis sentinel master name. Used in conjunction with --redis-use-sentinel")
94+ flagSet.String("redis-ca-path", "", "Redis custom CA path")
95+ flagSet.Bool("redis-insecure-tls", false, "Use insecure TLS connection to redis")
9496 flagSet.Var(&redisSentinelConnectionURLs, "redis-sentinel-connection-urls", "List of Redis sentinel connection URLs (eg redis://HOST[:PORT]). Used in conjunction with --redis-use-sentinel")
9597
9698 flagSet.String("logging-filename", "", "File to log requests to, empty for stdout")
pkg/apis/options/sessions.go+2
@@ -27,4 +27,6 @@ type RedisStoreOptions struct {
2727 UseSentinel bool `flag:"redis-use-sentinel" cfg:"redis_use_sentinel" env:"OAUTH2_PROXY_REDIS_USE_SENTINEL"`
2828 SentinelMasterName string `flag:"redis-sentinel-master-name" cfg:"redis_sentinel_master_name" env:"OAUTH2_PROXY_REDIS_SENTINEL_MASTER_NAME"`
2929 SentinelConnectionURLs []string `flag:"redis-sentinel-connection-urls" cfg:"redis_sentinel_connection_urls" env:"OAUTH2_PROXY_REDIS_SENTINEL_CONNECTION_URLS"`
30+ RedisCAPath string `flag:"redis-ca-path" cfg:"redis_ca_path" env:"OAUTH2_PROXY_REDIS_CA_PATH"`
31+ RedisInsecureTLS bool `flag:"redis-insecure-tls" cfg:"redis_insecure_tls" env:"OAUTH2_PROXY_REDIS_INSECURE_TLS"`
3032}
pkg/sessions/redis/redis_store.go+25
@@ -4,10 +4,13 @@ import (
44 "crypto/aes"
55 "crypto/cipher"
66 "crypto/rand"
7+ "crypto/x509"
78 "encoding/base64"
89 "encoding/hex"
910 "fmt"
11+ "github.com/pusher/oauth2_proxy/pkg/logger"
1012 "io"
13+ "io/ioutil"
1114 "net/http"
1215 "strings"
1316 "time"
@@ -64,6 +67,28 @@ func newRedisClient(opts options.RedisStoreOptions) (*redis.Client, error) {
6467 return nil, fmt.Errorf("unable to parse redis url: %s", err)
6568 }
6669
70+ if opts.RedisInsecureTLS != false {
71+ opt.TLSConfig.InsecureSkipVerify = true
72+ }
73+
74+ if opts.RedisCAPath != "" {
75+ rootCAs, _ := x509.SystemCertPool()
76+ if rootCAs == nil {
77+ rootCAs = x509.NewCertPool()
78+ }
79+ certs, err := ioutil.ReadFile(opts.RedisCAPath)
80+ if err != nil {
81+ return nil, fmt.Errorf("failed to load %q, %v", opts.RedisCAPath, err)
82+ }
83+
84+ // Append our cert to the system pool
85+ if ok := rootCAs.AppendCertsFromPEM(certs); !ok {
86+ logger.Printf("no certs appended, using system certs only")
87+ }
88+
89+ opt.TLSConfig.RootCAs = rootCAs
90+ }
91+
6792 client := redis.NewClient(opt)
6893 return client, nil
6994}