Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,14 @@ func createUnauthenticatedClient(cmd *cobra.Command, serverURL *url.URL) (*coder
}
transport.headers[parts[0]] = parts[1]
}

client.HTTPClient.Transport = transport
client.DERPHeader = &http.Header{}

for header, value := range transport.headers {
client.DERPHeader.Set(header, value)
}

return client, nil
}

Expand Down
2 changes: 2 additions & 0 deletions codersdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type Client struct {
HTTPClient *http.Client
URL *url.URL

DERPHeader *http.Header

// Logger is optionally provided to log requests.
// Method, URL, and response code will be logged by default.
Logger slog.Logger
Expand Down
1 change: 1 addition & 0 deletions codersdk/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (c *Client) DialWorkspaceAgent(ctx context.Context, agentID uuid.UUID, opti
conn, err := tailnet.NewConn(&tailnet.Options{
Addresses: []netip.Prefix{netip.PrefixFrom(ip, 128)},
DERPMap: connInfo.DERPMap,
DERPHeader: c.DERPHeader,
Logger: options.Logger,
BlockEndpoints: options.BlockEndpoints,
})
Expand Down
10 changes: 8 additions & 2 deletions tailnet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net"
"net/http"
"net/netip"
"reflect"
"strconv"
Expand Down Expand Up @@ -50,8 +51,9 @@ func init() {
}

type Options struct {
Addresses []netip.Prefix
DERPMap *tailcfg.DERPMap
Addresses []netip.Prefix
DERPMap *tailcfg.DERPMap
DERPHeader *http.Header

// BlockEndpoints specifies whether P2P endpoints are blocked.
// If so, only DERPs can establish connections.
Expand Down Expand Up @@ -160,6 +162,10 @@ func NewConn(options *Options) (conn *Conn, err error) {
return nil, xerrors.New("get wireguard internals")
}

if options.DERPHeader != nil {
magicConn.SetDERPHeader(options.DERPHeader.Clone())
}

// Update the keys for the magic connection!
err = magicConn.SetPrivateKey(nodePrivateKey)
if err != nil {
Expand Down