Skip to content

Commit ad0ba07

Browse files
committed
Remove any host keys generated during build
We ship the images without ssh host keys as they have to be generated in the machine itself Signed-off-by: Itxaka <[email protected]>
1 parent 58f180a commit ad0ba07

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/stages/stages.go

+7
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ func GetCleanupStage(sis values.System, l types.KairosLogger) []schema.Stage {
441441
"truncate -s 0 /etc/hostname",
442442
},
443443
},
444+
{
445+
Name: "Remove host ssh keys",
446+
If: "test -d /etc/ssh",
447+
Commands: []string{
448+
"rm -f /etc/ssh/ssh_host_*_key*",
449+
},
450+
},
444451
}
445452

446453
var pkgs []values.VersionMap

pkg/validation/validate.go

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/kairos-io/kairos-sdk/types"
1111
"os"
1212
"os/exec"
13+
"path/filepath"
1314
"strings"
1415
)
1516

@@ -189,5 +190,17 @@ func (v *Validator) Validate() error {
189190
}
190191
}
191192

193+
// Check if there are any ssh host keys in /etc/ssh
194+
matches, err := filepath.Glob("/etc/ssh/ssh_host_*_key")
195+
if err != nil {
196+
multi = multierror.Append(multi, fmt.Errorf("error checking for SSH host keys: %s", err))
197+
}
198+
if len(matches) > 0 {
199+
v.Log.Logger.Warn().Strs("ssh_host_keys", matches).Msg("Found SSH host keys in the system")
200+
multi = multierror.Append(multi, fmt.Errorf("found SSH host keys in the system: %v", matches))
201+
} else {
202+
v.Log.Logger.Info().Msg("No SSH host keys found bundled in the system")
203+
}
204+
192205
return multi.ErrorOrNil()
193206
}

0 commit comments

Comments
 (0)