Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: allow DERP headers to be set #6572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 21, 2023
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