Worker Domain Refactor (#5338)
* feat(server): Refactor LookupWorkerByName to be a test method * feat(server): Split worker tags table * refact(worker): Export api and config tags * refact(server): Return worker id from UpsertWorkerStatus * refact(server): Create ListWorkerStorageBucketUpdates domain function * refact(server): Use dedicated HCPb-worker list func * refact(server): Create ConnectionRoute domain function * refact(handlers): Move worker selection logic to internal/server package This commit moves all the logic to select a worker to handle a session to the internal/server package. Most functions were moved to this package with no changes, however, there are a couple of notable exceptions: - Given that we don't use GRPC errors in repos, all errors were adjusted to use the internal/errors package instead. - StorageBucketFilterCredIdFn is now used to prevent the internal/server package from importing internal/storage/plugin, which would cause a dep cycle. Callers of SelectSessionWorkers must implement this func which is responsible for returning a storage bucket's worker filter as well as its associated credential id. - authorizeSessionWithWorkerFilter now receives an internal/server.(*Repository) object when called. This is transparent to SelectSessionWorkers callers as it is handled internally. * feat(server): Add FilteredWithFeatures fn and new server options * refact(server): create new list and lookup worker queries * test(server): Add WorkerList unit tests * feat(server): Implement WorkerList randomness using crypto/rand pkg * chore(db): add index to server_worker table * refact(server): prefix test method with Test * refact(server): rename Downstreamers interface to Graph * chore(server): unexport and rename method * chore: add doc string to WorkerAddress (#5420) --------- Co-authored-by: Irena Rindos <irenarindos@users.noreply.github.com> Co-authored-by: irenarindos <irena.rindos@gmail.com>
This commit is contained in:
43 files changed
+2064
-1086
No files matched your search
@@ -46,11 +46,3 @@ type (
|
||||
AliasRepoFactory func() (*alias.Repository, error)
|
||||
TargetAliasRepoFactory func() (*target.Repository, error)
|
||||
)
|
||||
|
||||
// Downstreamers provides at least a minimum interface that must be met by a
|
||||
// Controller.downstreamWorkers field which is far better than allowing any (empty
|
||||
// interface)
|
||||
type Downstreamers interface {
|
||||
// RootId returns the root ID of the downstreamers' graph
|
||||
RootId() string
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/credential/vault"
|
||||
"github.com/hashicorp/boundary/internal/daemon/cluster"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/common"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/downstream"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/handlers/health"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/internal/metric"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
@@ -89,8 +90,8 @@ type downstreamWorkersTicker interface {
|
||||
var (
|
||||
downstreamReceiverFactory func(*atomic.Int64) (downstreamReceiver, error)
|
||||
|
||||
downstreamersFactory func(context.Context, string, string) (common.Downstreamers, error)
|
||||
downstreamWorkersTickerFactory func(context.Context, string, string, common.Downstreamers, downstreamReceiver, *atomic.Int64) (downstreamWorkersTicker, error)
|
||||
graphFactory func(context.Context, string, string) (downstream.Graph, error)
|
||||
downstreamWorkersTickerFactory func(context.Context, string, string, downstream.Graph, downstreamReceiver, *atomic.Int64) (downstreamWorkersTicker, error)
|
||||
commandClientFactory func(context.Context, *Controller) error
|
||||
extControllerFactory func(ctx context.Context, c *Controller, r db.Reader, w db.Writer, kms *kms.Kms) (intglobals.ControllerExtension, error)
|
||||
)
|
||||
@@ -109,7 +110,7 @@ type Controller struct {
|
||||
workerAuthCache *sync.Map
|
||||
|
||||
// downstream workers and routes to those workers
|
||||
downstreamWorkers common.Downstreamers
|
||||
downstreamWorkers downstream.Graph
|
||||
downstreamConns downstreamReceiver
|
||||
|
||||
apiListeners []*base.ServerListener
|
||||
@@ -494,9 +495,9 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
event.WriteSysEvent(ctx, op, "unable to ensure worker auth roots exist, may be due to multiple controllers starting at once, continuing")
|
||||
}
|
||||
|
||||
if downstreamersFactory != nil {
|
||||
if graphFactory != nil {
|
||||
boundVer := version.Get().VersionNumber()
|
||||
c.downstreamWorkers, err = downstreamersFactory(ctx, "root", boundVer)
|
||||
c.downstreamWorkers, err = graphFactory(ctx, "root", boundVer)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to initialize downstream workers graph: %w", err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package downstream
|
||||
|
||||
// Graph provides at least a minimum interface that must be met by a
|
||||
// Controller.downstreamWorkers field which is far better than allowing any (empty
|
||||
// interface)
|
||||
// This is used to interact with downstream workers DAG
|
||||
type Graph interface {
|
||||
// RootId returns the root ID of the graph
|
||||
RootId() string
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/common"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/downstream"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
|
||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
@@ -102,9 +103,9 @@ var (
|
||||
|
||||
validateCredentialSourcesFn = func(context.Context, globals.Subtype, []target.CredentialSource) error { return nil }
|
||||
ValidateIngressWorkerFilterFn = IngressWorkerFilterUnsupported
|
||||
AuthorizeSessionWorkerFilterFn = AuthorizeSessionWithWorkerFilter
|
||||
SessionRecordingFn = NoSessionRecording
|
||||
WorkerFilterDeprecationMessage = fmt.Sprintf("This field is deprecated. Use %s instead.", globals.EgressWorkerFilterField)
|
||||
StorageBucketFilterCredIdFn = noStorageBucket
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -129,7 +130,7 @@ type Service struct {
|
||||
staticHostRepoFn common.StaticRepoFactory
|
||||
vaultCredRepoFn common.VaultCredentialRepoFactory
|
||||
staticCredRepoFn common.StaticCredentialRepoFactory
|
||||
downstreams common.Downstreamers
|
||||
downstreams downstream.Graph
|
||||
kmsCache *kms.Kms
|
||||
workerStatusGracePeriod *atomic.Int64
|
||||
maxPageSize uint
|
||||
@@ -151,7 +152,7 @@ func NewService(
|
||||
vaultCredRepoFn common.VaultCredentialRepoFactory,
|
||||
staticCredRepoFn common.StaticCredentialRepoFactory,
|
||||
aliasRepoFn common.TargetAliasRepoFactory,
|
||||
downstreams common.Downstreamers,
|
||||
downstreams downstream.Graph,
|
||||
workerStatusGracePeriod *atomic.Int64,
|
||||
maxPageSize uint,
|
||||
controllerExt intglobals.ControllerExtension,
|
||||
@@ -743,49 +744,7 @@ func (s Service) RemoveTargetCredentialSources(ctx context.Context, req *pbs.Rem
|
||||
return &pbs.RemoveTargetCredentialSourcesResponse{Item: item}, nil
|
||||
}
|
||||
|
||||
// If set, use the worker_filter or egress_worker_filter to filter the selected workers
|
||||
// and ensure we have workers available to service this request. The second return
|
||||
// argument is always nil.
|
||||
func AuthorizeSessionWithWorkerFilter(
|
||||
_ context.Context,
|
||||
t target.Target,
|
||||
selectedWorkers server.WorkerList,
|
||||
_ string,
|
||||
_ intglobals.ControllerExtension,
|
||||
_ common.Downstreamers,
|
||||
_ ...target.Option,
|
||||
) (server.WorkerList, *server.Worker, error) {
|
||||
if len(selectedWorkers) > 0 {
|
||||
var eval *bexpr.Evaluator
|
||||
var err error
|
||||
switch {
|
||||
case len(t.GetEgressWorkerFilter()) > 0:
|
||||
eval, err = bexpr.CreateEvaluator(t.GetEgressWorkerFilter())
|
||||
case len(t.GetWorkerFilter()) > 0:
|
||||
eval, err = bexpr.CreateEvaluator(t.GetWorkerFilter())
|
||||
default: // No filter
|
||||
return selectedWorkers, nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
selectedWorkers, err = selectedWorkers.Filtered(eval)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if len(selectedWorkers) == 0 {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(
|
||||
codes.FailedPrecondition,
|
||||
"No workers are available to handle this session, or all have been filtered.")
|
||||
}
|
||||
|
||||
return selectedWorkers, nil, nil
|
||||
}
|
||||
|
||||
func NoSessionRecording(context.Context, intglobals.ControllerExtension, *kms.Kms, target.Target, *session.Session, *server.Worker) (string, error) {
|
||||
func NoSessionRecording(context.Context, intglobals.ControllerExtension, *kms.Kms, target.Target, *session.Session, string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -981,22 +940,24 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
}
|
||||
|
||||
// Get workers and filter down to ones that can service this request
|
||||
selectedWorkers, err := serversRepo.ListWorkers(ctx, []string{scope.Global.String()}, server.WithLiveness(time.Duration(s.workerStatusGracePeriod.Load())))
|
||||
selectedWorkers, protoWorkerId, err := serversRepo.SelectSessionWorkers(
|
||||
ctx,
|
||||
time.Duration(s.workerStatusGracePeriod.Load()),
|
||||
t,
|
||||
h,
|
||||
s.controllerExt,
|
||||
StorageBucketFilterCredIdFn,
|
||||
s.downstreams,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(selectedWorkers) == 0 {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(
|
||||
codes.FailedPrecondition,
|
||||
"No workers are available to handle this session.")
|
||||
}
|
||||
|
||||
selectedWorkers, protoWorker, err := AuthorizeSessionWorkerFilterFn(ctx, t, selectedWorkers, h, s.controllerExt, s.downstreams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Randomize the workers
|
||||
rand.Shuffle(len(selectedWorkers), func(i, j int) {
|
||||
selectedWorkers[i], selectedWorkers[j] = selectedWorkers[j], selectedWorkers[i]
|
||||
@@ -1038,9 +999,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
DynamicCredentials: dynCreds,
|
||||
StaticCredentials: staticCreds,
|
||||
CorrelationId: correlationId,
|
||||
}
|
||||
if protoWorker != nil {
|
||||
sessionComposition.ProtocolWorkerId = protoWorker.GetPublicId()
|
||||
ProtocolWorkerId: protoWorkerId,
|
||||
}
|
||||
sess, err := session.New(ctx, sessionComposition)
|
||||
if err != nil {
|
||||
@@ -1050,7 +1009,12 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sess, err = sessionRepo.CreateSession(ctx, wrapper, sess, server.WorkerList(selectedWorkers).Addresses())
|
||||
|
||||
workerAddresses := make([]string, 0, len(selectedWorkers))
|
||||
for _, sw := range selectedWorkers {
|
||||
workerAddresses = append(workerAddresses, sw.Address)
|
||||
}
|
||||
sess, err = sessionRepo.CreateSession(ctx, wrapper, sess, workerAddresses)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1178,6 +1142,10 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
hostId = t.GetPublicId()
|
||||
}
|
||||
|
||||
workerInfos := make([]*pb.WorkerInfo, 0, len(selectedWorkers))
|
||||
for _, sw := range selectedWorkers {
|
||||
workerInfos = append(workerInfos, &pb.WorkerInfo{Address: sw.Address})
|
||||
}
|
||||
sad := &pb.SessionAuthorizationData{
|
||||
SessionId: sess.PublicId,
|
||||
TargetId: t.GetPublicId(),
|
||||
@@ -1190,7 +1158,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
PrivateKey: sess.CertificatePrivateKey,
|
||||
HostId: hostId,
|
||||
Endpoint: endpointUrl.String(),
|
||||
WorkerInfo: server.WorkerList(selectedWorkers).WorkerInfos(),
|
||||
WorkerInfo: workerInfos,
|
||||
ConnectionLimit: t.GetSessionConnectionLimit(),
|
||||
DefaultClientPort: t.GetDefaultClientPort(),
|
||||
}
|
||||
@@ -1223,7 +1191,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
s.kmsCache,
|
||||
t,
|
||||
sess,
|
||||
protoWorker,
|
||||
protoWorkerId,
|
||||
)
|
||||
if err != nil {
|
||||
// Errors here will automatically delete the session and associated resources
|
||||
@@ -2240,3 +2208,7 @@ func validateAuthorizeSessionRequest(req *pbs.AuthorizeSessionRequest) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func noStorageBucket(_ context.Context, _ intglobals.ControllerExtension, _ string) (string, string, error) {
|
||||
return "", "", fmt.Errorf("not supported")
|
||||
}
|
||||
@@ -4,20 +4,12 @@
|
||||
package targets
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/server"
|
||||
"github.com/hashicorp/boundary/internal/target/targettest"
|
||||
"github.com/hashicorp/boundary/internal/target/targettest/store"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/targets"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestWorkerList_Addresses(t *testing.T) {
|
||||
@@ -38,97 +30,3 @@ func TestWorkerList_Addresses(t *testing.T) {
|
||||
assert.Equal(t, addresses, tested.Addresses())
|
||||
assert.Equal(t, workerInfos, tested.WorkerInfos())
|
||||
}
|
||||
|
||||
func TestWorkerList_EgressFilter(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
// This prevents us from running tests in parallel.
|
||||
SetupSuiteTargetFilters(t)
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
wrapper := db.TestWrapper(t)
|
||||
kmsCache := kms.TestKms(t, conn, wrapper)
|
||||
require.NoError(t, kmsCache.CreateKeys(context.Background(), scope.Global.String(), kms.WithRandomReader(rand.Reader)))
|
||||
|
||||
var workers []*server.Worker
|
||||
for i := 0; i < 5; i++ {
|
||||
switch {
|
||||
case i%2 == 0:
|
||||
workers = append(workers, server.TestKmsWorker(t, conn, wrapper,
|
||||
server.WithName(fmt.Sprintf("test_worker_%d", i)),
|
||||
server.WithWorkerTags(&server.Tag{
|
||||
Key: fmt.Sprintf("key%d", i),
|
||||
Value: fmt.Sprintf("value%d", i),
|
||||
})))
|
||||
default:
|
||||
workers = append(workers, server.TestPkiWorker(t, conn, wrapper,
|
||||
server.WithName(fmt.Sprintf("test_worker_%d", i)),
|
||||
server.WithWorkerTags(&server.Tag{
|
||||
Key: "key",
|
||||
Value: "configvalue",
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
in []*server.Worker
|
||||
out []*server.Worker
|
||||
filter string
|
||||
errContains string
|
||||
}{
|
||||
{
|
||||
name: "no-workers",
|
||||
in: []*server.Worker{},
|
||||
out: []*server.Worker{},
|
||||
filter: "",
|
||||
errContains: "No workers are available to handle this session, or all have been filtered",
|
||||
},
|
||||
{
|
||||
name: "no-filter",
|
||||
in: workers,
|
||||
out: workers,
|
||||
},
|
||||
{
|
||||
name: "filter-no-matches",
|
||||
in: workers,
|
||||
out: workers,
|
||||
filter: `"/name" matches "test_worker_[13]" and "configvalue2" in "/tags/key"`,
|
||||
errContains: "No workers are available to handle this session, or all have been filtered",
|
||||
},
|
||||
{
|
||||
name: "filter-one-match",
|
||||
in: workers,
|
||||
out: []*server.Worker{workers[1]},
|
||||
filter: `"/name" matches "test_worker_[12]" and "configvalue" in "/tags/key"`,
|
||||
},
|
||||
{
|
||||
name: "filter-two-matches",
|
||||
in: workers,
|
||||
out: []*server.Worker{workers[1], workers[3]},
|
||||
filter: `"configvalue" in "/tags/key"`,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
target := &targettest.Target{
|
||||
Target: &store.Target{},
|
||||
}
|
||||
if len(tc.filter) > 0 {
|
||||
target.EgressWorkerFilter = tc.filter
|
||||
}
|
||||
out, protocolWorker, err := AuthorizeSessionWithWorkerFilter(ctx, target, tc.in, "", nil, nil)
|
||||
if tc.errContains != "" {
|
||||
assert.Contains(err.Error(), tc.errContains)
|
||||
assert.Nil(out)
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(err)
|
||||
require.Len(out, len(tc.out))
|
||||
for i, exp := range tc.out {
|
||||
assert.Equal(exp.Name, out[i].Name)
|
||||
}
|
||||
require.Nil(protocolWorker)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1272,7 +1272,6 @@ func TestDelete_twice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -1298,9 +1297,9 @@ func TestCreate(t *testing.T) {
|
||||
_ = iam.TestRoleGrant(t, conn, r.GetPublicId(), "ids=*;type=*;actions=*")
|
||||
_ = iam.TestRoleGrantScope(t, conn, r.GetPublicId(), globals.GrantScopeDescendants)
|
||||
|
||||
// Ensure we are using the OSS worker filter function
|
||||
workerFilterFn := targets.AuthorizeSessionWorkerFilterFn
|
||||
targets.AuthorizeSessionWorkerFilterFn = targets.AuthorizeSessionWithWorkerFilter
|
||||
// Ensure we are using the OSS worker filter function. This prevents us from
|
||||
// running tests in parallel.
|
||||
server.TestUseCommunityFilterWorkersFn(t)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
@@ -1650,12 +1649,9 @@ func TestCreate(t *testing.T) {
|
||||
), "CreateTarget(%q)\n got response %q\n, wanted %q\n", tc.req, got, tc.res)
|
||||
})
|
||||
}
|
||||
// Reset worker filter func
|
||||
targets.AuthorizeSessionWorkerFilterFn = workerFilterFn
|
||||
}
|
||||
|
||||
func TestCreate_AliasAuthCheck(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -1698,12 +1694,9 @@ func TestCreate_AliasAuthCheck(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
// Ensure we are using the OSS worker filter function
|
||||
workerFilterFn := targets.AuthorizeSessionWorkerFilterFn
|
||||
targets.AuthorizeSessionWorkerFilterFn = targets.AuthorizeSessionWithWorkerFilter
|
||||
t.Cleanup(func() {
|
||||
targets.AuthorizeSessionWorkerFilterFn = workerFilterFn
|
||||
})
|
||||
// Ensure we are using the OSS worker filter function. This prevents us from
|
||||
// running tests in parallel.
|
||||
server.TestUseCommunityFilterWorkersFn(t)
|
||||
|
||||
s, err := testService(t, context.Background(), conn, kms, wrapper)
|
||||
require.NoError(t, err, "Failed to create a new host set service.")
|
||||
@@ -1742,7 +1735,6 @@ func TestCreate_AliasAuthCheck(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -1810,9 +1802,9 @@ func TestUpdate(t *testing.T) {
|
||||
tested, err := testService(t, context.Background(), conn, kms, wrapper)
|
||||
require.NoError(t, err, "Failed to create a new host set service.")
|
||||
|
||||
// Ensure we are using the OSS worker filter functions
|
||||
workerFilterFn := targets.AuthorizeSessionWorkerFilterFn
|
||||
targets.AuthorizeSessionWorkerFilterFn = targets.AuthorizeSessionWithWorkerFilter
|
||||
// Ensure we are using the OSS worker filter functions. This prevents us
|
||||
// from running tests in parallel.
|
||||
server.TestUseCommunityFilterWorkersFn(t)
|
||||
validateIngressFn := targets.ValidateIngressWorkerFilterFn
|
||||
targets.ValidateIngressWorkerFilterFn = targets.IngressWorkerFilterUnsupported
|
||||
|
||||
@@ -2252,7 +2244,6 @@ func TestUpdate(t *testing.T) {
|
||||
})
|
||||
}
|
||||
// Reset worker filter funcs
|
||||
targets.AuthorizeSessionWorkerFilterFn = workerFilterFn
|
||||
targets.ValidateIngressWorkerFilterFn = validateIngressFn
|
||||
}
|
||||
|
||||
@@ -3390,7 +3381,7 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
func TestAuthorizeSession(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
// This prevents us from running tests in parallel.
|
||||
targets.SetupSuiteTargetFilters(t)
|
||||
server.TestUseCommunityFilterWorkersFn(t)
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -3730,7 +3721,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
kms := kms.TestKms(t, conn, wrapper)
|
||||
|
||||
// This prevents us from running tests in parallel.
|
||||
targets.SetupSuiteTargetFilters(t)
|
||||
server.TestUseCommunityFilterWorkersFn(t)
|
||||
|
||||
sche := scheduler.TestScheduler(t, conn, wrapper)
|
||||
err := vault.RegisterJobs(context.Background(), sche, rw, rw, kms)
|
||||
@@ -4346,7 +4337,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
func TestAuthorizeSession_Errors(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
// This prevents us from running tests in parallel.
|
||||
targets.SetupSuiteTargetFilters(t)
|
||||
server.TestUseCommunityFilterWorkersFn(t)
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package targets
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// SetupSuiteTargetFilters is used to ensure that OSS tests run from the ENT repo use the OSS level of target filtering
|
||||
// WARNING: Do NOT run tests in parallel when using this.
|
||||
func SetupSuiteTargetFilters(t *testing.T) {
|
||||
oldFn := AuthorizeSessionWorkerFilterFn
|
||||
AuthorizeSessionWorkerFilterFn = AuthorizeSessionWithWorkerFilter
|
||||
|
||||
t.Cleanup(func() {
|
||||
AuthorizeSessionWorkerFilterFn = oldFn
|
||||
})
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/common"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/common/scopeids"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/downstream"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
@@ -85,7 +86,7 @@ func init() {
|
||||
action.RegisterResource(resource.Worker, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
func emptyDownstreamWorkers(context.Context, string, common.Downstreamers) []string {
|
||||
func emptyDownstreamWorkers(context.Context, string, downstream.Graph) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -96,14 +97,14 @@ type Service struct {
|
||||
repoFn common.ServersRepoFactory
|
||||
workerAuthFn common.WorkerAuthRepoStorageFactory
|
||||
iamRepoFn common.IamRepoFactory
|
||||
downstreams common.Downstreamers
|
||||
downstreams downstream.Graph
|
||||
}
|
||||
|
||||
var _ pbs.WorkerServiceServer = (*Service)(nil)
|
||||
|
||||
// NewService returns a worker service which handles worker related requests to boundary.
|
||||
func NewService(ctx context.Context, repo common.ServersRepoFactory, iamRepoFn common.IamRepoFactory,
|
||||
workerAuthFn common.WorkerAuthRepoStorageFactory, ds common.Downstreamers,
|
||||
workerAuthFn common.WorkerAuthRepoStorageFactory, ds downstream.Graph,
|
||||
) (Service, error) {
|
||||
const op = "workers.NewService"
|
||||
if repo == nil {
|
||||
@@ -899,7 +900,7 @@ func (s Service) toProto(ctx context.Context, in *server.Worker, opt ...handlers
|
||||
out.LastStatusTime = in.GetLastStatusTime().GetTimestamp()
|
||||
}
|
||||
if outputFields.Has(globals.ActiveConnectionCountField) {
|
||||
out.ActiveConnectionCount = &wrapperspb.UInt32Value{Value: in.ActiveConnectionCount()}
|
||||
out.ActiveConnectionCount = &wrapperspb.UInt32Value{Value: in.ActiveConnectionCount}
|
||||
}
|
||||
if outputFields.Has(globals.ControllerGeneratedActivationToken) && in.ControllerGeneratedActivationToken != "" {
|
||||
out.ControllerGeneratedActivationToken = &wrapperspb.StringValue{Value: in.ControllerGeneratedActivationToken}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/common"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/downstream"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
@@ -98,7 +98,7 @@ func TestGet(t *testing.T) {
|
||||
downstreamWorkers = oldDownstramFn
|
||||
})
|
||||
connectedDownstreams := []string{"first", "second", "third"}
|
||||
downstreamWorkers = func(_ context.Context, id string, _ common.Downstreamers) []string {
|
||||
downstreamWorkers = func(_ context.Context, id string, _ downstream.Graph) []string {
|
||||
return connectedDownstreams
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func TestGet(t *testing.T) {
|
||||
server.WithDescription("test pki worker description"),
|
||||
server.WithTestPkiWorkerAuthorizedKeyId(&pkiWorkerKeyId))
|
||||
// Add config tags to the created worker
|
||||
pkiWorker, err = repo.UpsertWorkerStatus(context.Background(),
|
||||
pkiWorker, err = server.TestUpsertAndReturnWorker(context.Background(), t,
|
||||
server.NewWorker(pkiWorker.GetScopeId(),
|
||||
server.WithAddress("test pki worker address"),
|
||||
server.WithLocalStorageState(server.AvailableLocalStorageState.String()),
|
||||
@@ -156,9 +156,11 @@ func TestGet(t *testing.T) {
|
||||
Key: "config",
|
||||
Value: "test",
|
||||
})),
|
||||
repo,
|
||||
server.WithUpdateTags(true),
|
||||
server.WithPublicId(pkiWorker.GetPublicId()),
|
||||
server.WithKeyId(pkiWorkerKeyId))
|
||||
server.WithKeyId(pkiWorkerKeyId),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
wantPkiWorker := &pb.Worker{
|
||||
@@ -201,7 +203,7 @@ func TestGet(t *testing.T) {
|
||||
)
|
||||
|
||||
// Add config tags to the created worker
|
||||
managedPkiWorker, err = repo.UpsertWorkerStatus(context.Background(),
|
||||
managedPkiWorker, err = server.TestUpsertAndReturnWorker(context.Background(), t,
|
||||
server.NewWorker(managedPkiWorker.GetScopeId(),
|
||||
server.WithAddress("test managed pki worker address"),
|
||||
server.WithLocalStorageState(server.AvailableLocalStorageState.String()),
|
||||
@@ -209,6 +211,7 @@ func TestGet(t *testing.T) {
|
||||
Key: server.ManagedWorkerTag,
|
||||
Value: "true",
|
||||
})),
|
||||
repo,
|
||||
server.WithUpdateTags(true),
|
||||
server.WithPublicId(managedPkiWorker.GetPublicId()),
|
||||
server.WithKeyId(managedPkiWorkerKeyId))
|
||||
@@ -330,7 +333,7 @@ func TestList(t *testing.T) {
|
||||
downstreamWorkers = oldDownstramFn
|
||||
})
|
||||
connectedDownstreams := []string{"first", "second", "third"}
|
||||
downstreamWorkers = func(_ context.Context, id string, _ common.Downstreamers) []string {
|
||||
downstreamWorkers = func(_ context.Context, id string, _ downstream.Graph) []string {
|
||||
return connectedDownstreams
|
||||
}
|
||||
|
||||
@@ -589,7 +592,7 @@ func TestUpdate(t *testing.T) {
|
||||
downstreamWorkers = oldDownstramFn
|
||||
})
|
||||
connectedDownstreams := []string{"first", "second", "third"}
|
||||
downstreamWorkers = func(_ context.Context, id string, _ common.Downstreamers) []string {
|
||||
downstreamWorkers = func(_ context.Context, id string, _ downstream.Graph) []string {
|
||||
return connectedDownstreams
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user