Skip to content

Commit

Permalink
fix: allow ssh-tunnel to work with password-auth
Browse files Browse the repository at this point in the history
Running the provider without a `private_key` in auth no
longer produces a runtime error.
Also, when provided password-authentication takes precedence
over ssh-socket-authentication.

Fixes AndrewChubatiuk#12
  • Loading branch information
david-jointech committed Jan 17, 2024
1 parent 50eb9a2 commit 740ad77
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,29 @@ func (p *SSHProvider) Configure(ctx context.Context, req provider.ConfigureReque
}

sshTunnel.Auth = []ssh.SSHAuth{}
privateKey := ssh.SSHPrivateKey{}
if data.Auth.PrivateKey.Content.ValueString() != "" {
privateKey.PrivateKey = data.Auth.PrivateKey.Content.ValueString()
}
if data.Auth.PrivateKey.Password.ValueString() != "" {
privateKey.Password = data.Auth.PrivateKey.Password.ValueString()
}
if data.Auth.PrivateKey.Certificate.ValueString() != "" {
privateKey.Certificate = data.Auth.PrivateKey.Certificate.ValueString()
if data.Auth.PrivateKey != nil {
privateKey := ssh.SSHPrivateKey{}
if data.Auth.PrivateKey.Content.ValueString() != "" {
privateKey.PrivateKey = data.Auth.PrivateKey.Content.ValueString()
}
if data.Auth.PrivateKey.Password.ValueString() != "" {
privateKey.Password = data.Auth.PrivateKey.Password.ValueString()
}
if data.Auth.PrivateKey.Certificate.ValueString() != "" {
privateKey.Certificate = data.Auth.PrivateKey.Certificate.ValueString()
}
sshTunnel.Auth = append(sshTunnel.Auth, privateKey)
}
if data.Auth.Password.ValueString() != "" {
sshTunnel.Auth = append(sshTunnel.Auth, ssh.SSHPassword{
Password: data.Auth.Password.ValueString(),
})
}
sshTunnel.Auth = append(sshTunnel.Auth, privateKey)
if authSock != "" {
sshTunnel.Auth = append(sshTunnel.Auth, ssh.SSHAuthSock{
Path: authSock,
})
}
if data.Auth.Password.ValueString() != "" {
sshTunnel.Auth = append(sshTunnel.Auth, ssh.SSHPassword{
Password: data.Auth.Password.ValueString(),
})
}
resp.DataSourceData = &sshTunnel
}

Expand Down

0 comments on commit 740ad77

Please sign in to comment.