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

[WIP] Autoseal: Automatically upgrade stored keys when seal keys are upgraded #5764

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion vault/seal_autoseal.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ func (d *autoSeal) GetStoredKeys(ctx context.Context) ([][]byte, error) {
// Decode the barrier entry
var keys [][]byte
if err := json.Unmarshal(pt, &keys); err != nil {
return nil, fmt.Errorf("failed to decode stored keys: %v, plaintext was %q", err, pe.Value)
return nil, errwrap.Wrapf("failed to decode stored keys: {{err}}", err)
}

// Upgrade the stored keys if the seal key has been rotated
if blobInfo.KeyInfo != nil && blobInfo.KeyInfo.KeyID != d.Access.KeyID() {
d.core.logger.Info("autoseal: upgrading stored keys")
if err := d.SetStoredKeys(ctx, keys); err != nil {
return nil, errwrap.Wrapf("failed to upgrade stored keys: {{err}}", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These upgrades should be happening only on the active node

}

return keys, nil
Expand Down Expand Up @@ -393,6 +401,14 @@ func (d *autoSeal) VerifyRecoveryKey(ctx context.Context, key []byte) error {
return fmt.Errorf("recovery key does not match submitted values")
}

// Upgrade the recovery keys if the seal key has been rotated
if blobInfo.KeyInfo != nil && blobInfo.KeyInfo.KeyID != d.Access.KeyID() {
d.core.logger.Info("autoseal: upgrading recovery keys")
if err := d.SetRecoveryKey(ctx, pt); err != nil {
return errwrap.Wrapf("failed to upgrade recovery keys: {{err}}", err)
}
}

return nil
}

Expand Down