From dc5587d5800798346dec58e40500db46b5e0cb3e Mon Sep 17 00:00:00 2001 From: Naushadh Ali Date: Mon, 7 Nov 2022 21:48:00 -0800 Subject: [PATCH 1/3] Address out-of-bounds access error The validation and API expects the resource identifier to be made up of 3 parts, but we're accessing the 4th element which will always be undefined. This results in a imports for these resource types failing with a cryptic error: "error: code = Canceled desc = context canceled" --- .../resource_keycloak_openid_client_authorization_permission.go | 2 +- .../resource_keycloak_openid_client_authorization_resource.go | 2 +- provider/resource_keycloak_openid_client_authorization_scope.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/provider/resource_keycloak_openid_client_authorization_permission.go b/provider/resource_keycloak_openid_client_authorization_permission.go index 0a58d5ced..fc7046671 100644 --- a/provider/resource_keycloak_openid_client_authorization_permission.go +++ b/provider/resource_keycloak_openid_client_authorization_permission.go @@ -195,7 +195,7 @@ func resourceKeycloakOpenidClientAuthorizationPermissionImport(_ context.Context } d.Set("realm_id", parts[0]) d.Set("resource_server_id", parts[1]) - d.SetId(parts[3]) + d.SetId(parts[2]) return []*schema.ResourceData{d}, nil } diff --git a/provider/resource_keycloak_openid_client_authorization_resource.go b/provider/resource_keycloak_openid_client_authorization_resource.go index b4c617338..150b45bef 100644 --- a/provider/resource_keycloak_openid_client_authorization_resource.go +++ b/provider/resource_keycloak_openid_client_authorization_resource.go @@ -187,7 +187,7 @@ func resourceKeycloakOpenidClientAuthorizationResourceImport(_ context.Context, } d.Set("realm_id", parts[0]) d.Set("resource_server_id", parts[1]) - d.SetId(parts[3]) + d.SetId(parts[2]) return []*schema.ResourceData{d}, nil } diff --git a/provider/resource_keycloak_openid_client_authorization_scope.go b/provider/resource_keycloak_openid_client_authorization_scope.go index 1214ba42f..4e50f4fc7 100644 --- a/provider/resource_keycloak_openid_client_authorization_scope.go +++ b/provider/resource_keycloak_openid_client_authorization_scope.go @@ -130,7 +130,7 @@ func resourceKeycloakOpenidClientAuthorizationScopeImport(_ context.Context, d * } d.Set("realm_id", parts[0]) d.Set("resource_server_id", parts[1]) - d.SetId(parts[3]) + d.SetId(parts[2]) return []*schema.ResourceData{d}, nil } From ad0031373c9e881a38fa9640a4f3c2004b4c9fc5 Mon Sep 17 00:00:00 2001 From: Naushadh Ali Date: Mon, 7 Nov 2022 21:51:32 -0800 Subject: [PATCH 2/3] Improve local build process In CI/CD environment, we can use helper modules to automatically install specific versions of GoLang and other system dependencies. For local development, not all devs/contributors may have the right GoLang or OS deps setup already. So we offer one using docker-compose. This simplifies the (local) build process to this; all you need is docker + compose. ```bash $ docker-compose run --rm app bash $ make build ``` --- docker-compose.yml | 7 +++++++ makefile | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index c7bc0d8a5..95a079e6b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,3 +42,10 @@ services: # Make the custom-user-federation-example extension available to Keycloak. The :z option is required and tells Docker that the volume content will be shared between containers. - ./custom-user-federation-example/build/libs/custom-user-federation-example.jar:/opt/jboss/keycloak/standalone/deployments/custom-user-federation-example.jar:z + app: + image: golang:1.18 + profiles: + - build + volumes: + - .:/app + working_dir: /app diff --git a/makefile b/makefile index 8c35741ca..2ad60584c 100644 --- a/makefile +++ b/makefile @@ -4,8 +4,10 @@ GOARCH?=amd64 MAKEFLAGS += --silent +VERSION=$$(git describe --tags) + build: - go build -o terraform-provider-keycloak + CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$(VERSION)" -o terraform-provider-keycloak_$(VERSION) build-example: build mkdir -p example/.terraform/plugins/terraform.local/mrparkers/keycloak/4.0.0/$(GOOS)_$(GOARCH) From 2e23e2382f1b41b0478925798c2d7a8f24e56a43 Mon Sep 17 00:00:00 2001 From: Naushadh Ali Date: Fri, 18 Nov 2022 15:33:03 -0500 Subject: [PATCH 3/3] Drop app service used for local dev As requested by maintainer: https://github.com/mrparkers/terraform-provider-keycloak/pull/763/commits/ad0031373c9e881a38fa9640a4f3c2004b4c9fc5#r1026743975 --- docker-compose.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 95a079e6b..932625da6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,11 +41,3 @@ services: volumes: # Make the custom-user-federation-example extension available to Keycloak. The :z option is required and tells Docker that the volume content will be shared between containers. - ./custom-user-federation-example/build/libs/custom-user-federation-example.jar:/opt/jboss/keycloak/standalone/deployments/custom-user-federation-example.jar:z - - app: - image: golang:1.18 - profiles: - - build - volumes: - - .:/app - working_dir: /app