zitadel / terraform-provider-zitadel

Official Terraform provider for ZITADEL
https://zitadel.com
Apache License 2.0
25 stars 16 forks source link

failed to respond to the plugin6.(*GRPCProvider).ReadDataSource call #171

Closed musicformellons closed 2 days ago

musicformellons commented 5 months ago

Preflight Checklist

Version

v1.1.1

ZITADEL Version

2.50.3

Describe the problem caused by this bug

Running terraform plan the plugin crashes.

To reproduce

The hcl I'm running the terraform plan on:

terraform {
  required_version = ">= 0.14.0"
  required_providers {
    zitadel = {
      source  = "zitadel/zitadel"
      version = "1.1.1"
    }
  }
}

provider "zitadel" {
  domain           = "localhost"
  insecure         = "true"
  port             = "8080"
  jwt_profile_json = <<EOF
    {
      "client_id": "zitadel-admin",
      "client_secret": "Password1!"
    }
EOF
}

resource "zitadel_org" "default" {
  name = "myorg"
}

data "zitadel_project" "default" {
  org_id     = data.zitadel_org.default.id
  project_id = "123456789012345678"
}

data "zitadel_org" "default" {
  id = "123456789012345678"
}

resource "zitadel_application_oidc" "default" {
  project_id = data.zitadel_project.default.id
  org_id     = data.zitadel_org.default.id

  name                        = "mytest"
  redirect_uris               = ["http://localhost:5173/auth/signinwin/zitadel"]
  response_types              = ["OIDC_RESPONSE_TYPE_CODE"]
  grant_types                 = ["OIDC_GRANT_TYPE_AUTHORIZATION_CODE", "OIDC_GRANT_TYPE_REFRESH_TOKEN"]
  post_logout_redirect_uris   = ["https://localhost:5137"]
  app_type                    = "OIDC_APP_TYPE_WEB"
  auth_method_type            = "OIDC_AUTH_METHOD_TYPE_NONE"
  version                     = "OIDC_VERSION_1_0"
  clock_skew                  = "0s"
  dev_mode                    = true
  access_token_type           = "OIDC_TOKEN_TYPE_BEARER"
  access_token_role_assertion = false
  id_token_role_assertion     = false
  id_token_userinfo_assertion = false
  additional_origins          = []
}

resource "zitadel_human_user" "default" {
  org_id             = data.zitadel_org.default.id
  user_name          = "myuser@localhost.com"
  first_name         = "my"
  last_name          = "user"
  nick_name          = "ricky"
  display_name       = "displayname"
  preferred_language = "nl"
  gender             = "GENDER_MALE"
  phone              = "+31799999999"
  is_phone_verified  = true
  email              = "myuser@gmail.com"
  is_email_verified  = true
  initial_password   = "Test@123"
}

It then crashes with:

▶ tf plan
data.zitadel_org.default: Reading...

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

╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-zitadel_v1.1.1 plugin:

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

goroutine 8 [running]:
github.com/zitadel/oidc/pkg/crypto.BytesToPrivateKey({0x40002e2c80?, 0x14546c?, 0x16?})
        github.com/zitadel/oidc@v1.13.5/pkg/crypto/key.go:11 +0x20
github.com/zitadel/oidc/pkg/client.NewSignerFromPrivateKeyByte({0x40002e2c80?, 0x4000215320?, 0x40002e2bf8?}, {0x0, 0x0})
        github.com/zitadel/oidc@v1.13.5/pkg/client/client.go:152 +0x28
github.com/zitadel/oidc/pkg/client/profile.NewJWTProfileTokenSource({0x4000142888, 0x15}, {0x0, 0x0}, {0x0?, 0x0?}, {0x40002e2c80?, 0x1cf6e8?, 0x40002e2c68?}, {0x40003ff000, ...}, ...)
        github.com/zitadel/oidc@v1.13.5/pkg/client/profile/jwt_profile.go:43 +0x5c
github.com/zitadel/oidc/pkg/client/profile.NewJWTProfileTokenSourceFromKeyFileData({0x4000142888, 0x15}, {0x400013b380?, 0xf0ed4?, 0x4000339500?}, {0x40003ff000, 0x2, 0x2}, {0x0, 0x0, ...})
        github.com/zitadel/oidc@v1.13.5/pkg/client/profile/jwt_profile.go:39 +0xdc
github.com/zitadel/zitadel-go/v2/pkg/client/middleware.JWTProfileFromFileData.func1({0x4000142888?, 0x1bf94?}, {0x40003ff000?, 0x18?, 0x18?})
        github.com/zitadel/zitadel-go/v2@v2.1.8/pkg/client/middleware/auth.go:35 +0x54
github.com/zitadel/zitadel-go/v2/pkg/client/middleware.NewAuthenticator({0x4000142888?, 0xc05120?}, 0x4000682fc0?, {0x40003ff000?, 0xffffa4626288?, 0xffffa48bb108?})
        github.com/zitadel/zitadel-go/v2@v2.1.8/pkg/client/middleware/auth.go:49 +0x38
github.com/zitadel/zitadel-go/v2/pkg/client/zitadel.(*Connection).setInterceptors(0x4000215290, {0x4000142888?, 0x400011ae80?}, {0x0, 0x0}, {0x40003ff000?, 0x40002e2e68?, 0x1bf94?}, 0x17913d0?)
        github.com/zitadel/zitadel-go/v2@v2.1.8/pkg/client/zitadel/client.go:69 +0x4c
github.com/zitadel/zitadel-go/v2/pkg/client/zitadel.NewConnection({0x4000142888, 0x15}, {0x400075d510, 0xe}, {0x40003ff000, 0x2, 0x2}, {0x4000177be0, 0x2, 0x846ae8?})
        github.com/zitadel/zitadel-go/v2@v2.1.8/pkg/client/zitadel/client.go:41 +0x17c
github.com/zitadel/zitadel-go/v2/pkg/client/admin.NewClient({0x4000142888?, 0x25?}, {0x400075d510?, 0x1?}, {0x40003ff000?, 0x0?, 0x0?}, {0x4000177be0?, 0x0?, 0x0?})
        github.com/zitadel/zitadel-go/v2@v2.1.8/pkg/client/admin/client.go:14 +0x2c
github.com/zitadel/terraform-provider-zitadel/zitadel/helper.GetAdminClient(0x400072bc20)
        github.com/zitadel/terraform-provider-zitadel/zitadel/helper/client.go:92 +0x1ac
github.com/zitadel/terraform-provider-zitadel/zitadel/org.get({0xeaa3a8, 0x4000343f20}, 0x0?, {0x9d30e0?, 0x400072bc20})
        github.com/zitadel/terraform-provider-zitadel/zitadel/org/funcs.go:112 +0x80
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x40000c87e0, {0xeaa3e0, 0x400024cea0}, 0xd?, {0x9d30e0, 0x400072bc20})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:724 +0xe8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0x40000c87e0, {0xeaa3e0, 0x400024cea0}, 0x40004db800, {0x9d30e0, 0x400072bc20})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:943 +0x10c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0x400013c000, {0xeaa3e0?, 0x400024c8a0?}, 0x40003fef00)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/grpc_provider.go:1195 +0x2f8
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ReadDataSource({{0xeafc28?, 0x400013c000?}}, {0xeaa3e0?, 0x400024c8a0?}, 0x40003feee0?)
        github.com/hashicorp/terraform-plugin-mux@v0.7.0/tf5to6server/tf5to6server.go:94 +0x210
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.muxServer.ReadDataSource({0x4000126390, 0x40001263f0, {0x400034a680, 0x2, 0x2}, 0x40001263c0, 0x40001777a0, 0x400026a210, 0x4000126420}, {0xeaa3e0?, ...}, ...)
        github.com/hashicorp/terraform-plugin-mux@v0.7.0/tf6muxserver/mux_server_ReadDataSource.go:27 +0x108
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadDataSource(0x400023b7c0, {0xeaa3e0?, 0x400017f8c0?}, 0x4000795540)
        github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov6/tf6server/server.go:656 +0x334
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadDataSource_Handler({0xbd6960?, 0x400023b7c0}, {0xeaa3e0, 0x400017f8c0}, 0x40004db400, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:421 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x40001f5e00, {0xeaa3e0, 0x400017f800}, {0xeaf158, 0x4000548000}, 0x40004e9d40, 0x4000686750, 0x173d6b0, 0x0)
        google.golang.org/grpc@v1.61.0/server.go:1385 +0xbec
google.golang.org/grpc.(*Server).handleStream(0x40001f5e00, {0xeaf158, 0x4000548000}, 0x40004e9d40)
        google.golang.org/grpc@v1.61.0/server.go:1796 +0xc7c
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.61.0/server.go:1029 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2
        google.golang.org/grpc@v1.61.0/server.go:1040 +0x15c

Error: The terraform-provider-zitadel_v1.1.1 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.

Screenshots

No response

Expected behavior

Pretty sure the 'jwt_profile_json' is not valid, but still crashing seems not ok.

Relevant Configuration

No response

Additional Context

No response

stebenz commented 2 days ago

@musicformellons If I try to reproduce this nil-pointer I get this with the current provider version: Image

So I will close this issue for now, please retry it with the newest version, if the problem still consists then please reopen the issue.