Check if plugin version matches running version (#17182)

Check if plugin version matches running version

When registering a plugin, we check if the request version matches the
self-reported version from the plugin. If these do not match, we log a
warning.

This uncovered a few missing pieces for getting the database version
code fully working.

We added an environment variable that helps us unit test the running
version behavior as well, but only for approle, postgresql, and consul
plugins.

Return 400 on plugin not found or version mismatch

Populate the running SHA256 of plugins in the mount and auth tables (#17217)
This commit is contained in:
Christopher Swenson
2022-09-21 12:25:04 -07:00
committed by GitHub
parent c3c323d8d8
commit 0b34b73c47
13 changed files with 394 additions and 72 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
"github.com/hashicorp/vault/sdk/helper/dbtxn"
"github.com/hashicorp/vault/sdk/helper/template"
"github.com/hashicorp/vault/sdk/logical"
_ "github.com/jackc/pgx/v4/stdlib"
)
@@ -32,7 +33,8 @@ ALTER ROLE "{{username}}" WITH PASSWORD '{{password}}';
)
var (
_ dbplugin.Database = &PostgreSQL{}
_ dbplugin.Database = (*PostgreSQL)(nil)
_ logical.PluginVersioner = (*PostgreSQL)(nil)
// postgresEndStatement is basically the word "END" but
// surrounded by a word boundary to differentiate it from
@@ -46,6 +48,9 @@ var (
// singleQuotedPhrases finds substrings like 'hello'
// and pulls them out with the quotes included.
singleQuotedPhrases = regexp.MustCompile(`('.*?')`)
// ReportedVersion is used to report a specific version to Vault.
ReportedVersion = ""
)
func New() (interface{}, error) {
@@ -469,6 +474,10 @@ func (p *PostgreSQL) secretValues() map[string]string {
}
}
func (p *PostgreSQL) PluginVersion() logical.PluginVersion {
return logical.PluginVersion{Version: ReportedVersion}
}
// containsMultilineStatement is a best effort to determine whether
// a particular statement is multiline, and therefore should not be
// split upon semicolons. If it's unsure, it defaults to false.