From 83826aa866723ed3710ea566efb30c710d06adc6 Mon Sep 17 00:00:00 2001 From: Elim Tsiagbey Date: Fri, 12 May 2023 10:56:58 -0400 Subject: [PATCH] fix: default auth method with recovery kms (#406) * add test coverage for authenticating with recovery kms mechanism & oidc primary auth method * Skip fetching default auth method when recovery_kms_hcl is set or the client token isn't null --- internal/provider/provider.go | 5 +- internal/provider/provider_test.go | 55 +++++++++++++++++-- .../resource_auth_method_oidc_test.go | 4 +- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 6c5ab047..8b2442f7 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -156,9 +156,10 @@ func providerAuthenticate(ctx context.Context, d *schema.ResourceData, md *metaD md.client.SetToken(token.(string)) } - // If auth_method_id is not set, get the default auth method ID for the given scope ID + // If auth_method_id is not set, get the default auth method ID for the given scope ID. + // Skip fetching default auth method when recovery_kms_hcl is set or the client token isn't null. authMethodId, authMethodIdOk := d.GetOk("auth_method_id") - if !authMethodIdOk { + if !authMethodIdOk && !recoveryKmsHclOk && md.client.Token() == "" { defaultAuthMethodId, err := getDefaultAuthMethodId(ctx, amClient, providerScope, "") if err != nil { return err diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 3808c57b..314c4b6c 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/boundary/testing/controller" "github.com/hashicorp/cap/ldap" + "github.com/hashicorp/cap/oidc" wrapping "github.com/hashicorp/go-kms-wrapping/v2" "github.com/hashicorp/go-kms-wrapping/v2/aead" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -143,9 +144,6 @@ func testConfigWithRecovery(url string, res ...string) string { provider := fmt.Sprintf(` provider "boundary" { addr = "%s" - auth_method_id = "%s" - password_auth_method_login_name = "%s" - password_auth_method_password = "%s" recovery_kms_hcl = <