-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plugin version to GRPC interface (#17088)
Add plugin version to GRPC interface Added a version interface in the sdk/logical so that it can be shared between all plugin types, and then wired it up to RunningVersion in the mounts, auth list, and database systems. I've tested that this works with auth, database, and secrets plugin types, with the following logic to populate RunningVersion: If a plugin has a PluginVersion() method implemented, then that is used If not, and the plugin is built into the Vault binary, then the go.mod version is used Otherwise, the it will be the empty string. My apologies for the length of this PR. * Placeholder backend should be external We use a placeholder backend (previously a framework.Backend) before a GRPC plugin is lazy-loaded. This makes us later think the plugin is a builtin plugin. So we added a `placeholderBackend` type that overrides the `IsExternal()` method so that later we know that the plugin is external, and don't give it a default builtin version.
- Loading branch information
Christopher Swenson
authored
Sep 15, 2022
1 parent
b4e9ee8
commit 70278c2
Showing
40 changed files
with
954 additions
and
178 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
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,3 @@ | ||
```release-note:improvement | ||
plugins: Adding version to plugin GRPC interface | ||
``` |
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,54 @@ | ||
package versions | ||
|
||
import ( | ||
"fmt" | ||
"runtime/debug" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/hashicorp/vault/sdk/helper/consts" | ||
"github.com/hashicorp/vault/sdk/version" | ||
) | ||
|
||
var ( | ||
buildInfoOnce sync.Once // once is used to ensure we only parse build info once. | ||
buildInfo *debug.BuildInfo | ||
DefaultBuiltinVersion = "v" + version.GetVersion().Version + "+builtin.vault" | ||
) | ||
|
||
func GetBuiltinVersion(pluginType consts.PluginType, pluginName string) string { | ||
buildInfoOnce.Do(func() { | ||
buildInfo, _ = debug.ReadBuildInfo() | ||
}) | ||
|
||
// Should never happen, means the binary was built without Go modules. | ||
// Fall back to just the Vault version. | ||
if buildInfo == nil { | ||
return DefaultBuiltinVersion | ||
} | ||
|
||
// Vault builtin plugins are all either: | ||
// a) An external repo within the hashicorp org - return external repo version with +builtin | ||
// b) Within the Vault repo itself - return Vault version with +builtin.vault | ||
// | ||
// The repo names are predictable, but follow slightly different patterns | ||
// for each plugin type. | ||
t := pluginType.String() | ||
switch pluginType { | ||
case consts.PluginTypeDatabase: | ||
// Database plugin built-ins are registered as e.g. "postgresql-database-plugin" | ||
pluginName = strings.TrimSuffix(pluginName, "-database-plugin") | ||
case consts.PluginTypeSecrets: | ||
// Repos use "secrets", pluginType.String() is "secret". | ||
t = "secrets" | ||
} | ||
pluginModulePath := fmt.Sprintf("github.com/hashicorp/vault-plugin-%s-%s", t, pluginName) | ||
|
||
for _, dep := range buildInfo.Deps { | ||
if dep.Path == pluginModulePath { | ||
return dep.Version + "+builtin" | ||
} | ||
} | ||
|
||
return DefaultBuiltinVersion | ||
} |
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
Oops, something went wrong.