Ensure upgrades have a valid HMAC key
This commit is contained in:
parent
0ff76e16d2
commit
676e7e0f07
|
@ -345,6 +345,10 @@ func (p *policy) needsUpgrade() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
if p.Keys[p.LatestVersion].HMACKey == nil || len(p.Keys[p.LatestVersion].HMACKey) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -380,6 +384,17 @@ func (p *policy) upgrade(storage logical.Storage) error {
|
|||
persistNeeded = true
|
||||
}
|
||||
|
||||
if p.Keys[p.LatestVersion].HMACKey == nil || len(p.Keys[p.LatestVersion].HMACKey) == 0 {
|
||||
entry := p.Keys[p.LatestVersion]
|
||||
hmacKey, err := uuid.GenerateRandomBytes(32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entry.HMACKey = hmacKey
|
||||
p.Keys[p.LatestVersion] = entry
|
||||
persistNeeded = true
|
||||
}
|
||||
|
||||
if persistNeeded {
|
||||
err := p.Persist(storage)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue