Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: invalid memory address or nil pointer dereference when using ssh and not having .ssh/config #1118

Open
skt-mvencel opened this issue Oct 23, 2024 · 0 comments

Comments

@skt-mvencel
Copy link

System Information

Linux distribution

Oracle Linux Server 9.4

Terraform version

Terraform v1.9.8

Provider and libvirt versions

terraform-provider-libvirt_0.8.0


Description of Issue/Question

When using qemu+ssh if there is no .ssh/config file for the user running terraform the provider will crash.
If you just touch ~/.ssh/config it will work just fine.

Setup

terraform {
  required_providers {
    libvirt = {
      source = "dmacvicar/libvirt"
      version = "0.8.0"
    }
  }

provider "libvirt" {
  uri = "qemu+ssh://user@host/system?no_verify=1"
}

Steps to Reproduce Issue

Do not have ~/.ssh/config file.

Planning failed. Terraform encountered an error while generating this plan.
╷
│ Error: Plugin did not respond
│ 
│   with provider["registry.terraform.io/dmacvicar/libvirt"],
│   on terraform.tf line 20, in provider "libvirt":
│   20: provider "libvirt" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ConfigureProvider call. The plugin logs may contain more details.
╵
2024-10-22T16:06:36.802Z [DEBUG] POST https://<TFBACKEND>/unlock

Stack trace from the terraform-provider-libvirt_v0.8.0 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x79911c]

goroutine 49 [running]:
github.com/kevinburke/ssh_config.(*Config).Get(0x0, {0xc000516112, 0xc}, {0xe88d73, 0x8})
	github.com/kevinburke/[email protected]/config.go:343 +0x5c
github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri.(*ConnectionURI).dialHost(0xc00053c0a8, {0xc000516112, 0xc}, 0x0, 0x0)
	github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri/ssh.go:166 +0x259
github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri.(*ConnectionURI).dialSSH(0xc00053c0a8)
	github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri/ssh.go:129 +0x1c5
github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri.(*ConnectionURI).Dial(0xc00053c0a8)
	github.com/dmacvicar/terraform-provider-libvirt/libvirt/uri/connection_uri.go:81 +0x3d
github.com/digitalocean/go-libvirt/socket.(*Socket).Connect(0xc000514550)
	github.com/digitalocean/[email protected]/socket/socket.go:141 +0xbd
github.com/digitalocean/go-libvirt.(*Libvirt).ConnectToURI(0xc000510360, {0xc0005121f8, 0xe})
	github.com/digitalocean/[email protected]/libvirt.go:287 +0x2c
github.com/dmacvicar/terraform-provider-libvirt/libvirt.(*Config).Client(0xc000198450?)
	github.com/dmacvicar/terraform-provider-libvirt/libvirt/config.go:36 +0x215
github.com/dmacvicar/terraform-provider-libvirt/libvirt.providerConfigure(0xc000506880)
	github.com/dmacvicar/terraform-provider-libvirt/libvirt/provider.go:71 +0x147
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Provider).Configure(0xc000308770, {0xfd7228, 0xc000502ff0}, 0xc000514320)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/provider.go:359 +0x1bb
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ConfigureProvider(0xc0003ea870, {0xfd7228?, 0xc000502cc0?}, 0xc000520120)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:616 +0x3c5
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).Configure(0xc0002ff680, {0xfd7228?, 0xc0005022a0?}, 0xc0005140f0)
	github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:587 +0x342
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_Configure_Handler({0xe5ad20, 0xc0002ff680}, {0xfd7228, 0xc0005022a0}, 0xc000506100, 0x0)
	github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:491 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001c3800, {0xfd7228, 0xc000502210}, {0xfdc420, 0xc000498000}, 0xc000522000, 0xc0003ed800, 0x15da1f0, 0x0)
	google.golang.org/[email protected]/server.go:1394 +0xe2b
google.golang.org/grpc.(*Server).handleStream(0xc0001c3800, {0xfdc420, 0xc000498000}, 0xc000522000)
	google.golang.org/[email protected]/server.go:1805 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/[email protected]/server.go:1029 +0x7f
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 21
	google.golang.org/[email protected]/server.go:1040 +0x125
Error: The terraform-provider-libvirt_v0.8.0 plugin crashed!
2024-10-22T16:06:36.788Z [TRACE] provider.terraform-provider-libvirt_v0.8.0: Calling downstream: tf_req_id=s0m3id tf_rpc=Configure @caller=github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:615 @module=sdk.helper_schema tf_provider_addr=provider timestamp=2024-10-22T16:06:36.787Z
2024-10-22T16:06:36.788Z [INFO]  provider.terraform-provider-libvirt_v0.8.0: 2024/10/22 16:06:36 [DEBUG] Configuring provider for 'qemu+ssh://user@host/system?no_verify=1': &{map[uri:0xc00025be00] 0xc000514320 <nil> 0xc000506780 map[] <nil> {{<nil>} <nil>} 0xc0005201c0 0xc00050a2a0 0xc00055c340 false {{{} 1} {0 0}} false false}: timestamp=2024-10-22T16:06:36.787Z
2024-10-22T16:06:36.788Z [INFO]  provider.terraform-provider-libvirt_v0.8.0: 2024/10/22 16:06:36 [WARN] Failed to open ssh config file: open /userhome/.ssh/config: no such file or directory: timestamp=2024-10-22T16:06:36.787Z
2024-10-22T16:06:36.788Z [INFO]  provider.terraform-provider-libvirt_v0.8.0: 2024/10/22 16:06:36 [WARN] Failed to parse ssh config file: invalid argument: timestamp=2024-10-22T16:06:36.787Z
2024-10-22T16:06:36.788Z [INFO]  provider.terraform-provider-libvirt_v0.8.0: 2024/10/22 16:06:36 [INFO] establishing ssh connection to 'host': timestamp=2024-10-22T16:06:36.787Z
2024-10-22T16:06:36.788Z [TRACE] provider.terraform-provider-libvirt_v0.8.0: Served request: tf_proto_version=5.6 @module=sdk.proto tf_provider_addr=provider tf_req_id=s0m3id tf_rpc=Configure @caller=runtime/panic.go:785 timestamp=2024-10-22T16:06:36.787Z
module.vm_instances["someinstance2"].data.template_file.network_config: Read complete after 0s [id=s0m30th3rid]
2024-10-22T16:06:36.789Z [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/hashicorp/template" is in the global cache
2024-10-22T16:06:36.789Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to refreshState for module.vm_instances["someinstance2"].data.template_file.network_config
2024-10-22T16:06:36.789Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for module.vm_instances["someinstance2"].data.template_file.network_config
module.vm_instances["someinstance2"].data.template_file.user_data: Read complete after 0s [id=s0m30th3rid]
module.vm_instances["someinstance1"].data.template_file.network_config: Read complete after 0s [id=s0m30th3rid]
2024-10-22T16:06:36.789Z [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/hashicorp/template" is in the global cache
2024-10-22T16:06:36.789Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to refreshState for module.vm_instances["someinstance1"].data.template_file.network_config
2024-10-22T16:06:36.789Z [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/hashicorp/template" is in the global cache
2024-10-22T16:06:36.789Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to refreshState for module.vm_instances["someinstance2"].data.template_file.user_data
2024-10-22T16:06:36.789Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for module.vm_instances["someinstance2"].data.template_file.user_data
2024-10-22T16:06:36.789Z [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/hashicorp/template" is in the global cache
2024-10-22T16:06:36.789Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for module.vm_instances["someinstance2"].data.template_file.user_data
2024-10-22T16:06:36.789Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for module.vm_instances["someinstance2"].data.template_file.user_data
2024-10-22T16:06:36.790Z [TRACE] vertex "module.vm_instances[\"someinstance2\"].data.template_file.user_data": visit complete
2024-10-22T16:06:36.790Z [TRACE] vertex "root": starting visit (terraform.graphNodeRoot)
2024-10-22T16:06:36.790Z [TRACE] vertex "root": does not belong to any module instance
2024-10-22T16:06:36.790Z [TRACE] vertex "root": visit complete
2024-10-22T16:06:36.790Z [TRACE] vertex "module.vm_instances.data.template_file.user_data (expand)": dynamic subgraph completed successfully
2024-10-22T16:06:36.790Z [TRACE] vertex "module.vm_instances.data.template_file.user_data (expand)": visit complete
2024-10-22T16:06:36.790Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for module.vm_instances["someinstance1"].data.template_file.network_config
2024-10-22T16:06:36.790Z [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/hashicorp/template" is in the global cache
2024-10-22T16:06:36.790Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for module.vm_instances["someinstance2"].data.template_file.network_config
2024-10-22T16:06:36.790Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for module.vm_instances["someinstance2"].data.template_file.network_config
2024-10-22T16:06:36.790Z [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/hashicorp/template" is in the global cache
2024-10-22T16:06:36.790Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for module.vm_instances["someinstance1"].data.template_file.network_config
2024-10-22T16:06:36.790Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for module.vm_instances["someinstance1"].data.template_file.network_config
2024-10-22T16:06:36.790Z [TRACE] vertex "module.vm_instances[\"someinstance2\"].data.template_file.network_config": visit complete
2024-10-22T16:06:36.790Z [TRACE] vertex "module.vm_instances[\"someinstance1\"].data.template_file.network_config": visit complete
2024-10-22T16:06:36.790Z [TRACE] vertex "root": starting visit (terraform.graphNodeRoot)
2024-10-22T16:06:36.791Z [TRACE] vertex "root": does not belong to any module instance
2024-10-22T16:06:36.791Z [TRACE] vertex "root": visit complete
2024-10-22T16:06:36.791Z [TRACE] vertex "module.vm_instances.data.template_file.network_config (expand)": dynamic subgraph completed successfully
2024-10-22T16:06:36.791Z [TRACE] vertex "module.vm_instances.data.template_file.network_config (expand)": visit complete
2024-10-22T16:06:36.791Z [TRACE] vertex "provider[\"registry.terraform.io/hashicorp/template\"] (close)": starting visit (*terraform.graphNodeCloseProvider)
2024-10-22T16:06:36.791Z [TRACE] vertex "provider[\"registry.terraform.io/hashicorp/template\"] (close)": does not belong to any module instance
2024-10-22T16:06:36.791Z [TRACE] GRPCProvider: Close
2024-10-22T16:06:36.794Z [INFO]  provider: plugin process exited: plugin=.terraform/providers/registry.terraform.io/hashicorp/template/2.2.0/linux_amd64/terraform-provider-template_v2.2.0_x4 id=20345
2024-10-22T16:06:36.794Z [DEBUG] provider: plugin exited
2024-10-22T16:06:36.794Z [TRACE] vertex "provider[\"registry.terraform.io/hashicorp/template\"] (close)": visit complete
2024-10-22T16:06:36.795Z [DEBUG] provider.terraform-provider-libvirt_v0.8.0: panic: runtime error: invalid memory address or nil pointer dereference
2024-10-22T16:06:36.796Z [DEBUG] provider.terraform-provider-libvirt_v0.8.0: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x79911c]
2024-10-22T16:06:36.796Z [DEBUG] provider.terraform-provider-libvirt_v0.8.0

Additional information:

I can reporduce it in the same way on Fedora. Crashes whether or not selinux is enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant