Skip to content

Commit

Permalink
set cache default values as documented
Browse files Browse the repository at this point in the history
This commit fixes a bug in the cache configuration logic.
As documented in https://github.com/minio/kes/blob/master/server-config.yaml#L147
KES is supposed to apply a default KES configuration when none
is provided.

With this commit, a KES server (started via the `kes server` command)
applies a default cache config, if none is set. The `kes/kesconf` package
does not implement the default configuration since we don't want to modify
the user input at this level.
  • Loading branch information
aead committed Apr 12, 2024
1 parent 37cc7c0 commit 60d4037
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions cmd/kes/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func startServer(addrFlag, configFlag string) error {
defer conf.Keys.Close()

srv := &kes.Server{}
conf.Cache = configureCache(conf.Cache)
if rawConfig.Log != nil {
srv.ErrLevel.Set(rawConfig.Log.ErrLevel)
srv.AuditLevel.Set(rawConfig.Log.AuditLevel)
Expand Down Expand Up @@ -242,6 +243,7 @@ func startServer(addrFlag, configFlag string) error {
fmt.Fprintf(os.Stderr, "Failed to reload server config: %v\n", err)
continue
}
config.Cache = configureCache(config.Cache)

closer, err := srv.Update(config)
if err != nil {
Expand Down Expand Up @@ -345,8 +347,12 @@ func startDevServer(addr string) error {
conf := &kes.Config{
Admin: apiKey.Identity(),
TLS: tlsConf,
Cache: &kes.CacheConfig{},
Keys: &kes.MemKeyStore{},
Cache: &kes.CacheConfig{
Expiry: 5 * time.Minute,
ExpiryUnused: 30 * time.Second,
ExpiryOffline: 0,
},
Keys: &kes.MemKeyStore{},
}
srv := &kes.Server{}

Expand Down Expand Up @@ -382,6 +388,21 @@ func startDevServer(addr string) error {
return nil
}

// configureCache sets default values for each cache config option
// as documented in: https://github.com/minio/kes/blob/master/server-config.yaml
func configureCache(c *kes.CacheConfig) *kes.CacheConfig {
if c == nil {
c = &kes.CacheConfig{}
}
if c.Expiry == 0 {
c.Expiry = 5 * time.Minute
}
if c.ExpiryUnused == 0 {
c.Expiry = 30 * time.Second
}
return c
}

// lookupInterfaceIPs returns a list of IP addrs for which a listener
// listening on listenerIP is reachable. If listenerIP is not
// unspecified (0.0.0.0) it returns []net.IP{listenerIP}.
Expand Down

0 comments on commit 60d4037

Please sign in to comment.