From 06ba006f9bb7fe4fe8fb97bbda594f3c438cb6ad Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Nov 2020 12:03:58 -0800 Subject: acme_server: switch to bbolt storage (#3868) * acme_server: switch to bbolt storage There have been some issues with the badger storage engine being used by the embedded acme_server. This will replace the storage engine with bbolt * Switch database path back to acme_server/db and remove if directory --- modules/caddypki/acmeserver/acmeserver.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'modules/caddypki') diff --git a/modules/caddypki/acmeserver/acmeserver.go b/modules/caddypki/acmeserver/acmeserver.go index 9d8a6fc..5c9f74b 100644 --- a/modules/caddypki/acmeserver/acmeserver.go +++ b/modules/caddypki/acmeserver/acmeserver.go @@ -32,6 +32,7 @@ import ( "github.com/smallstep/certificates/authority/provisioner" "github.com/smallstep/certificates/db" "github.com/smallstep/nosql" + "go.uber.org/zap" ) func init() { @@ -77,6 +78,7 @@ func (Handler) CaddyModule() caddy.ModuleInfo { // Provision sets up the ACME server handler. func (ash *Handler) Provision(ctx caddy.Context) error { + logger := ctx.Logger(ash) // set some defaults if ash.CA == "" { ash.CA = caddypki.DefaultCAID @@ -99,7 +101,8 @@ func (ash *Handler) Provision(ctx caddy.Context) error { return fmt.Errorf("no certificate authority configured with id: %s", ash.CA) } - dbFolder := filepath.Join(caddy.AppDataDir(), "acme_server", "db") + dbFolder := filepath.Join(caddy.AppDataDir(), "acme_server") + dbPath := filepath.Join(dbFolder, "db") // TODO: See https://github.com/smallstep/nosql/issues/7 err = os.MkdirAll(dbFolder, 0755) @@ -107,6 +110,18 @@ func (ash *Handler) Provision(ctx caddy.Context) error { return fmt.Errorf("making folder for ACME server database: %v", err) } + // Check to see if previous db exists + var stat os.FileInfo + stat, err = os.Stat(dbPath) + if stat != nil && err == nil { + // A badger db is found and should be removed + if stat.IsDir() { + logger.Warn("Found an old badger database and removing it", + zap.String("path", dbPath)) + _ = os.RemoveAll(dbPath) + } + } + authorityConfig := caddypki.AuthorityConfig{ AuthConfig: &authority.AuthConfig{ Provisioners: provisioner.List{ @@ -122,8 +137,8 @@ func (ash *Handler) Provision(ctx caddy.Context) error { }, }, DB: &db.Config{ - Type: "badger", - DataSource: dbFolder, + Type: "bbolt", + DataSource: dbPath, }, } -- cgit v1.2.3