@@ -4,10 +4,12 @@ import (
44 "crypto/aes"
55 "crypto/cipher"
66 "crypto/rand"
7+ "crypto/x509"
78 "encoding/base64"
89 "encoding/hex"
910 "fmt"
1011 "io"
12+ "io/ioutil"
1113 "net/http"
1214 "strings"
1315 "time"
@@ -17,6 +19,7 @@ import (
1719 "github.com/pusher/oauth2_proxy/pkg/apis/sessions"
1820 "github.com/pusher/oauth2_proxy/pkg/cookies"
1921 "github.com/pusher/oauth2_proxy/pkg/encryption"
22+ "github.com/pusher/oauth2_proxy/pkg/logger"
2023)
2124
2225// TicketData is a structure representing the ticket used in server session storage
@@ -64,6 +67,31 @@ 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, err := x509.SystemCertPool()
76+ if err != nil {
77+ logger.Printf("failed to load system cert pool for redis connection, falling back to empty cert pool")
78+ }
79+ if rootCAs == nil {
80+ rootCAs = x509.NewCertPool()
81+ }
82+ certs, err := ioutil.ReadFile(opts.RedisCAPath)
83+ if err != nil {
84+ return nil, fmt.Errorf("failed to load %q, %v", opts.RedisCAPath, err)
85+ }
86+
87+ // Append our cert to the system pool
88+ if ok := rootCAs.AppendCertsFromPEM(certs); !ok {
89+ logger.Printf("no certs appended, using system certs only")
90+ }
91+
92+ opt.TLSConfig.RootCAs = rootCAs
93+ }
94+
6795 client := redis.NewClient(opt)
6896 return client, nil
6997}