Skip to content

Commit 417bf03

Browse files
committed
Set the CookieStore key in Auth API Server
This commit sets CookieStore key to a random string earlier it was empty and due change in `gorilla/securecookie` package CookieStore expects to set the key Signed-off-by: Shiv Verma <[email protected]>
1 parent fdd2d38 commit 417bf03

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Diff for: api/pkg/auth/base.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package auth
1616

1717
import (
18+
"crypto/rand"
19+
"encoding/base64"
1820
"net/http"
1921
"os"
2022
"strings"
@@ -31,11 +33,25 @@ import (
3133
auth "github.com/tektoncd/hub/api/pkg/auth/service"
3234
)
3335

36+
// generateRandomKey return a random generated key
37+
func generateRandomKey(length int) (string, error) {
38+
key := make([]byte, length)
39+
_, err := rand.Read(key)
40+
if err != nil {
41+
return "", err
42+
}
43+
return base64.StdEncoding.EncodeToString(key), nil
44+
}
45+
3446
// Auth Provider provides routes for authentication
3547
// and also defines git providers using goth
3648
func AuthProvider(r *mux.Router, api app.Config) {
3749

38-
key := "" // Replace with your SESSION_SECRET or similar
50+
key, err := generateRandomKey(32)
51+
if err != nil {
52+
panic(err)
53+
}
54+
3955
maxAge := 86400 * 30 // 30 days
4056
isProd := true // Set to false when not serving over https
4157
if api.Environment() != app.EnvMode("production") {

0 commit comments

Comments
 (0)