Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinschoonover committed Feb 24, 2024
1 parent 5a2d88e commit 9ae7467
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
21 changes: 11 additions & 10 deletions command/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ type Retry struct {

// Vault contains configuration for connecting to Vault servers
type Vault struct {
Address string `hcl:"address"`
CACert string `hcl:"ca_cert"`
CAPath string `hcl:"ca_path"`
TLSSkipVerify bool `hcl:"-"`
TLSSkipVerifyRaw interface{} `hcl:"tls_skip_verify"`
ClientCert string `hcl:"client_cert"`
ClientKey string `hcl:"client_key"`
TLSServerName string `hcl:"tls_server_name"`
Retry *Retry `hcl:"retry"`
LeaseRenewalThreshold *float64 `hcl:"lease_renewal_threshold"`
Address string `hcl:"address"`
CACert string `hcl:"ca_cert"`
CAPath string `hcl:"ca_path"`
TLSSkipVerify bool `hcl:"-"`
TLSSkipVerifyRaw interface{} `hcl:"tls_skip_verify"`
ClientCert string `hcl:"client_cert"`
ClientKey string `hcl:"client_key"`
TLSServerName string `hcl:"tls_server_name"`
Namespace string `hcl:"namespace"`
Retry *Retry `hcl:"retry"`
}

// transportDialer is an interface that allows passing a custom dialer function
Expand Down Expand Up @@ -169,6 +169,7 @@ type TemplateConfig struct {
StaticSecretRenderInt time.Duration `hcl:"-"`
MaxConnectionsPerHostRaw interface{} `hcl:"max_connections_per_host"`
MaxConnectionsPerHost int `hcl:"-"`
LeaseRenewalThreshold *float64 `hcl:"lease_renewal_threshold"`
}

type ExecConfig struct {
Expand Down
5 changes: 5 additions & 0 deletions command/agent/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"golang.org/x/exp/slices"
)

func FloatPtr(t float64) *float64 {
return &t
}

func TestLoadConfigFile_AgentCache(t *testing.T) {
config, err := LoadConfigFile("./test-fixtures/config-cache.hcl")
if err != nil {
Expand Down Expand Up @@ -1046,6 +1050,7 @@ func TestLoadConfigFile_TemplateConfig(t *testing.T) {
ExitOnRetryFailure: true,
StaticSecretRenderInt: 1 * time.Minute,
MaxConnectionsPerHost: 100,
LeaseRenewalThreshold: FloatPtr(0.8),
},
},
"empty": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ template_config {
exit_on_retry_failure = true
static_secret_render_interval = 60
max_connections_per_host = 100
lease_renewal_threshold = 0.8
}

template {
Expand Down
12 changes: 6 additions & 6 deletions command/agent/internal/ctmanager/runner_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ func NewConfig(mc ManagerConfig, templates ctconfig.TemplateConfigs) (*ctconfig.
conf.Vault.Token = pointerutil.StringPtr("")
conf.Vault.Address = &mc.AgentConfig.Vault.Address

if mc.AgentConfig.Vault != nil {
conf.Vault.LeaseRenewalThreshold = mc.AgentConfig.Vault.LeaseRenewalThreshold
}

if mc.Namespace != "" {
conf.Vault.Namespace = &mc.Namespace
}

if mc.AgentConfig.TemplateConfig != nil && mc.AgentConfig.TemplateConfig.StaticSecretRenderInt != 0 {
conf.Vault.DefaultLeaseDuration = &mc.AgentConfig.TemplateConfig.StaticSecretRenderInt
if mc.AgentConfig.TemplateConfig != nil {
conf.Vault.LeaseRenewalThreshold = mc.AgentConfig.TemplateConfig.LeaseRenewalThreshold

if mc.AgentConfig.TemplateConfig.StaticSecretRenderInt != 0 {
conf.Vault.DefaultLeaseDuration = &mc.AgentConfig.TemplateConfig.StaticSecretRenderInt
}
}

if mc.AgentConfig.DisableIdleConnsTemplating {
Expand Down
4 changes: 4 additions & 0 deletions website/content/docs/agent-and-proxy/agent/template.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ failures.
that the Vault Agent templating engine can use for a particular Vault host. This limit
includes connections in the dialing, active, and idle states.

- `lease_renewal_threshold` `(float: 0.9)` - How long Vault Agent's template
engine should wait for to refresh dynamic, non-renewable leases, measured as
a fraction of the lease duration.

### `template_config` stanza example

```hcl
Expand Down

0 comments on commit 9ae7467

Please sign in to comment.