Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for 'LeaseRenewalThreshold' in vault agent #25212

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/25212.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
agent: Added a new config option, `lease_renewal_threshold`, that controls the refresh rate of non-renewable leases in Agent's template engine.
```
1 change: 1 addition & 0 deletions command/agent/config/config.go
Original file line number Diff line number Diff line change
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
8 changes: 6 additions & 2 deletions command/agent/internal/ctmanager/runner_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ func NewConfig(mc ManagerConfig, templates ctconfig.TemplateConfigs) (*ctconfig.
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