git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge branch 'master' into master
commitead1f43e1497bd589d37473f601eeb226a9c4f4d authorTero Pihlaja <tero.pihlaja@vilant.com> dateThu 28 May 2020, 10:41 (6 years ago) parent59da0136a88da7
5 files changed+98−2
CHANGELOG.md+1 go.mod+2 go.sum+11 pkg/sessions/redis/redis_store.go+24−2 pkg/sessions/redis/redis_store_test.go+60
CHANGELOG.md+1
@@ -52,6 +52,7 @@
5252## Changes since v5.1.1
5353
5454- [#583](https://github.com/oauth2-proxy/oauth2-proxy/pull/583) Add configurable proxy timeout (@RO-29, @TeroPihlaja)
55+- [#573](https://github.com/oauth2-proxy/oauth2-proxy/pull/573) Properly parse redis urls for cluster and sentinel connections (@amnay-mo)
5556- [#574](https://github.com/oauth2-proxy/oauth2-proxy/pull/574) render error page on 502 proxy status (@amnay-mo)
5657- [#559](https://github.com/oauth2-proxy/oauth2-proxy/pull/559) Rename cookie-domain config to cookie-domains (@JoelSpeed)
5758- [#569](https://github.com/oauth2-proxy/oauth2-proxy/pull/569) Updated autocompletion for `--` long options. (@Izzette)
go.mod+2
@@ -3,6 +3,8 @@ module github.com/oauth2-proxy/oauth2-proxy
33go 1.14
44
55require (
6+ github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb
7+ github.com/alicebob/miniredis v2.5.0+incompatible // indirect
68 github.com/alicebob/miniredis/v2 v2.11.2
79 github.com/bitly/go-simplejson v0.5.0
810 github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
go.sum+11
@@ -2,13 +2,19 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
22cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
33cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
44cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
5+github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb h1:ZVN4Iat3runWOFLaBCDVU5a9X/XikSRBosye++6gojw=
6+github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb/go.mod h1:WsAABbY4HQBgd3mGuG4KMNTbHJCPvx9IVBHzysbknss=
57github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
68github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
9+github.com/FZambia/sentinel v1.0.0/go.mod h1:ytL1Am/RLlAoAXG6Kj5LNuw/TRRQrv2rt2FT26vP5gI=
710github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
811github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
912github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
1013github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6 h1:45bxf7AZMwWcqkLzDAQugVEwedisr5nRJ1r+7LYnv0U=
1114github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
15+github.com/alicebob/miniredis v2.5.0+incompatible h1:yBHoLpsyjupjz3NL3MhKMVkR41j82Yjf3KFv7ApYzUI=
16+github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk=
17+github.com/alicebob/miniredis/v2 v2.11.1/go.mod h1:UA48pmi7aSazcGAvcdKcBB49z521IC9VjTTRz2nIaJE=
1218github.com/alicebob/miniredis/v2 v2.11.2 h1:OtWO7akm5otuhssnE/sNfsWxG4gZ8DbGhShDtRrByJs=
1319github.com/alicebob/miniredis/v2 v2.11.2/go.mod h1:VL3UDEfAH59bSa7MuHMuFToxkqyHh69s/WUbYlOAuyg=
1420github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
@@ -72,6 +78,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
7278github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
7379github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
7480github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
81+github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
82+github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7583github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
7684github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
7785github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
@@ -106,6 +114,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
106114github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
107115github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
108116github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
117+github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
109118github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
110119github.com/mbland/hmacauth v0.0.0-20170912233209-44256dfd4bfa h1:hI1uC2A3vJFjwvBn0G0a7QBRdBUp6Y048BtLAHRTKPo=
111120github.com/mbland/hmacauth v0.0.0-20170912233209-44256dfd4bfa/go.mod h1:8vxFeeg++MqgCHwehSuwTlYCF0ALyDJbYJ1JsKi7v6s=
@@ -172,6 +181,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
172181github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
173182github.com/yhat/wsutil v0.0.0-20170731153501-1d66fa95c997 h1:1+FQ4Ns+UZtUiQ4lP0sTCyKSQ0EXoiwAdHZB0Pd5t9Q=
174183github.com/yhat/wsutil v0.0.0-20170731153501-1d66fa95c997/go.mod h1:DIGbh/f5XMAessMV/uaIik81gkDVjUeQ9ApdaU7wRKE=
184+github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
185+github.com/yuin/gopher-lua v0.0.0-20191213034115-f46add6fdb5c/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
175186github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0=
176187github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
177188go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
pkg/sessions/redis/redis_store.go+24−2
@@ -60,16 +60,24 @@ func newRedisCmdable(opts options.RedisStoreOptions) (Client, error) {
6060 }
6161
6262 if opts.UseSentinel {
63+ addrs, err := parseRedisURLs(opts.SentinelConnectionURLs)
64+ if err != nil {
65+ return nil, fmt.Errorf("could not parse redis urls: %v", err)
66+ }
6367 client := redis.NewFailoverClient(&redis.FailoverOptions{
6468 MasterName: opts.SentinelMasterName,
65− SentinelAddrs: opts.SentinelConnectionURLs,
69+ SentinelAddrs: addrs,
6670 })
6771 return newClient(client), nil
6872 }
6973
7074 if opts.UseCluster {
75+ addrs, err := parseRedisURLs(opts.ClusterConnectionURLs)
76+ if err != nil {
77+ return nil, fmt.Errorf("could not parse redis urls: %v", err)
78+ }
7179 client := redis.NewClusterClient(&redis.ClusterOptions{
72− Addrs: opts.ClusterConnectionURLs,
80+ Addrs: addrs,
7381 })
7482 return newClusterClient(client), nil
7583 }
@@ -108,6 +116,20 @@ func newRedisCmdable(opts options.RedisStoreOptions) (Client, error) {
108116 return newClient(client), nil
109117}
110118
119+// parseRedisURLs parses a list of redis urls and returns a list
120+// of addresses in the form of host:port that can be used to connnect to Redis
121+func parseRedisURLs(urls []string) ([]string, error) {
122+ addrs := []string{}
123+ for _, u := range urls {
124+ parsedURL, err := redis.ParseURL(u)
125+ if err != nil {
126+ return nil, fmt.Errorf("unable to parse redis url: %v", err)
127+ }
128+ addrs = append(addrs, parsedURL.Addr)
129+ }
130+ return addrs, nil
131+}
132+
111133// Save takes a sessions.SessionState and stores the information from it
112134// to redies, and adds a new ticket cookie on the HTTP response writer
113135func (store *SessionStore) Save(rw http.ResponseWriter, req *http.Request, s *sessions.SessionState) error {
pkg/sessions/redis/redis_store_test.gonew file+60
@@ -0,0 +1,60 @@
1+package redis
2+
3+import (
4+ "net/http"
5+ "net/http/httptest"
6+ "net/url"
7+ "testing"
8+
9+ "github.com/Bose/minisentinel"
10+ "github.com/alicebob/miniredis/v2"
11+ "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/options"
12+ "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions"
13+ "github.com/stretchr/testify/assert"
14+ "github.com/stretchr/testify/require"
15+)
16+
17+func TestRedisStore(t *testing.T) {
18+ t.Run("save session on redis standalone", func(t *testing.T) {
19+ redisServer, err := miniredis.Run()
20+ require.NoError(t, err)
21+ defer redisServer.Close()
22+ opts := options.NewOptions()
23+ redisURL := url.URL{
24+ Scheme: "redis",
25+ Host: redisServer.Addr(),
26+ }
27+ opts.Session.Redis.ConnectionURL = redisURL.String()
28+ redisStore, err := NewRedisSessionStore(&opts.Session, &opts.Cookie)
29+ require.NoError(t, err)
30+ err = redisStore.Save(
31+ httptest.NewRecorder(),
32+ httptest.NewRequest(http.MethodGet, "/", nil),
33+ &sessions.SessionState{})
34+ assert.NoError(t, err)
35+ })
36+ t.Run("save session on redis sentinel", func(t *testing.T) {
37+ redisServer, err := miniredis.Run()
38+ require.NoError(t, err)
39+ defer redisServer.Close()
40+ sentinel := minisentinel.NewSentinel(redisServer)
41+ err = sentinel.Start()
42+ require.NoError(t, err)
43+ defer sentinel.Close()
44+ opts := options.NewOptions()
45+ sentinelURL := url.URL{
46+ Scheme: "redis",
47+ Host: sentinel.Addr(),
48+ }
49+ opts.Session.Redis.SentinelConnectionURLs = []string{sentinelURL.String()}
50+ opts.Session.Redis.UseSentinel = true
51+ opts.Session.Redis.SentinelMasterName = sentinel.MasterInfo().Name
52+ redisStore, err := NewRedisSessionStore(&opts.Session, &opts.Cookie)
53+ require.NoError(t, err)
54+ err = redisStore.Save(
55+ httptest.NewRecorder(),
56+ httptest.NewRequest(http.MethodGet, "/", nil),
57+ &sessions.SessionState{})
58+ assert.NoError(t, err)
59+ })
60+}