onelogin / onelogin-go-sdk

golang sdk for onelogin apis
MIT License
10 stars 24 forks source link

null pointer in SDK crashes OL terraform provider #63

Closed rjhornsby closed 1 year ago

rjhornsby commented 1 year ago

Having an issue onelogin/terraform-provider-onelogin/issues/83 with the OL Terraform provider crashing.

After digging more into the problem, it looks like the problem might be in this library the TF provider depends on. The error message is

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

I'm more or less a Golang novice, but it looks like the problem in this library is services/apps/v2.go#L175:

func (svc *V2Service) pruneParameters(requestedParams map[string]AppParameters, app *App) error {
    var delErrors []error
    keepMap := make(map[int32]bool, len(requestedParams))
    for _, param := range requestedParams {
        keepMap[*param.ID] = true     ## <-- crash happens here
    }
        ...

I'm not sure why, but when trying to use the TF provider to modify an existing resource, param.ID is nil here which results in the crash. Using the TF provider to create a onelogin_saml_apps resource appears to work (the tf-apply completes), but when you run tf-plan it wants to make changes to the resource, as if it wasn't applied correctly the first time. When running tf-apply again to modify/update the OL SAML app is when the crash happens.

Screenshot attached below showing the run state immediately before golang drops into the panic handler.

Stack trace from the terraform-provider-onelogin plugin:

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

goroutine 83 [running]:
github.com/onelogin/onelogin-go-sdk/pkg/services/apps.(*V2Service).pruneParameters(0x1400071ca50, 0x1400022ef70, 0x14000736420)
    /Users/rhornsby/go/pkg/mod/github.com/onelogin/onelogin-go-sdk@v1.1.20/pkg/services/apps/v2.go:175 +0xd0
github.com/onelogin/onelogin-go-sdk/pkg/services/apps.(*V2Service).Update(0x1400071ca50, 0x14000736420)
    /Users/rhornsby/go/pkg/mod/github.com/onelogin/onelogin-go-sdk@v1.1.20/pkg/services/apps/v2.go:142 +0x2f8
github.com/onelogin/terraform-provider-onelogin/onelogin.samlAppUpdate(0x140000e8d80, {0x1028dab60?, 0x1400071e230})
    /Users/rhornsby/projects/work/esp/golang/terraform-provider-onelogin/onelogin/resource_onelogin_saml_apps.go:136 +0x63c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x10292a0e0?, {0x1029f24d8?, 0x140002f4a40?}, 0x24?, {0x1028dab60?, 0x1400071e230?})
    /Users/rhornsby/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.4.3/helper/schema/resource.go:302 +0x58
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x14000234cc0, {0x1029f24d8, 0x140002f4a40}, 0x14000738700, 0x140004aba20, {0x1028dab60, 0x1400071e230})
    /Users/rhornsby/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.4.3/helper/schema/resource.go:404 +0x478
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x140001ab2c0, {0x1029f24d8, 0x140002f4a40}, 0x140006143c0)
    /Users/rhornsby/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.4.3/helper/schema/grpc_provider.go:955 +0x868
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0x140001cf600, {0x1029f2580?, 0x14000197f80?}, 0x140005dea00?)
    /Users/rhornsby/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.2.1/tfprotov5/server/server.go:332 +0x64
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1029be040?, 0x140001cf600}, {0x1029f2580, 0x14000197f80}, 0x1400007e3c0, 0x0)
    /Users/rhornsby/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.2.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x140002a6fc0, {0x1029f5c98, 0x140004fa000}, 0x1400035e000, 0x14000397950, 0x102e09b00, 0x0)
    /Users/rhornsby/go/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:1194 +0xadc
google.golang.org/grpc.(*Server).handleStream(0x140002a6fc0, {0x1029f5c98, 0x140004fa000}, 0x1400035e000, 0x0)
    /Users/rhornsby/go/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:1517 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    /Users/rhornsby/go/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:859 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
    /Users/rhornsby/go/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:857 +0x290

Error: The terraform-provider-onelogin plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Screen Shot 2022-11-08 at 21 42 34

berv63 commented 1 year ago

@gkhaburzaniya-onelogin Would you have a chance to check this out soon? We have an app being blocked by any updates because of this.

gkhaburzaniya-onelogin commented 1 year ago

We are modifying our process to incorporate OpenAPI standards. We will be releasing a new version of both the Go SDK as well as the Terraform provider SDK. You can check out the alpha version of the Go SDK https://github.com/onelogin/onelogin-go-sdk/tree/v3.0.0-alpha.1

berv63 commented 1 year ago

@gkhaburzaniya-onelogin Thank you! Do you happen to have a timeline of the expected release?

Jmfwolf commented 1 year ago

Is this still occuring? The terraform-provider-onelogin is now indepent of this SDK and the newest GO SDK, shouldn't have the issue either, but please let me know

rjhornsby commented 1 year ago

Is this still occuring? The terraform-provider-onelogin is now indepent of this SDK and the newest GO SDK, shouldn't have the issue either, but please let me know

It looks like the TF provider got a significant overhaul to its interface. No big deal, just need to re-work our code to match. Will keep you posted.

rjhornsby commented 1 year ago

@Jmfwolf The new TF provider (0.3.6) is broken, but based on its behavior and your comment that it's now decoupled from this SDK I have no reason to believe the provider issues I'm seeing now are related to this SDK.

Unfortunately our only use of the SDK was via the TF provider, so I don't have any additional insight to offer.

Jmfwolf commented 1 year ago

I am continuing to work on it. I am digging through the tooling to figure out, please feel free to open issues in the terraform repo and I will keep you posted