@@ -52,6 +52,7 @@ type connectionBase struct {
5252 AgentSocketPath * string `pulumi:"agentSocketPath,optional"`
5353 DialErrorLimit * int `pulumi:"dialErrorLimit,optional"`
5454 PerDialTimeout * int `pulumi:"perDialTimeout,optional"`
55+ HostKey * string `pulumi:"hostKey,optional"`
5556}
5657
5758func (c * Connection ) Annotate (a infer.Annotator ) {
@@ -70,13 +71,28 @@ func (c *Connection) Annotate(a infer.Annotator) {
7071 a .SetDefault (& c .DialErrorLimit , dialErrorDefault )
7172 a .Describe (& c .PerDialTimeout , "Max number of seconds for each dial attempt. 0 implies no maximum. Default value is 15 seconds." )
7273 a .SetDefault (& c .PerDialTimeout , 15 )
74+ a .Describe (& c .HostKey , "The expected host key to verify the server's identity. If not provided, the host key will be ignored." )
7375}
7476
7577func (con * connectionBase ) SShConfig () (* ssh.ClientConfig , error ) {
78+ var hostKeyCallback ssh.HostKeyCallback
79+ var hostKeyAlgorithms []string
80+ if con .HostKey != nil {
81+ publicKey , _ , _ , _ , err := ssh .ParseAuthorizedKey ([]byte (* con .HostKey ))
82+ if err != nil {
83+ return nil , fmt .Errorf ("failed to parse host key: %w" , err )
84+ }
85+ hostKeyCallback = ssh .FixedHostKey (publicKey )
86+ hostKeyAlgorithms = []string {publicKey .Type ()}
87+ } else {
88+ hostKeyCallback = ssh .InsecureIgnoreHostKey ()
89+ }
90+
7691 config := & ssh.ClientConfig {
77- User : * con .User ,
78- HostKeyCallback : ssh .InsecureIgnoreHostKey (),
79- Timeout : time .Second * time .Duration (* con .PerDialTimeout ),
92+ User : * con .User ,
93+ HostKeyCallback : hostKeyCallback ,
94+ HostKeyAlgorithms : hostKeyAlgorithms ,
95+ Timeout : time .Second * time .Duration (* con .PerDialTimeout ),
8096 }
8197 if con .PrivateKey != nil {
8298 var signer ssh.Signer
0 commit comments