feat: workers filtered by sbc state

This commit is contained in:
Damian Debkowski authored and Elim Tsiagbey committed 2024-07-17 14:23:11 -04:00
1 parent 130010a2ca
commit 00e4c5448b
11 files changed
+71 -43

No files matched your search

+1
View File
@@ -241,6 +241,7 @@ func (c *Controller) registerGrpcServices(s *grpc.Server) error {
srs, err := session_recordings.NewServiceFn(
c.baseContext,
c.IamRepoFn,
c.ServersRepoFn,
c.workerStatusGracePeriod,
c.kms,
c.conf.RawConfig.Controller.MaxPageSize,
@@ -43,6 +43,7 @@ func init() {
// NewServiceFn returns a storage bucket service which is not implemented in OSS
var NewServiceFn = func(ctx context.Context,
iamRepoFn common.IamRepoFactory,
serverRepoFn common.ServersRepoFactory,
workerStatusGracePeriod *atomic.Int64,
kms *kms.Kms,
maxPageSize uint,
@@ -19,7 +19,6 @@ import (
"github.com/hashicorp/boundary/internal/alias"
talias "github.com/hashicorp/boundary/internal/alias/target"
"github.com/hashicorp/boundary/internal/credential"
wl "github.com/hashicorp/boundary/internal/daemon/common"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
@@ -749,12 +748,12 @@ func (s Service) RemoveTargetCredentialSources(ctx context.Context, req *pbs.Rem
func AuthorizeSessionWithWorkerFilter(
_ context.Context,
t target.Target,
selectedWorkers wl.WorkerList,
selectedWorkers server.WorkerList,
_ string,
_ intglobals.ControllerExtension,
_ common.Downstreamers,
_ ...target.Option,
) (wl.WorkerList, *server.Worker, error) {
) (server.WorkerList, *server.Worker, error) {
if len(selectedWorkers) > 0 {
var eval *bexpr.Evaluator
var err error
@@ -1057,7 +1056,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
if err != nil {
return nil, err
}
sess, err = sessionRepo.CreateSession(ctx, wrapper, sess, wl.WorkerList(selectedWorkers).Addresses())
sess, err = sessionRepo.CreateSession(ctx, wrapper, sess, server.WorkerList(selectedWorkers).Addresses())
if err != nil {
return nil, err
}
@@ -1197,7 +1196,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
PrivateKey: sess.CertificatePrivateKey,
HostId: hostId,
Endpoint: endpointUrl.String(),
WorkerInfo: wl.WorkerList(selectedWorkers).WorkerInfos(),
WorkerInfo: server.WorkerList(selectedWorkers).WorkerInfos(),
ConnectionLimit: t.GetSessionConnectionLimit(),
DefaultClientPort: t.GetDefaultClientPort(),
}
@@ -9,7 +9,6 @@ import (
"fmt"
"testing"
"github.com/hashicorp/boundary/internal/daemon/common"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/server"
@@ -29,7 +28,7 @@ func TestWorkerList_Addresses(t *testing.T) {
"test4",
}
var workerInfos []*pb.WorkerInfo
var tested common.WorkerList
var tested server.WorkerList
for _, a := range addresses {
workerInfos = append(workerInfos, &pb.WorkerInfo{Address: a})
tested = append(tested, server.NewWorker(scope.Global.String(),
@@ -12,7 +12,6 @@ import (
"strings"
"github.com/hashicorp/boundary/globals"
wl "github.com/hashicorp/boundary/internal/daemon/common"
"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"
@@ -331,7 +330,7 @@ func (s Service) DeleteWorker(ctx context.Context, req *pbs.DeleteWorkerRequest)
return nil, err
}
if wl.IsManagedWorker(w) {
if server.IsManagedWorker(w) {
return nil, handlers.InvalidArgumentErrorf("Error in provided request.", map[string]string{"id": "Managed workers cannot be deleted."})
}
@@ -368,7 +367,7 @@ func (s Service) UpdateWorker(ctx context.Context, req *pbs.UpdateWorkerRequest)
// generated from the scope and name, it's functionally equivalent to
// checking the type, but works for both KMS-PKI and old-style KMS workers.
switch {
case wl.IsManagedWorker(w):
case server.IsManagedWorker(w):
return nil, handlers.InvalidArgumentErrorf(
"Error in provided request.",
map[string]string{"id": "Managed workers cannot be updated."},
@@ -879,7 +878,7 @@ func (s Service) toProto(ctx context.Context, in *server.Worker, opt ...handlers
}
}
// Managed workers cannot be deleted
if wl.IsManagedWorker(in) {
if server.IsManagedWorker(in) {
allActions := out.AuthorizedActions
out.AuthorizedActions = make([]string, 0, len(allActions))
for _, act := range allActions {
@@ -1069,7 +1068,7 @@ func validateStringForDb(str string) string {
return "must be non-empty."
case len(str) > 512:
return "must be within 512 characters."
case str == wl.ManagedWorkerTag:
case str == server.ManagedWorkerTag:
return "cannot be the managed worker tag."
default:
return ""
@@ -13,7 +13,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/hashicorp/boundary/globals"
wl "github.com/hashicorp/boundary/internal/daemon/common"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
@@ -205,7 +204,7 @@ func TestGet(t *testing.T) {
server.WithAddress("test managed pki worker address"),
server.WithLocalStorageState(server.AvailableLocalStorageState.String()),
server.WithWorkerTags(&server.Tag{
Key: wl.ManagedWorkerTag,
Key: server.ManagedWorkerTag,
Value: "true",
})),
server.WithUpdateTags(true),
@@ -233,10 +232,10 @@ func TestGet(t *testing.T) {
LastStatusTime: managedPkiWorker.GetLastStatusTime().GetTimestamp(),
ReleaseVersion: managedPkiWorker.ReleaseVersion,
CanonicalTags: map[string]*structpb.ListValue{
wl.ManagedWorkerTag: structListValue(t, "true"),
server.ManagedWorkerTag: structListValue(t, "true"),
},
ConfigTags: map[string]*structpb.ListValue{
wl.ManagedWorkerTag: structListValue(t, "true"),
server.ManagedWorkerTag: structListValue(t, "true"),
},
Type: PkiWorkerType,
DirectlyConnectedDownstreamWorkers: connectedDownstreams,
@@ -499,7 +498,7 @@ func TestDelete(t *testing.T) {
Value: "bar",
}))
wManaged := server.TestKmsWorker(t, conn, wrap, server.WithWorkerTags(&server.Tag{
Key: wl.ManagedWorkerTag,
Key: server.ManagedWorkerTag,
Value: "bar",
}))
@@ -2059,7 +2058,7 @@ func TestService_AddWorkerTags(t *testing.T) {
return &pbs.AddWorkerTagsRequest{
Id: worker.PublicId,
Version: worker.Version,
ApiTags: map[string]*structpb.ListValue{wl.ManagedWorkerTag: {Values: []*structpb.Value{structpb.NewStringValue("value2")}}},
ApiTags: map[string]*structpb.ListValue{server.ManagedWorkerTag: {Values: []*structpb.Value{structpb.NewStringValue("value2")}}},
}
}(),
wantErrContains: "Tag keys cannot be the managed worker tag.",
@@ -2222,7 +2221,7 @@ func TestService_SetWorkerTags(t *testing.T) {
return &pbs.SetWorkerTagsRequest{
Id: worker.PublicId,
Version: worker.Version,
ApiTags: map[string]*structpb.ListValue{wl.ManagedWorkerTag: {Values: []*structpb.Value{structpb.NewStringValue("value2")}}},
ApiTags: map[string]*structpb.ListValue{server.ManagedWorkerTag: {Values: []*structpb.Value{structpb.NewStringValue("value2")}}},
}
}(),
wantErrContains: "Tag keys cannot be the managed worker tag.",
+1 -2
View File
@@ -10,7 +10,6 @@ import (
"time"
"github.com/hashicorp/boundary/internal/daemon/cluster"
"github.com/hashicorp/boundary/internal/daemon/common"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/event"
"github.com/hashicorp/boundary/internal/server"
@@ -204,7 +203,7 @@ func (c *Controller) startWorkerConnectionMaintenanceTicking(cancelCtx context.C
event.WriteError(cancelCtx, op, err, event.WithInfoMsg("couldn't get known workers from repo"))
break
}
connectionState.DisconnectMissingWorkers(common.WorkerList(knownWorker).PublicIds())
connectionState.DisconnectMissingWorkers(server.WorkerList(knownWorker).PublicIds())
}
if len(connectionState.UnmappedKeyIds()) > 0 {