Skip to content

Commit d7a7c30

Browse files
authored
openssh: add host keys for gateway[.dev].devbox.sh (#360)
The gateway servers have already been updated to use a stable host key in order to eliminate key verification errors. Now we can also enable strict host key checking for the devbox CLI by including the host public keys in ~/.config/devbox/ssh/config. The tests are simplified a little bit to use `fstest.MapFS` instead of creating the in/out testdata directories. This eliminates the need for a custom `perms.json` file to track permissions. It also makes viewing the data easier since it's no longer in hidden files.
1 parent c76ea83 commit d7a7c30

File tree

18 files changed

+251
-189
lines changed

18 files changed

+251
-189
lines changed

internal/cloud/openssh/config.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import (
2121
var sshConfigText string
2222
var sshConfigTmpl = template.Must(template.New("sshconfig").Parse(sshConfigText))
2323

24+
//go:embed known_hosts
25+
var sshKnownHosts []byte
26+
2427
// SetupDevbox updates the user's OpenSSH configuration so that they can connect
2528
// to Devbox Cloud hosts. It does nothing if Devbox Cloud is already
2629
// configured.
@@ -29,6 +32,20 @@ func SetupDevbox() error {
2932
if err != nil {
3033
return err
3134
}
35+
36+
devboxKnownHostsPath := filepath.Join(devboxSSHDir, "known_hosts")
37+
devboxKnownHosts, err := editFile(devboxKnownHostsPath, 0644)
38+
if err != nil {
39+
return err
40+
}
41+
defer devboxKnownHosts.Close()
42+
if _, err := devboxKnownHosts.Write(sshKnownHosts); err != nil {
43+
return err
44+
}
45+
if err := devboxKnownHosts.Commit(); err != nil {
46+
return err
47+
}
48+
3249
devboxIncludePath := filepath.Join(devboxSSHDir, "config")
3350
devboxSSHConfig, err := editFile(devboxIncludePath, 0644)
3451
if err != nil {

0 commit comments

Comments
 (0)