Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: make sftp could be configured dynamically #562

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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