Add fields to server_worker to be a boundary resource (#2083)
* Remove the server_id from session table, change it to worker_id on session_connection This is step 1 in updating the worker table. The worker is becoming a public resource so it must have a public id. We drop the server_id column on the session_connection table and add the worker_id column so we can use the wt_public_key type. Since db migrations are applied while the controller is offline, it should be safe to assume all session connections are not in a running state, thus allowing us to null out all the worker ids in the session_connection table. For now we don't have very good enforcement of the wt_public_id contraints, since the id is currently defined in the worker config, but this will soon change and the worker's id will be generated by the controller. * Updating server_id references to controller_id. * Adding worker tag db writing test. * Move the server table back to the top. * Update comment for the worker object. * Update comment for the worker table. * Update the newWorkerId call to take a context and fix its error. * Correct comment for the wt_network_address domain.
This commit is contained in:
33 files changed
+967
-457
No files matched your search
@@ -911,7 +911,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
if hasWorkerFilter && len(workerIds) > 0 {
|
||||
finalWorkers := make([]*pb.WorkerInfo, 0, len(workers))
|
||||
// Fetch the tags for the given worker IDs
|
||||
tags, err := serversRepo.ListTagsForWorkers(ctx, workerIds)
|
||||
workerTags, err := serversRepo.ListTagsForWorkers(ctx, workerIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -919,13 +919,15 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
// built from the worker config, but with one extra level: a map of the
|
||||
// worker's ID to its filter map.
|
||||
tagMap := make(map[string]map[string][]string)
|
||||
for _, tag := range tags {
|
||||
currWorkerMap := tagMap[tag.WorkerId]
|
||||
for wId, tags := range workerTags {
|
||||
currWorkerMap := tagMap[wId]
|
||||
if currWorkerMap == nil {
|
||||
currWorkerMap = make(map[string][]string)
|
||||
tagMap[tag.WorkerId] = currWorkerMap
|
||||
tagMap[wId] = currWorkerMap
|
||||
}
|
||||
for _, tag := range tags {
|
||||
currWorkerMap[tag.Key] = append(currWorkerMap[tag.Key], tag.Value)
|
||||
}
|
||||
currWorkerMap[tag.Key] = append(currWorkerMap[tag.Key], tag.Value)
|
||||
// We don't need to reinsert after the fact because maps are
|
||||
// reference types, so we don't need to re-insert into tagMap
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/servers/store"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/common"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
||||
@@ -16,6 +14,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/observability/event"
|
||||
"github.com/hashicorp/boundary/internal/servers"
|
||||
"github.com/hashicorp/boundary/internal/session"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/targets"
|
||||
"github.com/hashicorp/go-bexpr"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -74,20 +73,20 @@ func (ws *workerServiceServer) Status(ctx context.Context, req *pbs.StatusReques
|
||||
|
||||
reqServer := req.GetWorker()
|
||||
// Convert API tags to storage tags
|
||||
workerTags := make(map[string]*store.TagValues)
|
||||
workerTags := make([]*servers.Tag, 0, len(reqServer.Tags))
|
||||
for k, v := range reqServer.Tags {
|
||||
thisTag := &store.TagValues{
|
||||
Values: v.GetValues(),
|
||||
for _, val := range v.GetValues() {
|
||||
workerTags = append(workerTags, &servers.Tag{
|
||||
Key: k,
|
||||
Value: val,
|
||||
})
|
||||
}
|
||||
workerTags[k] = thisTag
|
||||
}
|
||||
worker := &store.Worker{
|
||||
PublicId: reqServer.PrivateId,
|
||||
Address: reqServer.Address,
|
||||
CreateTime: reqServer.CreateTime,
|
||||
UpdateTime: reqServer.UpdateTime,
|
||||
Tags: workerTags,
|
||||
}
|
||||
|
||||
worker := servers.NewWorker(scope.Global.String(),
|
||||
servers.WithPublicId(reqServer.PrivateId),
|
||||
servers.WithAddress(reqServer.Address),
|
||||
servers.WithWorkerTags(workerTags...))
|
||||
controllers, _, err := serverRepo.UpsertWorker(ctx, worker, servers.WithUpdateTags(req.GetUpdateTags()))
|
||||
if err != nil {
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error storing worker status"))
|
||||
@@ -199,17 +198,19 @@ func (ws *workerServiceServer) LookupSession(ctx context.Context, req *pbs.Looku
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error getting servers repo"))
|
||||
return &pbs.LookupSessionResponse{}, status.Errorf(codes.Internal, "Error acquiring server repo when looking up session: %v", err)
|
||||
}
|
||||
tags, err := serversRepo.ListTagsForWorkers(ctx, []string{req.ServerId})
|
||||
workerTags, err := serversRepo.ListTagsForWorkers(ctx, []string{req.ServerId})
|
||||
if err != nil {
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error looking up tags for server", "server_id", req.ServerId))
|
||||
return &pbs.LookupSessionResponse{}, status.Errorf(codes.Internal, "Error looking up tags for server: %v", err)
|
||||
}
|
||||
// Build the map for filtering.
|
||||
tagMap := make(map[string][]string)
|
||||
for _, tag := range tags {
|
||||
tagMap[tag.Key] = append(tagMap[tag.Key], tag.Value)
|
||||
// We don't need to reinsert after the fact because maps are
|
||||
// reference types, so we don't need to re-insert into tagMap
|
||||
for _, tags := range workerTags {
|
||||
for _, tag := range tags {
|
||||
tagMap[tag.Key] = append(tagMap[tag.Key], tag.Value)
|
||||
// We don't need to reinsert after the fact because maps are
|
||||
// reference types, so we don't need to re-insert into tagMap
|
||||
}
|
||||
}
|
||||
|
||||
// Create the evaluator
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/servers/store"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
@@ -37,10 +38,10 @@ func TestStatus(t *testing.T) {
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
})
|
||||
serverRepo.UpsertWorker(ctx, &store.Worker{
|
||||
PublicId: "test_worker1",
|
||||
Address: "127.0.0.1",
|
||||
})
|
||||
serverRepo.UpsertWorker(ctx, servers.NewWorker(
|
||||
scope.Global.String(),
|
||||
servers.WithPublicId("test_worker1"),
|
||||
servers.WithAddress("127.0.0.1")))
|
||||
|
||||
serversRepoFn := func() (*servers.Repository, error) {
|
||||
return serverRepo, nil
|
||||
@@ -205,10 +206,10 @@ func TestStatusSessionClosed(t *testing.T) {
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
})
|
||||
serverRepo.UpsertWorker(ctx, &store.Worker{
|
||||
PublicId: "test_worker1",
|
||||
Address: "127.0.0.1",
|
||||
})
|
||||
serverRepo.UpsertWorker(ctx, servers.NewWorker(
|
||||
scope.Global.String(),
|
||||
servers.WithPublicId("test_worker1"),
|
||||
servers.WithAddress("127.0.0.1")))
|
||||
|
||||
serversRepoFn := func() (*servers.Repository, error) {
|
||||
return serverRepo, nil
|
||||
@@ -387,10 +388,10 @@ func TestStatusDeadConnection(t *testing.T) {
|
||||
PrivateId: "test_controller1",
|
||||
Address: "127.0.0.1",
|
||||
})
|
||||
serverRepo.UpsertWorker(ctx, &store.Worker{
|
||||
PublicId: "test_worker1",
|
||||
Address: "127.0.0.1",
|
||||
})
|
||||
serverRepo.UpsertWorker(ctx, servers.NewWorker(
|
||||
scope.Global.String(),
|
||||
servers.WithPublicId("test_worker1"),
|
||||
servers.WithAddress("127.0.0.1")))
|
||||
|
||||
serversRepoFn := func() (*servers.Repository, error) {
|
||||
return serverRepo, nil
|
||||
|
||||
Reference in new issue
Block a user