Skip to content

Commit

Permalink
reload agent configuration before specific server/client
Browse files Browse the repository at this point in the history
lock keyloader before loading/caching a new certificate
  • Loading branch information
chelseakomlo committed Nov 2, 2017
1 parent fd204b4 commit de37397
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,12 @@ func (c *Command) handleReload(config *Config) *Config {
newConf.LogLevel = config.LogLevel
}

// Reloads configuration for an agent running in both client and server mode
err := c.agent.Reload(newConf)
if err != nil {
c.agent.logger.Printf("[ERR] agent: failed to reload the config: %v", err)
}

if s := c.agent.Server(); s != nil {
sconf, err := convertServerConfig(newConf, c.logOutput)
if err != nil {
Expand All @@ -656,11 +662,6 @@ func (c *Command) handleReload(config *Config) *Config {
}
}

err := c.agent.Reload(newConf)
if err != nil {
c.agent.logger.Printf("[ERR] agent: failed to reload the config: %v", err)
}

return newConf
}

Expand Down
5 changes: 5 additions & 0 deletions nomad/structs/config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"crypto/tls"
"fmt"
"sync"
)

// TLSConfig provides TLS related configuration
Expand Down Expand Up @@ -42,6 +43,7 @@ type TLSConfig struct {
}

type KeyLoader struct {
cacheLock sync.Mutex
Certificate *tls.Certificate
}

Expand All @@ -59,6 +61,9 @@ func (k *KeyLoader) LoadKeyPair(certFile, keyFile string) (*tls.Certificate, err
return nil, fmt.Errorf("Failed to load cert/key pair: %v", err)
}

k.cacheLock.Lock()
defer k.cacheLock.Unlock()

k.Certificate = &cert
return k.Certificate, nil
}
Expand Down

0 comments on commit de37397

Please sign in to comment.