feat: add SSO workspace, named shares and Debian release tooling
This commit is contained in:
1 parent
833d908884
commit
87bc33e675
106 files changed
+4160
-5637
No files matched your search
+1
-4
@@ -1,6 +1,3 @@
|
||||
package cmd
|
||||
|
||||
// Execute executes the commands.
|
||||
func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
func Execute() error { return rootCmd.Execute() }
|
||||
+2
-2
@@ -48,10 +48,10 @@ func TestGetSettingsFollowExternalSymlinks(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
set := &settings.Settings{AuthMethod: auth.MethodJSONAuth}
|
||||
set := &settings.Settings{AuthMethod: auth.MethodSSO}
|
||||
ser := &settings.Server{}
|
||||
|
||||
if _, err := getSettings(flags, set, ser, &auth.JSONAuth{}, false); err != nil {
|
||||
if _, err := getSettings(flags, set, ser, &auth.SSOAuth{}, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
+2
-112
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"github.com/filebrowser/filebrowser/v2/auth"
|
||||
fberrors "github.com/filebrowser/filebrowser/v2/errors"
|
||||
"github.com/filebrowser/filebrowser/v2/settings"
|
||||
)
|
||||
|
||||
@@ -35,22 +34,12 @@ func addConfigFlags(flags *pflag.FlagSet) {
|
||||
flags.Bool("hideLoginButton", false, "hide login button from public pages")
|
||||
flags.Bool("createUserDir", false, "generate user's home directory automatically")
|
||||
flags.Uint("minimumPasswordLength", settings.DefaultMinimumPasswordLength, "minimum password length for new users")
|
||||
flags.String("shell", "", "shell command to which other commands should be appended")
|
||||
|
||||
// NB: these are string so they can be presented as octal in the help text
|
||||
// as that's the conventional representation for modes in Unix.
|
||||
flags.String("fileMode", fmt.Sprintf("%O", settings.DefaultFileMode), "mode bits that new files are created with")
|
||||
flags.String("dirMode", fmt.Sprintf("%O", settings.DefaultDirMode), "mode bits that new directories are created with")
|
||||
|
||||
flags.String("auth.method", string(auth.MethodJSONAuth), "authentication type")
|
||||
flags.String("auth.header", "", "HTTP header for auth.method=proxy")
|
||||
flags.String("auth.command", "", "command for auth.method=hook")
|
||||
flags.String("auth.logoutPage", "", "url of custom logout page")
|
||||
|
||||
flags.String("recaptcha.host", "https://www.google.com", "use another host for ReCAPTCHA. recaptcha.net might be useful in China")
|
||||
flags.String("recaptcha.key", "", "ReCaptcha site key")
|
||||
flags.String("recaptcha.secret", "", "ReCaptcha secret")
|
||||
|
||||
flags.String("branding.name", "", "replace 'File Browser' by this name")
|
||||
flags.String("branding.theme", "", "set the theme")
|
||||
flags.String("branding.color", "", "set the theme color")
|
||||
@@ -93,107 +82,8 @@ func getAuthMethod(flags *pflag.FlagSet, defaults ...interface{}) (settings.Auth
|
||||
return method, defaultAuther, nil
|
||||
}
|
||||
|
||||
func getProxyAuth(flags *pflag.FlagSet, defaultAuther map[string]interface{}) (auth.Auther, error) {
|
||||
header, err := flags.GetString("auth.header")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if header == "" && defaultAuther != nil {
|
||||
header = defaultAuther["header"].(string)
|
||||
}
|
||||
|
||||
if header == "" {
|
||||
return nil, errors.New("you must set the flag 'auth.header' for method 'proxy'")
|
||||
}
|
||||
|
||||
return &auth.ProxyAuth{Header: header}, nil
|
||||
}
|
||||
|
||||
func getNoAuth() auth.Auther {
|
||||
return &auth.NoAuth{}
|
||||
}
|
||||
|
||||
func getJSONAuth(flags *pflag.FlagSet, defaultAuther map[string]interface{}) (auth.Auther, error) {
|
||||
jsonAuth := &auth.JSONAuth{}
|
||||
host, err := flags.GetString("recaptcha.host")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
key, err := flags.GetString("recaptcha.key")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
secret, err := flags.GetString("recaptcha.secret")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if key == "" {
|
||||
if kmap, ok := defaultAuther["recaptcha"].(map[string]interface{}); ok {
|
||||
key = kmap["key"].(string)
|
||||
}
|
||||
}
|
||||
|
||||
if secret == "" {
|
||||
if smap, ok := defaultAuther["recaptcha"].(map[string]interface{}); ok {
|
||||
secret = smap["secret"].(string)
|
||||
}
|
||||
}
|
||||
|
||||
if key != "" && secret != "" {
|
||||
jsonAuth.ReCaptcha = &auth.ReCaptcha{
|
||||
Host: host,
|
||||
Key: key,
|
||||
Secret: secret,
|
||||
}
|
||||
}
|
||||
return jsonAuth, nil
|
||||
}
|
||||
|
||||
func getHookAuth(flags *pflag.FlagSet, defaultAuther map[string]interface{}) (auth.Auther, error) {
|
||||
command, err := flags.GetString("auth.command")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if command == "" {
|
||||
command = defaultAuther["command"].(string)
|
||||
}
|
||||
|
||||
if command == "" {
|
||||
return nil, errors.New("you must set the flag 'auth.command' for method 'hook'")
|
||||
}
|
||||
|
||||
return &auth.HookAuth{Command: command}, nil
|
||||
}
|
||||
|
||||
func getAuthentication(flags *pflag.FlagSet, defaults ...interface{}) (settings.AuthMethod, auth.Auther, error) {
|
||||
method, defaultAuther, err := getAuthMethod(flags, defaults...)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
var auther auth.Auther
|
||||
switch method {
|
||||
case auth.MethodProxyAuth:
|
||||
auther, err = getProxyAuth(flags, defaultAuther)
|
||||
case auth.MethodNoAuth:
|
||||
auther = getNoAuth()
|
||||
case auth.MethodJSONAuth:
|
||||
auther, err = getJSONAuth(flags, defaultAuther)
|
||||
case auth.MethodHookAuth:
|
||||
auther, err = getHookAuth(flags, defaultAuther)
|
||||
default:
|
||||
return "", nil, fberrors.ErrInvalidAuthMethod
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
return method, auther, nil
|
||||
func getAuthentication(_ *pflag.FlagSet, _ ...interface{}) (settings.AuthMethod, auth.Auther, error) {
|
||||
return auth.MethodSSO, &auth.SSOAuth{}, nil
|
||||
}
|
||||
|
||||
func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Auther) error {
|
||||
|
||||
+5
-30
@@ -67,37 +67,12 @@ The path must be for a json or yaml file.`,
|
||||
return err
|
||||
}
|
||||
|
||||
var rawAuther = file.Auther
|
||||
|
||||
var auther auth.Auther
|
||||
var autherErr error
|
||||
switch file.Settings.AuthMethod {
|
||||
case auth.MethodJSONAuth:
|
||||
var a interface{}
|
||||
a, autherErr = getAuther(auth.JSONAuth{}, rawAuther)
|
||||
auther = a.(*auth.JSONAuth)
|
||||
case auth.MethodNoAuth:
|
||||
var a interface{}
|
||||
a, autherErr = getAuther(auth.NoAuth{}, rawAuther)
|
||||
auther = a.(*auth.NoAuth)
|
||||
case auth.MethodProxyAuth:
|
||||
var a interface{}
|
||||
a, autherErr = getAuther(auth.ProxyAuth{}, rawAuther)
|
||||
auther = a.(*auth.ProxyAuth)
|
||||
case auth.MethodHookAuth:
|
||||
var a interface{}
|
||||
a, autherErr = getAuther(&auth.HookAuth{}, rawAuther)
|
||||
auther = a.(*auth.HookAuth)
|
||||
default:
|
||||
return errors.New("invalid auth method")
|
||||
file.Settings.AuthMethod = auth.MethodSSO
|
||||
auther := &auth.SSOAuth{}
|
||||
if err = st.Settings.Save(file.Settings); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if autherErr != nil {
|
||||
return autherErr
|
||||
}
|
||||
|
||||
err = st.Auth.Save(auther)
|
||||
if err != nil {
|
||||
if err = st.Auth.Save(auther); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
fbhttp "github.com/filebrowser/filebrowser/v2/http"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
type initialConfig struct {
|
||||
CacheDir string `json:"cacheDir"`
|
||||
ImageProcessors int `json:"imageProcessors"`
|
||||
Address string `json:"address"`
|
||||
Port string `json:"port"`
|
||||
Root string `json:"root"`
|
||||
Database string `json:"database"`
|
||||
BaseURL string `json:"baseURL"`
|
||||
DisableExec bool `json:"disableExec"`
|
||||
SSO fbhttp.SSOConfig `json:"sso"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(initCmd)
|
||||
initCmd.Flags().String("output", ".filebrowser.json", "configuration file to create; existing files are never overwritten")
|
||||
}
|
||||
|
||||
var initCmd = &cobra.Command{
|
||||
Use: "init", Short: "Initial setup: SSO, file directory and database", Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
out, _ := cmd.Flags().GetString("output")
|
||||
out, err := filepath.Abs(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = os.Stat(out); err == nil {
|
||||
return errors.New("configuration already exists; edit it or select another --output")
|
||||
} else if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
reader := bufio.NewReader(cmd.InOrStdin())
|
||||
ask := func(label, fallback string) (string, error) {
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "%s [%s]: ", label, fallback)
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil && !(errors.Is(err, io.EOF) && line != "") {
|
||||
return "", err
|
||||
}
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
line = fallback
|
||||
}
|
||||
return line, nil
|
||||
}
|
||||
var c initialConfig
|
||||
fmt.Fprintln(cmd.OutOrStdout(), "File Browser — initial setup\nSSO roles Master Admin and FS Admin grant administrator access.")
|
||||
if c.SSO.Issuer, err = ask("SSO issuer URL", "https://sso.anidev.ru"); err != nil {
|
||||
return err
|
||||
}
|
||||
if c.SSO.ClientID, err = ask("SSO Client ID", ""); err != nil {
|
||||
return err
|
||||
}
|
||||
if term.IsTerminal(int(os.Stdin.Fd())) && cmd.InOrStdin() == os.Stdin {
|
||||
fmt.Fprint(cmd.OutOrStdout(), "SSO Client secret (hidden): ")
|
||||
var secret []byte
|
||||
secret, err = term.ReadPassword(int(os.Stdin.Fd()))
|
||||
c.SSO.ClientSecret = strings.TrimSpace(string(secret))
|
||||
fmt.Fprintln(cmd.OutOrStdout())
|
||||
} else {
|
||||
c.SSO.ClientSecret, err = ask("SSO Client secret", "")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c.SSO.PublicURL, err = ask("Public File Browser URL", "https://files.anidev.ru"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = validateSetupURL(c.SSO.Issuer); err != nil {
|
||||
return fmt.Errorf("issuer: %w", err)
|
||||
}
|
||||
if err = validateSetupURL(c.SSO.PublicURL); err != nil {
|
||||
return fmt.Errorf("public URL: %w", err)
|
||||
}
|
||||
if c.SSO.ClientID == "" || c.SSO.ClientSecret == "" {
|
||||
return errors.New("Client ID and secret are required")
|
||||
}
|
||||
if c.Root, err = ask("File directory", "./files"); err != nil {
|
||||
return err
|
||||
}
|
||||
if c.Database, err = ask("Database path", "./filebrowser.db"); err != nil {
|
||||
return err
|
||||
}
|
||||
if c.Address, err = ask("Listen address", "127.0.0.1"); err != nil {
|
||||
return err
|
||||
}
|
||||
if c.Port, err = ask("Listen port", "8080"); err != nil {
|
||||
return err
|
||||
}
|
||||
port, e := strconv.Atoi(c.Port)
|
||||
if e != nil || port < 1 || port > 65535 {
|
||||
return errors.New("invalid port")
|
||||
}
|
||||
c.Root, err = filepath.Abs(c.Root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Database, err = filepath.Abs(c.Database)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.CacheDir = filepath.Join(filepath.Dir(c.Database), "cache")
|
||||
c.ImageProcessors = min(2, runtime.NumCPU())
|
||||
public, _ := url.Parse(c.SSO.PublicURL)
|
||||
c.BaseURL = strings.TrimRight(public.Path, "/")
|
||||
c.DisableExec = true
|
||||
if err = os.MkdirAll(c.Root, 0750); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = os.MkdirAll(filepath.Dir(c.Database), 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := json.MarshalIndent(c, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.OpenFile(out, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = f.Write(append(b, '\n'))
|
||||
closeErr := f.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if closeErr != nil {
|
||||
return closeErr
|
||||
}
|
||||
bootstrapCmd := &cobra.Command{Use: "bootstrap"}
|
||||
bootstrapCmd.Flags().String("config", out, "")
|
||||
bootstrapCmd.Flags().String("database", c.Database, "")
|
||||
addServerFlags(bootstrapCmd.Flags())
|
||||
bootstrap := withViperAndStore(func(_ *cobra.Command, _ []string, v *viper.Viper, st *store) error {
|
||||
if !st.databaseExisted {
|
||||
return quickSetup(v, st.Storage)
|
||||
}
|
||||
return nil
|
||||
}, storeOptions{allowsNoDatabase: true})
|
||||
if err = bootstrap(bootstrapCmd, nil); err != nil {
|
||||
return fmt.Errorf("configuration saved; database setup failed: %w", err)
|
||||
}
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "\nSaved %s (0600).\nRegister this callback in SSO:\n%s/auth/callback\nStart: filebrowser --config %q\n", out, strings.TrimRight(c.SSO.PublicURL, "/"), out)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func validateSetupURL(raw string) error {
|
||||
u, err := url.Parse(raw)
|
||||
if err != nil || u.Host == "" || u.User != nil || u.RawQuery != "" || u.Fragment != "" || (u.Scheme != "https" && !(u.Scheme == "http" && (u.Hostname() == "localhost" || u.Hostname() == "127.0.0.1"))) {
|
||||
return errors.New("use an HTTPS URL; HTTP is allowed only on loopback")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInitWizard(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
configPath := filepath.Join(dir, "settings.json")
|
||||
input := strings.Join([]string{"https://sso.example.test", "client-id", "client-secret", "https://files.example.test", filepath.Join(dir, "files"), filepath.Join(dir, "files.db"), "127.0.0.1", "8080", ""}, "\n")
|
||||
var output bytes.Buffer
|
||||
initCmd.SetIn(strings.NewReader(input))
|
||||
initCmd.SetOut(&output)
|
||||
defer func() { initCmd.SetIn(nil); initCmd.SetOut(nil) }()
|
||||
if err := initCmd.Flags().Set("output", configPath); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := initCmd.RunE(initCmd, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var c initialConfig
|
||||
b, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = json.Unmarshal(b, &c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.SSO.ClientSecret != "client-secret" || !c.DisableExec || c.Root != filepath.Join(dir, "files") {
|
||||
t.Fatal("configuration lost")
|
||||
}
|
||||
if strings.Contains(output.String(), "client-secret") {
|
||||
t.Fatal("secret leaked to output")
|
||||
}
|
||||
if _, err = os.Stat(c.Database); err != nil {
|
||||
t.Fatal("database not initialized", err)
|
||||
}
|
||||
if !strings.Contains(output.String(), "https://files.example.test/auth/callback") {
|
||||
t.Fatal("callback missing")
|
||||
}
|
||||
initCmd.SetIn(strings.NewReader(input))
|
||||
if err = initCmd.RunE(initCmd, nil); err == nil {
|
||||
t.Fatal("existing configuration overwritten")
|
||||
}
|
||||
}
|
||||
+17
-86
@@ -85,9 +85,6 @@ func init() {
|
||||
|
||||
// Runtime flags for the root command
|
||||
flags := rootCmd.Flags()
|
||||
flags.Bool("noauth", false, "use the noauth auther when using quick setup")
|
||||
flags.String("username", "admin", "username for the first user when using quick setup")
|
||||
flags.String("password", "", "hashed password for the first user when using quick setup")
|
||||
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")
|
||||
@@ -122,40 +119,7 @@ var rootCmd = &cobra.Command{
|
||||
manage your users and all the configurations without accessing the
|
||||
web interface.
|
||||
|
||||
If you've never run File Browser, you'll need to have a database for
|
||||
it. Don't worry: you don't need to setup a separate database server.
|
||||
We're using Bolt DB which is a single file database and all managed
|
||||
by ourselves.
|
||||
|
||||
For this command, all flags are available as environmental variables,
|
||||
except for "--config", which specifies the configuration file to use.
|
||||
The environment variables are prefixed by "FB_" followed by the flag name in
|
||||
UPPER_SNAKE_CASE. For example, the flag "--disablePreviewResize" is available
|
||||
as FB_DISABLE_PREVIEW_RESIZE.
|
||||
|
||||
If "--config" is not specified, File Browser will look for a configuration
|
||||
file named .filebrowser.{json, toml, yaml, yml} in the following directories:
|
||||
|
||||
- ./
|
||||
- $HOME/
|
||||
- /etc/filebrowser/
|
||||
|
||||
**Note:** Only the options listed below can be set via the config file or
|
||||
environment variables. Other configuration options live exclusively in the
|
||||
database and so they must be set by the "config set" or "config
|
||||
import" commands.
|
||||
|
||||
The precedence of the configuration values are as follows:
|
||||
|
||||
- Flags
|
||||
- Environment variables
|
||||
- Configuration file
|
||||
- Database values
|
||||
- Defaults
|
||||
|
||||
Also, if the database path doesn't exist, File Browser will enter into
|
||||
the quick setup mode and a new database will be bootstrapped and a new
|
||||
user created with the credentials from options "username" and "password".`,
|
||||
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 {
|
||||
if !st.databaseExisted {
|
||||
err := quickSetup(v, st.Storage)
|
||||
@@ -192,10 +156,7 @@ user created with the credentials from options "username" and "password".`,
|
||||
}
|
||||
setupLog(server.Log)
|
||||
|
||||
log.Println("NOTICE: File Browser is being wound down.")
|
||||
log.Println("NOTICE: The project is archived on 2026-09-01, after which there will be no")
|
||||
log.Println("NOTICE: further releases and no security fixes. Known unfixed issues are at")
|
||||
log.Println("NOTICE: https://github.com/filebrowser/filebrowser/security/advisories")
|
||||
log.Println("File Browser SSO edition")
|
||||
|
||||
root, err := filepath.Abs(server.Root)
|
||||
if err != nil {
|
||||
@@ -242,6 +203,13 @@ user created with the credentials from options "username" and "password".`,
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 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")})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
handler, err := fbhttp.NewHandler(imageService, fileCache, uploadCache, st.Storage, server, assetsFs)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -251,8 +219,10 @@ user created with the credentials from options "username" and "password".`,
|
||||
|
||||
log.Println("Listening on", listener.Addr().String())
|
||||
srv := &http.Server{
|
||||
Handler: handler,
|
||||
ReadHeaderTimeout: 60 * time.Second,
|
||||
Handler: sso.Wrap(handler),
|
||||
ReadHeaderTimeout: 10 * time.Second,
|
||||
IdleTimeout: 90 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
}
|
||||
|
||||
go func() {
|
||||
@@ -438,7 +408,7 @@ func quickSetup(v *viper.Viper, s *storage.Storage) error {
|
||||
AceEditorTheme: v.GetString("defaults.aceEditorTheme"),
|
||||
Perm: users.Permissions{
|
||||
Admin: false,
|
||||
Execute: true,
|
||||
Execute: false,
|
||||
Create: true,
|
||||
Rename: true,
|
||||
Modify: true,
|
||||
@@ -458,18 +428,11 @@ func quickSetup(v *viper.Viper, s *storage.Storage) error {
|
||||
Rules: nil,
|
||||
}
|
||||
|
||||
var err error
|
||||
if v.GetBool("noauth") {
|
||||
set.AuthMethod = auth.MethodNoAuth
|
||||
err = s.Auth.Save(&auth.NoAuth{})
|
||||
} else {
|
||||
set.AuthMethod = auth.MethodJSONAuth
|
||||
err = s.Auth.Save(&auth.JSONAuth{})
|
||||
}
|
||||
set.AuthMethod = auth.MethodSSO
|
||||
err := s.Auth.Save(&auth.SSOAuth{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.Settings.Save(set)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -497,37 +460,5 @@ func quickSetup(v *viper.Viper, s *storage.Storage) error {
|
||||
return err
|
||||
}
|
||||
|
||||
username := v.GetString("username")
|
||||
password := v.GetString("password")
|
||||
|
||||
if password == "" {
|
||||
var pwd string
|
||||
pwd, err = users.RandomPwd(set.MinimumPasswordLength)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("User '%s' initialized with randomly generated password: %s\n", username, pwd)
|
||||
password, err = users.ValidateAndHashPwd(pwd, set.MinimumPasswordLength)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
log.Printf("User '%s' initialize wth user-provided password\n", username)
|
||||
}
|
||||
|
||||
if username == "" || password == "" {
|
||||
log.Fatal("username and password cannot be empty during quick setup")
|
||||
}
|
||||
|
||||
user := &users.User{
|
||||
Username: username,
|
||||
Password: password,
|
||||
LockPassword: false,
|
||||
}
|
||||
|
||||
set.Defaults.Apply(user)
|
||||
user.Perm.Admin = true
|
||||
|
||||
return s.Users.Save(user)
|
||||
return nil
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(usersCmd)
|
||||
// Local password account management is removed; users are provisioned by SSO.
|
||||
}
|
||||
|
||||
var usersCmd = &cobra.Command{
|
||||
|
||||
@@ -153,6 +153,9 @@ 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") == "") {
|
||||
return errors.New("initial setup required: run filebrowser init")
|
||||
}
|
||||
|
||||
path, err := filepath.Abs(v.GetString("database"))
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user