Skip to content

Commit f1d5630

Browse files
committed
add -download enterprise command option to plugin register CLI
1 parent 7f1f50f commit f1d5630

5 files changed

Lines changed: 94 additions & 4 deletions

File tree

command/plugin_register.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type PluginRegisterCommand struct {
3333
flagOCIImage string
3434
flagRuntime string
3535
flagEnv []string
36+
flagDownload bool
3637
}
3738

3839
func (c *PluginRegisterCommand) Synopsis() string {
@@ -59,6 +60,12 @@ Usage: vault plugin register [options] TYPE NAME
5960
-args=--with-glibc,--with-cgo \
6061
auth my-custom-plugin
6162
63+
Register a plugin with -download (enterprise only):
64+
65+
$ vault plugin register \
66+
-version=v0.17.0+ent \
67+
-download=true \
68+
secret vault-plugin-secrets-keymgmt
6269
` + c.Flags().Help()
6370

6471
return strings.TrimSpace(helpText)
@@ -127,6 +134,14 @@ func (c *PluginRegisterCommand) Flags() *FlagSets {
127134
"flag can be specified multiple times to specify multiple environment variables.",
128135
})
129136

137+
f.BoolVar(&BoolVar{
138+
Name: "download",
139+
Target: &c.flagDownload,
140+
Completion: complete.PredictAnything,
141+
Usage: "Enterprise only. If set, Vault will automatically download plugins from" +
142+
"releases.hashicorp.com",
143+
})
144+
130145
return set
131146
}
132147

@@ -198,6 +213,7 @@ func (c *PluginRegisterCommand) Run(args []string) int {
198213
OCIImage: c.flagOCIImage,
199214
Runtime: c.flagRuntime,
200215
Env: c.flagEnv,
216+
Download: c.flagDownload,
201217
})
202218
if err != nil {
203219
c.UI.Error(fmt.Sprintf("Error registering plugin %s: %s", pluginName, err))

vault/extended_system_view.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,3 @@ func (e extendedSystemViewImpl) DeregisterWellKnownRedirect(ctx context.Context,
142142
func (e extendedSystemViewImpl) GetPinnedPluginVersion(ctx context.Context, pluginType consts.PluginType, pluginName string) (*pluginutil.PinnedVersion, error) {
143143
return e.core.pluginCatalog.GetPinnedVersion(ctx, pluginType, pluginName)
144144
}
145-
146-
func (e extendedSystemViewImpl) DownloadExtractVerifyPlugin(_ context.Context, _ *pluginutil.PluginRunner) error {
147-
return fmt.Errorf("cannot call DownloadExtractVerifyPlugin from a plugin backend")
148-
}

vault/logical_system.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ func (b *SystemBackend) handlePluginCatalogUpdate(ctx context.Context, _ *logica
538538
return logical.ErrorResponse("version %q is not allowed because 'builtin' is a reserved metadata identifier", pluginVersion), nil
539539
}
540540

541+
if download := d.Get("download").(bool); download {
542+
return logical.ErrorResponse("download is an enterprise only feature"), nil
543+
}
544+
541545
sha256 := d.Get("sha256").(string)
542546
if sha256 == "" {
543547
sha256 = d.Get("sha_256").(string)
@@ -6923,6 +6927,11 @@ Must already be present on the machine.`,
69236927
`The Vault plugin runtime to use when running the plugin.`,
69246928
"",
69256929
},
6930+
"plugin-catalog_download": {
6931+
`Downloads automatically official HashiCorp plugins
6932+
from releases.hashicorp.com (beta)`,
6933+
"",
6934+
},
69266935
"plugin-catalog-pins": {
69276936
"Configures pinned plugin versions from the plugin catalog",
69286937
`

vault/logical_system_oss_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: BUSL-1.1
3+
4+
//go:build !enterprise
5+
6+
package vault
7+
8+
import (
9+
"fmt"
10+
"os"
11+
"path/filepath"
12+
"testing"
13+
14+
"github.com/hashicorp/vault/helper/namespace"
15+
"github.com/hashicorp/vault/sdk/helper/consts"
16+
"github.com/hashicorp/vault/sdk/logical"
17+
)
18+
19+
// TestSystemBackend_PluginCatalog_Update_Download_Fails tests the update failure
20+
// case when download is true
21+
func TestSystemBackend_PluginCatalog_Update_Download_Should_Fail(t *testing.T) {
22+
sym, err := filepath.EvalSymlinks(os.TempDir())
23+
if err != nil {
24+
t.Fatalf("error: %v", err)
25+
}
26+
c, _, _ := TestCoreUnsealedWithConfig(t, &CoreConfig{
27+
PluginDirectory: sym,
28+
})
29+
b := c.systemBackend
30+
31+
tests := []struct {
32+
pluginType consts.PluginType
33+
pluginVersion string
34+
pluginName string
35+
}{
36+
{
37+
pluginName: "vault-plugin-database-redis",
38+
pluginVersion: "v0.6.0",
39+
pluginType: consts.PluginTypeDatabase,
40+
},
41+
{
42+
pluginName: "vault-plugin-secrets-kv",
43+
pluginVersion: "v0.24.0",
44+
pluginType: consts.PluginTypeSecrets,
45+
},
46+
{
47+
pluginName: "vault-plugin-auth-jwt",
48+
pluginVersion: "v0.24.1",
49+
pluginType: consts.PluginTypeCredential,
50+
},
51+
}
52+
53+
for _, tt := range tests {
54+
t.Run(fmt.Sprintf("%s %s", tt.pluginName, tt.pluginVersion), func(t *testing.T) {
55+
req := logical.TestRequest(t, logical.UpdateOperation,
56+
"plugins/catalog/"+tt.pluginType.String()+"/"+tt.pluginName)
57+
req.Data["version"] = tt.pluginVersion
58+
req.Data["download"] = true
59+
resp, err := b.HandleRequest(namespace.RootContext(nil), req)
60+
if err != nil || resp.Error() == nil {
61+
t.Fatalf("expected error when download is true, got resp: %v, err: %v", resp, err)
62+
}
63+
})
64+
}
65+
}

vault/logical_system_paths.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,10 @@ func (b *SystemBackend) pluginsCatalogCRUDPath() *framework.Path {
18911891
Type: framework.TypeString,
18921892
Description: strings.TrimSpace(sysHelp["plugin-catalog_version"][0]),
18931893
},
1894+
"download": {
1895+
Type: framework.TypeBool,
1896+
Description: strings.TrimSpace(sysHelp["plugin-catalog_download"][0]),
1897+
},
18941898
},
18951899

18961900
Operations: map[logical.Operation]framework.OperationHandler{

0 commit comments

Comments
 (0)