Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Phase 2] Complete the provider configuration setup #2090

Merged

Conversation

fairclothjm
Copy link
Contributor

@fairclothjm fairclothjm commented Nov 17, 2023

Description

Complete the provider configuration setup for the auth login methods.

This PR

Phase 2

  • Modifies the internal/provider/auth.go file to handle defaults and required fields since those can no longer be set on the Provider Schema
  • Modifies the auth login methods to remove defaults and make use of the new setDefaultFields method
  • Adds tests for the changes to default value and env var handling
  • Implements the Password Policy resources to show how a resource can work with the multiplexed providers
    • Currently, there is an issue with an import cycle, so the tests will be implemented in a separate PR

Previous Phases

Phase 0

Phase 1

  • [Phase 1] Multiplex provider - minimal TF Plugin Framework provider implementation #2067
  • Introduces (in internal/provider/fwprovider) a minimal provider implementation that uses the TF Plugin Framework and muxes it with the current SDK v2-based provider's server. This new skeleton provider
  • Implements 0 resources and data sources
  • Is required to declare a provider schema that is identical to the schema(s) declared by all other providers in the muxed provider server
  • Removes Default values from the SDK v2-based provider's schema declaration as the TF Framework-based provider does not have that facility. Defaults should be handled in the provider's ConfigureFunc

Subsequent Phases

Phase 3

  • Fully migrate a resource/data source to the TF Plugin Framework

…tion (#2097)

make updates to all auth logins and fix build

run go mod tidy

register all auth logins to test build

add all auth login blocks and match schema implementations

set default for azure scope

address todos

- remove commented code; neither are read from env vars
- add validators
@fairclothjm fairclothjm force-pushed the VAULT-21288/auth-login-fwprovider branch from 3799f9a to fe6136b Compare November 30, 2023 18:05
Copy link
Contributor

@austingebauer austingebauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some very minor suggestions and questions. Overall this is looking good!

I do wonder if there is a clean way to define the schema attributes of the various auth login methods in a single location instead of having them duplicated for both sdkv2/fw providers. That said, it might not be worth it if the change frequency is low for them. We can document that changes must match in each provider.

internal/framework/validators/gcp_test.go Outdated Show resolved Hide resolved
internal/framework/validators/gcp_test.go Outdated Show resolved Hide resolved
website/docs/index.html.markdown Show resolved Hide resolved
internal/provider/provider.go Outdated Show resolved Hide resolved
internal/provider/auth.go Show resolved Hide resolved
@fairclothjm fairclothjm force-pushed the VAULT-21288/auth-login-fwprovider branch from 70ea03b to 9f607e2 Compare December 4, 2023 20:26
@fairclothjm
Copy link
Contributor Author

@austingebauer Thanks for the review!

clean way to define the schema attributes of the various auth login methods in a single location instead of having them duplicated for both sdkv2/fw providers

I think we could do that if we wrote a wrapper to convert to either sdkv2 or Framework but I am not convinced that it would be worth it. I do think the change frequency is pretty low. I am happy to discuss more if you like.

Also, I am working on adding tests to assert the multiplexing schemas match. terraform apply will fail if the schemas don't match but of course we want to catch it before then. :)

@austingebauer
Copy link
Contributor

@fairclothjm - Thanks! I'm good with having the fields defined in both places provided the test can make developers aware of diffs. If it becomes a pain, we can write that conversion code at a later date 👍

Copy link
Contributor

@benashz benashz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a first pass, looks like good progress!

internal/provider/auth.go Outdated Show resolved Hide resolved
Required: true,
DefaultFunc: schema.EnvDefaultFunc(consts.EnvVarTokenFilename, nil),
Type: schema.TypeString,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this is still required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct. I tested it and the behavior is the same whether we set this to Optional or Required because we assert the required fields in checkRequiredFields. I do think it makes it confusing to not set it as required here though, so I will revert these Schema changes for any required Auth Login fields.

Copy link
Contributor Author

@fairclothjm fairclothjm Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction to the above which is not entirely true. For fields that we previously set from a DefaultFunc and env vars we cannot set them as Required anymore. This is because we are handling setting them from env vars after the Provider has verified all required fields are set. So, for example, if we set this field to Required we would get a Error: Missing required argument error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add test cases to capture this behavior for the fields that are set via env vars.

internal/provider/auth_token_file.go Show resolved Hide resolved
internal/provider/fwprovider/provider.go Outdated Show resolved Hide resolved
@@ -0,0 +1,39 @@
package client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks pretty similar to what we have in the internal/provider package, would it be possible to colocate it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we could move it there. Initially it was doing more things that included Framework only types so I created a separate package. However, this is only intended for resources implemented with the TF Plugin Framework so I kept it in the internal/framework package for that reason. I thought it would be good to have a package that contains framework-only client helpers. I don't feel too strongly about it either way though.

@@ -142,6 +144,18 @@ func (p *fwprovider) Schema(ctx context.Context, req provider.SchemaRequest, res
},
},
},
"auth_login": AuthLoginGenericSchema(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't use the auth login registry as before? That solved some issues where not all expected AuthLogin were properly set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, we might need to use that. I will look into it. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a closer look at this again.

These lines define the schema for the Framework Provider (which must match 1-1 with the sdkv2 Provider). The auth login registry is still being used by the Framework Provider. The entrypoint for the auth login registry is in setClient:

authLogin, err := GetAuthLogin(d)

As such, there should be no behavior change for the Framework Provider since we are sharing the auth login code with the sdkv2 provider. Please let me know if you need more clarification!

internal/provider/auth.go Show resolved Hide resolved
internal/provider/auth.go Outdated Show resolved Hide resolved
internal/provider/auth.go Outdated Show resolved Hide resolved
@fairclothjm fairclothjm marked this pull request as ready for review December 8, 2023 16:50
@fairclothjm fairclothjm changed the title WIP - [Phase 2] Complete the provider configuration setup [Phase 2] Complete the provider configuration setup Dec 8, 2023
internal/provider/auth_aws.go Outdated Show resolved Hide resolved
internal/provider/auth_aws.go Outdated Show resolved Hide resolved
internal/provider/fwprovider/auth_aws.go Outdated Show resolved Hide resolved
internal/provider/fwprovider/auth_aws.go Outdated Show resolved Hide resolved
Copy link
Contributor

@austingebauer austingebauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few minor comments but generally LGTM. Nice job on this @fairclothjm!

internal/provider/fwprovider/auth_kerberos.go Outdated Show resolved Hide resolved
internal/sys/password_policy.go Outdated Show resolved Hide resolved
internal/sys/password_policy.go Outdated Show resolved Hide resolved
internal/sys/password_policy.go Show resolved Hide resolved
Comment on lines +139 to +141
// TestAccMuxServer uses ExternalProviders (vault) to generate a state file
// with a previous version of the provider and then verify that there are no
// planned changes after migrating to the Framework.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Contributor

@vinay-gopalan vinay-gopalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work on this! Looks great to me, had a couple nits and questions, not blocking a merge

@@ -0,0 +1,61 @@
package fwprovider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sorry I forgot to add the copywrite headers for these! Definitely can let the copywrite bot take care of these before we merge to main, but just wanted to add a comment here to keep track. not a blocker

internal/provider/fwprovider/auth_kerberos.go Outdated Show resolved Hide resolved
internal/provider/fwprovider/auth_kerberos.go Outdated Show resolved Hide resolved
@@ -671,12 +673,32 @@ func TestNewProviderMeta(t *testing.T) {
},
},
},
env: map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I confirmed this with commenting out the env in this test and the test passes so we're definitely good here, but curious if it's worth it to add a test case for the default behavior where no env is passed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are testing that in several test cases above this one

website/docs/index.html.markdown Show resolved Hide resolved
@fairclothjm fairclothjm merged commit bbf6580 into VAULT-21287/minimum-fwprovider Dec 12, 2023
11 checks passed
fairclothjm added a commit that referenced this pull request Dec 12, 2023
…mplementation (#2067)

* implement the framework provider

* setup provider server factory

* setup framework provider schema

* handle defaults in configure

* [Phase 2] Complete the provider configuration setup (#2090)

* setup framework provider schema

* handle defaults in configure

* WIP: handle auth login methods

* [Phase 2] Include Auth Login blocks in multiplexed Provider configuration (#2097)

make updates to all auth logins and fix build

run go mod tidy

register all auth logins to test build

add all auth login blocks and match schema implementations

set default for azure scope

address todos

- remove commented code; neither are read from env vars
- add validators

* remove set_namespace_from_token field

* add custom path validator

* configure namespace for vault client

* review comments

* add muxed provider acc tests

* use consts, set required fields and update tests

* add tests for multi envs and fix bug

* fix bug with overriding config val

* add custom URI validator for OIDC auth

* fix a few default mount types

* add comments and migration state example acc test

* remove dupe default entries; add validators

* remove client_auth docs

* add kerbos token and file path validators

* don't use double pointer and remove redundant return

---------

Co-authored-by: vinay-gopalan <86625824+vinay-gopalan@users.noreply.github.com>

---------

Co-authored-by: vinay-gopalan <86625824+vinay-gopalan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants