mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 19:47:54 +00:00
Rename config lease_duration parameters to lease_ttl in line with current standardization efforts
This commit is contained in:
@@ -125,15 +125,15 @@ func (c *ServerCommand) Run(args []string) int {
|
|||||||
|
|
||||||
// Initialize the core
|
// Initialize the core
|
||||||
core, err := vault.NewCore(&vault.CoreConfig{
|
core, err := vault.NewCore(&vault.CoreConfig{
|
||||||
AdvertiseAddr: config.Backend.AdvertiseAddr,
|
AdvertiseAddr: config.Backend.AdvertiseAddr,
|
||||||
Physical: backend,
|
Physical: backend,
|
||||||
AuditBackends: c.AuditBackends,
|
AuditBackends: c.AuditBackends,
|
||||||
CredentialBackends: c.CredentialBackends,
|
CredentialBackends: c.CredentialBackends,
|
||||||
LogicalBackends: c.LogicalBackends,
|
LogicalBackends: c.LogicalBackends,
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
DisableMlock: config.DisableMlock,
|
DisableMlock: config.DisableMlock,
|
||||||
MaxLeaseDuration: config.MaxLeaseDuration,
|
MaxLeaseTTL: config.MaxLeaseTTL,
|
||||||
DefaultLeaseDuration: config.DefaultLeaseDuration,
|
DefaultLeaseTTL: config.DefaultLeaseTTL,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf("Error initializing core: %s", err))
|
c.Ui.Error(fmt.Sprintf("Error initializing core: %s", err))
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ type Config struct {
|
|||||||
|
|
||||||
Telemetry *Telemetry `hcl:"telemetry"`
|
Telemetry *Telemetry `hcl:"telemetry"`
|
||||||
|
|
||||||
MaxLeaseDuration time.Duration `hcl:"-"`
|
MaxLeaseTTL time.Duration `hcl:"-"`
|
||||||
MaxLeaseDurationRaw string `hcl:"max_lease_duration"`
|
MaxLeaseTTLRaw string `hcl:"max_lease_ttl"`
|
||||||
DefaultLeaseDuration time.Duration `hcl:"-"`
|
DefaultLeaseTTL time.Duration `hcl:"-"`
|
||||||
DefaultLeaseDurationRaw string `hcl:"default_lease_duration"`
|
DefaultLeaseTTLRaw string `hcl:"default_lease_ttl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DevConfig is a Config that is used for dev mode of Vault.
|
// DevConfig is a Config that is used for dev mode of Vault.
|
||||||
@@ -48,8 +48,8 @@ func DevConfig() *Config {
|
|||||||
|
|
||||||
Telemetry: &Telemetry{},
|
Telemetry: &Telemetry{},
|
||||||
|
|
||||||
MaxLeaseDuration: 30 * 24 * time.Hour,
|
MaxLeaseTTL: 30 * 24 * time.Hour,
|
||||||
DefaultLeaseDuration: 30 * 24 * time.Hour,
|
DefaultLeaseTTL: 30 * 24 * time.Hour,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,14 +113,14 @@ func (c *Config) Merge(c2 *Config) *Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// merge these integers via a MAX operation
|
// merge these integers via a MAX operation
|
||||||
result.MaxLeaseDuration = c.MaxLeaseDuration
|
result.MaxLeaseTTL = c.MaxLeaseTTL
|
||||||
if c2.MaxLeaseDuration > result.MaxLeaseDuration {
|
if c2.MaxLeaseTTL > result.MaxLeaseTTL {
|
||||||
result.MaxLeaseDuration = c2.MaxLeaseDuration
|
result.MaxLeaseTTL = c2.MaxLeaseTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
result.DefaultLeaseDuration = c.DefaultLeaseDuration
|
result.DefaultLeaseTTL = c.DefaultLeaseTTL
|
||||||
if c2.DefaultLeaseDuration > result.DefaultLeaseDuration {
|
if c2.DefaultLeaseTTL > result.DefaultLeaseTTL {
|
||||||
result.DefaultLeaseDuration = c2.DefaultLeaseDuration
|
result.DefaultLeaseTTL = c2.DefaultLeaseTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -161,13 +161,13 @@ func LoadConfigFile(path string) (*Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.MaxLeaseDurationRaw != "" {
|
if result.MaxLeaseTTLRaw != "" {
|
||||||
if result.MaxLeaseDuration, err = time.ParseDuration(result.MaxLeaseDurationRaw); err != nil {
|
if result.MaxLeaseTTL, err = time.ParseDuration(result.MaxLeaseTTLRaw); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if result.DefaultLeaseDurationRaw != "" {
|
if result.DefaultLeaseTTLRaw != "" {
|
||||||
if result.DefaultLeaseDuration, err = time.ParseDuration(result.DefaultLeaseDurationRaw); err != nil {
|
if result.DefaultLeaseTTL, err = time.ParseDuration(result.DefaultLeaseTTLRaw); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,17 +31,17 @@ func TestLoadConfigFile(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Telemetry: &Telemetry{
|
Telemetry: &Telemetry{
|
||||||
StatsdAddr: "bar",
|
StatsdAddr: "bar",
|
||||||
StatsiteAddr: "foo",
|
StatsiteAddr: "foo",
|
||||||
DisableHostname: false,
|
DisableHostname: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
DisableMlock: true,
|
DisableMlock: true,
|
||||||
|
|
||||||
MaxLeaseDuration: 10 * time.Hour,
|
MaxLeaseTTL: 10 * time.Hour,
|
||||||
MaxLeaseDurationRaw: "10h",
|
MaxLeaseTTLRaw: "10h",
|
||||||
DefaultLeaseDuration: 10 * time.Hour,
|
DefaultLeaseTTL: 10 * time.Hour,
|
||||||
DefaultLeaseDurationRaw: "10h",
|
DefaultLeaseTTLRaw: "10h",
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(config, expected) {
|
if !reflect.DeepEqual(config, expected) {
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
@@ -72,15 +72,15 @@ func TestLoadConfigFile_json(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Telemetry: &Telemetry{
|
Telemetry: &Telemetry{
|
||||||
StatsiteAddr: "baz",
|
StatsiteAddr: "baz",
|
||||||
StatsdAddr: "",
|
StatsdAddr: "",
|
||||||
DisableHostname: false,
|
DisableHostname: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
MaxLeaseDuration: 10 * time.Hour,
|
MaxLeaseTTL: 10 * time.Hour,
|
||||||
MaxLeaseDurationRaw: "10h",
|
MaxLeaseTTLRaw: "10h",
|
||||||
DefaultLeaseDuration: 10 * time.Hour,
|
DefaultLeaseTTL: 10 * time.Hour,
|
||||||
DefaultLeaseDurationRaw: "10h",
|
DefaultLeaseTTLRaw: "10h",
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(config, expected) {
|
if !reflect.DeepEqual(config, expected) {
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
@@ -111,8 +111,8 @@ func TestLoadConfigFile_json2(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Telemetry: &Telemetry{
|
Telemetry: &Telemetry{
|
||||||
StatsiteAddr: "foo",
|
StatsiteAddr: "foo",
|
||||||
StatsdAddr: "bar",
|
StatsdAddr: "bar",
|
||||||
DisableHostname: true,
|
DisableHostname: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -147,13 +147,13 @@ func TestLoadConfigDir(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Telemetry: &Telemetry{
|
Telemetry: &Telemetry{
|
||||||
StatsiteAddr: "qux",
|
StatsiteAddr: "qux",
|
||||||
StatsdAddr: "baz",
|
StatsdAddr: "baz",
|
||||||
DisableHostname: true,
|
DisableHostname: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
MaxLeaseDuration: 10 * time.Hour,
|
MaxLeaseTTL: 10 * time.Hour,
|
||||||
DefaultLeaseDuration: 10 * time.Hour,
|
DefaultLeaseTTL: 10 * time.Hour,
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(config, expected) {
|
if !reflect.DeepEqual(config, expected) {
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
|
|||||||
@@ -5,5 +5,5 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"max_lease_duration": "10h"
|
"max_lease_ttl": "10h"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ telemetry {
|
|||||||
disable_hostname = true
|
disable_hostname = true
|
||||||
}
|
}
|
||||||
|
|
||||||
default_lease_duration = "10h"
|
default_lease_ttl = "10h"
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ backend "consul" {
|
|||||||
advertise_addr = "foo"
|
advertise_addr = "foo"
|
||||||
}
|
}
|
||||||
|
|
||||||
max_lease_duration = "10h"
|
max_lease_ttl = "10h"
|
||||||
default_lease_duration = "10h"
|
default_lease_ttl = "10h"
|
||||||
|
|||||||
@@ -15,6 +15,6 @@
|
|||||||
"statsite_address": "baz"
|
"statsite_address": "baz"
|
||||||
},
|
},
|
||||||
|
|
||||||
"max_lease_duration": "10h",
|
"max_lease_ttl": "10h",
|
||||||
"default_lease_duration": "10h"
|
"default_lease_ttl": "10h"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,25 +239,25 @@ type Core struct {
|
|||||||
// metricsCh is used to stop the metrics streaming
|
// metricsCh is used to stop the metrics streaming
|
||||||
metricsCh chan struct{}
|
metricsCh chan struct{}
|
||||||
|
|
||||||
defaultLeaseDuration time.Duration
|
defaultLeaseTTL time.Duration
|
||||||
maxLeaseDuration time.Duration
|
maxLeaseTTL time.Duration
|
||||||
|
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// CoreConfig is used to parameterize a core
|
// CoreConfig is used to parameterize a core
|
||||||
type CoreConfig struct {
|
type CoreConfig struct {
|
||||||
LogicalBackends map[string]logical.Factory
|
LogicalBackends map[string]logical.Factory
|
||||||
CredentialBackends map[string]logical.Factory
|
CredentialBackends map[string]logical.Factory
|
||||||
AuditBackends map[string]audit.Factory
|
AuditBackends map[string]audit.Factory
|
||||||
Physical physical.Backend
|
Physical physical.Backend
|
||||||
Logger *log.Logger
|
Logger *log.Logger
|
||||||
DisableCache bool // Disables the LRU cache on the physical backend
|
DisableCache bool // Disables the LRU cache on the physical backend
|
||||||
DisableMlock bool // Disables mlock syscall
|
DisableMlock bool // Disables mlock syscall
|
||||||
CacheSize int // Custom cache size of zero for default
|
CacheSize int // Custom cache size of zero for default
|
||||||
AdvertiseAddr string // Set as the leader address for HA
|
AdvertiseAddr string // Set as the leader address for HA
|
||||||
DefaultLeaseDuration time.Duration
|
DefaultLeaseTTL time.Duration
|
||||||
MaxLeaseDuration time.Duration
|
MaxLeaseTTL time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCore is used to construct a new core
|
// NewCore is used to construct a new core
|
||||||
@@ -271,15 +271,15 @@ func NewCore(conf *CoreConfig) (*Core, error) {
|
|||||||
return nil, fmt.Errorf("missing advertisement address")
|
return nil, fmt.Errorf("missing advertisement address")
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.DefaultLeaseDuration == 0 {
|
if conf.DefaultLeaseTTL == 0 {
|
||||||
conf.DefaultLeaseDuration = defaultLeaseDuration
|
conf.DefaultLeaseTTL = defaultLeaseTTL
|
||||||
}
|
}
|
||||||
if conf.MaxLeaseDuration == 0 {
|
if conf.MaxLeaseTTL == 0 {
|
||||||
conf.MaxLeaseDuration = maxLeaseDuration
|
conf.MaxLeaseTTL = maxLeaseTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.DefaultLeaseDuration > conf.MaxLeaseDuration {
|
if conf.DefaultLeaseTTL > conf.MaxLeaseTTL {
|
||||||
return nil, fmt.Errorf("cannot have DefaultLeaseDuration larger than MaxLeaseDuration")
|
return nil, fmt.Errorf("cannot have DefaultLeaseTTL larger than MaxLeaseTTL")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the advertise addr if its given to us
|
// Validate the advertise addr if its given to us
|
||||||
@@ -333,16 +333,16 @@ func NewCore(conf *CoreConfig) (*Core, error) {
|
|||||||
|
|
||||||
// Setup the core
|
// Setup the core
|
||||||
c := &Core{
|
c := &Core{
|
||||||
ha: haBackend,
|
ha: haBackend,
|
||||||
advertiseAddr: conf.AdvertiseAddr,
|
advertiseAddr: conf.AdvertiseAddr,
|
||||||
physical: conf.Physical,
|
physical: conf.Physical,
|
||||||
barrier: barrier,
|
barrier: barrier,
|
||||||
router: NewRouter(),
|
router: NewRouter(),
|
||||||
sealed: true,
|
sealed: true,
|
||||||
standby: true,
|
standby: true,
|
||||||
logger: conf.Logger,
|
logger: conf.Logger,
|
||||||
defaultLeaseDuration: conf.DefaultLeaseDuration,
|
defaultLeaseTTL: conf.DefaultLeaseTTL,
|
||||||
maxLeaseDuration: conf.MaxLeaseDuration,
|
maxLeaseTTL: conf.MaxLeaseTTL,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the backends
|
// Setup the backends
|
||||||
@@ -479,12 +479,12 @@ func (c *Core) handleRequest(req *logical.Request) (retResp *logical.Response, r
|
|||||||
if resp != nil && resp.Secret != nil && !strings.HasPrefix(req.Path, "sys/renew/") {
|
if resp != nil && resp.Secret != nil && !strings.HasPrefix(req.Path, "sys/renew/") {
|
||||||
// Apply the default lease if none given
|
// Apply the default lease if none given
|
||||||
if resp.Secret.TTL == 0 {
|
if resp.Secret.TTL == 0 {
|
||||||
resp.Secret.TTL = c.defaultLeaseDuration
|
resp.Secret.TTL = c.defaultLeaseTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit the lease duration
|
// Limit the lease duration
|
||||||
if resp.Secret.TTL > c.maxLeaseDuration {
|
if resp.Secret.TTL > c.maxLeaseTTL {
|
||||||
resp.Secret.TTL = c.maxLeaseDuration
|
resp.Secret.TTL = c.maxLeaseTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the lease
|
// Register the lease
|
||||||
@@ -511,12 +511,12 @@ func (c *Core) handleRequest(req *logical.Request) (retResp *logical.Response, r
|
|||||||
|
|
||||||
// Set the default lease if non-provided, root tokens are exempt
|
// Set the default lease if non-provided, root tokens are exempt
|
||||||
if resp.Auth.TTL == 0 && !strListContains(resp.Auth.Policies, "root") {
|
if resp.Auth.TTL == 0 && !strListContains(resp.Auth.Policies, "root") {
|
||||||
resp.Auth.TTL = c.defaultLeaseDuration
|
resp.Auth.TTL = c.defaultLeaseTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit the lease duration
|
// Limit the lease duration
|
||||||
if resp.Auth.TTL > c.maxLeaseDuration {
|
if resp.Auth.TTL > c.maxLeaseTTL {
|
||||||
resp.Auth.TTL = c.maxLeaseDuration
|
resp.Auth.TTL = c.maxLeaseTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register with the expiration manager
|
// Register with the expiration manager
|
||||||
@@ -583,12 +583,12 @@ func (c *Core) handleLoginRequest(req *logical.Request) (*logical.Response, *log
|
|||||||
|
|
||||||
// Set the default lease if non-provided, root tokens are exempt
|
// Set the default lease if non-provided, root tokens are exempt
|
||||||
if auth.TTL == 0 && !strListContains(auth.Policies, "root") {
|
if auth.TTL == 0 && !strListContains(auth.Policies, "root") {
|
||||||
auth.TTL = c.defaultLeaseDuration
|
auth.TTL = c.defaultLeaseTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit the lease duration
|
// Limit the lease duration
|
||||||
if resp.Auth.TTL > c.maxLeaseDuration {
|
if resp.Auth.TTL > c.maxLeaseTTL {
|
||||||
resp.Auth.TTL = c.maxLeaseDuration
|
resp.Auth.TTL = c.maxLeaseTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register with the expiration manager
|
// Register with the expiration manager
|
||||||
|
|||||||
@@ -442,7 +442,7 @@ func TestCore_HandleRequest_Lease_MaxLength(t *testing.T) {
|
|||||||
if resp == nil || resp.Secret == nil || resp.Data == nil {
|
if resp == nil || resp.Secret == nil || resp.Data == nil {
|
||||||
t.Fatalf("bad: %#v", resp)
|
t.Fatalf("bad: %#v", resp)
|
||||||
}
|
}
|
||||||
if resp.Secret.TTL != c.maxLeaseDuration {
|
if resp.Secret.TTL != c.maxLeaseTTL {
|
||||||
t.Fatalf("bad: %#v", resp.Secret)
|
t.Fatalf("bad: %#v", resp.Secret)
|
||||||
}
|
}
|
||||||
if resp.Secret.LeaseID == "" {
|
if resp.Secret.LeaseID == "" {
|
||||||
@@ -483,7 +483,7 @@ func TestCore_HandleRequest_Lease_DefaultLength(t *testing.T) {
|
|||||||
if resp == nil || resp.Secret == nil || resp.Data == nil {
|
if resp == nil || resp.Secret == nil || resp.Data == nil {
|
||||||
t.Fatalf("bad: %#v", resp)
|
t.Fatalf("bad: %#v", resp)
|
||||||
}
|
}
|
||||||
if resp.Secret.TTL != c.defaultLeaseDuration {
|
if resp.Secret.TTL != c.defaultLeaseTTL {
|
||||||
t.Fatalf("bad: %#v", resp.Secret)
|
t.Fatalf("bad: %#v", resp.Secret)
|
||||||
}
|
}
|
||||||
if resp.Secret.LeaseID == "" {
|
if resp.Secret.LeaseID == "" {
|
||||||
@@ -829,7 +829,7 @@ func TestCore_HandleLogin_Token(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that we have a lease with default duration
|
// Check that we have a lease with default duration
|
||||||
if lresp.Auth.TTL != c.defaultLeaseDuration {
|
if lresp.Auth.TTL != c.defaultLeaseTTL {
|
||||||
t.Fatalf("bad: %#v", lresp.Auth)
|
t.Fatalf("bad: %#v", lresp.Auth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1016,7 +1016,7 @@ func TestCore_HandleRequest_CreateToken_Lease(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that we have a lease with default duration
|
// Check that we have a lease with default duration
|
||||||
if resp.Auth.TTL != c.defaultLeaseDuration {
|
if resp.Auth.TTL != c.defaultLeaseTTL {
|
||||||
t.Fatalf("bad: %#v", resp.Auth)
|
t.Fatalf("bad: %#v", resp.Auth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ const (
|
|||||||
minRevokeDelay = 5 * time.Second
|
minRevokeDelay = 5 * time.Second
|
||||||
|
|
||||||
// maxLeaseDuration is the default maximum lease duration
|
// maxLeaseDuration is the default maximum lease duration
|
||||||
maxLeaseDuration = 30 * 24 * time.Hour
|
maxLeaseTTL = 30 * 24 * time.Hour
|
||||||
|
|
||||||
// defaultLeaseDuration is the default lease duration used when no lease is specified
|
// defaultLeaseDuration is the default lease duration used when no lease is specified
|
||||||
defaultLeaseDuration = maxLeaseDuration
|
defaultLeaseTTL = maxLeaseTTL
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExpirationManager is used by the Core to manage leases. Secrets
|
// ExpirationManager is used by the Core to manage leases. Secrets
|
||||||
|
|||||||
Reference in New Issue
Block a user