Skip to content

Commit 29935d6

Browse files
authored
Implement Sftp keyOnly authentication (#110)
1 parent d3b0581 commit 29935d6

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ type SftpConfiguration struct {
7070
Port int `default:"2022" json:"bind_port" yaml:"bind_port"`
7171
// If set to true, no write actions will be allowed on the SFTP server.
7272
ReadOnly bool `default:"false" yaml:"read_only"`
73+
// If set to true users won't be able to login using their password.
74+
KeyOnly bool `default:"false" yaml:"key_only"`
7375
}
7476

7577
// ApiConfiguration defines the configuration for the internal API that is

remote/errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ type SftpInvalidCredentialsError struct{}
6262
func (ice SftpInvalidCredentialsError) Error() string {
6363
return "the credentials provided were invalid"
6464
}
65+
66+
type SftpKeyOnlyError struct{}
67+
68+
func (ice SftpKeyOnlyError) Error() string {
69+
return "password authentication is disabled; only SSH keys are allowed"
70+
}

sftp/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ func (c *SFTPServer) makeCredentialsRequest(conn ssh.ConnMetadata, t remote.Sftp
223223
return nil, &remote.SftpInvalidCredentialsError{}
224224
}
225225

226+
if t == remote.SftpAuthPassword && config.Get().System.Sftp.KeyOnly {
227+
logger.Warn("failed to validate user credentials (password authentication is disabled; only SSH keys are allowed)")
228+
return nil, &remote.SftpKeyOnlyError{}
229+
}
230+
226231
resp, err := c.manager.Client().ValidateSftpCredentials(context.Background(), request)
227232
if err != nil {
228233
if _, ok := err.(*remote.SftpInvalidCredentialsError); ok {

0 commit comments

Comments
 (0)