WorkerCoordination and GetSession API refactoring (#354)
* Possible api changes. * Worker API update. * Updating import alias name. * Moving session down a level as a member of the GetSessionResponse. * Marshal the auth flag into the GetSessionResponse proto instead of the session.
This commit is contained in:
1 parent
2914b4c14c
commit
33e7b4538e
18 files changed
+1923
-936
No files matched your search
@@ -19,7 +19,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
||||
"github.com/hashicorp/vault/sdk/helper/base62"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/resolver"
|
||||
@@ -111,7 +111,7 @@ func (w *Worker) createClientConn(addr string) error {
|
||||
return fmt.Errorf("error dialing controller for worker auth: %w", err)
|
||||
}
|
||||
|
||||
client := services.NewWorkerServiceClient(cc)
|
||||
client := pbs.NewServerCoordinationServiceClient(cc)
|
||||
w.controllerConn.Store(client)
|
||||
|
||||
w.logger.Info("connected to controller", "address", addr)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/sessions"
|
||||
"github.com/hashicorp/boundary/internal/proxy"
|
||||
"github.com/hashicorp/shared-secure-libs/configutil"
|
||||
"nhooyr.io/websocket"
|
||||
@@ -45,7 +45,7 @@ func (w *Worker) handleProxy() http.HandlerFunc {
|
||||
wr.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
jobInfo := jobInfoRaw.(*services.ValidateSessionResponse)
|
||||
jobInfo := jobInfoRaw.(*pb.Session)
|
||||
|
||||
opts := &websocket.AcceptOptions{
|
||||
Subprotocols: []string{globals.TcpProxyV1},
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -30,7 +30,7 @@ func (w *Worker) getJobTls(hello *tls.ClientHelloInfo) (*tls.Config, error) {
|
||||
if rawConn == nil {
|
||||
return nil, errors.New("could not get a controller client")
|
||||
}
|
||||
conn, ok := rawConn.(services.WorkerServiceClient)
|
||||
conn, ok := rawConn.(pbs.SessionServiceClient)
|
||||
if !ok {
|
||||
return nil, errors.New("could not cast atomic controller client to the real thing")
|
||||
}
|
||||
@@ -41,14 +41,14 @@ func (w *Worker) getJobTls(hello *tls.ClientHelloInfo) (*tls.Config, error) {
|
||||
timeoutContext, cancel := context.WithTimeout(w.baseContext, validateSessionTimeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := conn.ValidateSession(timeoutContext, &services.ValidateSessionRequest{
|
||||
resp, err := conn.GetSession(timeoutContext, &pbs.GetSessionRequest{
|
||||
Id: jobId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error validating session: %w", err)
|
||||
}
|
||||
|
||||
parsedCert, err := x509.ParseCertificate(resp.GetCertificate())
|
||||
parsedCert, err := x509.ParseCertificate(resp.GetSession().GetCertificate())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing session certificate: %w", err)
|
||||
}
|
||||
@@ -63,8 +63,8 @@ func (w *Worker) getJobTls(hello *tls.ClientHelloInfo) (*tls.Config, error) {
|
||||
tlsConf := &tls.Config{
|
||||
Certificates: []tls.Certificate{
|
||||
{
|
||||
Certificate: [][]byte{resp.GetCertificate()},
|
||||
PrivateKey: ed25519.PrivateKey(resp.GetPrivateKey()),
|
||||
Certificate: [][]byte{resp.GetSession().GetCertificate()},
|
||||
PrivateKey: ed25519.PrivateKey(resp.GetSession().GetPrivateKey()),
|
||||
Leaf: parsedCert,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
||||
"github.com/hashicorp/boundary/internal/servers"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"google.golang.org/grpc/resolver"
|
||||
@@ -46,14 +45,17 @@ func (w *Worker) startStatusTicking(cancelCtx context.Context) {
|
||||
return
|
||||
|
||||
case <-timer.C:
|
||||
var activeJobs []string
|
||||
var activeJobs []*pbs.JobStatus
|
||||
w.cancellationMap.Range(func(key, value interface{}) bool {
|
||||
activeJobs = append(activeJobs, key.(string))
|
||||
activeJobs = append(activeJobs, &pbs.JobStatus{
|
||||
Job: &pbs.Job{JobId: key.(string)},
|
||||
Status: pbs.JobStatus_STATUS_ACTIVE,
|
||||
})
|
||||
return true
|
||||
})
|
||||
client := w.controllerConn.Load().(services.WorkerServiceClient)
|
||||
client := w.controllerConn.Load().(pbs.ServerCoordinationServiceClient)
|
||||
result, err := client.Status(cancelCtx, &pbs.StatusRequest{
|
||||
ActiveJobIds: activeJobs,
|
||||
Jobs: activeJobs,
|
||||
Worker: &servers.Server{
|
||||
PrivateId: w.conf.RawConfig.Worker.Name,
|
||||
Name: w.conf.RawConfig.Worker.Name,
|
||||
@@ -76,7 +78,7 @@ func (w *Worker) startStatusTicking(cancelCtx context.Context) {
|
||||
w.logger.Trace("found controllers", "addresses", strAddrs)
|
||||
w.lastStatusSuccess.Store(&LastStatusInformation{StatusResponse: result, StatusTime: time.Now()})
|
||||
|
||||
for _, id := range result.GetCancelJobIds() {
|
||||
for _, id := range result.GetJobsRequests() {
|
||||
if cancel, ok := w.cancellationMap.LoadAndDelete(id); ok {
|
||||
cancel.(context.CancelFunc)()
|
||||
w.logger.Info("canceled job", "job_id", id)
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/sessions"
|
||||
"nhooyr.io/websocket"
|
||||
)
|
||||
|
||||
func (w *Worker) handleTcpProxyV1(jobCtx context.Context, conn *websocket.Conn, jobInfo *services.ValidateSessionResponse) {
|
||||
func (w *Worker) handleTcpProxyV1(jobCtx context.Context, conn *websocket.Conn, jobInfo *pb.Session) {
|
||||
remoteConn, err := net.Dial("tcp", jobInfo.Endpoint)
|
||||
if err != nil {
|
||||
w.logger.Error("error dialing endpoint", "error", err, "endpoint", jobInfo.Endpoint)
|
||||
|
||||
Reference in new issue
Block a user