hashicorp / terraform-provider-consul

Terraform Consul provider
https://www.terraform.io/docs/providers/consul/
Mozilla Public License 2.0
124 stars 113 forks source link

consul_config_entry_service_intentions: Fix NPE when optional JWT unset #386

Closed sundbry closed 1 month ago

sundbry commented 9 months ago

jwt is an optional parameter on the service intention config. When it was not set, the plugin would segfault due to a null pointer dereference on the ServiceIntentionsConfigEntry.JWT.

This adds a check for si.JWT != nil and skips building the jwt payload when it is not set.

Stack trace observed:

Stack trace from the terraform-provider-consul plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xf0eb82]

goroutine 49 [running]:
github.com/hashicorp/terraform-provider-consul/consul.(*serviceIntentions).Write(0xc000b97598?, {0x14eb950?, 0xc000813100?}, 0xc00078c150?, 0x12?)
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/consul/resource_consul_config_entry_service_intentions.go:441 +0x3a2
github.com/hashicorp/terraform-provider-consul/consul.configEntryImplementationRead.func1(0xc0007a0fc0, {0x102a6a0?, 0xc00041c2a0?})
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/consul/resource_consul_config_entry_concrete.go:111 +0x202
github.com/hashicorp/terraform-provider-consul/consul.configEntryImplementationWrite.func1(0x10442e0?, {0x102a6a0, 0xc00041c2a0})
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/consul/resource_consul_config_entry_concrete.go:85 +0x2fd
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc0003de500, 0xc000781720, 0xc00010f680, {0x102a6a0, 0xc00041c2a0})
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:320 +0x438
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc00038a680, 0xc0005bf8f0, 0x11c25c3?, 0xf?)
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider.go:294 +0x70
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000015240, {0xc0007a0a80?, 0x4c4e86?}, 0xc0007a0a80)
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin/grpc_provider.go:895 +0x805
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1177e00?, 0xc000015240}, {0x14e77d0, 0xc000793f80}, 0xc0007a0a10, 0x0)
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5/tfplugin5.pb.go:3305 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00020a5a0, {0x14ecda0, 0xc000702680}, 0xc000985320, 0xc0002828a0, 0x1c089a0, 0x0)
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/vendor/google.golang.org/grpc/server.go:1335 +0xdf3
google.golang.org/grpc.(*Server).handleStream(0xc00020a5a0, {0x14ecda0, 0xc000702680}, 0xc000985320, 0x0)
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/vendor/google.golang.org/grpc/server.go:1712 +0xa36
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/vendor/google.golang.org/grpc/server.go:947 +0xca
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /tmp/guix-build-terraform-provider-consul-2.20.0.drv-0/source/source/vendor/google.golang.org/grpc/server.go:958 +0x15c

Error: The terraform-provider-consul plugin crashed!
sorenisanerd commented 7 months ago

This seems like a no-brainer and a straightforward fix. ping @remilapeyre or someone else who can merge.

pc2459 commented 5 months ago

+1! Any idea if this will be merged soon?

mkeefe8 commented 1 month ago

Our team also ran into this problem ...

Esity commented 1 month ago

@blake @nathancoleman

Can you guys please take a look at this and get this prioritized? this has been pending for some time I also opened github issue for tracking and this PR should fix it https://github.com/hashicorp/terraform-provider-consul/issues/410

mkeefe8 commented 1 month ago

Thank you for merging this. Any idea on when a new release will be published so we can use this resource?

Thank you, Mary

Téléchargez Outlook pour iOShttps://aka.ms/o0ukef


De : Nathan Coleman @.> Envoyé : Monday, July 15, 2024 11:28:01 AM À : hashicorp/terraform-provider-consul @.> Cc : mkeefe8 @.>; Comment @.> Objet : Re: [hashicorp/terraform-provider-consul] consul_config_entry_service_intentions: Fix NPE when optional JWT unset (PR #386)

Merged #386https://github.com/hashicorp/terraform-provider-consul/pull/386 into main.

— Reply to this email directly, view it on GitHubhttps://github.com/hashicorp/terraform-provider-consul/pull/386#event-13508199347, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AC2V7YGRMSSKM6NJHVEPZ2LZMP2BDAVCNFSM6AAAAAA76ST54OVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJTGUYDQMJZHEZTINY. You are receiving this because you commented.Message ID: @.***>

nathancoleman commented 1 month ago

Hi @mkeefe8 :wave:

Apologies for the delay while I was on vacation. I'm working to get a new release out this week