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:
Todd authored and GitHub committed 2022-05-18 17:03:24 -07:00
1 parent 472d7d520a
commit 2ecd550e27
33 files changed
+967 -457

No files matched your search

@@ -19,10 +19,10 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/servers/store"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/target/tcp"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/testing/dbtest"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
@@ -132,10 +132,9 @@ func TestGenerateSessionBenchmarkTemplateDumps(t *testing.T) {
require.NoError(err)
serversRepo, err := servers.NewRepository(rw, rw, kms)
require.NoError(err)
worker := &store.Worker{
PublicId: "test_worker_1",
Address: "127.0.0.1",
}
worker := servers.NewWorker(scope.Global.String(),
servers.WithPublicId("test_worker_1"),
servers.WithAddress("127.0.0.1"))
_, _, err = serversRepo.UpsertWorker(ctx, worker)
require.NoError(err)
@@ -196,7 +195,7 @@ func TestGenerateSessionBenchmarkTemplateDumps(t *testing.T) {
ScopeId: users[userIndex].scopeId,
Endpoint: "tcp://127.0.0.1:22",
})
cycleSessionStates(t, ctx, sess, sessRepo, connRepo, conn, worker, scenario.connsPerSession)
cycleSessionStates(t, ctx, sess, sessRepo, connRepo, conn, scenario.connsPerSession)
return nil
})
}
@@ -220,7 +219,7 @@ func TestGenerateSessionBenchmarkTemplateDumps(t *testing.T) {
}
}
func cycleSessionStates(t testing.TB, ctx context.Context, sess *session.Session, sessRepo *session.Repository, connRepo *session.ConnectionRepository, conn *db.DB, worker *store.Worker, numConns int) {
func cycleSessionStates(t testing.TB, ctx context.Context, sess *session.Session, sessRepo *session.Repository, connRepo *session.ConnectionRepository, conn *db.DB, numConns int) {
sess, _, err := sessRepo.ActivateSession(ctx, sess.PublicId, sess.Version, []byte(`tofu`))
require.NoError(t, err)
var closeWiths []session.CloseWith