@@ -160,16 +160,22 @@ func (m *managerImpl) getSSHClientOptions(ctx context.Context, authSecret map[st
160160 var tempFilePath string
161161 if knownHostsData , ok := authSecret ["known_hosts" ]; ok {
162162 tmpFile , err := os .CreateTemp ("" , "known_hosts-*" )
163- if err == nil {
164- if _ , err := tmpFile .Write (knownHostsData ); err == nil {
165- _ = tmpFile .Close ()
166- tempFilePath = tmpFile .Name ()
167- cb , err := gitssh .NewKnownHostsCallback (tempFilePath )
168- if err == nil {
169- auth .HostKeyCallback = cb
170- }
171- }
163+ if err != nil {
164+ return nil , "" , fmt .Errorf ("failed to create known_hosts temp file: %w" , err )
165+ }
166+ if _ , err := tmpFile .Write (knownHostsData ); err != nil {
167+ _ = tmpFile .Close ()
168+ _ = os .Remove (tmpFile .Name ())
169+ return nil , "" , fmt .Errorf ("failed to write known_hosts temp file: %w" , err )
170+ }
171+ _ = tmpFile .Close ()
172+ tempFilePath = tmpFile .Name ()
173+ cb , err := gitssh .NewKnownHostsCallback (tempFilePath )
174+ if err != nil {
175+ _ = os .Remove (tempFilePath )
176+ return nil , "" , fmt .Errorf ("failed to configure known_hosts callback: %w" , err )
172177 }
178+ auth .HostKeyCallback = cb
173179 } else {
174180 logger .Info ("SSH host key verification is disabled, provide known_hosts in auth secret to enable verification" )
175181 auth .HostKeyCallback = gossh .InsecureIgnoreHostKey ()
0 commit comments