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

PostgreSQL - Add username customization #10766

Merged
merged 7 commits into from
Feb 4, 2021
Merged

Conversation

pcman312
Copy link
Contributor

Adds the ability to customize username generation for dynamic users in PostgreSQL.

Uses the new field username_template with the go template language.

Docs PR will come after all other updates for username customization are complete for this release.

@vercel
Copy link

vercel bot commented Jan 25, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

vault-storybook – ./ui

🔍 Inspect: https://vercel.com/hashicorp/vault-storybook/bp51xa2n2
✅ Preview: Canceled

[Deployment for 3b2f71f canceled]

@vercel vercel bot temporarily deployed to Preview – vault-storybook January 25, 2021 23:12 Inactive
@vercel vercel bot temporarily deployed to Preview – vault January 25, 2021 23:12 Inactive
@vercel vercel bot temporarily deployed to Preview – vault January 26, 2021 18:03 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook January 26, 2021 18:03 Inactive
@vercel vercel bot temporarily deployed to Preview – vault January 26, 2021 22:01 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook January 26, 2021 22:01 Inactive
@pcman312 pcman312 requested a review from calvn January 26, 2021 22:02

_, err = p.usernameProducer.Generate(dbplugin.UsernameMetadata{})
if err != nil {
return dbplugin.InitializeResponse{}, fmt.Errorf("invalid username template - did you reference a field that isn't available? : %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: does the error returned here tell you which field evaluated was invalid? I feel that "invalid username template: %w" might be sufficient here if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Example errors:

Input: foo-{{random 5}}-{{.FooBar}}
unable to apply template: template: template:1:19: executing "template" at <.FooBar>: can't evaluate field FooBar in type dbplugin.UsernameMetadata

Input: foo-{{random 5}}-{{FooBar}}
unable to parse template: template: template:1: function "FooBar" not defined

I'll look to see if the error that's returned is structured in any meaningful way so we can make this a bit nicer to users who aren't familiar with these errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately the errors coming back from the template library (the Go one, not the one in Vault) are not structured in a useful way here. I will remove this message and put a note in the docs about common error messages.

plugins/database/postgresql/postgresql.go Outdated Show resolved Hide resolved
plugins/database/postgresql/postgresql.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – vault February 3, 2021 21:04 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook February 3, 2021 21:04 Inactive
Copy link
Contributor

@catsby catsby left a comment

Choose a reason for hiding this comment

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

LGTM

@vercel vercel bot temporarily deployed to Preview – vault February 4, 2021 22:32 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook February 4, 2021 22:32 Inactive
@pcman312 pcman312 merged commit cf85a86 into master Feb 4, 2021
@pcman312 pcman312 deleted the customize-username-postgres branch February 4, 2021 23:06
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.

3 participants