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

Vault 32676 add vault build date to system view plugin env #29082

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
022a2e2
add VaultInfo rpc to SystemView service then make proto
helenfufu Nov 27, 2024
57c5178
implement VaultInfo in static, grpc, and dynamic system views
helenfufu Nov 28, 2024
a918734
add version.GetVaultBuildDate helper to be used in both ce and ent (t…
helenfufu Dec 2, 2024
08edbaf
add dynamic system view unit tests
helenfufu Dec 2, 2024
8df8a82
add VaultBuildDate and VaultBuiltinPublicKeys to PluginEnvironment proto
helenfufu Dec 3, 2024
027513f
extend PluginEnv implementation in dynamic system view
helenfufu Dec 3, 2024
3d60701
remove VaultInfo protos and implementations
helenfufu Dec 3, 2024
f333edf
update unit tests
helenfufu Dec 3, 2024
806cdb4
strb getter GetBuiltinPublicKeys instead of variable (which wouldn't …
helenfufu Dec 3, 2024
4447857
add changelog
helenfufu Dec 3, 2024
3ef19e9
init version.BuildDate following testing_util_ent
helenfufu Dec 3, 2024
de115fb
lint (add go doc to new tests) and TestDynamicSystemView_PluginEnv_su…
helenfufu Dec 3, 2024
f96ea93
remove TestDynamicSystemView_PluginEnv_failed since it's incompatible…
helenfufu Dec 4, 2024
ceb7506
try 1 year ago for testing_util init BuildDate
helenfufu Dec 4, 2024
fe7bf90
rename testing_util.go to testing_util_stubs_oss.go and move init Bui…
helenfufu Dec 4, 2024
637b813
Merge branch 'main' into vault-32676-add-vault-license-check-info-to-…
thyton Dec 6, 2024
a6f3ce7
remove VaultBuiltinPublicKeys from PluginEnvironment
thyton Dec 6, 2024
6d0848f
update changelog
thyton Dec 6, 2024
c9982b5
Merge branch 'main' into vault-32676-add-vault-license-check-info-to-…
thyton Dec 6, 2024
7ba9cfc
Merge branch 'main' into vault-32676-add-vault-license-check-info-to-…
thyton Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/29082.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
sdk: Add Vault build date to system view plugin environment response
```
59 changes: 39 additions & 20 deletions sdk/logical/plugin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions sdk/logical/plugin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ syntax = "proto3";

package logical;

import "google/protobuf/timestamp.proto";

option go_package = "github.com/hashicorp/vault/sdk/logical";

message PluginEnvironment {
Expand All @@ -16,4 +18,7 @@ message PluginEnvironment {

// VaultVersionMetadata is the version metadata of the Vault server
string vault_version_metadata = 3;

// VaultBuildDate is the build date of the Vault server
google.protobuf.Timestamp vault_build_date = 4;
}
8 changes: 8 additions & 0 deletions vault/dynamic_system_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault/plugincatalog"
"github.com/hashicorp/vault/version"
"google.golang.org/protobuf/types/known/timestamppb"
)

type ctxKeyForwardedRequestMountAccessor struct{}
Expand Down Expand Up @@ -407,10 +408,17 @@ func (d dynamicSystemView) GroupsForEntity(entityID string) ([]*logical.Group, e

func (d dynamicSystemView) PluginEnv(_ context.Context) (*logical.PluginEnvironment, error) {
v := version.GetVersion()

buildDate, err := version.GetVaultBuildDate()
if err != nil {
return nil, err
}

return &logical.PluginEnvironment{
VaultVersion: v.Version,
VaultVersionPrerelease: v.VersionPrerelease,
VaultVersionMetadata: v.VersionMetadata,
VaultBuildDate: timestamppb.New(buildDate),
}, nil
}

Expand Down
46 changes: 46 additions & 0 deletions vault/dynamic_system_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/version"
"google.golang.org/protobuf/types/known/timestamppb"
)

var (
Expand Down Expand Up @@ -286,6 +288,50 @@ 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) {
Copy link
Contributor Author

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!

Copy link
Contributor

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

coreConfig := &CoreConfig{
CredentialBackends: map[string]logical.Factory{},
}

cluster := NewTestCluster(t, coreConfig, &TestClusterOptions{})

cluster.Start()
defer cluster.Cleanup()

core := cluster.Cores[0].Core
TestWaitActive(t, core)

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()

ctx = namespace.RootContext(ctx)
dsv := TestDynamicSystemView(cluster.Cores[0].Core, nil)

pluginEnv, err := dsv.PluginEnv(ctx)
if err != nil {
t.Fatalf("no error expected, but got: %s", err)
}

expectedVersionInfo := version.GetVersion()

expectedBuildDate, err := version.GetVaultBuildDate()
if err != nil {
t.Fatalf("failed to set up expectedBuildDate: %v", err)
}

expectedPluginEnv := &logical.PluginEnvironment{
VaultVersion: expectedVersionInfo.Version,
VaultVersionPrerelease: expectedVersionInfo.VersionPrerelease,
VaultVersionMetadata: expectedVersionInfo.VersionMetadata,
VaultBuildDate: timestamppb.New(expectedBuildDate),
}

if !reflect.DeepEqual(pluginEnv, expectedPluginEnv) {
t.Fatalf("got %q, expected %q", pluginEnv, expectedPluginEnv)
}
}

type runes []rune

func (r runes) Len() int { return len(r) }
Expand Down
21 changes: 11 additions & 10 deletions vault/testing_util.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

//go:build !enterprise

package vault

import (
"crypto/ed25519"
"testing"
"time"

"github.com/hashicorp/vault/version"
)

func GenerateTestLicenseKeys() (ed25519.PublicKey, ed25519.PrivateKey, error) { return nil, nil, nil }
func testGetLicensingConfig(key ed25519.PublicKey) *LicensingConfig { return &LicensingConfig{} }
func testExtraTestCoreSetup(testing.TB, ed25519.PrivateKey, *TestClusterCore) {}
func testAdjustUnderlyingStorage(tcc *TestClusterCore) {
tcc.UnderlyingStorage = tcc.physical
func init() {
// The BuildDate is set as part of the build process in CI so we need to
// initialize it for testing. By setting it to now minus one year we
// provide some headroom to ensure that test license expiration (for enterprise)
// does not exceed the BuildDate as that is invalid.
if version.BuildDate == "" {
version.BuildDate = time.Now().UTC().AddDate(-1, 0, 0).Format(time.RFC3339)
}
}
func testApplyEntBaseConfig(coreConfig, base *CoreConfig) {}
21 changes: 21 additions & 0 deletions vault/testing_util_stubs_oss.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

//go:build !enterprise

package vault

import (
"crypto/ed25519"
"testing"
)

//go:generate go run github.com/hashicorp/vault/tools/stubmaker

func GenerateTestLicenseKeys() (ed25519.PublicKey, ed25519.PrivateKey, error) { return nil, nil, nil }
func testGetLicensingConfig(key ed25519.PublicKey) *LicensingConfig { return &LicensingConfig{} }
func testExtraTestCoreSetup(testing.TB, ed25519.PrivateKey, *TestClusterCore) {}
func testAdjustUnderlyingStorage(tcc *TestClusterCore) {
tcc.UnderlyingStorage = tcc.physical
}
func testApplyEntBaseConfig(coreConfig, base *CoreConfig) {}
9 changes: 9 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package version
import (
"bytes"
"fmt"
"time"
)

type VersionInfo struct {
Expand Down Expand Up @@ -33,6 +34,14 @@ func GetVersion() *VersionInfo {
}
}

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
}
Comment on lines +37 to +43
Copy link
Contributor Author

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.


func (c *VersionInfo) VersionNumber() string {
if Version == "unknown" && VersionPrerelease == "unknown" {
return "(version unknown)"
Expand Down
Loading