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

Support Vault agent auth config for AWS/GCP CA provider auth #15970

Merged
merged 6 commits into from
Jan 18, 2023

Conversation

cthain
Copy link
Contributor

@cthain cthain commented Jan 12, 2023

Description

This PR addresses #11921 and adds support for supplying an existing Vault agent auto-auth configuration as the provider configuration when using the Vault CA provider. Support has been added for the AWS and GCP auth methods.

The changes have been made such that backwards compatibility is maintained for existing AWS/GCP CA auth configurations.

Testing & Reproduction steps

  • Unit tests have been added and updated.

PR Checklist

  • updated test coverage
  • external facing docs updated
  • not a security concern

@github-actions github-actions bot added pr/dependencies PR specifically updates dependencies of project theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies labels Jan 12, 2023
@cthain cthain requested a review from kisunji January 12, 2023 21:54
@cthain cthain self-assigned this Jan 12, 2023
mount := authMethod.Type
if authMethod.MountPath != "" {
mount = authMethod.MountPath
}
Copy link

Choose a reason for hiding this comment

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

nit/minor: configureVaultAuthMethod also has the "default mount path to type" logic. Is it easy to have this defaulting logic in just one place?

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, good call. I think it is fair to assume that the caller sets the MountPath correctly.

var _ VaultAuthenticator = (*gcp.GCPAuth)(nil)

// NewGCPAuthClient returns a VaultAuthenticator that can log into Vault using the GCP auth method.
func NewGCPAuthClient(authMethod *structs.VaultAuthMethod) (VaultAuthenticator, error) {
Copy link

Choose a reason for hiding this comment

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

nit: It would be nice to put the GCP stuff here in its own file, and maybe the AWS stuff in its own file. I guess, provider_vault_auth_gcp.go, provider_vault_auth_aws.go? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I think this makes sense.

}

authMethod.Params["jwt"] = string(serviceAccountToken)
}
loginPath = fmt.Sprintf("auth/%s/login", authMethod.MountPath)
return NewVaultAPIAuthClient(authMethod, loginPath), nil
Copy link

Choose a reason for hiding this comment

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

non-blocking: You don't have to do this here, but for organizational purposes, I wouldn't mind if we added functions for the other auth-method types that have non-default config: NewK8sAuthClient, NewOCIAuthClient, NewAuthClientWithUsername(?) - where those could check/set params and call NewVaultAPIAuthClient.

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 I fully agree. I've added a new issue to our backlog for this.


if c.isExplicit {
// in this case a JWT is provided so we'll call the login API directly using a VaultAuthClient.
_ = auth.(*VaultAuthClient)
Copy link

Choose a reason for hiding this comment

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

nit: We could use require.IsType for these type assertions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion!

// NewCredentialsConfig creates an awsutil.CredentialsConfig from the given set of parameters.
// It is mostly copied from the awsutil package because that package does not currently provide
// an easy way to configure all the available options.
func NewCredentialsConfig(config map[string]interface{}) (*awsutil.CredentialsConfig, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're not namespacing each auth provider with its own package, prefixing this with AWS might help discover related functions together

Suggested change
func NewCredentialsConfig(config map[string]interface{}) (*awsutil.CredentialsConfig, string, error) {
func NewAWSCredentialsConfig(config map[string]interface{}) (*awsutil.CredentialsConfig, string, error) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Or if this is an implementation detail, we could simply unexport it?

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 call. I've added AWS and unexported it.

Comment on lines 40 to 43
// LoginDataGen derives the parameter map containing the data for the login API request.
// For some auth methods this is needed to transform the AuthMethod.Params into the login data
// needed for the API request.
LoginDataGen LoginDataGenerator
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that we either use AuthMethod.Params directly or transform it with LoginDataGen to ultimately produce a map[string]interface{}.

Could this simply be func(*structs.VaultAuthMethod) map[string]any with a default that returns AuthMethod.Params? The LoginDataGenerator feels like a level of indirection which isn't entirely necessary.

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, I like this suggestion. We don't really need an interface for this. I've updated the type to a func definition as suggested.

Copy link
Contributor

@kisunji kisunji left a comment

Choose a reason for hiding this comment

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

Non-blocking comments but otherwise LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/dependencies PR specifically updates dependencies of project theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants