SFTP: support reloading user store on HUP signal (#7651)

Fixes #7650

This change enables the SFTP server to reload the user store configuration
(sftp_userstore.json) when a HUP signal is sent to the process, without
requiring a service restart.

Changes:
- Add Reload() method to FileStore to re-read users from disk
- Add Reload() method to SFTPService to handle reload requests
- Register reload hook with grace.OnReload() in sftp command

This allows administrators to add users or change access policies
dynamically by editing the user store file and sending a HUP signal
(e.g., 'systemctl reload seaweedfs' or 'kill -HUP <pid>').
This commit is contained in:
Chris Lu
2025-12-08 01:24:42 -08:00
committed by GitHub
parent f5c0bcafa3
commit 982aae6d53
3 changed files with 21 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/sftpd" "github.com/seaweedfs/seaweedfs/weed/sftpd"
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats" stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
"github.com/seaweedfs/seaweedfs/weed/util" "github.com/seaweedfs/seaweedfs/weed/util"
"github.com/seaweedfs/seaweedfs/weed/util/grace"
) )
var ( var (
@@ -148,6 +149,9 @@ func (sftpOpt *SftpOptions) startSftpServer() bool {
UserStoreFile: *sftpOpt.userStoreFile, UserStoreFile: *sftpOpt.userStoreFile,
}) })
// Register reload hook for HUP signal
grace.OnReload(service.Reload)
// Set up Unix socket if on non-Windows platforms // Set up Unix socket if on non-Windows platforms
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
localSocket := *sftpOpt.localSocket localSocket := *sftpOpt.localSocket

View File

@@ -300,3 +300,15 @@ func (s *SFTPService) handleSFTP(channel ssh.Channel, fs *SftpServer) {
glog.Errorf("SFTP server finished with error: %v", err) glog.Errorf("SFTP server finished with error: %v", err)
} }
} }
// Reload reloads the user store from disk, useful for HUP signal handling
func (s *SFTPService) Reload() {
glog.V(0).Info("Reload SFTP server...")
if fileStore, ok := s.userStore.(*user.FileStore); ok {
if err := fileStore.Reload(); err != nil {
glog.Errorf("Failed to reload user store: %v", err)
} else {
glog.V(0).Info("Successfully reloaded SFTP user store")
}
}
}

View File

@@ -264,3 +264,8 @@ func (s *FileStore) CreateUser(username, password string) (*User, error) {
return user, nil return user, nil
} }
// Reload reloads users from the file, useful for HUP signal handling
func (s *FileStore) Reload() error {
return s.loadUsers()
}