Skip to content

Commit

Permalink
Attempt to retry PKI migration if it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Simons authored and tsaarni committed Jan 16, 2025
1 parent 7ae4eca commit de0dba7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 9 additions & 0 deletions builtin/logical/pki/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,15 @@ func (b *backend) invalidate(ctx context.Context, key string) {
}

func (b *backend) periodicFunc(ctx context.Context, request *logical.Request) error {
if b.UseLegacyBundleCaStorage() {
b.Logger().Info("periodicFunc: Performing extra PKI backend migration")
if err := b.initialize(ctx, &logical.InitializationRequest{}); err != nil {
b.Logger().Error("periodicFunc: extra PKI backend migration failed")
return err
}
b.Logger().Info("periodicFunc: extra PKI backend migration succeeded")
}

sc := b.makeStorageContext(ctx, request.Storage)

doCRL := func() error {
Expand Down
7 changes: 6 additions & 1 deletion builtin/logical/pki/path_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ func (b *backend) pathCAGenerateRoot(ctx context.Context, req *logical.Request,
var err error

if b.UseLegacyBundleCaStorage() {
return logical.ErrorResponse("Can not create root CA until migration has completed"), nil
// Try to do migration
b.Logger().Info("pathCAGenerateRoot: Performing extra PKI backend migration")
if err = b.initialize(ctx, &logical.InitializationRequest{}); err != nil {
return logical.ErrorResponse("Could not migrate, can not create root CA until migration has completed"), nil
}
b.Logger().Info("pathCAGenerateRoot: extra PKI backend migration succeeded")
}

sc := b.makeStorageContext(ctx, req.Storage)
Expand Down
6 changes: 5 additions & 1 deletion builtin/plugin/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ func (b *PluginBackend) startBackend(ctx context.Context, storage logical.Storag
b.loaded = true

// call Initialize() explicitly here.
return b.Backend.Initialize(ctx, &logical.InitializationRequest{
err = b.Backend.Initialize(ctx, &logical.InitializationRequest{
Storage: storage,
})
if err != nil {
b.Logger().Error("startBackend: backend initialize() failed, will be retried")
}
return err
}

// lazyLoad lazy-loads the backend before running a method
Expand Down

0 comments on commit de0dba7

Please sign in to comment.