Skip to content

Commit

Permalink
config: make sftp could be configured dynamically
Browse files Browse the repository at this point in the history
    - add `harvester.os.sshd.sftp` to config `sftp` dynamically

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
  • Loading branch information
Vicente-Cheng authored and bk201 committed Jan 5, 2024
1 parent 03ad687 commit c3aab22
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,18 @@ type OS struct {
Password string `json:"password,omitempty"`
Environment map[string]string `json:"environment,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
SSHD SSHDConfig `json:"sshd,omitempty"`

PersistentStatePaths []string `json:"persistentStatePaths,omitempty"`
}

// SSHDConfig is the SSHD configuration for the node
//
// - SFTP: the switch to enable/disable SFTP
type SSHDConfig struct {
SFTP bool `json:"sftp,omitempty"`
}

type HarvesterConfig struct {
// Harvester will use scheme version to determine current version and migrate config to new scheme version
SchemeVersion uint32 `json:"schemeVersion,omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ func ConvertToCOS(config *HarvesterConfig) (*yipSchema.YipConfig, error) {
},
}

// Handle the sshd components
overwriteSSHDComponent(config)

// Add after-install-chroot stage
if len(config.OS.AfterInstallChrootCommands) > 0 {
afterInstallChroot := yipSchema.Stage{}
Expand All @@ -217,6 +220,13 @@ func ConvertToCOS(config *HarvesterConfig) (*yipSchema.YipConfig, error) {
return cosConfig, nil
}

func overwriteSSHDComponent(config *HarvesterConfig) {
if config.OS.SSHD.SFTP {
config.OS.AfterInstallChrootCommands = append(config.OS.AfterInstallChrootCommands, "mkdir -p /etc/ssh/sshd_config.d")
config.OS.AfterInstallChrootCommands = append(config.OS.AfterInstallChrootCommands, "echo 'Subsystem sftp /usr/lib/ssh/sftp-server' > /etc/ssh/sshd_config.d/sftp.conf")
}
}

func overwriteAfterInstallChrootStage(config *HarvesterConfig, stage *yipSchema.Stage) error {
content, err := render("cos-after-install-chroot.yaml", config)
if err != nil {
Expand Down

0 comments on commit c3aab22

Please sign in to comment.