2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-07-25 02:02:27 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2023-05-19 22:11:41 +00:00
|
|
|
"syscall"
|
2018-07-25 02:02:27 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-test/deep"
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
ctconfig "github.com/hashicorp/consul-template/config"
|
2023-05-24 20:56:06 +00:00
|
|
|
"golang.org/x/exp/slices"
|
|
|
|
|
2023-05-19 17:17:48 +00:00
|
|
|
"github.com/hashicorp/vault/command/agentproxyshared"
|
2020-10-13 23:38:21 +00:00
|
|
|
"github.com/hashicorp/vault/internalshared/configutil"
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/pointerutil"
|
2018-07-25 02:02:27 +00:00
|
|
|
)
|
|
|
|
|
2019-02-15 01:10:36 +00:00
|
|
|
func TestLoadConfigFile_AgentCache(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-cache.hcl")
|
2019-02-15 01:10:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2020-05-14 13:19:27 +00:00
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "unix",
|
|
|
|
Address: "/path/to/socket",
|
|
|
|
TLSDisable: true,
|
|
|
|
SocketMode: "configmode",
|
|
|
|
SocketUser: "configuser",
|
|
|
|
SocketGroup: "configgroup",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
2022-11-25 21:00:56 +00:00
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:3000",
|
|
|
|
Role: "metrics_only",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
2020-05-14 13:19:27 +00:00
|
|
|
{
|
|
|
|
Type: "tcp",
|
2022-11-25 21:00:56 +00:00
|
|
|
Role: "default",
|
2020-05-14 13:19:27 +00:00
|
|
|
Address: "127.0.0.1:8400",
|
|
|
|
TLSKeyFile: "/path/to/cakey.pem",
|
|
|
|
TLSCertFile: "/path/to/cacert.pem",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-02-15 01:10:36 +00:00
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
2020-05-14 13:19:27 +00:00
|
|
|
{
|
2019-02-15 01:10:36 +00:00
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-05 15:51:03 +00:00
|
|
|
APIProxy: &APIProxy{
|
|
|
|
UseAutoAuthToken: true,
|
|
|
|
ForceAutoAuthToken: false,
|
|
|
|
},
|
2019-02-15 01:10:36 +00:00
|
|
|
Cache: &Cache{
|
2020-02-14 21:48:12 +00:00
|
|
|
UseAutoAuthToken: true,
|
|
|
|
UseAutoAuthTokenRaw: true,
|
|
|
|
ForceAutoAuthToken: false,
|
2023-05-19 17:17:48 +00:00
|
|
|
Persist: &agentproxyshared.PersistConfig{
|
2021-03-03 22:01:33 +00:00
|
|
|
Type: "kubernetes",
|
|
|
|
Path: "/vault/agent-cache/",
|
|
|
|
KeepAfterImport: true,
|
|
|
|
ExitOnErr: true,
|
|
|
|
ServiceAccountTokenFile: "/tmp/serviceaccount/token",
|
|
|
|
},
|
2019-03-15 18:58:53 +00:00
|
|
|
},
|
2019-02-28 22:29:28 +00:00
|
|
|
Vault: &Vault{
|
2019-04-13 07:44:06 +00:00
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
CACert: "config_ca_cert",
|
|
|
|
CAPath: "config_ca_path",
|
|
|
|
TLSSkipVerifyRaw: interface{}("true"),
|
|
|
|
TLSSkipVerify: true,
|
|
|
|
ClientCert: "config_client_cert",
|
|
|
|
ClientKey: "config_client_key",
|
2021-03-18 18:14:09 +00:00
|
|
|
Retry: &Retry{
|
|
|
|
NumRetries: 12,
|
|
|
|
},
|
2019-02-28 22:29:28 +00:00
|
|
|
},
|
2019-02-15 01:10:36 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2019-02-15 01:10:36 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err = LoadConfigFile("./test-fixtures/config-cache-embedded-type.hcl")
|
2019-02-15 01:10:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-04-13 07:44:06 +00:00
|
|
|
expected.Vault.TLSSkipVerifyRaw = interface{}(true)
|
2019-02-15 01:10:36 +00:00
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2019-02-15 01:10:36 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:50:19 +00:00
|
|
|
func TestLoadConfigDir_AgentCache(t *testing.T) {
|
|
|
|
config, err := LoadConfig("./test-fixtures/config-dir-cache/")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "unix",
|
|
|
|
Address: "/path/to/socket",
|
|
|
|
TLSDisable: true,
|
|
|
|
SocketMode: "configmode",
|
|
|
|
SocketUser: "configuser",
|
|
|
|
SocketGroup: "configgroup",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:3000",
|
|
|
|
Role: "metrics_only",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Role: "default",
|
|
|
|
Address: "127.0.0.1:8400",
|
|
|
|
TLSKeyFile: "/path/to/cakey.pem",
|
|
|
|
TLSCertFile: "/path/to/cacert.pem",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
APIProxy: &APIProxy{
|
|
|
|
UseAutoAuthToken: true,
|
|
|
|
ForceAutoAuthToken: false,
|
|
|
|
},
|
|
|
|
Cache: &Cache{
|
|
|
|
UseAutoAuthToken: true,
|
|
|
|
UseAutoAuthTokenRaw: true,
|
|
|
|
ForceAutoAuthToken: false,
|
2023-05-19 17:17:48 +00:00
|
|
|
Persist: &agentproxyshared.PersistConfig{
|
2023-01-03 17:50:19 +00:00
|
|
|
Type: "kubernetes",
|
|
|
|
Path: "/vault/agent-cache/",
|
|
|
|
KeepAfterImport: true,
|
|
|
|
ExitOnErr: true,
|
|
|
|
ServiceAccountTokenFile: "/tmp/serviceaccount/token",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
CACert: "config_ca_cert",
|
|
|
|
CAPath: "config_ca_path",
|
|
|
|
TLSSkipVerifyRaw: interface{}("true"),
|
|
|
|
TLSSkipVerify: true,
|
|
|
|
ClientCert: "config_client_cert",
|
|
|
|
ClientKey: "config_client_key",
|
|
|
|
Retry: &Retry{
|
|
|
|
NumRetries: 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
config, err = LoadConfigFile("./test-fixtures/config-dir-cache/config-cache1.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
config2, err := LoadConfigFile("./test-fixtures/config-dir-cache/config-cache2.hcl")
|
|
|
|
|
|
|
|
mergedConfig := config.Merge(config2)
|
|
|
|
|
|
|
|
mergedConfig.Prune()
|
|
|
|
if diff := deep.Equal(mergedConfig, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigDir_AutoAuthAndListener(t *testing.T) {
|
|
|
|
config, err := LoadConfig("./test-fixtures/config-dir-auto-auth-and-listener/")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
config, err = LoadConfigFile("./test-fixtures/config-dir-auto-auth-and-listener/config1.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
config2, err := LoadConfigFile("./test-fixtures/config-dir-auto-auth-and-listener/config2.hcl")
|
|
|
|
|
|
|
|
mergedConfig := config.Merge(config2)
|
|
|
|
|
|
|
|
mergedConfig.Prune()
|
|
|
|
if diff := deep.Equal(mergedConfig, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigDir_VaultBlock(t *testing.T) {
|
|
|
|
config, err := LoadConfig("./test-fixtures/config-dir-vault-block/")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
CACert: "config_ca_cert",
|
|
|
|
CAPath: "config_ca_path",
|
|
|
|
TLSSkipVerifyRaw: interface{}("true"),
|
|
|
|
TLSSkipVerify: true,
|
|
|
|
ClientCert: "config_client_cert",
|
|
|
|
ClientKey: "config_client_key",
|
|
|
|
Retry: &Retry{
|
|
|
|
NumRetries: 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
config, err = LoadConfigFile("./test-fixtures/config-dir-vault-block/config1.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
config2, err := LoadConfigFile("./test-fixtures/config-dir-vault-block/config2.hcl")
|
|
|
|
|
|
|
|
mergedConfig := config.Merge(config2)
|
|
|
|
|
|
|
|
mergedConfig.Prune()
|
|
|
|
if diff := deep.Equal(mergedConfig, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-16 00:22:19 +00:00
|
|
|
func TestLoadConfigFile_AgentCache_NoListeners(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-cache-no-listeners.hcl")
|
2021-10-16 00:22:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-01-03 17:50:19 +00:00
|
|
|
APIProxy: &APIProxy{
|
|
|
|
UseAutoAuthToken: true,
|
|
|
|
ForceAutoAuthToken: false,
|
|
|
|
},
|
2021-10-16 00:22:19 +00:00
|
|
|
Cache: &Cache{
|
|
|
|
UseAutoAuthToken: true,
|
|
|
|
UseAutoAuthTokenRaw: true,
|
|
|
|
ForceAutoAuthToken: false,
|
2023-05-19 17:17:48 +00:00
|
|
|
Persist: &agentproxyshared.PersistConfig{
|
2021-10-16 00:22:19 +00:00
|
|
|
Type: "kubernetes",
|
|
|
|
Path: "/vault/agent-cache/",
|
|
|
|
KeepAfterImport: true,
|
|
|
|
ExitOnErr: true,
|
|
|
|
ServiceAccountTokenFile: "/tmp/serviceaccount/token",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
CACert: "config_ca_cert",
|
|
|
|
CAPath: "config_ca_path",
|
|
|
|
TLSSkipVerifyRaw: interface{}("true"),
|
|
|
|
TLSSkipVerify: true,
|
|
|
|
ClientCert: "config_client_cert",
|
|
|
|
ClientKey: "config_client_key",
|
|
|
|
Retry: &Retry{
|
|
|
|
NumRetries: 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Templates: []*ctconfig.TemplateConfig{
|
|
|
|
{
|
|
|
|
Source: pointerutil.StringPtr("/path/on/disk/to/template.ctmpl"),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render.txt"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:02:27 +00:00
|
|
|
func TestLoadConfigFile(t *testing.T) {
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
if err := os.Setenv("TEST_AAD_ENV", "aad"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := os.Unsetenv("TEST_AAD_ENV"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2018-07-25 02:02:27 +00:00
|
|
|
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config.hcl")
|
2018-07-25 02:02:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2020-05-14 13:19:27 +00:00
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
2022-11-29 14:07:04 +00:00
|
|
|
LogFile: "/var/log/vault/vault-agent.log",
|
2020-05-14 13:19:27 +00:00
|
|
|
},
|
2018-07-25 02:02:27 +00:00
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
2019-07-03 07:33:20 +00:00
|
|
|
Namespace: "my-namespace/",
|
2018-07-25 02:02:27 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
2021-02-23 20:04:21 +00:00
|
|
|
MaxBackoff: 0,
|
2018-07-25 02:02:27 +00:00
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
2020-05-14 13:19:27 +00:00
|
|
|
{
|
2018-07-25 02:02:27 +00:00
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
2020-05-14 13:19:27 +00:00
|
|
|
{
|
2020-09-15 14:01:26 +00:00
|
|
|
Type: "file",
|
|
|
|
WrapTTL: 5 * time.Minute,
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath2",
|
|
|
|
AAD: "aad",
|
2020-08-17 16:36:16 +00:00
|
|
|
DeriveKey: true,
|
2018-07-25 02:02:27 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2018-07-25 02:02:27 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err = LoadConfigFile("./test-fixtures/config-embedded-type.hcl")
|
2018-07-25 02:02:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2018-07-25 02:02:27 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 18:58:53 +00:00
|
|
|
|
2019-04-05 20:12:54 +00:00
|
|
|
func TestLoadConfigFile_Method_Wrapping(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-method-wrapping.hcl")
|
2019-04-05 20:12:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2020-05-14 13:19:27 +00:00
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
2019-04-05 20:12:54 +00:00
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
2022-09-15 18:00:31 +00:00
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
ExitOnError: false,
|
|
|
|
WrapTTL: 5 * time.Minute,
|
|
|
|
MaxBackoff: 2 * time.Minute,
|
2019-04-05 20:12:54 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
2020-05-14 13:19:27 +00:00
|
|
|
{
|
2019-04-05 20:12:54 +00:00
|
|
|
Type: "file",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2019-04-05 20:12:54 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 16:31:32 +00:00
|
|
|
func TestLoadConfigFile_Method_InitialBackoff(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-method-initial-backoff.hcl")
|
2022-04-29 16:31:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
2022-09-15 18:00:31 +00:00
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
ExitOnError: false,
|
|
|
|
WrapTTL: 5 * time.Minute,
|
|
|
|
MinBackoff: 5 * time.Second,
|
|
|
|
MaxBackoff: 2 * time.Minute,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Method_ExitOnErr(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-method-exit-on-err.hcl")
|
2022-09-15 18:00:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
ExitOnError: true,
|
|
|
|
WrapTTL: 5 * time.Minute,
|
|
|
|
MinBackoff: 5 * time.Second,
|
|
|
|
MaxBackoff: 2 * time.Minute,
|
2022-04-29 16:31:32 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 18:58:53 +00:00
|
|
|
func TestLoadConfigFile_AgentCache_NoAutoAuth(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-cache-no-auto_auth.hcl")
|
2019-03-15 18:58:53 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2023-06-01 19:14:17 +00:00
|
|
|
Cache: &Cache{},
|
2020-05-14 13:19:27 +00:00
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
2019-03-15 18:58:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2019-03-15 18:58:53 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Bad_AgentCache_InconsisentAutoAuth(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/bad-config-cache-inconsistent-auto_auth.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("LoadConfigFile should not return an error for this config, err: %v", err)
|
|
|
|
}
|
|
|
|
if config == nil {
|
|
|
|
t.Fatal("config was nil")
|
|
|
|
}
|
|
|
|
err = config.ValidateConfig()
|
2019-03-15 18:58:53 +00:00
|
|
|
if err == nil {
|
2023-01-03 17:50:19 +00:00
|
|
|
t.Fatal("ValidateConfig should return an error when use_auto_auth_token=true and no auto_auth section present")
|
2019-03-15 18:58:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 21:48:12 +00:00
|
|
|
func TestLoadConfigFile_Bad_AgentCache_ForceAutoAuthNoMethod(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/bad-config-cache-force-token-no-auth-method.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("LoadConfigFile should not return an error for this config, err: %v", err)
|
|
|
|
}
|
|
|
|
if config == nil {
|
|
|
|
t.Fatal("config was nil")
|
|
|
|
}
|
|
|
|
err = config.ValidateConfig()
|
2020-02-14 21:48:12 +00:00
|
|
|
if err == nil {
|
2023-01-03 17:50:19 +00:00
|
|
|
t.Fatal("ValidateConfig should return an error when use_auto_auth_token=force and no auto_auth section present")
|
2020-02-14 21:48:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 18:58:53 +00:00
|
|
|
func TestLoadConfigFile_Bad_AgentCache_NoListeners(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
_, err := LoadConfigFile("./test-fixtures/bad-config-cache-no-listeners.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("LoadConfigFile should return an error for this config")
|
2019-03-15 18:58:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-01 20:26:41 +00:00
|
|
|
|
2019-04-05 20:12:54 +00:00
|
|
|
func TestLoadConfigFile_Bad_AutoAuth_Wrapped_Multiple_Sinks(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
_, err := LoadConfigFile("./test-fixtures/bad-config-auto_auth-wrapped-multiple-sinks.hcl")
|
2019-04-05 20:12:54 +00:00
|
|
|
if err == nil {
|
2023-01-03 17:50:19 +00:00
|
|
|
t.Fatalf("LoadConfigFile should return an error for this config, err: %v", err)
|
2019-04-05 20:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-26 17:52:14 +00:00
|
|
|
func TestLoadConfigFile_Bad_AutoAuth_Nosinks_Nocache_Notemplates(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/bad-config-auto_auth-nosinks-nocache-notemplates.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("LoadConfigFile should not return an error for this config, err: %v", err)
|
|
|
|
}
|
|
|
|
if config == nil {
|
|
|
|
t.Fatal("config was nil")
|
|
|
|
}
|
|
|
|
err = config.ValidateConfig()
|
2020-05-26 17:52:14 +00:00
|
|
|
if err == nil {
|
2023-01-03 17:50:19 +00:00
|
|
|
t.Fatal("ValidateConfig should return an error when auto_auth configured and there are no sinks, caches or templates")
|
2020-05-26 17:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 20:12:54 +00:00
|
|
|
func TestLoadConfigFile_Bad_AutoAuth_Both_Wrapping_Types(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
_, err := LoadConfigFile("./test-fixtures/bad-config-method-wrapping-and-sink-wrapping.hcl")
|
2019-04-05 20:12:54 +00:00
|
|
|
if err == nil {
|
2023-01-03 17:50:19 +00:00
|
|
|
t.Fatalf("LoadConfigFile should return an error for this config")
|
2019-04-05 20:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Bad_AgentCache_AutoAuth_Method_wrapping(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/bad-config-cache-auto_auth-method-wrapping.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("LoadConfigFile should not return an error for this config, err: %v", err)
|
|
|
|
}
|
|
|
|
if config == nil {
|
|
|
|
t.Fatal("config was nil")
|
|
|
|
}
|
|
|
|
err = config.ValidateConfig()
|
2019-04-05 20:12:54 +00:00
|
|
|
if err == nil {
|
2023-01-03 17:50:19 +00:00
|
|
|
t.Fatal("ValidateConfig should return an error when auth_auth.method.wrap_ttl nonzero and cache.use_auto_auth_token=true")
|
2019-04-05 20:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 15:51:03 +00:00
|
|
|
func TestLoadConfigFile_Bad_APIProxy_And_Cache_Same_Config(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/bad-config-api_proxy-cache.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("LoadConfigFile should not return an error for this config, err: %v", err)
|
|
|
|
}
|
|
|
|
if config == nil {
|
|
|
|
t.Fatal("config was nil")
|
|
|
|
}
|
|
|
|
err = config.ValidateConfig()
|
2022-12-05 15:51:03 +00:00
|
|
|
if err == nil {
|
2023-01-03 17:50:19 +00:00
|
|
|
t.Fatal("ValidateConfig should return an error when cache and api_proxy try and configure the same value")
|
2022-12-05 15:51:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 20:26:41 +00:00
|
|
|
func TestLoadConfigFile_AgentCache_AutoAuth_NoSink(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-cache-auto_auth-no-sink.hcl")
|
2019-04-01 20:26:41 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2020-05-14 13:19:27 +00:00
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
2019-04-01 20:26:41 +00:00
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-05 15:51:03 +00:00
|
|
|
APIProxy: &APIProxy{
|
|
|
|
UseAutoAuthToken: true,
|
|
|
|
ForceAutoAuthToken: false,
|
|
|
|
},
|
2019-04-01 20:26:41 +00:00
|
|
|
Cache: &Cache{
|
2020-02-14 21:48:12 +00:00
|
|
|
UseAutoAuthToken: true,
|
|
|
|
UseAutoAuthTokenRaw: true,
|
|
|
|
ForceAutoAuthToken: false,
|
2020-01-30 15:08:42 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2020-01-30 15:08:42 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_AgentCache_AutoAuth_Force(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-cache-auto_auth-force.hcl")
|
2020-01-30 15:08:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2020-05-14 13:19:27 +00:00
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
2020-01-30 15:08:42 +00:00
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-05 15:51:03 +00:00
|
|
|
APIProxy: &APIProxy{
|
|
|
|
UseAutoAuthToken: true,
|
|
|
|
ForceAutoAuthToken: true,
|
|
|
|
},
|
2020-01-30 15:08:42 +00:00
|
|
|
Cache: &Cache{
|
2020-02-14 21:48:12 +00:00
|
|
|
UseAutoAuthToken: true,
|
|
|
|
UseAutoAuthTokenRaw: "force",
|
|
|
|
ForceAutoAuthToken: true,
|
2020-01-30 15:08:42 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2020-01-30 15:08:42 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_AgentCache_AutoAuth_True(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-cache-auto_auth-true.hcl")
|
2020-01-30 15:08:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2020-05-14 13:19:27 +00:00
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
2020-01-30 15:08:42 +00:00
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-05 15:51:03 +00:00
|
|
|
APIProxy: &APIProxy{
|
|
|
|
UseAutoAuthToken: true,
|
|
|
|
ForceAutoAuthToken: false,
|
|
|
|
},
|
2020-01-30 15:08:42 +00:00
|
|
|
Cache: &Cache{
|
2020-02-14 21:48:12 +00:00
|
|
|
UseAutoAuthToken: true,
|
|
|
|
UseAutoAuthTokenRaw: "true",
|
|
|
|
ForceAutoAuthToken: false,
|
2020-01-30 15:08:42 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2020-01-30 15:08:42 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 15:51:03 +00:00
|
|
|
func TestLoadConfigFile_Agent_AutoAuth_APIProxyAllConfig(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-api_proxy-auto_auth-all-api_proxy-config.hcl")
|
2022-12-05 15:51:03 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
APIProxy: &APIProxy{
|
|
|
|
UseAutoAuthToken: true,
|
|
|
|
UseAutoAuthTokenRaw: "force",
|
|
|
|
ForceAutoAuthToken: true,
|
|
|
|
EnforceConsistency: "always",
|
|
|
|
WhenInconsistent: "forward",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-30 15:08:42 +00:00
|
|
|
func TestLoadConfigFile_AgentCache_AutoAuth_False(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-cache-auto_auth-false.hcl")
|
2020-01-30 15:08:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2020-05-14 13:19:27 +00:00
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
2020-01-30 15:08:42 +00:00
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
2020-05-14 13:19:27 +00:00
|
|
|
{
|
2020-01-30 15:08:42 +00:00
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Cache: &Cache{
|
2020-02-14 21:48:12 +00:00
|
|
|
UseAutoAuthToken: false,
|
|
|
|
UseAutoAuthTokenRaw: "false",
|
|
|
|
ForceAutoAuthToken: false,
|
2019-04-01 20:26:41 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2019-04-01 20:26:41 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
|
2021-03-03 22:01:33 +00:00
|
|
|
func TestLoadConfigFile_AgentCache_Persist(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-cache-persist-false.hcl")
|
2021-03-03 22:01:33 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Cache: &Cache{
|
2023-05-19 17:17:48 +00:00
|
|
|
Persist: &agentproxyshared.PersistConfig{
|
2021-03-03 22:01:33 +00:00
|
|
|
Type: "kubernetes",
|
|
|
|
Path: "/vault/agent-cache/",
|
|
|
|
KeepAfterImport: false,
|
|
|
|
ExitOnErr: false,
|
|
|
|
ServiceAccountTokenFile: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2021-03-03 22:01:33 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_AgentCache_PersistMissingType(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
_, err := LoadConfigFile("./test-fixtures/config-cache-persist-empty-type.hcl")
|
2021-03-03 22:01:33 +00:00
|
|
|
if err == nil || os.IsNotExist(err) {
|
|
|
|
t.Fatal("expected error or file is missing")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-21 23:10:15 +00:00
|
|
|
func TestLoadConfigFile_TemplateConfig(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
fixturePath string
|
|
|
|
expectedTemplateConfig TemplateConfig
|
|
|
|
}{
|
|
|
|
"set-true": {
|
|
|
|
"./test-fixtures/config-template_config.hcl",
|
|
|
|
TemplateConfig{
|
2021-06-24 19:40:31 +00:00
|
|
|
ExitOnRetryFailure: true,
|
|
|
|
StaticSecretRenderInt: 1 * time.Minute,
|
2021-06-21 23:10:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"empty": {
|
|
|
|
"./test-fixtures/config-template_config-empty.hcl",
|
|
|
|
TemplateConfig{
|
|
|
|
ExitOnRetryFailure: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile(tc.fixturePath)
|
2021-06-21 23:10:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
NumRetries: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TemplateConfig: &tc.expectedTemplateConfig,
|
|
|
|
Templates: []*ctconfig.TemplateConfig{
|
|
|
|
{
|
|
|
|
Source: pointerutil.StringPtr("/path/on/disk/to/template.ctmpl"),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render.txt"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
// TestLoadConfigFile_Template tests template definitions in Vault Agent
|
|
|
|
func TestLoadConfigFile_Template(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
fixturePath string
|
|
|
|
expectedTemplates []*ctconfig.TemplateConfig
|
|
|
|
}{
|
|
|
|
"min": {
|
|
|
|
fixturePath: "./test-fixtures/config-template-min.hcl",
|
|
|
|
expectedTemplates: []*ctconfig.TemplateConfig{
|
2021-04-08 16:43:39 +00:00
|
|
|
{
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
Source: pointerutil.StringPtr("/path/on/disk/to/template.ctmpl"),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render.txt"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"full": {
|
|
|
|
fixturePath: "./test-fixtures/config-template-full.hcl",
|
|
|
|
expectedTemplates: []*ctconfig.TemplateConfig{
|
2021-04-08 16:43:39 +00:00
|
|
|
{
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
Backup: pointerutil.BoolPtr(true),
|
2022-04-19 19:51:11 +00:00
|
|
|
Command: []string{"restart service foo"},
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
CommandTimeout: pointerutil.TimeDurationPtr("60s"),
|
|
|
|
Contents: pointerutil.StringPtr("{{ keyOrDefault \"service/redis/maxconns@east-aws\" \"5\" }}"),
|
|
|
|
CreateDestDirs: pointerutil.BoolPtr(true),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render.txt"),
|
|
|
|
ErrMissingKey: pointerutil.BoolPtr(true),
|
|
|
|
LeftDelim: pointerutil.StringPtr("<<"),
|
2021-04-08 16:43:39 +00:00
|
|
|
Perms: pointerutil.FileModePtr(0o655),
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
RightDelim: pointerutil.StringPtr(">>"),
|
|
|
|
SandboxPath: pointerutil.StringPtr("/path/on/disk/where"),
|
2022-07-06 20:21:35 +00:00
|
|
|
Exec: &ctconfig.ExecConfig{
|
|
|
|
Command: []string{"foo"},
|
|
|
|
Timeout: pointerutil.TimeDurationPtr("10s"),
|
|
|
|
},
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
|
|
|
|
Wait: &ctconfig.WaitConfig{
|
|
|
|
Min: pointerutil.TimeDurationPtr("10s"),
|
|
|
|
Max: pointerutil.TimeDurationPtr("40s"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"many": {
|
|
|
|
fixturePath: "./test-fixtures/config-template-many.hcl",
|
|
|
|
expectedTemplates: []*ctconfig.TemplateConfig{
|
2021-04-08 16:43:39 +00:00
|
|
|
{
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
Source: pointerutil.StringPtr("/path/on/disk/to/template.ctmpl"),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render.txt"),
|
|
|
|
ErrMissingKey: pointerutil.BoolPtr(false),
|
|
|
|
CreateDestDirs: pointerutil.BoolPtr(true),
|
2022-04-19 19:51:11 +00:00
|
|
|
Command: []string{"restart service foo"},
|
2021-04-08 16:43:39 +00:00
|
|
|
Perms: pointerutil.FileModePtr(0o600),
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
{
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
Source: pointerutil.StringPtr("/path/on/disk/to/template2.ctmpl"),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render2.txt"),
|
|
|
|
Backup: pointerutil.BoolPtr(true),
|
2021-04-08 16:43:39 +00:00
|
|
|
Perms: pointerutil.FileModePtr(0o755),
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
Wait: &ctconfig.WaitConfig{
|
|
|
|
Min: pointerutil.TimeDurationPtr("2s"),
|
|
|
|
Max: pointerutil.TimeDurationPtr("10s"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile(tc.fixturePath)
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2020-05-14 13:19:27 +00:00
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
2020-05-14 13:19:27 +00:00
|
|
|
{
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Templates: tc.expectedTemplates,
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
Vault Agent Template (#7652)
* Vault Agent Template: parse templates (#7540)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* Update command/agent/config/config.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* return the decode error instead of swallowing it
* Update command/agent/config/config_test.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* go mod tidy
* change error checking style
* Add agent template doc
* TemplateServer: render secrets with Consul Template (#7621)
* add template config parsing, but it's wrong b/c it's not using mapstructure
* parsing consul templates in agent config
* add additional test to configuration parsing, to cover basics
* another test fixture, rework simple test into table
* refactor into table test
* rename test
* remove flattenKeys and add other test fixture
* add template package
* WIP: add runner
* fix panic, actually copy templates, etc
* rework how the config.Vault is created and enable reading from the environment
* this was supposed to be a part of the prior commit
* move/add methods to testhelpers for converting some values to pointers
* use new methods in testhelpers
* add an unblock channel to block agent until a template has been rendered
* add note
* unblock if there are no templates
* cleanups
* go mod tidy
* remove dead code
* simple test to starT
* add simple, empty templates test
* Update package doc, error logs, and add missing close() on channel
* update code comment to be clear what I'm referring to
* have template.NewServer return a (<- chan) type, even though it's a normal chan, as a better practice to enforce reading only
* Update command/agent.go
Co-Authored-By: Jim Kalafut <jkalafut@hashicorp.com>
* update with test
* Add README and doc.go to the command/agent directory (#7503)
* Add README and doc.go to the command/agent directory
* Add link to website
* address feedback for agent.go
* updated with feedback from Calvin
* Rework template.Server to export the unblock channel, and remove it from the NewServer function
* apply feedback from Nick
* fix/restructure rendering test
* Add pointerutil package for converting types to their pointers
* Remove pointer helper methods; use sdk/helper/pointerutil instead
* update newRunnerConfig to use pointerutil and empty strings
* only wait for unblock if template server is initialized
* drain the token channel in this test
* conditionally send on channel
2019-10-18 21:21:46 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-05-26 17:52:14 +00:00
|
|
|
|
|
|
|
// TestLoadConfigFile_Template_NoSinks tests template definitions without sinks in Vault Agent
|
|
|
|
func TestLoadConfigFile_Template_NoSinks(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
fixturePath string
|
|
|
|
expectedTemplates []*ctconfig.TemplateConfig
|
|
|
|
}{
|
|
|
|
"min": {
|
|
|
|
fixturePath: "./test-fixtures/config-template-min-nosink.hcl",
|
|
|
|
expectedTemplates: []*ctconfig.TemplateConfig{
|
2021-04-08 16:43:39 +00:00
|
|
|
{
|
2020-05-26 17:52:14 +00:00
|
|
|
Source: pointerutil.StringPtr("/path/on/disk/to/template.ctmpl"),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render.txt"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"full": {
|
|
|
|
fixturePath: "./test-fixtures/config-template-full-nosink.hcl",
|
|
|
|
expectedTemplates: []*ctconfig.TemplateConfig{
|
2021-04-08 16:43:39 +00:00
|
|
|
{
|
2020-05-26 17:52:14 +00:00
|
|
|
Backup: pointerutil.BoolPtr(true),
|
2022-04-19 19:51:11 +00:00
|
|
|
Command: []string{"restart service foo"},
|
2020-05-26 17:52:14 +00:00
|
|
|
CommandTimeout: pointerutil.TimeDurationPtr("60s"),
|
|
|
|
Contents: pointerutil.StringPtr("{{ keyOrDefault \"service/redis/maxconns@east-aws\" \"5\" }}"),
|
|
|
|
CreateDestDirs: pointerutil.BoolPtr(true),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render.txt"),
|
|
|
|
ErrMissingKey: pointerutil.BoolPtr(true),
|
|
|
|
LeftDelim: pointerutil.StringPtr("<<"),
|
2021-04-08 16:43:39 +00:00
|
|
|
Perms: pointerutil.FileModePtr(0o655),
|
2020-05-26 17:52:14 +00:00
|
|
|
RightDelim: pointerutil.StringPtr(">>"),
|
|
|
|
SandboxPath: pointerutil.StringPtr("/path/on/disk/where"),
|
|
|
|
|
|
|
|
Wait: &ctconfig.WaitConfig{
|
|
|
|
Min: pointerutil.TimeDurationPtr("10s"),
|
|
|
|
Max: pointerutil.TimeDurationPtr("40s"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"many": {
|
|
|
|
fixturePath: "./test-fixtures/config-template-many-nosink.hcl",
|
|
|
|
expectedTemplates: []*ctconfig.TemplateConfig{
|
2021-04-08 16:43:39 +00:00
|
|
|
{
|
2020-05-26 17:52:14 +00:00
|
|
|
Source: pointerutil.StringPtr("/path/on/disk/to/template.ctmpl"),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render.txt"),
|
|
|
|
ErrMissingKey: pointerutil.BoolPtr(false),
|
|
|
|
CreateDestDirs: pointerutil.BoolPtr(true),
|
2022-04-19 19:51:11 +00:00
|
|
|
Command: []string{"restart service foo"},
|
2021-04-08 16:43:39 +00:00
|
|
|
Perms: pointerutil.FileModePtr(0o600),
|
2020-05-26 17:52:14 +00:00
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
{
|
2020-05-26 17:52:14 +00:00
|
|
|
Source: pointerutil.StringPtr("/path/on/disk/to/template2.ctmpl"),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render2.txt"),
|
|
|
|
Backup: pointerutil.BoolPtr(true),
|
2021-04-08 16:43:39 +00:00
|
|
|
Perms: pointerutil.FileModePtr(0o755),
|
2020-05-26 17:52:14 +00:00
|
|
|
Wait: &ctconfig.WaitConfig{
|
|
|
|
Min: pointerutil.TimeDurationPtr("2s"),
|
|
|
|
Max: pointerutil.TimeDurationPtr("10s"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile(tc.fixturePath)
|
2020-05-26 17:52:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: nil,
|
|
|
|
},
|
|
|
|
Templates: tc.expectedTemplates,
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2020-05-26 17:52:14 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-01-25 19:00:17 +00:00
|
|
|
|
2023-06-01 19:14:17 +00:00
|
|
|
// TestLoadConfigFile_Template_WithCache tests ensures that cache {} stanza is
|
|
|
|
// permitted in vault agent configuration with template(s)
|
|
|
|
func TestLoadConfigFile_Template_WithCache(t *testing.T) {
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-template-with-cache.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Cache: &Cache{},
|
|
|
|
Templates: []*ctconfig.TemplateConfig{
|
|
|
|
{
|
|
|
|
Source: pointerutil.StringPtr("/path/on/disk/to/template.ctmpl"),
|
|
|
|
Destination: pointerutil.StringPtr("/path/on/disk/where/template/will/render.txt"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-25 19:00:17 +00:00
|
|
|
func TestLoadConfigFile_Vault_Retry(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-vault-retry.hcl")
|
2021-01-25 19:00:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
2021-03-18 18:14:09 +00:00
|
|
|
Retry: &Retry{
|
|
|
|
NumRetries: 5,
|
|
|
|
},
|
2021-01-25 19:00:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2021-01-25 19:00:17 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Vault_Retry_Empty(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-vault-retry-empty.hcl")
|
2021-01-25 19:00:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
2021-03-18 18:14:09 +00:00
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
2021-01-25 19:00:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2021-01-25 19:00:17 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 11:58:10 +00:00
|
|
|
|
|
|
|
func TestLoadConfigFile_EnforceConsistency(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-consistency.hcl")
|
2021-02-24 11:58:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PidFile: "",
|
|
|
|
},
|
|
|
|
Cache: &Cache{
|
|
|
|
EnforceConsistency: "always",
|
|
|
|
WhenInconsistent: "retry",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:47:56 +00:00
|
|
|
config.Prune()
|
2021-02-24 11:58:10 +00:00
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
2022-06-16 22:06:22 +00:00
|
|
|
|
2022-12-05 15:51:03 +00:00
|
|
|
func TestLoadConfigFile_EnforceConsistency_APIProxy(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-consistency-apiproxy.hcl")
|
2022-12-05 15:51:03 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
Listeners: []*configutil.Listener{
|
|
|
|
{
|
|
|
|
Type: "tcp",
|
|
|
|
Address: "127.0.0.1:8300",
|
|
|
|
TLSDisable: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PidFile: "",
|
|
|
|
},
|
|
|
|
APIProxy: &APIProxy{
|
|
|
|
EnforceConsistency: "always",
|
|
|
|
WhenInconsistent: "retry",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 22:06:22 +00:00
|
|
|
func TestLoadConfigFile_Disable_Idle_Conns_All(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-idle-connections-all.hcl")
|
2022-06-16 22:06:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableIdleConns: []string{"auto-auth", "caching", "templating", "proxying"},
|
|
|
|
DisableIdleConnsAPIProxy: true,
|
2022-06-16 22:06:22 +00:00
|
|
|
DisableIdleConnsAutoAuth: true,
|
|
|
|
DisableIdleConnsTemplating: true,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Idle_Conns_Auto_Auth(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-idle-connections-auto-auth.hcl")
|
2022-06-16 22:06:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableIdleConns: []string{"auto-auth"},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableIdleConnsAPIProxy: false,
|
2022-06-16 22:06:22 +00:00
|
|
|
DisableIdleConnsAutoAuth: true,
|
|
|
|
DisableIdleConnsTemplating: false,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Idle_Conns_Templating(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-idle-connections-templating.hcl")
|
2022-06-16 22:06:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableIdleConns: []string{"templating"},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableIdleConnsAPIProxy: false,
|
2022-06-16 22:06:22 +00:00
|
|
|
DisableIdleConnsAutoAuth: false,
|
|
|
|
DisableIdleConnsTemplating: true,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Idle_Conns_Caching(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-idle-connections-caching.hcl")
|
2022-06-16 22:06:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableIdleConns: []string{"caching"},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableIdleConnsAPIProxy: true,
|
|
|
|
DisableIdleConnsAutoAuth: false,
|
|
|
|
DisableIdleConnsTemplating: false,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Idle_Conns_Proxying(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-idle-connections-proxying.hcl")
|
2022-12-05 15:51:03 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableIdleConns: []string{"proxying"},
|
|
|
|
DisableIdleConnsAPIProxy: true,
|
2022-06-16 22:06:22 +00:00
|
|
|
DisableIdleConnsAutoAuth: false,
|
|
|
|
DisableIdleConnsTemplating: false,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Idle_Conns_Empty(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-idle-connections-empty.hcl")
|
2022-06-16 22:06:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableIdleConns: []string{},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableIdleConnsAPIProxy: false,
|
2022-06-16 22:06:22 +00:00
|
|
|
DisableIdleConnsAutoAuth: false,
|
|
|
|
DisableIdleConnsTemplating: false,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Idle_Conns_Env(t *testing.T) {
|
|
|
|
err := os.Setenv(DisableIdleConnsEnv, "auto-auth,caching,templating")
|
|
|
|
defer os.Unsetenv(DisableIdleConnsEnv)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-idle-connections-empty.hcl")
|
2022-06-16 22:06:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableIdleConns: []string{"auto-auth", "caching", "templating"},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableIdleConnsAPIProxy: true,
|
2022-06-16 22:06:22 +00:00
|
|
|
DisableIdleConnsAutoAuth: true,
|
|
|
|
DisableIdleConnsTemplating: true,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Bad_Value_Disable_Idle_Conns(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
_, err := LoadConfigFile("./test-fixtures/bad-config-disable-idle-connections.hcl")
|
2022-06-16 22:06:22 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error, it didn't")
|
|
|
|
}
|
|
|
|
}
|
2022-07-28 19:59:49 +00:00
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Keep_Alives_All(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-keep-alives-all.hcl")
|
2022-07-28 19:59:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableKeepAlives: []string{"auto-auth", "caching", "templating", "proxying"},
|
|
|
|
DisableKeepAlivesAPIProxy: true,
|
2022-07-28 19:59:49 +00:00
|
|
|
DisableKeepAlivesAutoAuth: true,
|
|
|
|
DisableKeepAlivesTemplating: true,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Keep_Alives_Auto_Auth(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-keep-alives-auto-auth.hcl")
|
2022-07-28 19:59:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableKeepAlives: []string{"auto-auth"},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableKeepAlivesAPIProxy: false,
|
2022-07-28 19:59:49 +00:00
|
|
|
DisableKeepAlivesAutoAuth: true,
|
|
|
|
DisableKeepAlivesTemplating: false,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Keep_Alives_Templating(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-keep-alives-templating.hcl")
|
2022-07-28 19:59:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableKeepAlives: []string{"templating"},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableKeepAlivesAPIProxy: false,
|
2022-07-28 19:59:49 +00:00
|
|
|
DisableKeepAlivesAutoAuth: false,
|
|
|
|
DisableKeepAlivesTemplating: true,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Keep_Alives_Caching(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-keep-alives-caching.hcl")
|
2022-07-28 19:59:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableKeepAlives: []string{"caching"},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableKeepAlivesAPIProxy: true,
|
|
|
|
DisableKeepAlivesAutoAuth: false,
|
|
|
|
DisableKeepAlivesTemplating: false,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Keep_Alives_Proxying(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-keep-alives-proxying.hcl")
|
2022-12-05 15:51:03 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableKeepAlives: []string{"proxying"},
|
|
|
|
DisableKeepAlivesAPIProxy: true,
|
2022-07-28 19:59:49 +00:00
|
|
|
DisableKeepAlivesAutoAuth: false,
|
|
|
|
DisableKeepAlivesTemplating: false,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Keep_Alives_Empty(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-keep-alives-empty.hcl")
|
2022-07-28 19:59:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableKeepAlives: []string{},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableKeepAlivesAPIProxy: false,
|
2022-07-28 19:59:49 +00:00
|
|
|
DisableKeepAlivesAutoAuth: false,
|
|
|
|
DisableKeepAlivesTemplating: false,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Disable_Keep_Alives_Env(t *testing.T) {
|
|
|
|
err := os.Setenv(DisableKeepAlivesEnv, "auto-auth,caching,templating")
|
|
|
|
defer os.Unsetenv(DisableKeepAlivesEnv)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-01-03 17:50:19 +00:00
|
|
|
config, err := LoadConfigFile("./test-fixtures/config-disable-keep-alives-empty.hcl")
|
2022-07-28 19:59:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
SharedConfig: &configutil.SharedConfig{
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
},
|
|
|
|
DisableKeepAlives: []string{"auto-auth", "caching", "templating"},
|
2022-12-05 15:51:03 +00:00
|
|
|
DisableKeepAlivesAPIProxy: true,
|
2022-07-28 19:59:49 +00:00
|
|
|
DisableKeepAlivesAutoAuth: true,
|
|
|
|
DisableKeepAlivesTemplating: true,
|
|
|
|
AutoAuth: &AutoAuth{
|
|
|
|
Method: &Method{
|
|
|
|
Type: "aws",
|
|
|
|
MountPath: "auth/aws",
|
|
|
|
Namespace: "my-namespace/",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"role": "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sinks: []*Sink{
|
|
|
|
{
|
|
|
|
Type: "file",
|
|
|
|
DHType: "curve25519",
|
|
|
|
DHPath: "/tmp/file-foo-dhpath",
|
|
|
|
AAD: "foobar",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"path": "/tmp/file-foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Vault: &Vault{
|
|
|
|
Address: "http://127.0.0.1:1111",
|
|
|
|
Retry: &Retry{
|
|
|
|
ctconfig.DefaultRetryAttempts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Prune()
|
|
|
|
if diff := deep.Equal(config, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_Bad_Value_Disable_Keep_Alives(t *testing.T) {
|
2023-01-03 17:50:19 +00:00
|
|
|
_, err := LoadConfigFile("./test-fixtures/bad-config-disable-keep-alives.hcl")
|
2022-07-28 19:59:49 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error, it didn't")
|
|
|
|
}
|
|
|
|
}
|
2023-05-19 22:11:41 +00:00
|
|
|
|
2023-05-23 18:37:08 +00:00
|
|
|
// TestLoadConfigFile_EnvTemplates_Simple loads and validates an env_template config
|
|
|
|
func TestLoadConfigFile_EnvTemplates_Simple(t *testing.T) {
|
2023-05-19 22:11:41 +00:00
|
|
|
cfg, err := LoadConfigFile("./test-fixtures/config-env-templates-simple.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error loading config file: %s", err)
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:37:08 +00:00
|
|
|
if err := cfg.ValidateConfig(); err != nil {
|
|
|
|
t.Fatalf("validation error: %s", err)
|
|
|
|
}
|
|
|
|
|
2023-05-19 22:11:41 +00:00
|
|
|
expectedKey := "MY_DATABASE_USER"
|
|
|
|
found := false
|
|
|
|
for _, envTemplate := range cfg.EnvTemplates {
|
|
|
|
if *envTemplate.MapToEnvironmentVariable == expectedKey {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
t.Fatalf("expected environment variable name to be populated")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:37:08 +00:00
|
|
|
// TestLoadConfigFile_EnvTemplates_Complex loads and validates an env_template config
|
|
|
|
func TestLoadConfigFile_EnvTemplates_Complex(t *testing.T) {
|
2023-05-19 22:11:41 +00:00
|
|
|
cfg, err := LoadConfigFile("./test-fixtures/config-env-templates-complex.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error loading config file: %s", err)
|
|
|
|
}
|
2023-05-23 18:37:08 +00:00
|
|
|
|
|
|
|
if err := cfg.ValidateConfig(); err != nil {
|
|
|
|
t.Fatalf("validation error: %s", err)
|
|
|
|
}
|
|
|
|
|
2023-05-19 22:11:41 +00:00
|
|
|
expectedKeys := []string{
|
2023-05-23 18:37:08 +00:00
|
|
|
"FOO_PASSWORD",
|
|
|
|
"FOO_USER",
|
2023-05-19 22:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
envExists := func(key string) bool {
|
|
|
|
for _, envTmpl := range cfg.EnvTemplates {
|
|
|
|
if *envTmpl.MapToEnvironmentVariable == key {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, expected := range expectedKeys {
|
|
|
|
if !envExists(expected) {
|
|
|
|
t.Fatalf("expected environment variable %s", expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:37:08 +00:00
|
|
|
// TestLoadConfigFile_EnvTemplates_WithSource loads and validates an
|
|
|
|
// env_template config with "source" instead of "contents"
|
|
|
|
func TestLoadConfigFile_EnvTemplates_WithSource(t *testing.T) {
|
|
|
|
cfg, err := LoadConfigFile("./test-fixtures/config-env-templates-with-source.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error loading config file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := cfg.ValidateConfig(); err != nil {
|
|
|
|
t.Fatalf("validation error: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestLoadConfigFile_EnvTemplates_NoName ensures that env_template with no name triggers an error
|
|
|
|
func TestLoadConfigFile_EnvTemplates_NoName(t *testing.T) {
|
2023-05-19 22:11:41 +00:00
|
|
|
_, err := LoadConfigFile("./test-fixtures/bad-config-env-templates-no-name.hcl")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expected error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:37:08 +00:00
|
|
|
// TestLoadConfigFile_EnvTemplates_ExecInvalidSignal ensures that an invalid signal triggers an error
|
|
|
|
func TestLoadConfigFile_EnvTemplates_ExecInvalidSignal(t *testing.T) {
|
2023-05-19 22:11:41 +00:00
|
|
|
_, err := LoadConfigFile("./test-fixtures/bad-config-env-templates-invalid-signal.hcl")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expected error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:37:08 +00:00
|
|
|
// TestLoadConfigFile_EnvTemplates_ExecSimple validates the exec section with default parameters
|
|
|
|
func TestLoadConfigFile_EnvTemplates_ExecSimple(t *testing.T) {
|
2023-05-19 22:11:41 +00:00
|
|
|
cfg, err := LoadConfigFile("./test-fixtures/config-env-templates-simple.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error loading config file: %s", err)
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:37:08 +00:00
|
|
|
if err := cfg.ValidateConfig(); err != nil {
|
|
|
|
t.Fatalf("validation error: %s", err)
|
2023-05-19 22:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedCmd := []string{"/path/to/my/app", "arg1", "arg2"}
|
|
|
|
if !slices.Equal(cfg.Exec.Command, expectedCmd) {
|
|
|
|
t.Fatal("exec.command does not have expected value")
|
|
|
|
}
|
|
|
|
|
|
|
|
// check defaults
|
|
|
|
if cfg.Exec.RestartOnSecretChanges != "always" {
|
|
|
|
t.Fatalf("expected cfg.Exec.RestartOnSecretChanges to be 'always', got '%s'", cfg.Exec.RestartOnSecretChanges)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.Exec.RestartStopSignal != syscall.SIGTERM {
|
|
|
|
t.Fatalf("expected cfg.Exec.RestartStopSignal to be 'syscall.SIGTERM', got '%s'", cfg.Exec.RestartStopSignal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:37:08 +00:00
|
|
|
// TestLoadConfigFile_EnvTemplates_ExecComplex validates the exec section with non-default parameters
|
|
|
|
func TestLoadConfigFile_EnvTemplates_ExecComplex(t *testing.T) {
|
2023-05-19 22:11:41 +00:00
|
|
|
cfg, err := LoadConfigFile("./test-fixtures/config-env-templates-complex.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error loading config file: %s", err)
|
|
|
|
}
|
|
|
|
|
2023-05-23 18:37:08 +00:00
|
|
|
if err := cfg.ValidateConfig(); err != nil {
|
|
|
|
t.Fatalf("validation error: %s", err)
|
|
|
|
}
|
|
|
|
|
2023-05-19 22:11:41 +00:00
|
|
|
if !slices.Equal(cfg.Exec.Command, []string{"env"}) {
|
|
|
|
t.Fatal("exec.command does not have expected value")
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.Exec.RestartOnSecretChanges != "never" {
|
|
|
|
t.Fatalf("expected cfg.Exec.RestartOnSecretChanges to be 'never', got %q", cfg.Exec.RestartOnSecretChanges)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.Exec.RestartStopSignal != syscall.SIGINT {
|
|
|
|
t.Fatalf("expected cfg.Exec.RestartStopSignal to be 'syscall.SIGINT', got %q", cfg.Exec.RestartStopSignal)
|
|
|
|
}
|
|
|
|
}
|
2023-05-23 18:37:08 +00:00
|
|
|
|
|
|
|
// TestLoadConfigFile_Bad_EnvTemplates_MissingExec ensures that ValidateConfig
|
|
|
|
// errors when "env_template" stanza(s) are specified but "exec" is missing
|
|
|
|
func TestLoadConfigFile_Bad_EnvTemplates_MissingExec(t *testing.T) {
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/bad-config-env-templates-missing-exec.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error loading config file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := config.ValidateConfig(); err == nil {
|
|
|
|
t.Fatal("expected an error from ValidateConfig: exec section is missing")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestLoadConfigFile_Bad_EnvTemplates_WithProxy ensures that ValidateConfig
|
|
|
|
// errors when both env_template and api_proxy stanzas are present
|
|
|
|
func TestLoadConfigFile_Bad_EnvTemplates_WithProxy(t *testing.T) {
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/bad-config-env-templates-with-proxy.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error loading config file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := config.ValidateConfig(); err == nil {
|
|
|
|
t.Fatal("expected an error from ValidateConfig: listener / api_proxy are not compatible with env_template")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestLoadConfigFile_Bad_EnvTemplates_WithFileTemplates ensures that
|
|
|
|
// ValidateConfig errors when both env_template and template stanzas are present
|
|
|
|
func TestLoadConfigFile_Bad_EnvTemplates_WithFileTemplates(t *testing.T) {
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/bad-config-env-templates-with-file-templates.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error loading config file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := config.ValidateConfig(); err == nil {
|
|
|
|
t.Fatal("expected an error from ValidateConfig: file template stanza is not compatible with env_template")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestLoadConfigFile_Bad_EnvTemplates_DisalowedFields ensure that
|
|
|
|
// ValidateConfig errors for disalowed env_template fields
|
|
|
|
func TestLoadConfigFile_Bad_EnvTemplates_DisalowedFields(t *testing.T) {
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/bad-config-env-templates-disalowed-fields.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error loading config file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := config.ValidateConfig(); err == nil {
|
|
|
|
t.Fatal("expected an error from ValidateConfig: disallowed fields specified in env_template")
|
|
|
|
}
|
|
|
|
}
|