From b9cc44122794d9833ac759dcb1a453da598605a0 Mon Sep 17 00:00:00 2001 From: Jim Date: Sat, 25 Mar 2023 13:47:39 -0400 Subject: [PATCH] feature (handlers): add UpstreamMessageService and its oss impl. Define OSS protos for UpstreamMessageService rpc which defines a way to send an upstream message to a controller (across multi-hops if needed). Implement OSS versions of both workers and controllers for the UpstreamMessageService. The upstream requests/responses are encrypted using the originating worker's NodeCredential's key. The worker always forwards the request upstream. The controller attends to find a registered UpstreamMessageHandler to handle the msg; if none if found, then an Unimplemented status error is returned. --- Makefile | 1 + internal/daemon/cluster/handlers/options.go | 36 ++ internal/daemon/cluster/handlers/testing.go | 193 +++++++ .../upstream_message_service_controller.go | 181 ++++++ .../handlers/upstream_message_service_test.go | 422 ++++++++++++++ .../upstream_message_service_worker.go | 174 ++++++ .../services/upstream_message_service.pb.go | 539 ++++++++++++++++++ .../upstream_message_service_grpc.pb.go | 104 ++++ .../v1/upstream_message_service.proto | 63 ++ 9 files changed, 1713 insertions(+) create mode 100644 internal/daemon/cluster/handlers/options.go create mode 100644 internal/daemon/cluster/handlers/testing.go create mode 100644 internal/daemon/cluster/handlers/upstream_message_service_controller.go create mode 100644 internal/daemon/cluster/handlers/upstream_message_service_test.go create mode 100644 internal/daemon/cluster/handlers/upstream_message_service_worker.go create mode 100644 internal/gen/controller/servers/services/upstream_message_service.pb.go create mode 100644 internal/gen/controller/servers/services/upstream_message_service_grpc.pb.go create mode 100644 internal/proto/controller/servers/services/v1/upstream_message_service.proto diff --git a/Makefile b/Makefile index 6be0efb94..e47627587 100644 --- a/Makefile +++ b/Makefile @@ -192,6 +192,7 @@ protobuild: @protoc-go-inject-tag -input=./internal/credential/static/store/static.pb.go @protoc-go-inject-tag -input=./internal/kms/store/audit_key.pb.go @protoc-go-inject-tag -input=./internal/auth/ldap/store/ldap.pb.go + @protoc-go-inject-tag -input=./internal/gen/controller/servers/services/upstream_message_service.pb.go # inject classification tags (see: https://github.com/hashicorp/go-eventlogger/tree/main/filters/encrypt) @protoc-go-inject-tag -input=./internal/gen/controller/api/services/auth_method_service.pb.go diff --git a/internal/daemon/cluster/handlers/options.go b/internal/daemon/cluster/handlers/options.go new file mode 100644 index 000000000..6d6ee1d19 --- /dev/null +++ b/internal/daemon/cluster/handlers/options.go @@ -0,0 +1,36 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package handlers + +import ( + "github.com/hashicorp/nodeenrollment/types" +) + +// getOpts - iterate the inbound Options and return a struct +func getOpts(opt ...Option) options { + opts := getDefaultOptions() + for _, o := range opt { + o(&opts) + } + return opts +} + +// Option - how Options are passed as arguments +type Option func(*options) + +// options = how options are represented +type options struct { + withNodeInfo *types.NodeInformation +} + +func getDefaultOptions() options { + return options{} +} + +// WithNodeInfo provides an option types.NodeInformation +func WithNodeInfo(nodeInfo *types.NodeInformation) Option { + return func(o *options) { + o.withNodeInfo = nodeInfo + } +} diff --git a/internal/daemon/cluster/handlers/testing.go b/internal/daemon/cluster/handlers/testing.go new file mode 100644 index 000000000..94a3e2e5b --- /dev/null +++ b/internal/daemon/cluster/handlers/testing.go @@ -0,0 +1,193 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package handlers + +import ( + "context" + "net" + "sync" + "testing" + + pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services" + "github.com/hashicorp/nodeenrollment" + "github.com/hashicorp/nodeenrollment/registration" + "github.com/hashicorp/nodeenrollment/rotation" + nodeefile "github.com/hashicorp/nodeenrollment/storage/file" + "github.com/hashicorp/nodeenrollment/types" + "github.com/stretchr/testify/require" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/test/bufconn" + "google.golang.org/protobuf/proto" +) + +// TestUpstreamService starts a controller with a downstream worker, which are +// tore down at the end of the test. +// +// Returns a UpstreamMessageServiceClientProducer for the worker, the worker's +// NodeInformation and the worker's KeyId. +func TestUpstreamService(t *testing.T) (UpstreamMessageServiceClientProducer, *types.NodeInformation, string) { + t.Helper() + testCtx := context.Background() + + // Get an initial set of authorized node credentials for the worker that's + // sending upstream requests + initStorage, err := nodeefile.New(testCtx) + require.NoError(t, err) + t.Cleanup(initStorage.Cleanup) + _, err = rotation.RotateRootCertificates(testCtx, initStorage) + require.NoError(t, err) + initNodeCreds, err := types.NewNodeCredentials(testCtx, initStorage) + require.NoError(t, err) + req, err := initNodeCreds.CreateFetchNodeCredentialsRequest(testCtx) + require.NoError(t, err) + _, err = registration.AuthorizeNode(testCtx, initStorage, req) + require.NoError(t, err) + fetchResp, err := registration.FetchNodeCredentials(testCtx, initStorage, req) + require.NoError(t, err) + initNodeCreds, err = initNodeCreds.HandleFetchNodeCredentialsResponse(testCtx, initStorage, fetchResp) + require.NoError(t, err) + initKeyId, err := nodeenrollment.KeyIdFromPkix(initNodeCreds.CertificatePublicKeyPkix) + require.NoError(t, err) + + nodeInfo, err := types.LoadNodeInformation(testCtx, initStorage, initKeyId) + require.NoError(t, err) + + // start an upstream controller + testController, err := newControllerUpstreamMessageServiceServer(testCtx, initStorage) + require.NoError(t, err) + require.NotNil(t, testController) + + controllerClient := pbs.NewUpstreamMessageServiceClient(grpcCCToServer(t, testCtx, testController)) + controllerClientProducer := func(context.Context) (pbs.UpstreamMessageServiceClient, error) { + return controllerClient, nil + } + + // start an upstream worker + testWorker, err := NewWorkerUpstreamMessageServiceServer(testCtx, controllerClientProducer) + require.NoError(t, err) + workerConn := grpcCCToServer(t, testCtx, testWorker) + workerClient := pbs.NewUpstreamMessageServiceClient(workerConn) + + workerClientProducer := func(context.Context) (pbs.UpstreamMessageServiceClient, error) { + return workerClient, nil + } + + return workerClientProducer, nodeInfo, initKeyId +} + +// TestRegisterHandlerFn returns a func that will register a handler for the +// test and then unregister it when the test is complete. This should not be +// used with t.Parallel() since it modifies the registered handlers for the pkg. +func TestRegisterHandlerFn(t *testing.T, msgType pbs.MsgType, h UpstreamMessageHandler) func(*testing.T) { + return func(t *testing.T) { + t.Helper() + testCtx := context.Background() + var cp sync.Map + upstreamMessageHandler.Range(func(k, v interface{}) bool { + cp.Store(k, v) + return true + }) + + require.NoError(t, RegisterUpstreamMessageHandler(testCtx, msgType, h)) + t.Cleanup(func() { + upstreamMessageHandler = cp + }) + } +} + +// TestMockUpstreamMessageHandler provides a test mock handler +type TestMockUpstreamMessageHandler struct { + WantHandlerErr error + WantResp proto.Message +} + +// Handler implements the handler for the mock +func (h *TestMockUpstreamMessageHandler) Handler(ctx context.Context, request proto.Message) (proto.Message, error) { + switch { + case h.WantHandlerErr != nil: + return nil, h.WantHandlerErr + case h.WantResp != nil: + return h.WantResp, nil + default: + return &pbs.EchoUpstreamMessageRequest{ + Msg: request.(*pbs.EchoUpstreamMessageRequest).Msg, + }, nil + } +} + +// Encrypted returns false; since the handler's request/response must be +// encrypted. +func (*TestMockUpstreamMessageHandler) Encrypted() bool { return false } + +// AllocRequest returns an allocated proto for the handler's request. +func (*TestMockUpstreamMessageHandler) AllocRequest() proto.Message { + return new(pbs.EchoUpstreamMessageRequest) +} + +// AllocResponse returns an allocated proto for the handler's response. +func (*TestMockUpstreamMessageHandler) AllocResponse() proto.Message { + return new(pbs.EchoUpstreamMessageResponse) +} + +// TestMockEncryptedUpstreamMessageHandler provides a test mock handler +type TestMockEncryptedUpstreamMessageHandler struct { + WantHandlerErr error + WantResp proto.Message +} + +// Handler implements the handler for the mock +func (h *TestMockEncryptedUpstreamMessageHandler) Handler(ctx context.Context, request proto.Message) (proto.Message, error) { + switch { + case h.WantHandlerErr != nil: + return nil, h.WantHandlerErr + case h.WantResp != nil: + return h.WantResp, nil + default: + return &pbs.EchoUpstreamMessageRequest{ + Msg: request.(*pbs.EchoUpstreamMessageRequest).Msg, + }, nil + } +} + +// Encrypted returns true; since the handler's request/response must be +// encrypted. +func (*TestMockEncryptedUpstreamMessageHandler) Encrypted() bool { return true } + +// AllocRequest returns an allocated proto for the handler's request. +func (*TestMockEncryptedUpstreamMessageHandler) AllocRequest() proto.Message { + return new(pbs.EchoUpstreamMessageRequest) +} + +// AllocResponse returns an allocated proto for the handler's response. +func (*TestMockEncryptedUpstreamMessageHandler) AllocResponse() proto.Message { + return new(pbs.EchoUpstreamMessageResponse) +} + +// grpcCCToServer starts a grpc service that is cleaned up after the test and +// returns a client connection to that service. +func grpcCCToServer(t *testing.T, ctx context.Context, srv pbs.UpstreamMessageServiceServer) *grpc.ClientConn { + t.Helper() + require := require.New(t) + + buffer := 1024 * 1024 + listener := bufconn.Listen(buffer) + + s := grpc.NewServer() + pbs.RegisterUpstreamMessageServiceServer(s, srv) + + go func() { + if err := s.Serve(listener); err != nil { + require.NoError(err) + } + }() + + conn, err := grpc.DialContext(ctx, "", grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { + return listener.Dial() + }), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + require.NoError(err) + + t.Cleanup(func() { s.Stop() }) + return conn +} diff --git a/internal/daemon/cluster/handlers/upstream_message_service_controller.go b/internal/daemon/cluster/handlers/upstream_message_service_controller.go new file mode 100644 index 000000000..dc07f68c7 --- /dev/null +++ b/internal/daemon/cluster/handlers/upstream_message_service_controller.go @@ -0,0 +1,181 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package handlers + +import ( + "context" + "fmt" + "sync" + + "github.com/hashicorp/boundary/internal/errors" + pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services" + "github.com/hashicorp/boundary/internal/observability/event" + "github.com/hashicorp/boundary/internal/util" + "github.com/hashicorp/nodeenrollment" + "github.com/hashicorp/nodeenrollment/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +var upstreamMessageHandler sync.Map + +// UpstreamMessageHandler defines a handler for an UpstreamMessageRequest(s). +// +// See controllerUpstreamMessageServiceServer.UpstreamMessage for how this is +// used to handle an UpstreamMessageRequest via registered upstream message +// handlers. +type UpstreamMessageHandler interface { + // Handler for the request. All errors returned must be a error created + // using google.golang.org/grpc/status + Handler(ctx context.Context, request proto.Message) (response proto.Message, statusErr error) + + // Encrypted returns true if the handler request/response should be encrypted + Encrypted() bool + + // AllocRequest will allocate handler specific request proto message + AllocRequest() proto.Message + + // AllocResponse will allocate a handler specific response proto message + AllocResponse() proto.Message +} + +// RegisterUpstreamMessageHandler will register an UpstreamMessageHandler for +// the specified msg name. +// +// See controllerUpstreamMessageServiceServer.UpstreamMessage for how this is +// used to handle an UpstreamMessageRequest via registered upstream message +// handlers. +func RegisterUpstreamMessageHandler(ctx context.Context, msgType pbs.MsgType, h UpstreamMessageHandler) error { + const op = "handlers.RegisterUpstreamMessageHandler" + switch { + case msgType == pbs.MsgType_MSG_TYPE_UNSPECIFIED: + return errors.New(ctx, errors.InvalidParameter, op, "missing msg type") + case util.IsNil(h): + return errors.New(ctx, errors.InvalidParameter, op, "missing handler") + } + if _, loaded := upstreamMessageHandler.LoadOrStore(msgType, h); loaded { + return errors.New(ctx, errors.InvalidParameter, op, "handler already registered for msg type") + } + + return nil +} + +func getUpstreamMessageHandler(ctx context.Context, msgType pbs.MsgType) (UpstreamMessageHandler, bool) { + const op = "handlers.getUpstreamMessageHandler" + switch { + case msgType == pbs.MsgType_MSG_TYPE_UNSPECIFIED: + event.WriteError(ctx, op, fmt.Errorf("missing msg type")) + return nil, false + } + v, ok := upstreamMessageHandler.Load(msgType) + if !ok { + return nil, false + } + + h, ok := v.(UpstreamMessageHandler) + if !ok { + event.WriteError(ctx, op, fmt.Errorf("malformed handler type %q registered as incorrect type %T", msgType.String(), v)) + return nil, false + } + return h, true +} + +// controllerUpstreamMessageServiceServer implements the +// UpstreamMessageServiceServer for OSS controllers +type controllerUpstreamMessageServiceServer struct { + pbs.UnimplementedUpstreamMessageServiceServer + storage nodeenrollment.Storage +} + +var _ pbs.UpstreamMessageServiceServer = (*controllerUpstreamMessageServiceServer)(nil) + +// newControllerUpstreamMessageServiceServer creates a new service implementing +// UpstreamMessageServiceServer, storing values used for the implementing +// functions. +func newControllerUpstreamMessageServiceServer( + ctx context.Context, + storage nodeenrollment.Storage, +) (pbs.UpstreamMessageServiceServer, error) { + const op = "handlers.NewControllerUpstreamMessageServiceServer" + switch { + case util.IsNil(storage): + return nil, errors.New(ctx, errors.InvalidParameter, op, "missing storage") + } + + return &controllerUpstreamMessageServiceServer{ + storage: storage, + }, nil +} + +// UpstreamMessage implements the grpc service of the same name for controllers. +// It decrypts the request using the originating workers ID using its +// types.NodeCredentials. If there's a registered UpstreamMessageHandler for the +// underlying message's protoreflect.FullName; then the msg is handled by the +// handler otherwise an codes.Unimplemented status error is returned +func (s *controllerUpstreamMessageServiceServer) UpstreamMessage(ctx context.Context, req *pbs.UpstreamMessageRequest) (*pbs.UpstreamMessageResponse, error) { + const op = "handlers.(controllerUpstreamMessageServiceServer).UpstreamMessage" + switch { + case req == nil: + return nil, status.Errorf(codes.Internal, "%s: missing request", op) + case req.GetOriginatingWorkerKeyId() == "": + return nil, status.Errorf(codes.Internal, "%s: missing originating worker id", op) + case req.GetMsgType() == pbs.MsgType_MSG_TYPE_UNSPECIFIED: + return nil, status.Errorf(codes.Internal, "%s: msg type %q is unsupported", op, req.GetMsgType().String()) + } + + h, ok := getUpstreamMessageHandler(ctx, req.GetMsgType()) + if !ok { + return nil, status.Errorf(codes.Unimplemented, "upstream message handler for %q is not implemented", req.GetMsgType().String()) + } + + msg := h.AllocRequest() + var nodeInfo *types.NodeInformation + + switch { + case h.Encrypted() == false: + if err := proto.Unmarshal(req.GetPt(), msg); err != nil { + return nil, status.Errorf(codes.Internal, "%s: error marshaling request message: %v", op, err) + } + default: + var err error + nodeInfo, err = types.LoadNodeInformation(ctx, s.storage, req.OriginatingWorkerKeyId) + if err != nil { + return nil, status.Errorf(codes.Internal, "%s: error loading node information: %v", op, err) + } + if nodeInfo == nil { + return nil, status.Errorf(codes.Internal, "%s: no error loading worker pki auth creds but nil creds, returning error", op) + } + if err := nodeenrollment.DecryptMessage(ctx, req.GetCt(), nodeInfo, msg); err != nil { + return nil, status.Errorf(codes.Internal, "%s: error decrypting request message: %v", op, err) + } + } + + respMsg, respStatusErr := h.Handler(ctx, msg) + if respStatusErr != nil { + return nil, respStatusErr + } + switch { + case h.Encrypted() == false: + pt, err := proto.Marshal(respMsg) + if err != nil { + return nil, status.Errorf(codes.Internal, "%s: error marshaling response: %v", op, err) + } + return &pbs.UpstreamMessageResponse{ + Message: &pbs.UpstreamMessageResponse_Pt{ + Pt: pt, + }, + }, nil + default: + ct, err := nodeenrollment.EncryptMessage(ctx, respMsg, nodeInfo) + if err != nil { + return nil, status.Errorf(codes.Internal, "%s: error encrypting response: %v", op, err) + } + return &pbs.UpstreamMessageResponse{ + Message: &pbs.UpstreamMessageResponse_Ct{ + Ct: ct, + }, + }, nil + } +} diff --git a/internal/daemon/cluster/handlers/upstream_message_service_test.go b/internal/daemon/cluster/handlers/upstream_message_service_test.go new file mode 100644 index 000000000..da1c077e5 --- /dev/null +++ b/internal/daemon/cluster/handlers/upstream_message_service_test.go @@ -0,0 +1,422 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package handlers + +import ( + "context" + "fmt" + "sync" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/hashicorp/boundary/internal/errors" + pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services" + "github.com/hashicorp/nodeenrollment" + "github.com/hashicorp/nodeenrollment/registration" + "github.com/hashicorp/nodeenrollment/rotation" + nodeefile "github.com/hashicorp/nodeenrollment/storage/file" + "github.com/hashicorp/nodeenrollment/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/testing/protocmp" +) + +func Test_RegisterUpstreamMessageHandler(t *testing.T) { + // IMPORTANT: cannot run with t.Parallel() because it operates on the + // handlers pkg state. + testCtx := context.Background() + tests := []struct { + name string + msgType pbs.MsgType + h UpstreamMessageHandler + wantErr bool + wantErrMatch *errors.Template + wantErrContains string + }{ + { + name: "missing-msg-type", + h: &TestMockUpstreamMessageHandler{}, + wantErr: true, + wantErrMatch: errors.T(errors.InvalidParameter), + wantErrContains: "missing msg type", + }, + { + name: "missing-handler", + msgType: pbs.MsgType_MSG_TYPE_ECHO, + wantErr: true, + wantErrMatch: errors.T(errors.InvalidParameter), + wantErrContains: "missing handler", + }, + { + name: "success", + msgType: pbs.MsgType_MSG_TYPE_ECHO, + h: &TestMockUpstreamMessageHandler{}, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + assert, require := assert.New(t), require.New(t) + var cp sync.Map + upstreamMessageHandler.Range(func(k, v interface{}) bool { + cp.Store(k, v) + return true + }) + err := RegisterUpstreamMessageHandler(testCtx, tc.msgType, tc.h) + t.Cleanup(func() { + upstreamMessageHandler = cp + }) + if tc.wantErr { + require.Error(err) + if tc.wantErrMatch != nil { + assert.Truef(errors.Match(tc.wantErrMatch, err), "unexpected error: %q", err.Error()) + } + if tc.wantErrContains != "" { + assert.Contains(err.Error(), tc.wantErrContains) + } + return + } + require.NoError(err) + _, ok := getUpstreamMessageHandler(testCtx, tc.msgType) + assert.True(ok) + }) + } +} + +func Test_controllerUpstreamMessageServiceServer_UpstreamMessage(t *testing.T) { + // IMPORTANT: cannot run with t.Parallel() because it operates on the + // handlers pkg state. + + testCtx := context.Background() + + // Get an initial set of authorized node credentials + initStorage, err := nodeefile.New(testCtx) + require.NoError(t, err) + t.Cleanup(initStorage.Cleanup) + _, err = rotation.RotateRootCertificates(testCtx, initStorage) + require.NoError(t, err) + initNodeCreds, err := types.NewNodeCredentials(testCtx, initStorage) + require.NoError(t, err) + req, err := initNodeCreds.CreateFetchNodeCredentialsRequest(testCtx) + require.NoError(t, err) + _, err = registration.AuthorizeNode(testCtx, initStorage, req) + require.NoError(t, err) + fetchResp, err := registration.FetchNodeCredentials(testCtx, initStorage, req) + require.NoError(t, err) + initNodeCreds, err = initNodeCreds.HandleFetchNodeCredentialsResponse(testCtx, initStorage, fetchResp) + require.NoError(t, err) + initKeyId, err := nodeenrollment.KeyIdFromPkix(initNodeCreds.CertificatePublicKeyPkix) + require.NoError(t, err) + nodeInfo, err := types.LoadNodeInformation(testCtx, initStorage, initKeyId) + require.NoError(t, err) + // define a test controller + testController, err := newControllerUpstreamMessageServiceServer(testCtx, initStorage) + require.NoError(t, err) + require.NotNil(t, testController) + + tests := []struct { + name string + controllerServer pbs.UpstreamMessageServiceServer + setupHandlers func(t *testing.T) + req *pbs.UpstreamMessageRequest + wantErr bool + wantErrContains string + }{ + { + name: "success-echo-unencrypted", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + OriginatingWorkerKeyId: initKeyId, + MsgType: pbs.MsgType_MSG_TYPE_ECHO, + Message: func() *pbs.UpstreamMessageRequest_Pt { + pt, err := proto.Marshal(&pbs.EchoUpstreamMessageRequest{Msg: "ping"}) + require.NoError(t, err) + return &pbs.UpstreamMessageRequest_Pt{Pt: pt} + }(), + }, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, &TestMockUpstreamMessageHandler{}), + }, + { + name: "unimplemented", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + OriginatingWorkerKeyId: initKeyId, + MsgType: pbs.MsgType_MSG_TYPE_UNSPECIFIED, + Message: func() *pbs.UpstreamMessageRequest_Pt { + return &pbs.UpstreamMessageRequest_Pt{Pt: []byte("Unimplemented.")} + }(), + }, + wantErr: true, + wantErrContains: "msg type \"MSG_TYPE_UNSPECIFIED\" is unsupported", + }, + { + name: "missing-originating-worker-id", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + MsgType: pbs.MsgType_MSG_TYPE_ECHO, + Message: func() *pbs.UpstreamMessageRequest_Pt { + pt, err := proto.Marshal(&pbs.EchoUpstreamMessageRequest{Msg: "ping"}) + require.NoError(t, err) + return &pbs.UpstreamMessageRequest_Pt{Pt: pt} + }(), + }, + wantErr: true, + wantErrContains: "missing originating worker id", + }, + { + name: "unsupported-msg-type", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + OriginatingWorkerKeyId: initKeyId, + MsgType: pbs.MsgType_MSG_TYPE_UNSPECIFIED, + Message: func() *pbs.UpstreamMessageRequest_Pt { + pt, err := proto.Marshal(&pbs.EchoUpstreamMessageRequest{Msg: "ping"}) + require.NoError(t, err) + return &pbs.UpstreamMessageRequest_Pt{Pt: pt} + }(), + }, + wantErr: true, + wantErrContains: "msg type \"MSG_TYPE_UNSPECIFIED\" is unsupported", + }, + { + name: "invalid-originating-worker-id", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + OriginatingWorkerKeyId: "bad-id", + MsgType: pbs.MsgType_MSG_TYPE_ECHO, + Message: func() *pbs.UpstreamMessageRequest_Ct { + r := &pbs.EchoUpstreamMessageRequest{Msg: "ping"} + ct, err := nodeenrollment.EncryptMessage(testCtx, r, nodeInfo) + require.NoError(t, err) + return &pbs.UpstreamMessageRequest_Ct{Ct: ct} + }(), + }, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, &TestMockEncryptedUpstreamMessageHandler{}), + wantErr: true, + wantErrContains: "error loading node information", + }, + { + name: "invalid-unencrypted-msg", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + OriginatingWorkerKeyId: initKeyId, + MsgType: pbs.MsgType_MSG_TYPE_ECHO, + Message: &pbs.UpstreamMessageRequest_Pt{Pt: []byte("not-a-proto")}, + }, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, &TestMockUpstreamMessageHandler{}), + wantErr: true, + wantErrContains: "error marshaling request message", + }, + { + name: "invalid-encrypted-msg", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + OriginatingWorkerKeyId: initKeyId, + MsgType: pbs.MsgType_MSG_TYPE_ECHO, + Message: &pbs.UpstreamMessageRequest_Ct{Ct: []byte("not-an-encrypted-proto")}, + }, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, &TestMockEncryptedUpstreamMessageHandler{}), + wantErr: true, + wantErrContains: "error decrypting request message", + }, + { + name: "message-handler-not-implemented", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + OriginatingWorkerKeyId: initKeyId, + MsgType: -1, + Message: &pbs.UpstreamMessageRequest_Ct{Ct: []byte("not-an-encrypted-proto")}, + }, + wantErr: true, + wantErrContains: "Unimplemented desc = upstream message handler for \"-1\" is not implemented", + }, + { + name: "success-echo-unencrypted", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + OriginatingWorkerKeyId: initKeyId, + MsgType: pbs.MsgType_MSG_TYPE_ECHO, + Message: func() *pbs.UpstreamMessageRequest_Pt { + pt, err := proto.Marshal(&pbs.EchoUpstreamMessageRequest{Msg: "ping"}) + require.NoError(t, err) + return &pbs.UpstreamMessageRequest_Pt{Pt: pt} + }(), + }, + // intentionally, no setupHandlers + wantErr: true, + wantErrContains: "upstream message handler for \"MSG_TYPE_ECHO\" is not implemented", + }, + { + name: "fail-echo-unencrypted", + controllerServer: testController, + req: &pbs.UpstreamMessageRequest{ + OriginatingWorkerKeyId: initKeyId, + MsgType: pbs.MsgType_MSG_TYPE_ECHO, + Message: func() *pbs.UpstreamMessageRequest_Pt { + pt, err := proto.Marshal(&pbs.EchoUpstreamMessageRequest{Msg: "ping"}) + require.NoError(t, err) + return &pbs.UpstreamMessageRequest_Pt{Pt: pt} + }(), + }, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, &TestMockUpstreamMessageHandler{WantHandlerErr: fmt.Errorf("fail-echo-unencrypted")}), + wantErr: true, + wantErrContains: "rpc error: code = Unknown desc = fail-echo-unencrypted", + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + assert, require := assert.New(t), require.New(t) + controllerClient := pbs.NewUpstreamMessageServiceClient(grpcCCToServer(t, testCtx, tc.controllerServer)) + if tc.setupHandlers != nil { + tc.setupHandlers(t) + } + + gotResp, err := controllerClient.UpstreamMessage(testCtx, tc.req) + if tc.wantErr { + require.Error(err) + assert.Nil(gotResp) + assert.Contains(err.Error(), tc.wantErrContains) + return + } + require.NoError(err) + require.NotNil(gotResp) + }) + } +} + +func Test_SendUpstreamMessage(t *testing.T) { + // IMPORTANT: cannot run with t.Parallel() because it operates on the + // handlers pkg state. + testCtx := context.Background() + workerClientProducer, workerNodeInfo, originatingWorkerId := TestUpstreamService(t) + testHandler := &TestMockUpstreamMessageHandler{} + testEncryptedHandler := &TestMockEncryptedUpstreamMessageHandler{} + + tests := []struct { + name string + setupHandlers func(t *testing.T) + clientProducer UpstreamMessageServiceClientProducer + originatingWorkerId string + req proto.Message + opt []Option + wantResp proto.Message + wantErr bool + wantErrContains string + }{ + { + name: "success-echo-unencrypted", + clientProducer: workerClientProducer, + originatingWorkerId: originatingWorkerId, + req: &pbs.EchoUpstreamMessageRequest{Msg: "ping"}, + wantResp: &pbs.EchoUpstreamMessageResponse{Msg: "ping"}, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, testHandler), + }, + { + name: "success-echo-encrypted", + clientProducer: workerClientProducer, + originatingWorkerId: originatingWorkerId, + req: &pbs.EchoUpstreamMessageRequest{Msg: "ping"}, + opt: []Option{WithNodeInfo(workerNodeInfo)}, + wantResp: &pbs.EchoUpstreamMessageResponse{Msg: "ping"}, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, testEncryptedHandler), + }, + { + name: "missing-client-producer", + originatingWorkerId: originatingWorkerId, + req: &pbs.EchoUpstreamMessageRequest{Msg: "ping"}, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, testHandler), + wantErr: true, + wantErrContains: "missing client producer", + }, + { + name: "missing-originating-worker-id", + clientProducer: workerClientProducer, + req: &pbs.EchoUpstreamMessageRequest{Msg: "ping"}, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, testHandler), + wantErr: true, + wantErrContains: "missing originating worker key id", + }, + { + name: "missing-req", + clientProducer: workerClientProducer, + originatingWorkerId: originatingWorkerId, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, testHandler), + wantErr: true, + wantErrContains: "missing message", + }, + { + name: "invalid-msg-type", + clientProducer: workerClientProducer, + originatingWorkerId: originatingWorkerId, + req: &pbs.CommandRequest{}, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, testHandler), + wantErr: true, + wantErrContains: "\"\" is an unknown msg type", + }, + { + name: "no-registered-handler", + clientProducer: workerClientProducer, + originatingWorkerId: originatingWorkerId, + req: &pbs.EchoUpstreamMessageRequest{Msg: "ping"}, + wantErr: true, + wantErrContains: "upstream message handler for \"MSG_TYPE_ECHO\" is not implemented", + }, + { + name: "no-registered-handler", + clientProducer: workerClientProducer, + originatingWorkerId: originatingWorkerId, + req: &pbs.EchoUpstreamMessageRequest{Msg: "ping"}, + wantErr: true, + wantErrContains: "upstream message handler for \"MSG_TYPE_ECHO\" is not implemented", + }, + { + name: "missing-node-info", + clientProducer: workerClientProducer, + originatingWorkerId: originatingWorkerId, + req: &pbs.EchoUpstreamMessageRequest{Msg: "ping"}, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, testEncryptedHandler), + wantErr: true, + wantErrContains: "missing node information required for encrypting unwrap keys message", + }, + { + name: "client-producer-err", + clientProducer: func(context.Context) (pbs.UpstreamMessageServiceClient, error) { + return nil, fmt.Errorf("client-producer-err") + }, + originatingWorkerId: originatingWorkerId, + req: &pbs.EchoUpstreamMessageRequest{Msg: "ping"}, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, testHandler), + wantErr: true, + wantErrContains: "error getting a client producer", + }, + { + name: "upstream-err", + clientProducer: workerClientProducer, + originatingWorkerId: originatingWorkerId, + req: &pbs.EchoUpstreamMessageRequest{Msg: "ping"}, + setupHandlers: TestRegisterHandlerFn(t, pbs.MsgType_MSG_TYPE_ECHO, &TestMockUpstreamMessageHandler{WantHandlerErr: fmt.Errorf("upstream-err")}), + wantErr: true, + wantErrContains: "error from upstream client", + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + assert, require := assert.New(t), require.New(t) + + if tc.setupHandlers != nil { + tc.setupHandlers(t) + } + gotResp, err := SendUpstreamMessage(testCtx, tc.clientProducer, tc.originatingWorkerId, tc.req, tc.opt...) + if tc.wantErr { + require.Error(err) + assert.Nil(gotResp) + assert.Contains(err.Error(), tc.wantErrContains) + return + } + require.NoError(err) + require.NotNil(gotResp) + assert.Empty(cmp.Diff(gotResp, tc.wantResp, protocmp.Transform())) + }) + } +} diff --git a/internal/daemon/cluster/handlers/upstream_message_service_worker.go b/internal/daemon/cluster/handlers/upstream_message_service_worker.go new file mode 100644 index 000000000..43ca5b343 --- /dev/null +++ b/internal/daemon/cluster/handlers/upstream_message_service_worker.go @@ -0,0 +1,174 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package handlers + +import ( + "context" + "fmt" + + "github.com/hashicorp/boundary/internal/errors" + pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services" + "github.com/hashicorp/boundary/internal/util" + "github.com/hashicorp/nodeenrollment" + "github.com/hashicorp/nodeenrollment/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// UpstreamMessageServiceClientProducer produces a client and should be +// self-healing if an existing grpc connection closes. +type UpstreamMessageServiceClientProducer func(context.Context) (pbs.UpstreamMessageServiceClient, error) + +// workerUpstreamMessageServiceServer implements the +// SessionRecordingServiceServer for workers and always forwards requests using +// its clients +type workerUpstreamMessageServiceServer struct { + pbs.UnimplementedUpstreamMessageServiceServer + clientProducer UpstreamMessageServiceClientProducer +} + +var _ pbs.UpstreamMessageServiceServer = (*workerUpstreamMessageServiceServer)(nil) + +// NewWorkerUpstreamMessageServiceServer creates a new service implementing +// UpstreamMessageServiceServer, storing values used for the implementing +// functions. +func NewWorkerUpstreamMessageServiceServer( + ctx context.Context, + clientProducer UpstreamMessageServiceClientProducer, +) (*workerUpstreamMessageServiceServer, error) { + const op = "handlers.NewWorkerUpstreamMessageServiceServer" + switch { + case clientProducer == nil: + return nil, errors.New(ctx, errors.InvalidParameter, op, "missing client producer") + } + + return &workerUpstreamMessageServiceServer{ + clientProducer: clientProducer, + }, nil +} + +// UpstreamMessage implements the grpc service of the same name for workers and +// simply forwards the request using its client +func (s *workerUpstreamMessageServiceServer) UpstreamMessage(ctx context.Context, req *pbs.UpstreamMessageRequest) (*pbs.UpstreamMessageResponse, error) { + const op = "handlers.(workerUpstreamMessageServiceServer).UpstreamMessage" + switch { + case req == nil: + return nil, status.Errorf(codes.Internal, "%s: missing request", op) + } + c, err := s.clientProducer(ctx) + if err != nil { + return nil, status.Errorf(codes.Internal, "%s: unable to get client: %v", op, err) + } + return c.UpstreamMessage(ctx, req) +} + +func SendUpstreamMessage(ctx context.Context, clientProducer UpstreamMessageServiceClientProducer, originatingWorkerKeyId string, msg proto.Message, opt ...Option) (proto.Message, error) { + const op = "handlers.SendUpstreamMessage" + switch { + case clientProducer == nil: + return nil, status.Errorf(codes.Internal, "%s: missing client producer", op) + case originatingWorkerKeyId == "": + return nil, status.Errorf(codes.Internal, "%s: missing originating worker key id", op) + case util.IsNil(msg): + return nil, status.Errorf(codes.Internal, "%s: missing message", op) + } + opts := getOpts(opt...) + + msgType, err := toMsgType(ctx, msg) + if err != nil { + return nil, status.Errorf(codes.Internal, "%s: %v", op, err) + } + h, ok := getUpstreamMessageHandler(ctx, msgType) + if !ok { + return nil, status.Errorf(codes.Unimplemented, "upstream message handler for %q is not implemented", msgType.String()) + } + + var req *pbs.UpstreamMessageRequest + switch { + case h.Encrypted() == false: + req, err = ptMsg(ctx, msgType, msg) + if err != nil { + return nil, errors.Wrap(ctx, err, op) + } + default: + if opts.withNodeInfo == nil { + return nil, errors.New(ctx, errors.InvalidParameter, op, "missing node information required for encrypting unwrap keys message") + } + req, err = ctMsg(ctx, opts.withNodeInfo, msgType, msg) + if err != nil { + return nil, errors.Wrap(ctx, err, op) + } + } + + req.OriginatingWorkerKeyId = originatingWorkerKeyId + + c, err := clientProducer(ctx) + if err != nil { + return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error getting a client producer")) + } + + rawResp, err := c.UpstreamMessage(ctx, req) + if err != nil { + return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error from upstream client")) + } + + switch { + case h.Encrypted() == false: + pt := h.AllocResponse() + if err := proto.Unmarshal(rawResp.GetPt(), pt); err != nil { + return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error marshaling echo request")) + } + return pt, nil + default: + ct := h.AllocResponse() + if err := nodeenrollment.DecryptMessage(ctx, rawResp.GetCt(), opts.withNodeInfo, ct); err != nil { + return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error decrypting unwrap keys response")) + } + return ct, nil + } +} + +func ptMsg(ctx context.Context, msgType pbs.MsgType, msg proto.Message) (*pbs.UpstreamMessageRequest, error) { + const op = "handlers.ptMsg" + + pt, err := proto.Marshal(msg) + if err != nil { + return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error marshaling upstream message")) + } + return &pbs.UpstreamMessageRequest{ + MsgType: msgType, + Message: &pbs.UpstreamMessageRequest_Pt{ + Pt: pt, + }, + }, nil +} + +func ctMsg(ctx context.Context, nodeInfo *types.NodeInformation, msgType pbs.MsgType, msg proto.Message) (*pbs.UpstreamMessageRequest, error) { + const op = "handlers.encryptMsg" + ct, err := nodeenrollment.EncryptMessage(ctx, msg, nodeInfo) + if err != nil { + return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error encrypting upstream message")) + } + return &pbs.UpstreamMessageRequest{ + MsgType: msgType, + Message: &pbs.UpstreamMessageRequest_Ct{ + Ct: ct, + }, + }, nil +} + +func toMsgType(ctx context.Context, m proto.Message) (pbs.MsgType, error) { + const op = "handlers.toMsgType" + switch t := m.(type) { + case *pbs.EchoUpstreamMessageRequest, *pbs.EchoUpstreamMessageResponse: + return pbs.MsgType_MSG_TYPE_ECHO, nil + case *pbs.UnwrapKeysRequest, *pbs.UnwrapKeysResponse: + return pbs.MsgType_MSG_TYPE_UNWRAP_KEYS, nil + case *pbs.VerifySignatureRequest, *pbs.VerifySignatureResponse: + return pbs.MsgType_MSG_TYPE_VERIFY_SIGNATURE, nil + default: + return pbs.MsgType_MSG_TYPE_UNSPECIFIED, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("%q is an unknown msg type", t)) + } +} diff --git a/internal/gen/controller/servers/services/upstream_message_service.pb.go b/internal/gen/controller/servers/services/upstream_message_service.pb.go new file mode 100644 index 000000000..b783e4b74 --- /dev/null +++ b/internal/gen/controller/servers/services/upstream_message_service.pb.go @@ -0,0 +1,539 @@ +// Copyright (c) HashiCorp, Inc. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.30.0 +// protoc (unknown) +// source: controller/servers/services/v1/upstream_message_service.proto + +package services + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// defines the set of unknown message types +type MsgType int32 + +const ( + MsgType_MSG_TYPE_UNSPECIFIED MsgType = 0 + MsgType_MSG_TYPE_ECHO MsgType = 1 // currently this only used for testing. + MsgType_MSG_TYPE_UNWRAP_KEYS MsgType = 2 + MsgType_MSG_TYPE_VERIFY_SIGNATURE MsgType = 3 +) + +// Enum value maps for MsgType. +var ( + MsgType_name = map[int32]string{ + 0: "MSG_TYPE_UNSPECIFIED", + 1: "MSG_TYPE_ECHO", + 2: "MSG_TYPE_UNWRAP_KEYS", + 3: "MSG_TYPE_VERIFY_SIGNATURE", + } + MsgType_value = map[string]int32{ + "MSG_TYPE_UNSPECIFIED": 0, + "MSG_TYPE_ECHO": 1, + "MSG_TYPE_UNWRAP_KEYS": 2, + "MSG_TYPE_VERIFY_SIGNATURE": 3, + } +) + +func (x MsgType) Enum() *MsgType { + p := new(MsgType) + *p = x + return p +} + +func (x MsgType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (MsgType) Descriptor() protoreflect.EnumDescriptor { + return file_controller_servers_services_v1_upstream_message_service_proto_enumTypes[0].Descriptor() +} + +func (MsgType) Type() protoreflect.EnumType { + return &file_controller_servers_services_v1_upstream_message_service_proto_enumTypes[0] +} + +func (x MsgType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use MsgType.Descriptor instead. +func (MsgType) EnumDescriptor() ([]byte, []int) { + return file_controller_servers_services_v1_upstream_message_service_proto_rawDescGZIP(), []int{0} +} + +type UpstreamMessageRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // the node credentials key id for the worker originated the request + OriginatingWorkerKeyId string `protobuf:"bytes,10,opt,name=originating_worker_key_id,json=originatingWorkerKeyId,proto3" json:"originating_worker_key_id,omitempty" class:"public"` // @gotags: `class:"public" + // the type of the encrypted_message which must have a + // RegisterUpstreamMessageHandler or codesUnimplemented will be returned + MsgType MsgType `protobuf:"varint,20,opt,name=msg_type,json=msgType,proto3,enum=controller.servers.services.v1.MsgType" json:"msg_type,omitempty"` + // message will either be encrypted (ct) or plaintext (pt) based on its + // msg_type + // + // Types that are assignable to Message: + // + // *UpstreamMessageRequest_Ct + // *UpstreamMessageRequest_Pt + Message isUpstreamMessageRequest_Message `protobuf_oneof:"message"` +} + +func (x *UpstreamMessageRequest) Reset() { + *x = UpstreamMessageRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpstreamMessageRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpstreamMessageRequest) ProtoMessage() {} + +func (x *UpstreamMessageRequest) ProtoReflect() protoreflect.Message { + mi := &file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpstreamMessageRequest.ProtoReflect.Descriptor instead. +func (*UpstreamMessageRequest) Descriptor() ([]byte, []int) { + return file_controller_servers_services_v1_upstream_message_service_proto_rawDescGZIP(), []int{0} +} + +func (x *UpstreamMessageRequest) GetOriginatingWorkerKeyId() string { + if x != nil { + return x.OriginatingWorkerKeyId + } + return "" +} + +func (x *UpstreamMessageRequest) GetMsgType() MsgType { + if x != nil { + return x.MsgType + } + return MsgType_MSG_TYPE_UNSPECIFIED +} + +func (m *UpstreamMessageRequest) GetMessage() isUpstreamMessageRequest_Message { + if m != nil { + return m.Message + } + return nil +} + +func (x *UpstreamMessageRequest) GetCt() []byte { + if x, ok := x.GetMessage().(*UpstreamMessageRequest_Ct); ok { + return x.Ct + } + return nil +} + +func (x *UpstreamMessageRequest) GetPt() []byte { + if x, ok := x.GetMessage().(*UpstreamMessageRequest_Pt); ok { + return x.Pt + } + return nil +} + +type isUpstreamMessageRequest_Message interface { + isUpstreamMessageRequest_Message() +} + +type UpstreamMessageRequest_Ct struct { + // the encrypted upstream message. This message is encrypted with the + // originating worker's types.NodeCredentials. + Ct []byte `protobuf:"bytes,30,opt,name=ct,proto3,oneof" class:"secret"` // @gotags: `class:"secret" +} + +type UpstreamMessageRequest_Pt struct { + // the plaintext upstream message. + Pt []byte `protobuf:"bytes,40,opt,name=pt,proto3,oneof" class:"public"` // @gotags: `class:"public" +} + +func (*UpstreamMessageRequest_Ct) isUpstreamMessageRequest_Message() {} + +func (*UpstreamMessageRequest_Pt) isUpstreamMessageRequest_Message() {} + +type UpstreamMessageResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // the encryped response message. This message is encrypted with the + // originating worker's types.NodeCredentials. + // message will either be encrypted (ct) or plaintext (pt) based on its + // msg_type + // + // Types that are assignable to Message: + // + // *UpstreamMessageResponse_Ct + // *UpstreamMessageResponse_Pt + Message isUpstreamMessageResponse_Message `protobuf_oneof:"message"` +} + +func (x *UpstreamMessageResponse) Reset() { + *x = UpstreamMessageResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpstreamMessageResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpstreamMessageResponse) ProtoMessage() {} + +func (x *UpstreamMessageResponse) ProtoReflect() protoreflect.Message { + mi := &file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpstreamMessageResponse.ProtoReflect.Descriptor instead. +func (*UpstreamMessageResponse) Descriptor() ([]byte, []int) { + return file_controller_servers_services_v1_upstream_message_service_proto_rawDescGZIP(), []int{1} +} + +func (m *UpstreamMessageResponse) GetMessage() isUpstreamMessageResponse_Message { + if m != nil { + return m.Message + } + return nil +} + +func (x *UpstreamMessageResponse) GetCt() []byte { + if x, ok := x.GetMessage().(*UpstreamMessageResponse_Ct); ok { + return x.Ct + } + return nil +} + +func (x *UpstreamMessageResponse) GetPt() []byte { + if x, ok := x.GetMessage().(*UpstreamMessageResponse_Pt); ok { + return x.Pt + } + return nil +} + +type isUpstreamMessageResponse_Message interface { + isUpstreamMessageResponse_Message() +} + +type UpstreamMessageResponse_Ct struct { + // the encrypted upstream message. This message is encrypted with the + // originating worker's types.NodeCredentials. + Ct []byte `protobuf:"bytes,10,opt,name=ct,proto3,oneof" class:"secret"` // @gotags: `class:"secret" +} + +type UpstreamMessageResponse_Pt struct { + // the plaintext upstream message. + Pt []byte `protobuf:"bytes,20,opt,name=pt,proto3,oneof" class:"public"` // @gotags: `class:"public" +} + +func (*UpstreamMessageResponse_Ct) isUpstreamMessageResponse_Message() {} + +func (*UpstreamMessageResponse_Pt) isUpstreamMessageResponse_Message() {} + +type EchoUpstreamMessageRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Msg string `protobuf:"bytes,10,opt,name=msg,proto3" json:"msg,omitempty" class:"secret"` // @gotags: `class:"secret" +} + +func (x *EchoUpstreamMessageRequest) Reset() { + *x = EchoUpstreamMessageRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EchoUpstreamMessageRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EchoUpstreamMessageRequest) ProtoMessage() {} + +func (x *EchoUpstreamMessageRequest) ProtoReflect() protoreflect.Message { + mi := &file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EchoUpstreamMessageRequest.ProtoReflect.Descriptor instead. +func (*EchoUpstreamMessageRequest) Descriptor() ([]byte, []int) { + return file_controller_servers_services_v1_upstream_message_service_proto_rawDescGZIP(), []int{2} +} + +func (x *EchoUpstreamMessageRequest) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + +type EchoUpstreamMessageResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Msg string `protobuf:"bytes,10,opt,name=msg,proto3" json:"msg,omitempty" class:"secret"` // @gotags: `class:"secret" +} + +func (x *EchoUpstreamMessageResponse) Reset() { + *x = EchoUpstreamMessageResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EchoUpstreamMessageResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EchoUpstreamMessageResponse) ProtoMessage() {} + +func (x *EchoUpstreamMessageResponse) ProtoReflect() protoreflect.Message { + mi := &file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EchoUpstreamMessageResponse.ProtoReflect.Descriptor instead. +func (*EchoUpstreamMessageResponse) Descriptor() ([]byte, []int) { + return file_controller_servers_services_v1_upstream_message_service_proto_rawDescGZIP(), []int{3} +} + +func (x *EchoUpstreamMessageResponse) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + +var File_controller_servers_services_v1_upstream_message_service_proto protoreflect.FileDescriptor + +var file_controller_servers_services_v1_upstream_message_service_proto_rawDesc = []byte{ + 0x0a, 0x3d, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x73, 0x65, 0x72, + 0x76, 0x65, 0x72, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x76, 0x31, + 0x2f, 0x75, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x1e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x73, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x22, + 0xc6, 0x01, 0x0a, 0x16, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x39, 0x0a, 0x19, 0x6f, 0x72, + 0x69, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x77, 0x6f, 0x72, 0x6b, 0x65, 0x72, + 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x16, 0x6f, + 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, + 0x4b, 0x65, 0x79, 0x49, 0x64, 0x12, 0x42, 0x0a, 0x08, 0x6d, 0x73, 0x67, 0x5f, 0x74, 0x79, 0x70, + 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x27, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, + 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x2e, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, + 0x52, 0x07, 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x02, 0x63, 0x74, 0x18, + 0x1e, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x02, 0x63, 0x74, 0x12, 0x10, 0x0a, 0x02, 0x70, + 0x74, 0x18, 0x28, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x02, 0x70, 0x74, 0x42, 0x09, 0x0a, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x48, 0x0a, 0x17, 0x55, 0x70, 0x73, 0x74, + 0x72, 0x65, 0x61, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x02, 0x63, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0c, 0x48, + 0x00, 0x52, 0x02, 0x63, 0x74, 0x12, 0x10, 0x0a, 0x02, 0x70, 0x74, 0x18, 0x14, 0x20, 0x01, 0x28, + 0x0c, 0x48, 0x00, 0x52, 0x02, 0x70, 0x74, 0x42, 0x09, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x22, 0x2e, 0x0a, 0x1a, 0x45, 0x63, 0x68, 0x6f, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, + 0x61, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, + 0x73, 0x67, 0x22, 0x2f, 0x0a, 0x1b, 0x45, 0x63, 0x68, 0x6f, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, + 0x61, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x6d, 0x73, 0x67, 0x2a, 0x6f, 0x0a, 0x07, 0x4d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, + 0x0a, 0x14, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, + 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x4d, 0x53, 0x47, 0x5f, + 0x54, 0x59, 0x50, 0x45, 0x5f, 0x45, 0x43, 0x48, 0x4f, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, + 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x57, 0x52, 0x41, 0x50, 0x5f, 0x4b, + 0x45, 0x59, 0x53, 0x10, 0x02, 0x12, 0x1d, 0x0a, 0x19, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, + 0x45, 0x5f, 0x56, 0x45, 0x52, 0x49, 0x46, 0x59, 0x5f, 0x53, 0x49, 0x47, 0x4e, 0x41, 0x54, 0x55, + 0x52, 0x45, 0x10, 0x03, 0x32, 0x9f, 0x01, 0x0a, 0x16, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, + 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x84, 0x01, 0x0a, 0x0f, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x12, 0x36, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, + 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x37, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, + 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x73, + 0x74, 0x72, 0x65, 0x61, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x51, 0x5a, 0x4f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62, + 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, + 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, +} + +var ( + file_controller_servers_services_v1_upstream_message_service_proto_rawDescOnce sync.Once + file_controller_servers_services_v1_upstream_message_service_proto_rawDescData = file_controller_servers_services_v1_upstream_message_service_proto_rawDesc +) + +func file_controller_servers_services_v1_upstream_message_service_proto_rawDescGZIP() []byte { + file_controller_servers_services_v1_upstream_message_service_proto_rawDescOnce.Do(func() { + file_controller_servers_services_v1_upstream_message_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_controller_servers_services_v1_upstream_message_service_proto_rawDescData) + }) + return file_controller_servers_services_v1_upstream_message_service_proto_rawDescData +} + +var file_controller_servers_services_v1_upstream_message_service_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_controller_servers_services_v1_upstream_message_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_controller_servers_services_v1_upstream_message_service_proto_goTypes = []interface{}{ + (MsgType)(0), // 0: controller.servers.services.v1.MsgType + (*UpstreamMessageRequest)(nil), // 1: controller.servers.services.v1.UpstreamMessageRequest + (*UpstreamMessageResponse)(nil), // 2: controller.servers.services.v1.UpstreamMessageResponse + (*EchoUpstreamMessageRequest)(nil), // 3: controller.servers.services.v1.EchoUpstreamMessageRequest + (*EchoUpstreamMessageResponse)(nil), // 4: controller.servers.services.v1.EchoUpstreamMessageResponse +} +var file_controller_servers_services_v1_upstream_message_service_proto_depIdxs = []int32{ + 0, // 0: controller.servers.services.v1.UpstreamMessageRequest.msg_type:type_name -> controller.servers.services.v1.MsgType + 1, // 1: controller.servers.services.v1.UpstreamMessageService.UpstreamMessage:input_type -> controller.servers.services.v1.UpstreamMessageRequest + 2, // 2: controller.servers.services.v1.UpstreamMessageService.UpstreamMessage:output_type -> controller.servers.services.v1.UpstreamMessageResponse + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_controller_servers_services_v1_upstream_message_service_proto_init() } +func file_controller_servers_services_v1_upstream_message_service_proto_init() { + if File_controller_servers_services_v1_upstream_message_service_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpstreamMessageRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpstreamMessageResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EchoUpstreamMessageRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EchoUpstreamMessageResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[0].OneofWrappers = []interface{}{ + (*UpstreamMessageRequest_Ct)(nil), + (*UpstreamMessageRequest_Pt)(nil), + } + file_controller_servers_services_v1_upstream_message_service_proto_msgTypes[1].OneofWrappers = []interface{}{ + (*UpstreamMessageResponse_Ct)(nil), + (*UpstreamMessageResponse_Pt)(nil), + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_controller_servers_services_v1_upstream_message_service_proto_rawDesc, + NumEnums: 1, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_controller_servers_services_v1_upstream_message_service_proto_goTypes, + DependencyIndexes: file_controller_servers_services_v1_upstream_message_service_proto_depIdxs, + EnumInfos: file_controller_servers_services_v1_upstream_message_service_proto_enumTypes, + MessageInfos: file_controller_servers_services_v1_upstream_message_service_proto_msgTypes, + }.Build() + File_controller_servers_services_v1_upstream_message_service_proto = out.File + file_controller_servers_services_v1_upstream_message_service_proto_rawDesc = nil + file_controller_servers_services_v1_upstream_message_service_proto_goTypes = nil + file_controller_servers_services_v1_upstream_message_service_proto_depIdxs = nil +} diff --git a/internal/gen/controller/servers/services/upstream_message_service_grpc.pb.go b/internal/gen/controller/servers/services/upstream_message_service_grpc.pb.go new file mode 100644 index 000000000..f4dbd5d16 --- /dev/null +++ b/internal/gen/controller/servers/services/upstream_message_service_grpc.pb.go @@ -0,0 +1,104 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. + +package services + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// UpstreamMessageServiceClient is the client API for UpstreamMessageService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type UpstreamMessageServiceClient interface { + // sends an upstream message to the controller. + UpstreamMessage(ctx context.Context, in *UpstreamMessageRequest, opts ...grpc.CallOption) (*UpstreamMessageResponse, error) +} + +type upstreamMessageServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewUpstreamMessageServiceClient(cc grpc.ClientConnInterface) UpstreamMessageServiceClient { + return &upstreamMessageServiceClient{cc} +} + +func (c *upstreamMessageServiceClient) UpstreamMessage(ctx context.Context, in *UpstreamMessageRequest, opts ...grpc.CallOption) (*UpstreamMessageResponse, error) { + out := new(UpstreamMessageResponse) + err := c.cc.Invoke(ctx, "/controller.servers.services.v1.UpstreamMessageService/UpstreamMessage", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// UpstreamMessageServiceServer is the server API for UpstreamMessageService service. +// All implementations must embed UnimplementedUpstreamMessageServiceServer +// for forward compatibility +type UpstreamMessageServiceServer interface { + // sends an upstream message to the controller. + UpstreamMessage(context.Context, *UpstreamMessageRequest) (*UpstreamMessageResponse, error) + mustEmbedUnimplementedUpstreamMessageServiceServer() +} + +// UnimplementedUpstreamMessageServiceServer must be embedded to have forward compatible implementations. +type UnimplementedUpstreamMessageServiceServer struct { +} + +func (UnimplementedUpstreamMessageServiceServer) UpstreamMessage(context.Context, *UpstreamMessageRequest) (*UpstreamMessageResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpstreamMessage not implemented") +} +func (UnimplementedUpstreamMessageServiceServer) mustEmbedUnimplementedUpstreamMessageServiceServer() { +} + +// UnsafeUpstreamMessageServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to UpstreamMessageServiceServer will +// result in compilation errors. +type UnsafeUpstreamMessageServiceServer interface { + mustEmbedUnimplementedUpstreamMessageServiceServer() +} + +func RegisterUpstreamMessageServiceServer(s grpc.ServiceRegistrar, srv UpstreamMessageServiceServer) { + s.RegisterService(&UpstreamMessageService_ServiceDesc, srv) +} + +func _UpstreamMessageService_UpstreamMessage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpstreamMessageRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UpstreamMessageServiceServer).UpstreamMessage(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/controller.servers.services.v1.UpstreamMessageService/UpstreamMessage", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UpstreamMessageServiceServer).UpstreamMessage(ctx, req.(*UpstreamMessageRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// UpstreamMessageService_ServiceDesc is the grpc.ServiceDesc for UpstreamMessageService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var UpstreamMessageService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "controller.servers.services.v1.UpstreamMessageService", + HandlerType: (*UpstreamMessageServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpstreamMessage", + Handler: _UpstreamMessageService_UpstreamMessage_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "controller/servers/services/v1/upstream_message_service.proto", +} diff --git a/internal/proto/controller/servers/services/v1/upstream_message_service.proto b/internal/proto/controller/servers/services/v1/upstream_message_service.proto new file mode 100644 index 000000000..6147de23d --- /dev/null +++ b/internal/proto/controller/servers/services/v1/upstream_message_service.proto @@ -0,0 +1,63 @@ +// Copyright (c) HashiCorp, Inc. + +syntax = "proto3"; + +package controller.servers.services.v1; + +option go_package = "github.com/hashicorp/boundary/internal/gen/controller/servers/services;services"; + +service UpstreamMessageService { + // sends an upstream message to the controller. + rpc UpstreamMessage(UpstreamMessageRequest) returns (UpstreamMessageResponse) {} +} + +message UpstreamMessageRequest { + // the node credentials key id for the worker originated the request + string originating_worker_key_id = 10; // @gotags: `class:"public" + + // the type of the encrypted_message which must have a + // RegisterUpstreamMessageHandler or codesUnimplemented will be returned + MsgType msg_type = 20; + + // message will either be encrypted (ct) or plaintext (pt) based on its + // msg_type + oneof message { + // the encrypted upstream message. This message is encrypted with the + // originating worker's types.NodeCredentials. + bytes ct = 30; // @gotags: `class:"secret" + + // the plaintext upstream message. + bytes pt = 40; // @gotags: `class:"public" + } +} + +message UpstreamMessageResponse { + // the encryped response message. This message is encrypted with the + // originating worker's types.NodeCredentials. + // message will either be encrypted (ct) or plaintext (pt) based on its + // msg_type + oneof message { + // the encrypted upstream message. This message is encrypted with the + // originating worker's types.NodeCredentials. + bytes ct = 10; // @gotags: `class:"secret" + + // the plaintext upstream message. + bytes pt = 20; // @gotags: `class:"public" + } +} + +// defines the set of unknown message types +enum MsgType { + MSG_TYPE_UNSPECIFIED = 0; + MSG_TYPE_ECHO = 1; // currently this only used for testing. + MSG_TYPE_UNWRAP_KEYS = 2; + MSG_TYPE_VERIFY_SIGNATURE = 3; +} + +message EchoUpstreamMessageRequest { + string msg = 10; // @gotags: `class:"secret" +} + +message EchoUpstreamMessageResponse { + string msg = 10; // @gotags: `class:"secret" +}