dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.54k stars 457 forks source link

libvirt provider fails with ssh.publicKeyCallback.auth if the SSH key is invalid #1078

Open rabin-io opened 3 months ago

rabin-io commented 3 months ago

System Information

Linux distribution

CentOS stream 9

Terraform version

# terraform -v
Terraform v1.7.5
on linux_amd64

Provider and libvirt versions

0.7.6

Checklist

Description of Issue/Question

Setup

We recently encrypted our SSH keys in our git repo using git-crypt, and when the libvirt provider tried to load it in its crypted state, if failed with a very long and cypted stack trace.

I know that it expected to fail, I just think it should be more informative and give the user a better error message, about the issue that the lib failed to load the SSH key.

Steps to Reproduce Issue

[2024-03-19T09:11:05.546Z]     Planning failed. Terraform encountered an error while generating this plan.
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]     STDERR:
[2024-03-19T09:11:05.546Z]     Error: Plugin did not respond
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]       with provider["registry.terraform.io/dmacvicar/libvirt"],
[2024-03-19T09:11:05.546Z]       on config.tf line 44, in provider "libvirt":
[2024-03-19T09:11:05.546Z]       44: provider "libvirt" {
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]     The plugin encountered an error, and failed to respond to the
[2024-03-19T09:11:05.546Z]     plugin.(*GRPCProvider).ConfigureProvider call. The plugin logs may contain
[2024-03-19T09:11:05.546Z]     more details.
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]     Stack trace from the terraform-provider-libvirt_v0.6.14 plugin:
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]     panic: runtime error: invalid memory address or nil pointer dereference
[2024-03-19T09:11:05.546Z]     [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x6812ea]
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]     goroutine 27 [running]:
[2024-03-19T09:11:05.546Z]     golang.org/x/crypto/ssh.publicKeyCallback.auth(0x11, {0xc00018b340, 0x20, 0x20}, {0xc00041460b, 0x4}, {0xfaed10, 0xc0001a8f00}, {0xf9f480, 0xc000092600})
[2024-03-19T09:11:05.546Z]             golang.org/x/crypto@v0.0.0-20220112180741-5e0467b6c7ce/ssh/client_auth.go:235 +0x24a
[2024-03-19T09:11:05.546Z]     golang.org/x/crypto/ssh.(*connection).clientAuthenticate(0xc0000f7000, 0xc0000de540)
[2024-03-19T09:11:05.546Z]             golang.org/x/crypto@v0.0.0-20220112180741-5e0467b6c7ce/ssh/client_auth.go:63 +0x3a9
[2024-03-19T09:11:05.546Z]     golang.org/x/crypto/ssh.(*connection).clientHandshake(0xc0000f7000, {0xc0001dc0f0, 0x11}, 0xc0000de540)
[2024-03-19T09:11:05.546Z]             golang.org/x/crypto@v0.0.0-20220112180741-5e0467b6c7ce/ssh/client.go:113 +0x26a
[2024-03-19T09:11:05.546Z]     golang.org/x/crypto/ssh.NewClientConn({0xfc3a48, 0xc00000f058}, {0xc0001dc0f0, 0x11}, 0xc0004eb800)
[2024-03-19T09:11:05.546Z]             golang.org/x/crypto@v0.0.0-20220112180741-5e0467b6c7ce/ssh/client.go:83 +0x12b
[2024-03-19T09:11:05.546Z]     golang.org/x/crypto/ssh.Dial({0xe238f1, 0x5}, {0xc0001dc0f0, 0x11}, 0xc0004eb800)
[2024-03-19T09:11:05.546Z]             golang.org/x/crypto@v0.0.0-20220112180741-5e0467b6c7ce/ssh/client.go:190 +0x59
[2024-03-19T09:11:05.546Z]     github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri.(*ConnectionURI).dialSSH(0xc0004eb9c8)
[2024-03-19T09:11:05.546Z]             github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri/ssh.go:130 +0x465
[2024-03-19T09:11:05.546Z]     github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri.(*ConnectionURI).DialTransport(0xc000414600)
[2024-03-19T09:11:05.546Z]             github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri/connection_uri.go:83 +0x45
[2024-03-19T09:11:05.546Z]     github.com/dmacvicar/terraform-provider-libvirt/libvirt.(*Config).Client(0xe4d2b3)
[2024-03-19T09:11:05.546Z]             github.com/dmacvicar/terraform-provider-libvirt/libvirt/config.go:35 +0x73
[2024-03-19T09:11:05.546Z]     github.com/dmacvicar/terraform-provider-libvirt/libvirt.providerConfigure(0xc0001aac40)
[2024-03-19T09:11:05.546Z]             github.com/dmacvicar/terraform-provider-libvirt/libvirt/provider.go:68 +0xff
[2024-03-19T09:11:05.546Z]     github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Configure(0xc0000f6900, 0xc00000eff0)
[2024-03-19T09:11:05.546Z]             github.com/hashicorp/terraform-plugin-sdk@v1.9.0/helper/schema/provider.go:275 +0xb4
[2024-03-19T09:11:05.546Z]     github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).Configure(0xc00000ec58, {0xc0001815c0, 0x516766}, 0xc0001815c0)
[2024-03-19T09:11:05.546Z]             github.com/hashicorp/terraform-plugin-sdk@v1.9.0/internal/helper/plugin/grpc_provider.go:487 +0x1d2
[2024-03-19T09:11:05.546Z]     github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_Configure_Handler({0xdf5140, 0xc00000ec58}, {0xfb64b0, 0xc0001a48d0}, 0xc00019b020, 0x0)
[2024-03-19T09:11:05.546Z]             github.com/hashicorp/terraform-plugin-sdk@v1.9.0/internal/tfplugin5/tfplugin5.pb.go:3251 +0x170
[2024-03-19T09:11:05.546Z]     google.golang.org/grpc.(*Server).processUnaryRPC(0xc000106780, {0xfc3c00, 0xc000106900}, 0xc0000ed300, 0xc0004d53e0, 0x155bf38, 0x0)
[2024-03-19T09:11:05.546Z]             google.golang.org/grpc@v1.27.1/server.go:1024 +0xd1e
[2024-03-19T09:11:05.546Z]     google.golang.org/grpc.(*Server).handleStream(0xc000106780, {0xfc3c00, 0xc000106900}, 0xc0000ed300, 0x0)
[2024-03-19T09:11:05.546Z]             google.golang.org/grpc@v1.27.1/server.go:1313 +0xa56
[2024-03-19T09:11:05.546Z]     google.golang.org/grpc.(*Server).serveStreams.func1.1()
[2024-03-19T09:11:05.546Z]             google.golang.org/grpc@v1.27.1/server.go:722 +0x98
[2024-03-19T09:11:05.546Z]     created by google.golang.org/grpc.(*Server).serveStreams.func1
[2024-03-19T09:11:05.546Z]             google.golang.org/grpc@v1.27.1/server.go:720 +0xef
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]     Error: The terraform-provider-libvirt_v0.6.14 plugin crashed!
[2024-03-19T09:11:05.546Z]   
[2024-03-19T09:11:05.546Z]     This is always indicative of a bug within the plugin. It would be immensely
[2024-03-19T09:11:05.546Z]     helpful if you could report the crash with the plugin's maintainers so that it
[2024-03-19T09:11:05.546Z]     can be fixed. The output above should help diagnose the issue.

Additional information:

The logs are from 0.6.14 but is happens with latest release as well.