core: add postSealMigration method (#7579)

* core: add postSealMigration method

The postSealMigration method is called at the end of the postUnseal
method if a seal migration has occurred. This starts a seal rewrap
process in the enterprise version of. It is a no-op in the OSS version.
This commit is contained in:
Michael Gaffney 2019-10-16 12:52:37 -04:00 committed by GitHub
parent c5b4fbd56f
commit 24f663403e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -203,6 +203,7 @@ type Core struct {
// migrationSeal is the seal to use during a migration operation. It is the
// seal we're migrating *from*.
migrationSeal Seal
sealMigrated *uint32
// unwrapSeal is the seal to use on Enterprise to unwrap values wrapped
// with the previous seal.
@ -645,6 +646,7 @@ func NewCore(conf *CoreConfig) (*Core, error) {
seal: conf.Seal,
router: NewRouter(),
sealed: new(uint32),
sealMigrated: new(uint32),
standby: true,
baseLogger: conf.Logger,
logger: conf.Logger.Named("core"),
@ -1175,6 +1177,7 @@ func (c *Core) unsealPart(ctx context.Context, seal Seal, key []byte, useRecover
// At this point we've swapped things around and need to ensure we
// don't migrate again
c.migrationSeal = nil
atomic.StoreUint32(c.sealMigrated, 1)
// Ensure we populate the new values
bc, err := c.seal.BarrierConfig(ctx)
@ -1738,6 +1741,11 @@ func (c *Core) postUnseal(ctx context.Context, ctxCancelFunc context.CancelFunc,
v()
}
if atomic.LoadUint32(c.sealMigrated) == 1 {
defer func() { atomic.StoreUint32(c.sealMigrated, 0) }()
c.postSealMigration(ctx)
}
c.logger.Info("post-unseal setup complete")
return nil
}

View File

@ -124,3 +124,5 @@ func (c *Core) perfStandbyClusterHandler() (*replication.Cluster, *cache.Cache,
}
func (c *Core) initSealsForMigration() {}
func (c *Core) postSealMigration(ctx context.Context) error { return nil }