Skip to content

Remove any host keys generated during build #67

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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions pkg/stages/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ func GetCleanupStage(sis values.System, l types.KairosLogger) []schema.Stage {
"truncate -s 0 /etc/hostname",
},
},
{
Name: "Remove host ssh keys",
If: "test -d /etc/ssh",
Commands: []string{
"rm -f /etc/ssh/ssh_host_*_key*",
},
},
}

var pkgs []values.VersionMap
Expand Down
13 changes: 13 additions & 0 deletions pkg/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/kairos-io/kairos-sdk/types"
"os"
"os/exec"
"path/filepath"
"strings"
)

Expand Down Expand Up @@ -189,5 +190,17 @@ func (v *Validator) Validate() error {
}
}

// Check if there are any ssh host keys in /etc/ssh
matches, err := filepath.Glob("/etc/ssh/ssh_host_*_key")
if err != nil {
multi = multierror.Append(multi, fmt.Errorf("error checking for SSH host keys: %s", err))
}
if len(matches) > 0 {
v.Log.Logger.Warn().Strs("ssh_host_keys", matches).Msg("Found SSH host keys in the system")
multi = multierror.Append(multi, fmt.Errorf("found SSH host keys in the system: %v", matches))
} else {
v.Log.Logger.Info().Msg("No SSH host keys found bundled in the system")
}

return multi.ErrorOrNil()
}