@@ -88,9 +88,34 @@ func (m *SSHHostManager) createSshClient() (*ssh.Client, error) {
8888 if err != nil {
8989 return nil , fmt .Errorf ("failed to read SSH key file: %w" , err )
9090 }
91- signer , err := ssh .ParsePrivateKey (key )
92- if err != nil {
93- return nil , fmt .Errorf ("failed to parse SSH private key: %w" , err )
91+ var signer ssh.Signer
92+ if m .ExporterHost .Spec .Management .SSH .SSHKeyPassword != "" {
93+ signer , err = ssh .ParsePrivateKeyWithPassphrase (key , []byte (m .ExporterHost .Spec .Management .SSH .SSHKeyPassword ))
94+ if err != nil {
95+ return nil , fmt .Errorf ("failed to parse encrypted SSH private key from file: %w" , err )
96+ }
97+ } else {
98+ signer , err = ssh .ParsePrivateKey (key )
99+ if err != nil {
100+ return nil , fmt .Errorf ("failed to parse SSH private key from file: %w" , err )
101+ }
102+ }
103+ auth = append (auth , ssh .PublicKeys (signer ))
104+ }
105+
106+ if m .ExporterHost .Spec .Management .SSH .SSHKeyData != "" {
107+ var signer ssh.Signer
108+ var err error
109+ if m .ExporterHost .Spec .Management .SSH .SSHKeyPassword != "" {
110+ signer , err = ssh .ParsePrivateKeyWithPassphrase ([]byte (m .ExporterHost .Spec .Management .SSH .SSHKeyData ), []byte (m .ExporterHost .Spec .Management .SSH .SSHKeyPassword ))
111+ if err != nil {
112+ return nil , fmt .Errorf ("failed to parse encrypted SSH private key from sshKeyData: %w" , err )
113+ }
114+ } else {
115+ signer , err = ssh .ParsePrivateKey ([]byte (m .ExporterHost .Spec .Management .SSH .SSHKeyData ))
116+ if err != nil {
117+ return nil , fmt .Errorf ("failed to parse SSH private key from sshKeyData: %w" , err )
118+ }
94119 }
95120 auth = append (auth , ssh .PublicKeys (signer ))
96121 }
@@ -102,19 +127,18 @@ func (m *SSHHostManager) createSshClient() (*ssh.Client, error) {
102127 // Check if SSH agent is running and use it if available
103128 agentSocket := os .Getenv ("SSH_AUTH_SOCK" )
104129 if agentSocket != "" {
105- log .Fatal ("SSH_AUTH_SOCK environment variable not set. Is ssh-agent running?" )
106-
107130 // Connect to the agent's socket.
108131 conn , err := net .Dial ("unix" , agentSocket )
109132 if err != nil {
110- log .Fatalf ("Failed to open SSH_AUTH_SOCK : %v" , err )
111- }
112- defer conn .Close () // nolint:errcheck
133+ log .Printf ("Failed to connect to SSH agent : %v" , err )
134+ } else {
135+ defer conn .Close () // nolint:errcheck
113136
114- // Create a new agent client.
115- agentClient := agent .NewClient (conn )
137+ // Create a new agent client.
138+ agentClient := agent .NewClient (conn )
116139
117- auth = append (auth , ssh .PublicKeysCallback (agentClient .Signers ))
140+ auth = append (auth , ssh .PublicKeysCallback (agentClient .Signers ))
141+ }
118142 }
119143
120144 config := & ssh.ClientConfig {
0 commit comments