@@ -13,27 +13,27 @@ import (
13
13
"golang.org/x/crypto/ssh"
14
14
)
15
15
16
- // CommonSSH is a common function for ssh'ing to a podman machine using system-connections
16
+ // LocalhostSSH is a common function for ssh'ing to a podman machine using system-connections
17
17
// and a port
18
18
// TODO This should probably be taught about an machineconfig to reduce input
19
- func CommonSSH (username , identityPath , name string , sshPort int , inputArgs []string ) error {
20
- return commonBuiltinSSH (username , identityPath , name , sshPort , inputArgs , true , os .Stdin )
19
+ func LocalhostSSH (username , identityPath , name string , sshPort int , inputArgs []string ) error {
20
+ return localhostBuiltinSSH (username , identityPath , name , sshPort , inputArgs , true , os .Stdin )
21
21
}
22
22
23
- func CommonSSHShell (username , identityPath , name string , sshPort int , inputArgs []string ) error {
24
- return commonNativeSSH (username , identityPath , name , sshPort , inputArgs , os .Stdin )
23
+ func LocalhostSSHShell (username , identityPath , name string , sshPort int , inputArgs []string ) error {
24
+ return localhostNativeSSH (username , identityPath , name , sshPort , inputArgs , os .Stdin )
25
25
}
26
26
27
- func CommonSSHSilent (username , identityPath , name string , sshPort int , inputArgs []string ) error {
28
- return commonBuiltinSSH (username , identityPath , name , sshPort , inputArgs , false , nil )
27
+ func LocalhostSSHSilent (username , identityPath , name string , sshPort int , inputArgs []string ) error {
28
+ return localhostBuiltinSSH (username , identityPath , name , sshPort , inputArgs , false , nil )
29
29
}
30
30
31
- func CommonSSHWithStdin (username , identityPath , name string , sshPort int , inputArgs []string , stdin io.Reader ) error {
32
- return commonBuiltinSSH (username , identityPath , name , sshPort , inputArgs , true , stdin )
31
+ func LocalhostSSHWithStdin (username , identityPath , name string , sshPort int , inputArgs []string , stdin io.Reader ) error {
32
+ return localhostBuiltinSSH (username , identityPath , name , sshPort , inputArgs , true , stdin )
33
33
}
34
34
35
- func commonBuiltinSSH (username , identityPath , name string , sshPort int , inputArgs []string , passOutput bool , stdin io.Reader ) error {
36
- config , err := createConfig (username , identityPath )
35
+ func localhostBuiltinSSH (username , identityPath , name string , sshPort int , inputArgs []string , passOutput bool , stdin io.Reader ) error {
36
+ config , err := createLocalhostConfig (username , identityPath ) // WARNING: This MUST NOT be generalized to allow communication over untrusted networks.
37
37
if err != nil {
38
38
return err
39
39
}
@@ -91,7 +91,10 @@ func runSessionWithDebug(session *ssh.Session, cmd string) error {
91
91
return session .Wait ()
92
92
}
93
93
94
- func createConfig (user string , identityPath string ) (* ssh.ClientConfig , error ) {
94
+ // createLocalhostConfig returns a *ssh.ClientConfig for authenticating a user using a private key
95
+ //
96
+ // WARNING: This MUST NOT be used to communicate over untrusted networks.
97
+ func createLocalhostConfig (user string , identityPath string ) (* ssh.ClientConfig , error ) {
95
98
key , err := os .ReadFile (identityPath )
96
99
if err != nil {
97
100
return nil , err
@@ -103,18 +106,23 @@ func createConfig(user string, identityPath string) (*ssh.ClientConfig, error) {
103
106
}
104
107
105
108
return & ssh.ClientConfig {
106
- User : user ,
107
- Auth : []ssh.AuthMethod {ssh .PublicKeys (signer )},
109
+ // Not specifying ciphers / MACs seems to allow fairly weak ciphers. This config is restricted
110
+ // to connecting to localhost: where we rely on the kernel’s process isolation, not primarily on cryptography.
111
+ User : user ,
112
+ Auth : []ssh.AuthMethod {ssh .PublicKeys (signer )},
113
+ // This config is restricted to connecting to localhost (and to a VM we manage),
114
+ // we rely on the kernel’s process isolation, not on cryptography,
115
+ // This would be UNACCEPTABLE for most other uses.
108
116
HostKeyCallback : ssh .InsecureIgnoreHostKey (),
109
117
}, nil
110
118
}
111
119
112
- func commonNativeSSH (username , identityPath , name string , sshPort int , inputArgs []string , stdin io.Reader ) error {
120
+ func localhostNativeSSH (username , identityPath , name string , sshPort int , inputArgs []string , stdin io.Reader ) error {
113
121
sshDestination := username + "@localhost"
114
122
port := strconv .Itoa (sshPort )
115
123
interactive := true
116
124
117
- args := append ([]string {"-i" , identityPath , "-p" , port , sshDestination }, CommonSSHArgs ()... )
125
+ args := append ([]string {"-i" , identityPath , "-p" , port , sshDestination }, LocalhostSSHArgs ()... ) // WARNING: This MUST NOT be generalized to allow communication over untrusted networks.
118
126
if len (inputArgs ) > 0 {
119
127
interactive = false
120
128
args = append (args , inputArgs ... )
@@ -134,7 +142,13 @@ func commonNativeSSH(username, identityPath, name string, sshPort int, inputArgs
134
142
return cmd .Run ()
135
143
}
136
144
137
- func CommonSSHArgs () []string {
145
+ // LocalhostSSHArgs returns OpenSSH command-line options for connecting with no host key identity checks.
146
+ //
147
+ // WARNING: This MUST NOT be used to communicate over untrusted networks.
148
+ func LocalhostSSHArgs () []string {
149
+ // This config is restricted to connecting to localhost (and to a VM we manage),
150
+ // we rely on the kernel’s process isolation, not on cryptography,
151
+ // This would be UNACCEPTABLE for most other uses.
138
152
return []string {
139
153
"-o" , "IdentitiesOnly=yes" ,
140
154
"-o" , "StrictHostKeyChecking=no" ,
0 commit comments