-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Removes _builtin_ versions from mount storage where it already exists * Stops new builtin versions being put into storage on mount creation/tuning * Stops the plugin catalog from returning a builtin plugin that has been overridden, so it more accurately reflects the plugins that are available to actually run Conflicts: vault/mount.go Co-authored-by: Tom Proctor <[email protected]>
- Loading branch information
1 parent
f8786e5
commit 3cc6b6a
Showing
16 changed files
with
518 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
builtin/logical/database/path_config_connection_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/helper/namespace" | ||
"github.com/hashicorp/vault/helper/versions" | ||
"github.com/hashicorp/vault/sdk/helper/consts" | ||
"github.com/hashicorp/vault/sdk/logical" | ||
) | ||
|
||
func TestWriteConfig_PluginVersionInStorage(t *testing.T) { | ||
cluster, sys := getCluster(t) | ||
t.Cleanup(cluster.Cleanup) | ||
|
||
config := logical.TestBackendConfig() | ||
config.StorageView = &logical.InmemStorage{} | ||
config.System = sys | ||
|
||
b, err := Factory(context.Background(), config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer b.Cleanup(context.Background()) | ||
|
||
const hdb = "hana-database-plugin" | ||
hdbBuiltin := versions.GetBuiltinVersion(consts.PluginTypeDatabase, hdb) | ||
|
||
// Configure a connection | ||
writePluginVersion := func() { | ||
t.Helper() | ||
req := &logical.Request{ | ||
Operation: logical.UpdateOperation, | ||
Path: "config/plugin-test", | ||
Storage: config.StorageView, | ||
Data: map[string]interface{}{ | ||
"connection_url": "test", | ||
"plugin_name": hdb, | ||
"plugin_version": hdbBuiltin, | ||
"verify_connection": false, | ||
}, | ||
} | ||
resp, err := b.HandleRequest(namespace.RootContext(nil), req) | ||
if err != nil || (resp != nil && resp.IsError()) { | ||
t.Fatalf("err:%s resp:%#v\n", err, resp) | ||
} | ||
} | ||
writePluginVersion() | ||
|
||
getPluginVersionFromAPI := func() string { | ||
t.Helper() | ||
req := &logical.Request{ | ||
Operation: logical.ReadOperation, | ||
Path: "config/plugin-test", | ||
Storage: config.StorageView, | ||
} | ||
|
||
resp, err := b.HandleRequest(namespace.RootContext(nil), req) | ||
if err != nil || (resp != nil && resp.IsError()) { | ||
t.Fatalf("err:%s resp:%#v\n", err, resp) | ||
} | ||
|
||
return resp.Data["plugin_version"].(string) | ||
} | ||
pluginVersion := getPluginVersionFromAPI() | ||
if pluginVersion != "" { | ||
t.Fatalf("expected plugin_version empty but got %s", pluginVersion) | ||
} | ||
|
||
// Directly store config to get the builtin plugin version into storage, | ||
// simulating a write that happened before upgrading to 1.12.2+ | ||
err = storeConfig(context.Background(), config.StorageView, "plugin-test", &DatabaseConfig{ | ||
PluginName: hdb, | ||
PluginVersion: hdbBuiltin, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Now replay the read request, and we still shouldn't get the builtin version back. | ||
pluginVersion = getPluginVersionFromAPI() | ||
if pluginVersion != "" { | ||
t.Fatalf("expected plugin_version empty but got %s", pluginVersion) | ||
} | ||
|
||
// Check the underlying data, which should still have the version in storage. | ||
getPluginVersionFromStorage := func() string { | ||
t.Helper() | ||
entry, err := config.StorageView.Get(context.Background(), "config/plugin-test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if entry == nil { | ||
t.Fatal() | ||
} | ||
|
||
var config DatabaseConfig | ||
if err := entry.DecodeJSON(&config); err != nil { | ||
t.Fatal(err) | ||
} | ||
return config.PluginVersion | ||
} | ||
|
||
storagePluginVersion := getPluginVersionFromStorage() | ||
if storagePluginVersion != hdbBuiltin { | ||
t.Fatalf("Expected %s, got: %s", hdbBuiltin, storagePluginVersion) | ||
} | ||
|
||
// Trigger a write to storage, which should clean up plugin version in the storage entry. | ||
writePluginVersion() | ||
|
||
storagePluginVersion = getPluginVersionFromStorage() | ||
if storagePluginVersion != "" { | ||
t.Fatalf("Expected empty, got: %s", storagePluginVersion) | ||
} | ||
|
||
// Finally, confirm API requests still return empty plugin version too | ||
pluginVersion = getPluginVersionFromAPI() | ||
if pluginVersion != "" { | ||
t.Fatalf("expected plugin_version empty but got %s", pluginVersion) | ||
} | ||
} | ||
|
||
func TestWriteConfig_HelpfulErrorMessageWhenBuiltinOverridden(t *testing.T) { | ||
cluster, sys := getCluster(t) | ||
t.Cleanup(cluster.Cleanup) | ||
|
||
config := logical.TestBackendConfig() | ||
config.StorageView = &logical.InmemStorage{} | ||
config.System = sys | ||
|
||
b, err := Factory(context.Background(), config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer b.Cleanup(context.Background()) | ||
|
||
const pg = "postgresql-database-plugin" | ||
pgBuiltin := versions.GetBuiltinVersion(consts.PluginTypeDatabase, pg) | ||
|
||
// Configure a connection | ||
data := map[string]interface{}{ | ||
"connection_url": "test", | ||
"plugin_name": pg, | ||
"plugin_version": pgBuiltin, | ||
"verify_connection": false, | ||
} | ||
req := &logical.Request{ | ||
Operation: logical.UpdateOperation, | ||
Path: "config/plugin-test", | ||
Storage: config.StorageView, | ||
Data: data, | ||
} | ||
resp, err := b.HandleRequest(namespace.RootContext(nil), req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if resp == nil || !resp.IsError() { | ||
t.Fatalf("resp:%#v", resp) | ||
} | ||
if !strings.Contains(resp.Error().Error(), "overridden by an unversioned plugin") { | ||
t.Fatalf("expected overridden error but got: %s", resp.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```release-note:change | ||
plugins: Mounts can no longer be pinned to a specific _builtin_ version. Mounts previously pinned to a specific builtin version will now automatically upgrade to the latest builtin version, and may now be overridden if an unversioned plugin of the same name and type is registered. Mounts using plugin versions without `builtin` in their metadata remain unaffected. | ||
``` | ||
```release-note:bug | ||
plugins: Vault upgrades will no longer fail if a mount has been created using an explicit builtin plugin version. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package versions | ||
|
||
import "testing" | ||
|
||
func TestIsBuiltinVersion(t *testing.T) { | ||
for _, tc := range []struct { | ||
version string | ||
builtin bool | ||
}{ | ||
{"v1.0.0+builtin", true}, | ||
{"v2.3.4+builtin.vault", true}, | ||
{"1.0.0+builtin.anythingelse", true}, | ||
{"v1.0.0+other.builtin", true}, | ||
{"v1.0.0+builtinbutnot", false}, | ||
{"v1.0.0", false}, | ||
{"not-a-semver", false}, | ||
} { | ||
builtin := IsBuiltinVersion(tc.version) | ||
if builtin != tc.builtin { | ||
t.Fatalf("%s should give: %v, but got %v", tc.version, tc.builtin, builtin) | ||
} | ||
} | ||
} |
Oops, something went wrong.