Skip to content

chore: add derpserver to proxy, add proxies to derpmap #7311

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 32 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eae4c3a
chore: add derpserver to proxy, add proxies to derpmap
deansheather Apr 27, 2023
ac99525
progress
deansheather May 1, 2023
4b68a0b
Merge branch 'main' into dean/proxy-derp-map
deansheather May 2, 2023
4ba7af6
progress
deansheather May 3, 2023
dcf072e
derp mesh probably working
deansheather May 4, 2023
2d2f1a3
deregister
deansheather May 4, 2023
28ae155
tests and various fixes
deansheather May 4, 2023
2baa362
Merge branch 'main' into dean/proxy-derp-map
deansheather May 4, 2023
5f5d4ff
more tests
deansheather May 5, 2023
5441dc8
merge main, remove proxy goingaway route
deansheather May 30, 2023
e4a3008
derp tests work
deansheather May 30, 2023
3caa692
Merge branch 'main' into dean/proxy-derp-map
deansheather May 30, 2023
404c3e4
update derp map on new connection
deansheather May 31, 2023
8544882
Merge branch 'main' into dean/proxy-derp-map
deansheather Jun 13, 2023
9b503fa
fixes
deansheather Jun 13, 2023
0e6d39a
tests for derp map changing
deansheather Jun 13, 2023
bb699fb
Merge branch 'main' into dean/proxy-derp-map
deansheather Jun 13, 2023
2943ac2
backwards compatible
deansheather Jun 20, 2023
f0fa578
other comments
deansheather Jun 20, 2023
9d90dc2
Merge branch 'main' into dean/proxy-derp-map
deansheather Jun 25, 2023
b405113
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jun 25, 2023
6a08a59
change derp map updates to be separate websocket
deansheather Jun 28, 2023
403eac5
Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 17, 2023
d220266
Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 24, 2023
9e658d6
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 24, 2023
67f2e5c
Working tests
deansheather Jul 25, 2023
3c96149
Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 25, 2023
c26936a
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 25, 2023
e59de5a
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 25, 2023
2df067f
fixup! Merge branch 'main' into dean/proxy-derp-map
deansheather Jul 25, 2023
dfbfa96
Please
deansheather Jul 26, 2023
8223a35
fixup! Please
deansheather Jul 26, 2023
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
Prev Previous commit
Next Next commit
Merge branch 'main' into dean/proxy-derp-map
  • Loading branch information
deansheather committed Jun 25, 2023
commit 9d90dc246a4b9cc933f58a1064408cbf58ab649c
1 change: 1 addition & 0 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ func New(options *Options) *API {
if options.HealthcheckFunc == nil {
options.HealthcheckFunc = func(ctx context.Context, apiKey string) *healthcheck.Report {
return healthcheck.Run(ctx, &healthcheck.ReportOptions{
DB: options.Database,
AccessURL: options.AccessURL,
DERPMap: api.DERPMap(),
APIKey: apiKey,
Expand Down
55 changes: 39 additions & 16 deletions coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,19 @@ func (api *API) workspaceAgentManifest(rw http.ResponseWriter, r *http.Request)
}

httpapi.Write(ctx, rw, http.StatusOK, agentsdk.Manifest{
Apps: convertApps(dbApps),
DERPMap: api.DERPMap(),
GitAuthConfigs: len(api.GitAuthConfigs),
EnvironmentVariables: apiAgent.EnvironmentVariables,
StartupScript: apiAgent.StartupScript,
Directory: apiAgent.Directory,
VSCodePortProxyURI: vscodeProxyURI,
MOTDFile: workspaceAgent.MOTDFile,
StartupScriptTimeout: time.Duration(apiAgent.StartupScriptTimeoutSeconds) * time.Second,
ShutdownScript: apiAgent.ShutdownScript,
ShutdownScriptTimeout: time.Duration(apiAgent.ShutdownScriptTimeoutSeconds) * time.Second,
Metadata: convertWorkspaceAgentMetadataDesc(metadata),
Apps: convertApps(dbApps),
DERPMap: api.DERPMap(),
GitAuthConfigs: len(api.GitAuthConfigs),
EnvironmentVariables: apiAgent.EnvironmentVariables,
StartupScript: apiAgent.StartupScript,
Directory: apiAgent.Directory,
VSCodePortProxyURI: vscodeProxyURI,
MOTDFile: workspaceAgent.MOTDFile,
StartupScriptTimeout: time.Duration(apiAgent.StartupScriptTimeoutSeconds) * time.Second,
ShutdownScript: apiAgent.ShutdownScript,
ShutdownScriptTimeout: time.Duration(apiAgent.ShutdownScriptTimeoutSeconds) * time.Second,
DisableDirectConnections: api.DeploymentValues.DERP.Config.BlockDirect.Value(),
Metadata: convertWorkspaceAgentMetadataDesc(metadata),
})
}

Expand Down Expand Up @@ -731,9 +732,10 @@ func (api *API) workspaceAgentListeningPorts(rw http.ResponseWriter, r *http.Req
func (api *API) dialWorkspaceAgentTailnet(agentID uuid.UUID) (*codersdk.WorkspaceAgentConn, error) {
clientConn, serverConn := net.Pipe()
conn, err := tailnet.NewConn(&tailnet.Options{
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
DERPMap: api.DERPMap(),
Logger: api.Logger.Named("tailnet"),
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
DERPMap: api.DERPMap(),
Logger: api.Logger.Named("tailnet"),
BlockEndpoints: api.DeploymentValues.DERP.Config.BlockDirect.Value(),
})
if err != nil {
_ = clientConn.Close()
Expand Down Expand Up @@ -806,7 +808,28 @@ func (api *API) workspaceAgentConnection(rw http.ResponseWriter, r *http.Request
ctx := r.Context()

httpapi.Write(ctx, rw, http.StatusOK, codersdk.WorkspaceAgentConnectionInfo{
DERPMap: api.DERPMap(),
DERPMap: api.DERPMap(),
DisableDirectConnections: api.DeploymentValues.DERP.Config.BlockDirect.Value(),
})
}

// workspaceAgentConnectionGeneric is the same as workspaceAgentConnection but
// without the workspaceagent path parameter.
//
// @Summary Get connection info for workspace agent generic
// @ID get-connection-info-for-workspace-agent-generic
// @Security CoderSessionToken
// @Produce json
// @Tags Agents
// @Success 200 {object} codersdk.WorkspaceAgentConnectionInfo
// @Router /workspaceagents/connection [get]
// @x-apidocgen {"skip": true}
func (api *API) workspaceAgentConnectionGeneric(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()

httpapi.Write(ctx, rw, http.StatusOK, codersdk.WorkspaceAgentConnectionInfo{
DERPMap: api.DERPMap(),
DisableDirectConnections: api.DeploymentValues.DERP.Config.BlockDirect.Value(),
})
}

Expand Down
2 changes: 1 addition & 1 deletion codersdk/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ type WorkspaceAgentConnectionInfo struct {
DisableDirectConnections bool `json:"disable_direct_connections"`
}

func (c *Client) WorkspaceAgentConnectionInfo(ctx context.Context) (*WorkspaceAgentConnectionInfo, error) {
func (c *Client) WorkspaceAgentConnectionInfoGeneric(ctx context.Context) (*WorkspaceAgentConnectionInfo, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/workspaceagents/connection", nil)
if err != nil {
return nil, err
Expand Down
28 changes: 28 additions & 0 deletions docs/admin/audit-logs.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ func (api *API) updateEntitlements(ctx context.Context) error {
if changed, enabled := featureChanged(codersdk.FeatureHighAvailability); changed {
coordinator := agpltailnet.NewCoordinator(api.Logger, api.AGPL.DERPMap)
if enabled {
haCoordinator, err := tailnet.NewCoordinator(api.Logger, api.Pubsub, api.AGPL.DERPMap)
var haCoordinator agpltailnet.Coordinator
if api.AGPL.Experiments.Enabled(codersdk.ExperimentTailnetPGCoordinator) {
haCoordinator, err = tailnet.NewPGCoord(ctx, api.Logger, api.Pubsub, api.Database)
} else {
haCoordinator, err = tailnet.NewCoordinator(api.Logger, api.Pubsub, api.AGPL.DERPMap, api.AGPL.DERPMap)
}
if err != nil {
api.Logger.Error(ctx, "unable to set up high availability coordinator", slog.Error(err))
// If we try to setup the HA coordinator and it fails, nothing
Expand Down
4 changes: 2 additions & 2 deletions enterprise/tailnet/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

// NewCoordinator creates a new high availability coordinator
// that uses PostgreSQL pubsub to exchange handshakes.
func NewCoordinator(logger slog.Logger, pubsub database.Pubsub, derpMapFn func() *tailcfg.DERPMap) (agpl.Coordinator, error) {
func NewCoordinator(logger slog.Logger, ps pubsub.Pubsub, derpMapFn func() *tailcfg.DERPMap) (agpl.Coordinator, error) {
ctx, cancelFunc := context.WithCancel(context.Background())

nameCache, err := lru.New[uuid.UUID, string](512)
Expand All @@ -34,7 +34,7 @@ func NewCoordinator(logger slog.Logger, pubsub database.Pubsub, derpMapFn func()
coord := &haCoordinator{
id: uuid.New(),
log: logger,
pubsub: pubsub,
pubsub: ps,
close: make(chan struct{}),
closeFunc: cancelFunc,
derpMapFn: derpMapFn,
Expand Down
8 changes: 4 additions & 4 deletions enterprise/tailnet/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestCoordinatorSingle(t *testing.T) {
t.Parallel()
t.Run("ClientWithoutAgent", func(t *testing.T) {
t.Parallel()
coordinator, err := tailnet.NewCoordinator(slogtest.Make(t, nil), database.NewPubsubInMemory(), emptyDerpMapFn)
coordinator, err := tailnet.NewCoordinator(slogtest.Make(t, nil), pubsub.NewInMemory(), emptyDerpMapFn)
require.NoError(t, err)
defer coordinator.Close()

Expand Down Expand Up @@ -51,7 +51,7 @@ func TestCoordinatorSingle(t *testing.T) {

t.Run("AgentWithoutClients", func(t *testing.T) {
t.Parallel()
coordinator, err := tailnet.NewCoordinator(slogtest.Make(t, nil), database.NewPubsubInMemory(), emptyDerpMapFn)
coordinator, err := tailnet.NewCoordinator(slogtest.Make(t, nil), pubsub.NewInMemory(), emptyDerpMapFn)
require.NoError(t, err)
defer coordinator.Close()

Expand Down Expand Up @@ -79,7 +79,7 @@ func TestCoordinatorSingle(t *testing.T) {
t.Run("AgentWithClient", func(t *testing.T) {
t.Parallel()

coordinator, err := tailnet.NewCoordinator(slogtest.Make(t, nil), database.NewPubsubInMemory(), emptyDerpMapFn)
coordinator, err := tailnet.NewCoordinator(slogtest.Make(t, nil), pubsub.NewInMemory(), emptyDerpMapFn)
require.NoError(t, err)
defer coordinator.Close()

Expand Down Expand Up @@ -184,7 +184,7 @@ func TestCoordinatorSingle(t *testing.T) {
}
}

coordinator, err := tailnet.NewCoordinator(slogtest.Make(t, nil), database.NewPubsubInMemory(), derpMapFn)
coordinator, err := tailnet.NewCoordinator(slogtest.Make(t, nil), pubsub.NewInMemory(), derpMapFn)
require.NoError(t, err)
defer coordinator.Close()

Expand Down
13 changes: 7 additions & 6 deletions tailnet/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ func newCore(logger slog.Logger, derpMapFn func() *tailcfg.DERPMap) *core {
var ErrWouldBlock = xerrors.New("would block")

type TrackedConn struct {
ctx context.Context
cancel func()
conn net.Conn
updates chan CoordinatorNodeUpdate
logger slog.Logger
ctx context.Context
cancel func()
conn net.Conn
updates chan CoordinatorNodeUpdate
logger slog.Logger
lastData []byte

// ID is an ephemeral UUID used to uniquely identify the owner of the
// connection.
Expand Down Expand Up @@ -242,7 +243,7 @@ func (t *TrackedConn) SendUpdates() {
return
}
if bytes.Equal(t.lastData, data) {
t.logger.Debug(t.ctx, "skipping duplicate update", slog.F("nodes", nodes))
t.logger.Debug(t.ctx, "skipping duplicate update", slog.F("update", update))
continue
}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.