feat: adopt shared internal SSO sessions and add no-sso launch mode
This commit is contained in:
1 parent
c209f1effc
commit
c02bf755f2
51 files changed
+2131
-362
No files matched your search
@@ -122,6 +122,7 @@ var initCmd = &cobra.Command{
|
||||
c.ImageProcessors = min(2, runtime.NumCPU())
|
||||
public, _ := url.Parse(c.SSO.PublicURL)
|
||||
c.BaseURL = strings.TrimRight(public.Path, "/")
|
||||
c.SSO.RedirectURI = strings.TrimRight(c.SSO.PublicURL, "/") + "/auth/callback"
|
||||
c.DisableExec = true
|
||||
if err = os.MkdirAll(c.Root, 0750); err != nil {
|
||||
return err
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOnlyExplicitNoSSOFlagSkipsInitialSSOSetup(t *testing.T) {
|
||||
for _, enabled := range []bool{false, true} {
|
||||
dir := t.TempDir()
|
||||
config := filepath.Join(dir, "config.json")
|
||||
// A JSON setting must not enable this process-only bypass.
|
||||
if err := os.WriteFile(config, []byte(`{"no-sso":true}`), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
command := &cobra.Command{Use: "filebrowser"}
|
||||
command.Flags().String("config", config, "")
|
||||
command.Flags().String("database", filepath.Join(dir, "test.db"), "")
|
||||
command.Flags().Bool("no-sso", false, "")
|
||||
if enabled {
|
||||
command.Flags().Set("no-sso", "true")
|
||||
}
|
||||
called := false
|
||||
err := withViperAndStore(func(_ *cobra.Command, _ []string, _ *viper.Viper, _ *store) error { called = true; return nil }, storeOptions{allowsNoDatabase: true})(command, nil)
|
||||
if enabled && (err != nil || !called) {
|
||||
t.Fatalf("explicit flag blocked: %v", err)
|
||||
}
|
||||
if !enabled && (err == nil || called) {
|
||||
t.Fatal("configuration silently enabled no-sso")
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-5
@@ -85,6 +85,7 @@ func init() {
|
||||
|
||||
// Runtime flags for the root command
|
||||
flags := rootCmd.Flags()
|
||||
flags.Bool("no-sso", false, "start without SSO or passwords; everyone with network access is an administrator")
|
||||
flags.Uint32("socketPerm", 0666, "unix socket file permissions")
|
||||
flags.String("cacheDir", "", "file cache directory (disabled if empty)")
|
||||
flags.String("redisCacheUrl", "", "redis cache URL (for multi-instance deployments), e.g. redis://user:pass@host:port")
|
||||
@@ -119,8 +120,8 @@ var rootCmd = &cobra.Command{
|
||||
manage your users and all the configurations without accessing the
|
||||
web interface.
|
||||
|
||||
Run filebrowser init for initial setup. It creates the configuration file, prepares the database and prints the SSO callback URL. Local password accounts and command execution are not supported. Runtime options can still be overridden using flags or FB_ environment variables.`,
|
||||
RunE: withViperAndStore(func(_ *cobra.Command, _ []string, v *viper.Viper, st *store) error {
|
||||
Run filebrowser init for initial setup. It creates the configuration file, prepares the database and prints the SSO callback URL. Local password accounts and command execution are not supported. Use --no-sso to start without SSO or passwords, granting administrator access to all visitors. Runtime options can still be overridden using flags or FB_ environment variables.`,
|
||||
RunE: withViperAndStore(func(cmd *cobra.Command, _ []string, v *viper.Viper, st *store) error {
|
||||
if !st.databaseExisted {
|
||||
err := quickSetup(v, st.Storage)
|
||||
if err != nil {
|
||||
@@ -156,7 +157,7 @@ Run filebrowser init for initial setup. It creates the configuration file, prepa
|
||||
}
|
||||
setupLog(server.Log)
|
||||
|
||||
log.Println("File Browser SSO edition")
|
||||
log.Println("File Browser")
|
||||
|
||||
root, err := filepath.Abs(server.Root)
|
||||
if err != nil {
|
||||
@@ -206,10 +207,20 @@ Run filebrowser init for initial setup. It creates the configuration file, prepa
|
||||
// Execution hooks and external symlinks are never enabled in this fork.
|
||||
server.EnableExec = false
|
||||
server.FollowExternalSymlinks = false
|
||||
sso, err := fbhttp.NewSSO(context.Background(), st.Storage, server, fbhttp.SSOConfig{Issuer: v.GetString("sso.issuer"), ClientID: v.GetString("sso.clientID"), ClientSecret: v.GetString("sso.clientSecret"), PublicURL: v.GetString("sso.publicURL")})
|
||||
var authentication interface {
|
||||
Wrap(http.Handler) http.Handler
|
||||
}
|
||||
noSSO, _ := cmd.Flags().GetBool("no-sso")
|
||||
if noSSO {
|
||||
authentication, err = fbhttp.NewNoSSO(st.Storage, server)
|
||||
log.Println("--no-sso: authentication disabled; all visitors have administrator access")
|
||||
} else {
|
||||
authentication, err = fbhttp.NewSSO(context.Background(), st.Storage, server, fbhttp.SSOConfig{Issuer: v.GetString("sso.issuer"), ClientID: v.GetString("sso.clientID"), ClientSecret: v.GetString("sso.clientSecret"), PublicURL: v.GetString("sso.publicURL"), RedirectURI: v.GetString("sso.redirectURI")})
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
handler, err := fbhttp.NewHandler(imageService, fileCache, uploadCache, st.Storage, server, assetsFs)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -219,7 +230,7 @@ Run filebrowser init for initial setup. It creates the configuration file, prepa
|
||||
|
||||
log.Println("Listening on", listener.Addr().String())
|
||||
srv := &http.Server{
|
||||
Handler: sso.Wrap(handler),
|
||||
Handler: authentication.Wrap(handler),
|
||||
ReadHeaderTimeout: 10 * time.Second,
|
||||
IdleTimeout: 90 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
|
||||
+2
-1
@@ -153,7 +153,8 @@ func withViperAndStore(fn func(cmd *cobra.Command, args []string, v *viper.Viper
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if cmd.Parent() == nil && cmd.Use == "filebrowser" && (v.GetString("sso.issuer") == "" || v.GetString("sso.clientID") == "" || v.GetString("sso.clientSecret") == "" || v.GetString("sso.publicURL") == "") {
|
||||
noSSO, _ := cmd.Flags().GetBool("no-sso")
|
||||
if cmd.Parent() == nil && cmd.Use == "filebrowser" && !noSSO && (v.GetString("sso.issuer") == "" || v.GetString("sso.clientID") == "" || v.GetString("sso.clientSecret") == "" || v.GetString("sso.publicURL") == "") {
|
||||
return errors.New("initial setup required: run filebrowser init")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user