diff --git a/changelog/16974.txt b/changelog/16974.txt new file mode 100644 index 0000000000..202670ea43 --- /dev/null +++ b/changelog/16974.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: Add a `--dev-no-kv` flag to prevent auto mounting a key-value secret backend when running a dev server +``` diff --git a/command/server.go b/command/server.go index c25f028543..cbb9c3db54 100644 --- a/command/server.go +++ b/command/server.go @@ -135,6 +135,7 @@ type ServerCommand struct { flagDevLatency int flagDevLatencyJitter int flagDevLeasedKV bool + flagDevNoKV bool flagDevKVV1 bool flagDevSkipInit bool flagDevThreeNode bool @@ -345,6 +346,13 @@ func (c *ServerCommand) Flags() *FlagSets { Hidden: true, }) + f.BoolVar(&BoolVar{ + Name: "dev-no-kv", + Target: &c.flagDevNoKV, + Default: false, + Hidden: true, + }) + f.BoolVar(&BoolVar{ Name: "dev-kv-v1", Target: &c.flagDevKVV1, @@ -1031,7 +1039,7 @@ func (c *ServerCommand) Run(args []string) int { } // Automatically enable dev mode if other dev flags are provided. - if c.flagDevConsul || c.flagDevHA || c.flagDevTransactional || c.flagDevLeasedKV || c.flagDevThreeNode || c.flagDevFourCluster || c.flagDevAutoSeal || c.flagDevKVV1 || c.flagDevTLS { + if c.flagDevConsul || c.flagDevHA || c.flagDevTransactional || c.flagDevLeasedKV || c.flagDevThreeNode || c.flagDevFourCluster || c.flagDevAutoSeal || c.flagDevKVV1 || c.flagDevNoKV || c.flagDevTLS { c.flagDev = true } @@ -2105,29 +2113,31 @@ func (c *ServerCommand) enableDev(core *vault.Core, coreConfig *vault.CoreConfig } } - kvVer := "2" - if c.flagDevKVV1 || c.flagDevLeasedKV { - kvVer = "1" - } - req := &logical.Request{ - Operation: logical.UpdateOperation, - ClientToken: init.RootToken, - Path: "sys/mounts/secret", - Data: map[string]interface{}{ - "type": "kv", - "path": "secret/", - "description": "key/value secret storage", - "options": map[string]string{ - "version": kvVer, + if !c.flagDevNoKV { + kvVer := "2" + if c.flagDevKVV1 || c.flagDevLeasedKV { + kvVer = "1" + } + req := &logical.Request{ + Operation: logical.UpdateOperation, + ClientToken: init.RootToken, + Path: "sys/mounts/secret", + Data: map[string]interface{}{ + "type": "kv", + "path": "secret/", + "description": "key/value secret storage", + "options": map[string]string{ + "version": kvVer, + }, }, - }, - } - resp, err := core.HandleRequest(ctx, req) - if err != nil { - return nil, fmt.Errorf("error creating default KV store: %w", err) - } - if resp.IsError() { - return nil, fmt.Errorf("failed to create default KV store: %w", resp.Error()) + } + resp, err := core.HandleRequest(ctx, req) + if err != nil { + return nil, fmt.Errorf("error creating default KV store: %w", err) + } + if resp.IsError() { + return nil, fmt.Errorf("failed to create default KV store: %w", resp.Error()) + } } return init, nil