Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Scoped Config Sources Upgrade Fix #4382

Merged
merged 2 commits into from
Jan 13, 2023
Merged

Conversation

paladin-devops
Copy link
Contributor

@paladin-devops paladin-devops commented Jan 10, 2023

This PR updates the Bolt DB implementation of config sources to "upgrade" a pre-v0.10.4 database record from the config_source table. Prior to v0.10.4, the unique identifier for each record in the table was the name of the plugin. This was changed in v0.10.4 with the addition of scoped config sources, and now the ID is a hashed value, whose hash structure is defined by the plugin name, scope, and workspace name.

This PR therefore deletes any "old" records, those whose ID is the name of any known config sourcer plugin, from Bolt DB, and creates new records with the ID correctly hashed. With this fix, users who had config sources prior to v0.10.3 may continue to interact with those config sources, whereas before this commit, they could not, and the config sources were permanently "stuck" in the database as they were before upgrading.

Fixes #4360.

// is the simplest way for users to upgrade since custom config sourcer
// plugins aren't yet supported, as of 1/10/2023.
key := string(k)
re := regexp.MustCompile(`aws-ssm|consul|kubernetes|null|packer|terraform-cloud|vault`)
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 think it's good for performance to compile your regex once at startup, and then use it throughout (example here:

reHelpHeader = regexp.MustCompile(`^[a-zA-Z0-9_-].*:$`)
)

I don't think it really matters here, because I don't think this is in a hot loop, so feel free to disregard in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@izaaklauer thanks for pointing that out! with bucket.ForEach we do loop through each record in the bucket, so I'd say it's a "warm" loop 😄 I'm going to set the regex before we enter the loop, but still in this function, since this function is called once at the start up of the server.

This commit updates the Bolt DB implementation of config sources to "upgrade" a pre-v0.10.4 database record from the config_source table. Prior to v0.10.4, the unique identifier for each record in the table was the name of the plugin. This was changed in v0.10.4 with the addition of scoped config sources, and now the ID is a hashed value, whose hash structure is defined by the plugin name, scope, and workspace name.

This commit therefore deletes any "old" records, those whose ID is the name of any known config sourcer plugin, from Bolt DB, and creates new records with the ID correctly hashed. With this fix, users who had config sources prior to v0.10.3 may continue to interact with those config sources, whereas before this commit, they could not, and the config sources were permanently "stuck" in the database as they were before upgrading.
Copy link
Contributor

@cicoyle cicoyle left a comment

Choose a reason for hiding this comment

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

This looks great! The regex enhancement and notes make it super easy to understand why you added this. 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/0.10.x bug Something isn't working core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vault Configuration Is Broken After 0.10.14
3 participants