okta / okta-sdk-golang

A Golang SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
https://github.com/okta/okta-sdk-golang
Other
173 stars 143 forks source link

nil pointer when orgurl is malformed #404

Closed monde closed 10 months ago

monde commented 11 months ago

Describe the bug?

Config nil pointer panic when cfg.Okta.Client.OrgUrl is is malformed.

What is expected to happen?

Graceful validation and failure.

What is the actual behavior?

nil pointer panic

Reproduction Steps?

have malformed org url

Additional Information?

No response

Golang Version

go version go1.21.0 darwin/amd64

SDK Version

Issue template seems to have misinformation.

$ make sdk-version
make: *** No rule to make target `sdk-version'.  Stop.

OS version

@duytiennguyen-okta there needs to be some validation or graceful failure in the v3 okta-sdk-golang client if org url is malformed. Here url.Parse is called, but without inspecting the error object:

purl, _ := url.Parse(cfg.Okta.Client.OrgUrl) https://github.com/okta/okta-sdk-golang/blob/master/.generator/templates/configuration.mustache#L260 The next line cfg.Host = purl.Hostname() will nil panic if there was a parse error.

Given an org url of "iadf^dfads.okta.com"

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Plugin did not respond
│
│   with provider["registry.terraform.io/okta/okta"],
│   on main.tf line 14, in provider "okta":
│   14: provider "okta" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ConfigureProvider call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-okta plugin:

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

goroutine 33 [running]:
net/url.(*URL).Hostname(...)
        /usr/local/Cellar/go/1.21.0/libexec/src/net/url/url.go:1144
github.com/okta/okta-sdk-golang/v3/okta.NewConfiguration({0xc0002de2a0, 0xc, 0xc0002d11f0?})
        /Users/mikemondragon/projects/pkg/mod/github.com/okta/okta-sdk-golang/v3@v3.0.14/okta/configuration.go:196 +0x4a3
github.com/okta/terraform-provider-okta/okta.oktaV3SDKClient(0xc000493680)

Was seeing this in TF: https://github.com/okta/terraform-provider-okta/issues/1712

github-actions[bot] commented 11 months ago

This issue has been marked stale because there has been no activity within the last 14 days. To keep this issue active, remove the stale label.

github-actions[bot] commented 10 months ago

This issue has been marked stale because there has been no activity within the last 14 days. To keep this issue active, remove the stale label.