refactor(worker): refactors the proxy handler to use endpoint scheme (#1491)
This commit is contained in:
1 parent
b599bb5eb2
commit
db8e9bb0c6
3 files changed
+14
-7
No files matched your search
@@ -501,7 +501,7 @@ func (c *Command) Run(args []string) (retCode int) {
|
||||
// The only way a user will be able to connect to the session is by
|
||||
// connecting directly to the port and address we report to them here.
|
||||
sessInfo := SessionInfo{
|
||||
Protocol: "tcp",
|
||||
Protocol: c.sessionAuthzData.GetType(),
|
||||
Address: c.listenerAddr.IP.String(),
|
||||
Port: c.listenerAddr.Port,
|
||||
Expiration: c.expiration,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
@@ -75,7 +76,6 @@ func (w *Worker) handleProxy() http.HandlerFunc {
|
||||
tofuToken := si.LookupSessionResponse.GetTofuToken()
|
||||
version := si.LookupSessionResponse.GetVersion()
|
||||
endpoint := si.LookupSessionResponse.GetEndpoint()
|
||||
// userId := si.LookupSessionResponse.GetAuthorization()
|
||||
sessStatus := si.Status
|
||||
si.RUnlock()
|
||||
|
||||
@@ -163,10 +163,18 @@ func (w *Worker) handleProxy() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// Verify the subprotocol has a supported proxy before calling AuthorizeConnection
|
||||
handleProxyFn, err := proxyHandlers.GetHandler(conn.Subprotocol())
|
||||
// Verify the protocol has a supported proxy before calling AuthorizeConnection
|
||||
endpointUrl, err := url.Parse(endpoint)
|
||||
if err != nil {
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("worker received request for unsupported protocol %s", conn.Subprotocol()))
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("worker failed to parse target endpoint", "endpoint", endpoint))
|
||||
if err = conn.Close(websocket.StatusProtocolError, "unsupported-protocol"); err != nil {
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error closing client connection"))
|
||||
}
|
||||
return
|
||||
}
|
||||
handleProxyFn, err := proxyHandlers.GetHandler(endpointUrl.Scheme)
|
||||
if err != nil {
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("worker received request for unsupported protocol", "protocol", endpointUrl.Scheme))
|
||||
if err = conn.Close(websocket.StatusProtocolError, "unsupported-protocol"); err != nil {
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error closing client connection"))
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"net/url"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
||||
"github.com/hashicorp/boundary/internal/observability/event"
|
||||
"github.com/hashicorp/boundary/internal/servers/worker/proxy"
|
||||
@@ -16,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
err := proxy.RegisterHandler(globals.TcpProxyV1, handleTcpProxyV1)
|
||||
err := proxy.RegisterHandler("tcp", handleTcpProxyV1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user