Don't always assume plugins should be activated (#1732)
This commit is contained in:
1 parent
3b83184700
commit
5559cf54d3
6 files changed
+48
-28
No files matched your search
@@ -21,6 +21,25 @@ import (
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
type EnabledPlugin uint
|
||||
|
||||
const (
|
||||
EnabledPluginUnknown EnabledPlugin = iota
|
||||
EnabledPluginHostAws
|
||||
EnabledPluginHostAzure
|
||||
)
|
||||
|
||||
func (e EnabledPlugin) String() string {
|
||||
switch e {
|
||||
case EnabledPluginHostAws:
|
||||
return "AWS"
|
||||
case EnabledPluginHostAzure:
|
||||
return "Azure"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
CommandSuccess int = iota
|
||||
CommandApiError
|
||||
|
||||
@@ -114,7 +114,8 @@ type Server struct {
|
||||
DevTargetSessionConnectionLimit int
|
||||
DevLoopbackHostPluginId string
|
||||
|
||||
HostPlugins map[string]plgpb.HostPluginServiceClient
|
||||
EnabledPlugins []EnabledPlugin
|
||||
HostPlugins map[string]plgpb.HostPluginServiceClient
|
||||
|
||||
DevOidcSetup oidcSetup
|
||||
|
||||
|
||||
@@ -596,6 +596,7 @@ func (c *Command) Run(args []string) int {
|
||||
c.ReleaseLogGate()
|
||||
|
||||
{
|
||||
c.EnabledPlugins = []base.EnabledPlugin{base.EnabledPluginHostAws, base.EnabledPluginHostAzure}
|
||||
conf := &controller.Config{
|
||||
RawConfig: c.Config,
|
||||
Server: c.Server,
|
||||
|
||||
@@ -457,6 +457,7 @@ func (c *Command) Run(args []string) int {
|
||||
c.ReleaseLogGate()
|
||||
|
||||
if c.Config.Controller != nil {
|
||||
c.EnabledPlugins = []base.EnabledPlugin{base.EnabledPluginHostAws, base.EnabledPluginHostAzure}
|
||||
if err := c.StartController(ctx); err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
return base.CommandCliError
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/auth/oidc"
|
||||
"github.com/hashicorp/boundary/internal/auth/password"
|
||||
"github.com/hashicorp/boundary/internal/authtoken"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/hashicorp/boundary/internal/cmd/config"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
@@ -75,6 +77,8 @@ type Controller struct {
|
||||
scheduler *scheduler.Scheduler
|
||||
|
||||
kms *kms.Kms
|
||||
|
||||
enabledPlugins []base.EnabledPlugin
|
||||
}
|
||||
|
||||
func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
@@ -86,6 +90,7 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
schedulerWg: new(sync.WaitGroup),
|
||||
workerAuthCache: new(sync.Map),
|
||||
workerStatusUpdateTimes: new(sync.Map),
|
||||
enabledPlugins: conf.Server.EnabledPlugins,
|
||||
}
|
||||
|
||||
c.started.Store(false)
|
||||
@@ -119,32 +124,24 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
}
|
||||
}
|
||||
|
||||
azureSvcClient, azureCleanup, err := external_host_plugins.CreateHostPlugin(
|
||||
ctx,
|
||||
"azure",
|
||||
external_host_plugins.WithHostPluginsFilesystem("boundary-plugin-host-", host_plugin_assets.FileSystem()),
|
||||
external_host_plugins.WithHostPluginExecutionDir(conf.RawConfig.Plugins.ExecutionDir),
|
||||
external_host_plugins.WithLogger(hclog.NewNullLogger()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating azure host plugin: %w", err)
|
||||
}
|
||||
conf.ShutdownFuncs = append(conf.ShutdownFuncs, azureCleanup)
|
||||
if _, err := conf.RegisterHostPlugin(ctx, "azure", azureSvcClient, hostplugin.WithDescription("Built-in Azure host plugin")); err != nil {
|
||||
return nil, fmt.Errorf("error registering azure host plugin: %w", err)
|
||||
}
|
||||
|
||||
awsSvcClient, awsCleanup, err := external_host_plugins.CreateHostPlugin(
|
||||
ctx,
|
||||
"aws",
|
||||
external_host_plugins.WithHostPluginsFilesystem("boundary-plugin-host-", host_plugin_assets.FileSystem()),
|
||||
external_host_plugins.WithHostPluginExecutionDir(conf.RawConfig.Plugins.ExecutionDir),
|
||||
external_host_plugins.WithLogger(hclog.NewNullLogger()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating aws host plugin")
|
||||
}
|
||||
conf.ShutdownFuncs = append(conf.ShutdownFuncs, awsCleanup)
|
||||
if _, err := conf.RegisterHostPlugin(ctx, "aws", awsSvcClient, hostplugin.WithDescription("Built-in AWS host plugin")); err != nil {
|
||||
return nil, fmt.Errorf("error registering aws host plugin: %w", err)
|
||||
for _, enabledPlugin := range c.enabledPlugins {
|
||||
switch enabledPlugin {
|
||||
case base.EnabledPluginHostAzure, base.EnabledPluginHostAws:
|
||||
pluginType := strings.ToLower(enabledPlugin.String())
|
||||
client, cleanup, err := external_host_plugins.CreateHostPlugin(
|
||||
ctx,
|
||||
pluginType,
|
||||
external_host_plugins.WithHostPluginsFilesystem("boundary-plugin-host-", host_plugin_assets.FileSystem()),
|
||||
external_host_plugins.WithHostPluginExecutionDir(conf.RawConfig.Plugins.ExecutionDir),
|
||||
external_host_plugins.WithLogger(hclog.NewNullLogger()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating %s host plugin: %w", pluginType, err)
|
||||
}
|
||||
conf.ShutdownFuncs = append(conf.ShutdownFuncs, cleanup)
|
||||
if _, err := conf.RegisterHostPlugin(ctx, pluginType, client, hostplugin.WithDescription(fmt.Sprintf("Built-in %s host plugin", enabledPlugin.String()))); err != nil {
|
||||
return nil, fmt.Errorf("error registering %s host plugin: %w", pluginType, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if conf.HostPlugins == nil {
|
||||
|
||||
@@ -48,6 +48,7 @@ const (
|
||||
DefaultTestOidcAccountId = "acctoidc_1234567890"
|
||||
DefaultTestUnprivilegedPasswordAccountId = intglobals.NewPasswordAccountPrefix + "_0987654321"
|
||||
DefaultTestUnprivilegedOidcAccountId = "acctoidc_0987654321"
|
||||
DefaultTestPluginId = "pl_1234567890"
|
||||
)
|
||||
|
||||
// TestController wraps a base.Server and Controller to provide a
|
||||
@@ -615,7 +616,7 @@ func TestControllerConfig(t *testing.T, ctx context.Context, tc *TestController,
|
||||
}
|
||||
} else if !opts.DisableDatabaseCreation {
|
||||
var createOpts []base.Option
|
||||
createOpts = append(createOpts, base.WithHostPlugin("pl_1234567890", plugin.NewWrappingPluginClient(plugin.NewLoopbackPlugin())))
|
||||
createOpts = append(createOpts, base.WithHostPlugin(DefaultTestPluginId, plugin.NewWrappingPluginClient(plugin.NewLoopbackPlugin())))
|
||||
if opts.DisableAuthMethodCreation {
|
||||
createOpts = append(createOpts, base.WithSkipAuthMethodCreation())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user