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/refactor: filestore feature flag #4617

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions docs/src/content/docs/self-hosting/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ The base path of the API. The default is `/`.
SCRUMLR_BASE_PATH=''
```

### Disable Anonymous Login
If set to `true`, users won't be able to log in anonymously, forcing them to use a provider (any OAuth or OIDC).
Note that if this is set to `true`, and no valid providers are available, login won't be possible at all.
Default is `false`.
```bash
SCRUMLR_DISABLE_ANONYMOUS_LOGIN=false
```

### Enable Experimental File System Store
Enables an experimental file store for session cookies.
Required for some OIDC providers, since their session cookies exceed the size limit of 4KB.
Default is `false`.
```bash
SCRUMLR_ENABLE_EXPERIMENTAL_AUTH_FILE_SYSTEM_STORE=false
```

### Auth Callback Host
The host to which the OAuth callback should redirect.
```bash
Expand Down
3 changes: 3 additions & 0 deletions server/config_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ base-path = "/"
# Enable/Disable the login of anonymous clients
disable-anonymous-login = false

# enables/disables experimental file system store, in order to allow larger session cookie sizes
auth-experimental-file-system-store = false

# Set the protocol and host for the auth provider callbacks (e.g. https://scrumlr.io)
auth-callback-host = ""

Expand Down
5 changes: 0 additions & 5 deletions server/src/api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import (
"fmt"
"math"
"net/http"
"os"
"strings"
"time"

"scrumlr.io/server/common"
"scrumlr.io/server/logger"

"github.com/go-chi/render"
"github.com/gorilla/sessions"
"github.com/markbates/goth/gothic"
"scrumlr.io/server/common/dto"
"scrumlr.io/server/database/types"
Expand Down Expand Up @@ -74,9 +72,6 @@ func (s *Server) logout(w http.ResponseWriter, r *http.Request) {

// beginAuthProviderVerification will redirect the user to the specified auth provider consent page
func (s *Server) beginAuthProviderVerification(w http.ResponseWriter, r *http.Request) {
store := sessions.NewFilesystemStore(os.TempDir(), []byte("scrumlr.io"))
store.MaxLength(0x8000)
gothic.Store = store
gothic.BeginAuthHandler(w, r)
}

Expand Down
21 changes: 19 additions & 2 deletions server/src/api/router.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package api

import (
"github.com/markbates/goth/gothic"
"net/http"
"os"
"time"

"github.com/go-chi/cors"
"github.com/go-chi/httprate"
"github.com/go-chi/jwtauth/v5"
"github.com/go-chi/render"
"github.com/google/uuid"
gorillaSessions "github.com/gorilla/sessions"
"github.com/gorilla/websocket"

"scrumlr.io/server/auth"
Expand Down Expand Up @@ -43,7 +46,9 @@ type Server struct {
boardSubscriptions map[uuid.UUID]*BoardSubscription
boardSessionRequestSubscriptions map[uuid.UUID]*BoardSessionRequestSubscription

anonymousLoginDisabled bool
// note: if more options come with time, it might be sensible to wrap them into a struct
anonymousLoginDisabled bool
experimentalFileSystemStore bool
}

func New(
Expand All @@ -65,6 +70,7 @@ func New(
verbose bool,
checkOrigin bool,
anonymousLoginDisabled bool,
experimentalFileSystemStore bool,
) chi.Router {
r := chi.NewRouter()
r.Use(middleware.Recoverer)
Expand Down Expand Up @@ -106,7 +112,8 @@ func New(
boardReactions: boardReactions,
boardTemplates: boardTemplates,

anonymousLoginDisabled: anonymousLoginDisabled,
anonymousLoginDisabled: anonymousLoginDisabled,
experimentalFileSystemStore: experimentalFileSystemStore,
}

// initialize websocket upgrader with origin check depending on options
Expand All @@ -115,6 +122,16 @@ func New(
WriteBufferSize: 1024,
}

// if enabled, this experimental feature allows for larger session cookies by storing them in a file store.
// this might be required when using some OIDC providers which exceed the 4KB limit.
// see https://github.com/markbates/goth/pull/141
if s.experimentalFileSystemStore {
logger.Get().Infow("using experimental file system store")
store := gorillaSessions.NewFilesystemStore(os.TempDir(), []byte("scrumlr.io"))
store.MaxLength(0x8000) // 32KB should be plenty of space
gothic.Store = store
}

if checkOrigin {
s.upgrader.CheckOrigin = nil
} else {
Expand Down
8 changes: 8 additions & 0 deletions server/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ func main() {
Required: false,
Value: false,
}),
altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "auth-enable-experimental-file-system-store",
EnvVars: []string{"SCRUMLR_ENABLE_EXPERIMENTAL_AUTH_FILE_SYSTEM_STORE"},
Usage: "enables/disables experimental file system store, in order to allow larger session cookie sizes",
Required: false,
Value: false,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "auth-callback-host",
Aliases: []string{"c"},
Expand Down Expand Up @@ -373,6 +380,7 @@ func run(c *cli.Context) error {
c.Bool("verbose"),
!c.Bool("disable-check-origin"),
c.Bool("disable-anonymous-login"),
c.Bool("auth-enable-experimental-file-system-store"),
)

port := fmt.Sprintf(":%d", c.Int("port"))
Expand Down
Loading