-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Vault 32676 add vault build date to system view plugin env #29082
Vault 32676 add vault build date to system view plugin env #29082
Conversation
CI Results: |
…o replace existing ent-specific vault.GetVaultBuildDate)
…ccessful no longer needs to override version.BuildDate
dfd51f9
to
de115fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a few notes around decision-making that hopefully help with review
@@ -286,6 +288,51 @@ func TestDynamicSystemView_GeneratePasswordFromPolicy_failed(t *testing.T) { | |||
} | |||
} | |||
|
|||
// TestDynamicSystemView_PluginEnv_successful checks that the PluginEnv method returns the expected values in a successful case. | |||
func TestDynamicSystemView_PluginEnv_successful(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two notes:
I followed the naming convention for separate success/failure tests from the above test (i.e.TestDynamicSystemView_GeneratePasswordFromPolicy_successful
and TestDynamicSystemView_GeneratePasswordFromPolicy_failed
). Open to renaming if consistency is less important.
I also omitted a failure case, because the only failure point in PluginEnv
is failure to parse the result of GetVaultBuildDate()
. I looked into overriding version.BuildDate
as it's done in an existing test TestGetSealStatus_RedactionSettings
, but found that this is incompatible with the ENT repo whose licensing tests all rely on this date being set. Happy to work/pair on a failure case if anyone has ideas!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also omitted a failure case, because the only failure point in PluginEnv is failure to parse the result of GetVaultBuildDate()
Good point
vault/testing_util.go
Outdated
func init() { | ||
// The BuildDate is set as part of the build process in CI so we need to | ||
// initialize it for testing. | ||
if version.BuildDate == "" { | ||
version.BuildDate = time.Now().UTC().Format(time.RFC3339) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed so a bunch of existing unit tests will pass without failing with failed to parse build date based on RFC3339: parsing time "" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "2006"
. The pattern is copied from testing_util_ent.go
in the ENT repo where we initialize the version.BuildDate
to 1 year ago from now (to account for license timing). In the CE repo, we can just initialize to now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If CE's version.BuildDate
initialized to 1 year ago from now also works, I wonder if it makes sense to
- rename
testing_util.go
totesting_util_stubs_oss.go
- put
init()
oftesting_util_ent.go
in a brand newtesting_util.go
, where all shared functions between CE and ENT repos will be stored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If CE's version.BuildDate initialized to 1 year ago from now also works
It should work - just pushed a commit to test it out so we can confirm. ceb7506
I wonder if it makes sense to
- rename testing_util.go to testing_util_stubs_oss.go
- put init() of testing_util_ent.go in a brand new testing_util.go, where all shared functions between CE and ENT repos will be stored.
Makes sense to me! Will keep an eye on the tests, and once they wrap, add a commit with the refactoring changes and update here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting CE's version.BuildDate
to 1 year ago worked. Here's the commit fe7bf90 that renames testing_util.go
to testing_util_stubs_oss.go
and moves init
BuildDate
to a new shared testing_util.go
.
After making the CE changes, checked the following for ENT pieces:
- re-ran the ENT tests on the latest pure CE changes to check there's no ENT breakage (https://github.com/hashicorp/vault-enterprise/pull/7086)
- updated the ENT PR with the latest from the CE PR plus the additional change to remove the ENT-only
testing_util_ent.go
init
so we rely on the new shared one intesting_util.go
(https://github.com/hashicorp/vault-enterprise/pull/7088)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ENT PR with the latest pure CE changes is failing with a data race condition (I re-ran once, and it's still failing), but the ENT PR with all our planned changes passes all tests. The failing tests don't look super related to this PR, but I wonder if the data race checks for re-initializing global variables, because after merging this CE PR but before merging the ENT PR, there will temporarily be two init()
functions setting version.BuildDate
to time.Now().UTC().AddDate(-1, 0, 0).Format(time.RFC3339)
. Thoughts:
- This race condition seems insignificant, since
version.BuildDate
is set at build time. These twoinit()
functions overwriting each other would only impact unit tests for the brief period after merging the CE PR and before merging the ENT PR, which seems like very limited impact. I'm not sure if it counts as ENT breakage though. - If this counts as ENT breakage and too complicated to sort out in light of time, reverting the most recent
testing_util
commit should avoid this problem, though ofc that means we wouldn't be applying your suggestion. - I'm not sure if there's a merge order for this refactoring that can avoid introducing any race: it seems there's no way to avoid both
init()
functions being present after merging a CE PR to add a shared function, but before merging the ENT PR to remove the ENT-only one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We synced and realized the data race condition is just a flaky test (failing on the same GetSecretEngineUsageMetrics
race) mentioned in #feed-vault-ci-official. On top of that, I had actually forgotten to push the change that removes the ENT-only init()
in the final ENT PR, so both branches had the two init()
functions with one branch passing and one branch failing the data race, suggesting further that it's just a flaky test.
func GetVaultBuildDate() (time.Time, error) { | ||
buildDate, err := time.Parse(time.RFC3339, BuildDate) | ||
if err != nil { | ||
return time.Time{}, fmt.Errorf("failed to parse build date based on RFC3339: %w", err) | ||
} | ||
return buildDate, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the PR description, this is a copy of the existing, ENT-only vault.GetVaultBuildDate
helper but we're making it shared in this common version
package now.
Build Results: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from the initial pass
vault/testing_util.go
Outdated
func init() { | ||
// The BuildDate is set as part of the build process in CI so we need to | ||
// initialize it for testing. | ||
if version.BuildDate == "" { | ||
version.BuildDate = time.Now().UTC().Format(time.RFC3339) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If CE's version.BuildDate
initialized to 1 year ago from now also works, I wonder if it makes sense to
- rename
testing_util.go
totesting_util_stubs_oss.go
- put
init()
oftesting_util_ent.go
in a brand newtesting_util.go
, where all shared functions between CE and ENT repos will be stored.
@@ -286,6 +288,51 @@ func TestDynamicSystemView_GeneratePasswordFromPolicy_failed(t *testing.T) { | |||
} | |||
} | |||
|
|||
// TestDynamicSystemView_PluginEnv_successful checks that the PluginEnv method returns the expected values in a successful case. | |||
func TestDynamicSystemView_PluginEnv_successful(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also omitted a failure case, because the only failure point in PluginEnv is failure to parse the result of GetVaultBuildDate()
Good point
0f140bf
to
49f8ce4
Compare
…ldDate to new shared testing_util.go
49f8ce4
to
fe7bf90
Compare
…system-view-plugin-env
febd9e4
to
6d0848f
Compare
…system-view-plugin-env
…system-view-plugin-env
The PR originally added build date and Vault builtin public keys to system view's plugin env. The PR is updated to only add build date. Vault builtin public keys will be baked in Enterprise plugin binaries |
--------- Co-authored-by: Thy Ton <[email protected]>
Description
This PR adds the Vault information (build date and builtin public keys) required for license checking in external plugins to the
SystemView
interface via thePluginEnv
function. We:PluginEnvironment
to includeVaultBuildDate
.GetVaultBuildDate
helper function in theversion
package to be shared across CE and ENT. In the subsequent ENT PR, we plan to remove the existing, ENT-onlyvault.GetVaultBuildDate
function and replace usages of it with this new, sharedversion.GetVaultBuildDate
.dynamicSystemView
unit tests.Related ENT PR: https://github.com/hashicorp/vault-enterprise/pull/7088 (which needs to be rebased off
main
after these CE changes are brought into ENTmain
)Ticket: VAULT-32676
RFC: https://go.hashi.co/rfc/vlt-337
Local testing:
Tested enabling external plugin with old SDK and new Vault (new SDK)
TODO only if you're a HashiCorp employee
backport/
label that matches the desired release branch. Note that in the CE repo, the latest release branch will look likebackport/x.x.x
, but older release branches will bebackport/ent/x.x.x+ent
.of a public function, even if that change is in a CE file, double check that
applying the patch for this PR to the ENT repo and running tests doesn't
break any tests. Sometimes ENT only tests rely on public functions in CE
files.
See vault-enterprise#7086 for ENT tests run with these CE changes. All tests passed.
in the PR description, commit message, or branch name.
description. Also, make sure the changelog is in this PR, not in your ENT PR.