ensure that defaults defined in code match the default config file

Fixes #754

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-03-14 10:42:14 +01:00
parent 0bec1c6012
commit 7e7f662a23
5 changed files with 9 additions and 5 deletions

View File

@@ -187,9 +187,9 @@ func Init() {
RateLimitersConfig: []common.RateLimiterConfig{defaultRateLimiter}, RateLimitersConfig: []common.RateLimiterConfig{defaultRateLimiter},
}, },
SFTPD: sftpd.Configuration{ SFTPD: sftpd.Configuration{
Banner: defaultSFTPDBanner,
Bindings: []sftpd.Binding{defaultSFTPDBinding}, Bindings: []sftpd.Binding{defaultSFTPDBinding},
MaxAuthTries: 0, MaxAuthTries: 0,
Banner: defaultSFTPDBanner,
HostKeys: []string{}, HostKeys: []string{},
KexAlgorithms: []string{}, KexAlgorithms: []string{},
Ciphers: []string{}, Ciphers: []string{},
@@ -259,7 +259,7 @@ func Init() {
RootCert: "", RootCert: "",
ClientCert: "", ClientCert: "",
ClientKey: "", ClientKey: "",
TrackQuota: 1, TrackQuota: 2,
PoolSize: 0, PoolSize: 0,
UsersBaseDir: "", UsersBaseDir: "",
Actions: dataprovider.ObjectsActions{ Actions: dataprovider.ObjectsActions{
@@ -355,7 +355,7 @@ func Init() {
TOTP: nil, TOTP: nil,
}, },
TelemetryConfig: telemetry.Conf{ TelemetryConfig: telemetry.Conf{
BindPort: 10000, BindPort: 0,
BindAddress: "127.0.0.1", BindAddress: "127.0.0.1",
EnableProfiler: false, EnableProfiler: false,
AuthUserFile: "", AuthUserFile: "",
@@ -572,6 +572,7 @@ func LoadConfig(configDir, configFile string) error {
logger.Warn(logSender, "", "error loading configuration file: %v", err) logger.Warn(logSender, "", "error loading configuration file: %v", err)
logger.WarnToConsole("error loading configuration file: %v", err) logger.WarnToConsole("error loading configuration file: %v", err)
} }
globalConf.MFAConfig.TOTP = []mfa.TOTPConfig{defaultTOTP}
} }
err = viper.Unmarshal(&globalConf) err = viper.Unmarshal(&globalConf)
if err != nil { if err != nil {

View File

@@ -67,6 +67,8 @@ func TestLoadConfigFileNotFound(t *testing.T) {
viper.SetConfigName("configfile") viper.SetConfigName("configfile")
err := config.LoadConfig(os.TempDir(), "") err := config.LoadConfig(os.TempDir(), "")
assert.NoError(t, err) assert.NoError(t, err)
mfaConf := config.GetMFAConfig()
assert.Len(t, mfaConf.TOTP, 1)
} }
func TestEmptyBanner(t *testing.T) { func TestEmptyBanner(t *testing.T) {

View File

@@ -133,7 +133,7 @@ The configuration file contains the following sections:
- `debug`, boolean. If enabled any FTP command will be logged. This will generate a lot of logs. Enable only if you are investigating a client compatibility issue or something similar. You shouldn't leave this setting enabled for production servers. Default `false`. - `debug`, boolean. If enabled any FTP command will be logged. This will generate a lot of logs. Enable only if you are investigating a client compatibility issue or something similar. You shouldn't leave this setting enabled for production servers. Default `false`.
- `banner`, string. Greeting banner displayed when a connection first comes in. Leave empty to use the default banner. Default `SFTPGo <version> ready`, for example `SFTPGo 1.0.0-dev ready`. - `banner`, string. Greeting banner displayed when a connection first comes in. Leave empty to use the default banner. Default `SFTPGo <version> ready`, for example `SFTPGo 1.0.0-dev ready`.
- `banner_file`, path to the banner file. The contents of the specified file, if any, are displayed when someone connects to the server. It can be a path relative to the config dir or an absolute one. If set, it overrides the banner string provided by the `banner` option. Leave empty to disable. - `banner_file`, path to the banner file. The contents of the specified file, if any, are displayed when someone connects to the server. It can be a path relative to the config dir or an absolute one. If set, it overrides the banner string provided by the `banner` option. Leave empty to disable.
- `active_transfers_port_non_20`, boolean. Do not impose the port 20 for active data transfers. Enabling this option allows to run SFTPGo with less privilege. Default: false. - `active_transfers_port_non_20`, boolean. Do not impose the port 20 for active data transfers. Enabling this option allows to run SFTPGo with less privilege. Default: `true`.
- `passive_port_range`, struct containing the key `start` and `end`. Port Range for data connections. Random if not specified. Default range is 50000-50100. - `passive_port_range`, struct containing the key `start` and `end`. Port Range for data connections. Random if not specified. Default range is 50000-50100.
- `disable_active_mode`, boolean. Set to `true` to disable active FTP, default `false`. - `disable_active_mode`, boolean. Set to `true` to disable active FTP, default `false`.
- `enable_site`, boolean. Set to true to enable the FTP SITE command. We support `chmod` and `symlink` if SITE support is enabled. Default `false` - `enable_site`, boolean. Set to true to enable the FTP SITE command. We support `chmod` and `symlink` if SITE support is enabled. Default `false`

View File

@@ -16,7 +16,7 @@ const (
var ( var (
supportedSSHCommands = []string{"scp", "md5sum", "sha1sum", "sha256sum", "sha384sum", "sha512sum", "cd", "pwd", supportedSSHCommands = []string{"scp", "md5sum", "sha1sum", "sha256sum", "sha384sum", "sha512sum", "cd", "pwd",
"git-receive-pack", "git-upload-pack", "git-upload-archive", "rsync", "sftpgo-copy", "sftpgo-remove"} "git-receive-pack", "git-upload-pack", "git-upload-archive", "rsync", "sftpgo-copy", "sftpgo-remove"}
defaultSSHCommands = []string{"md5sum", "sha1sum", "cd", "pwd", "scp"} defaultSSHCommands = []string{"md5sum", "sha1sum", "sha256sum", "cd", "pwd", "scp"}
sshHashCommands = []string{"md5sum", "sha1sum", "sha256sum", "sha384sum", "sha512sum"} sshHashCommands = []string{"md5sum", "sha1sum", "sha256sum", "sha384sum", "sha512sum"}
systemCommands = []string{"git-receive-pack", "git-upload-pack", "git-upload-archive", "rsync"} systemCommands = []string{"git-receive-pack", "git-upload-pack", "git-upload-archive", "rsync"}
serviceStatus ServiceStatus serviceStatus ServiceStatus

View File

@@ -70,6 +70,7 @@
"enabled_ssh_commands": [ "enabled_ssh_commands": [
"md5sum", "md5sum",
"sha1sum", "sha1sum",
"sha256sum",
"cd", "cd",
"pwd", "pwd",
"scp" "scp"