config for autoloading license (oss parts)

This commit is contained in:
Nick Cabatoff 2021-05-07 08:55:41 -04:00 committed by GitHub
parent 1480f26e3d
commit 53c7d1de7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 15 deletions

View file

@ -1121,6 +1121,13 @@ func (c *ServerCommand) Run(args []string) int {
} }
} }
if envLicensePath := os.Getenv("VAULT_LICENSE_PATH"); envLicensePath != "" {
config.LicensePath = envLicensePath
}
if envLicense := os.Getenv("VAULT_LICENSE"); envLicense != "" {
config.License = envLicense
}
// If mlockall(2) isn't supported, show a warning. We disable this in dev // If mlockall(2) isn't supported, show a warning. We disable this in dev
// because it is quite scary to see when first using Vault. We also disable // because it is quite scary to see when first using Vault. We also disable
// this if the user has explicitly disabled mlock in configuration. // this if the user has explicitly disabled mlock in configuration.
@ -1318,6 +1325,8 @@ func (c *ServerCommand) Run(args []string) int {
SecureRandomReader: secureRandomReader, SecureRandomReader: secureRandomReader,
EnableResponseHeaderHostname: config.EnableResponseHeaderHostname, EnableResponseHeaderHostname: config.EnableResponseHeaderHostname,
EnableResponseHeaderRaftNodeID: config.EnableResponseHeaderRaftNodeID, EnableResponseHeaderRaftNodeID: config.EnableResponseHeaderRaftNodeID,
License: config.License,
LicensePath: config.LicensePath,
} }
if c.flagDev { if c.flagDev {
coreConfig.EnableRaw = true coreConfig.EnableRaw = true

View file

@ -76,6 +76,9 @@ type Config struct {
EnableResponseHeaderRaftNodeID bool `hcl:"-"` EnableResponseHeaderRaftNodeID bool `hcl:"-"`
EnableResponseHeaderRaftNodeIDRaw interface{} `hcl:"enable_response_header_raft_node_id"` EnableResponseHeaderRaftNodeIDRaw interface{} `hcl:"enable_response_header_raft_node_id"`
License string `hcl:"-"`
LicensePath string `hcl:"license_path"`
} }
const ( const (
@ -276,6 +279,11 @@ func (c *Config) Merge(c2 *Config) *Config {
result.EnableResponseHeaderRaftNodeID = c2.EnableResponseHeaderRaftNodeID result.EnableResponseHeaderRaftNodeID = c2.EnableResponseHeaderRaftNodeID
} }
result.LicensePath = c.LicensePath
if c2.LicensePath != "" {
result.LicensePath = c2.LicensePath
}
// Use values from top-level configuration for storage if set // Use values from top-level configuration for storage if set
if storage := result.Storage; storage != nil { if storage := result.Storage; storage != nil {
if result.APIAddr != "" { if result.APIAddr != "" {

View file

@ -0,0 +1,19 @@
// +build !enterprise
package server
import (
"testing"
)
func TestLoadConfigFile_topLevel(t *testing.T) {
testLoadConfigFile_topLevel(t, nil)
}
func TestLoadConfigFile_json2(t *testing.T) {
testLoadConfigFile_json2(t, nil)
}
func TestParseEntropy(t *testing.T) {
testParseEntropy(t, true)
}

View file

@ -1,5 +1,3 @@
// +build !enterprise
package server package server
import ( import (
@ -10,18 +8,10 @@ func TestLoadConfigFile(t *testing.T) {
testLoadConfigFile(t) testLoadConfigFile(t)
} }
func TestLoadConfigFile_topLevel(t *testing.T) {
testLoadConfigFile_topLevel(t, nil)
}
func TestLoadConfigFile_json(t *testing.T) { func TestLoadConfigFile_json(t *testing.T) {
testLoadConfigFile_json(t) testLoadConfigFile_json(t)
} }
func TestLoadConfigFile_json2(t *testing.T) {
testLoadConfigFile_json2(t, nil)
}
func TestLoadConfigFileIntegerAndBooleanValues(t *testing.T) { func TestLoadConfigFileIntegerAndBooleanValues(t *testing.T) {
testLoadConfigFileIntegerAndBooleanValues(t) testLoadConfigFileIntegerAndBooleanValues(t)
} }
@ -46,10 +36,6 @@ func TestParseListeners(t *testing.T) {
testParseListeners(t) testParseListeners(t)
} }
func TestParseEntropy(t *testing.T) {
testParseEntropy(t, true)
}
func TestConfigRaftRetryJoin(t *testing.T) { func TestConfigRaftRetryJoin(t *testing.T) {
testConfigRaftRetryJoin(t) testConfigRaftRetryJoin(t)
} }

View file

@ -448,6 +448,8 @@ func testLoadConfigFile(t *testing.T) {
EnableResponseHeaderHostnameRaw: true, EnableResponseHeaderHostnameRaw: true,
EnableResponseHeaderRaftNodeID: true, EnableResponseHeaderRaftNodeID: true,
EnableResponseHeaderRaftNodeIDRaw: true, EnableResponseHeaderRaftNodeIDRaw: true,
LicensePath: "/path/to/license",
} }
addExpectedEntConfig(expected, []string{}) addExpectedEntConfig(expected, []string{})

View file

@ -48,3 +48,4 @@ disable_sealwrap = true
disable_printable_check = true disable_printable_check = true
enable_response_header_hostname = true enable_response_header_hostname = true
enable_response_header_raft_node_id = true enable_response_header_raft_node_id = true
license_path = "/path/to/license"

View file

@ -648,6 +648,8 @@ type CoreConfig struct {
ReloadFuncsLock *sync.RWMutex ReloadFuncsLock *sync.RWMutex
// Licensing // Licensing
License string
LicensePath string
LicensingConfig *LicensingConfig LicensingConfig *LicensingConfig
// Don't set this unless in dev mode, ideally only when using inmem // Don't set this unless in dev mode, ideally only when using inmem
DevLicenseDuration time.Duration DevLicenseDuration time.Duration