Skip to content

Commit e2dd093

Browse files
committed
fix: add --block-direct-connections to wsproxies
1 parent 52a7f86 commit e2dd093

File tree

6 files changed

+80
-3
lines changed

6 files changed

+80
-3
lines changed

codersdk/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,8 @@ when required by your organization's security policy.`,
880880
Env: "CODER_BLOCK_DIRECT",
881881
Value: &c.DERP.Config.BlockDirect,
882882
Group: &deploymentGroupNetworkingDERP,
883-
YAML: "blockDirect",
883+
YAML: "blockDirect", Annotations: clibase.Annotations{}.
884+
Mark(annotationExternalProxies, "true"),
884885
},
885886
{
886887
Name: "DERP Force WebSockets",

enterprise/cli/proxyserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
262262
AllowAllCors: cfg.Dangerous.AllowAllCors.Value(),
263263
DERPEnabled: cfg.DERP.Server.Enable.Value(),
264264
DERPOnly: derpOnly.Value(),
265+
BlockDirect: cfg.DERP.Config.BlockDirect.Value(),
265266
DERPServerRelayAddress: cfg.DERP.Server.RelayURL.String(),
266267
})
267268
if err != nil {

enterprise/cli/proxyserver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/coder/coder/v2/pty/ptytest"
1414
)
1515

16-
func Test_Headers(t *testing.T) {
16+
func Test_ProxyServer_Headers(t *testing.T) {
1717
t.Parallel()
1818

1919
const (

enterprise/coderd/coderdenttest/proxytest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type ProxyOptions struct {
3434
DisablePathApps bool
3535
DerpDisabled bool
3636
DerpOnly bool
37+
BlockDirect bool
3738

3839
// ProxyURL is optional
3940
ProxyURL *url.URL
@@ -140,6 +141,7 @@ func NewWorkspaceProxy(t *testing.T, coderdAPI *coderd.API, owner *codersdk.Clie
140141
DERPOnly: options.DerpOnly,
141142
DERPServerRelayAddress: accessURL.String(),
142143
StatsCollectorOptions: statsCollectorOptions,
144+
BlockDirect: options.BlockDirect,
143145
})
144146
require.NoError(t, err)
145147
t.Cleanup(func() {

enterprise/wsproxy/wsproxy.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ type Options struct {
7575
// DERPOnly determines whether this proxy only provides DERP and does not
7676
// provide access to workspace apps/terminal.
7777
DERPOnly bool
78+
// BlockDirect controls the servertailnet of the proxy, forcing it from
79+
// negotiating direct connections.
80+
BlockDirect bool
7881

7982
ProxySessionToken string
8083
// AllowAllCors will set all CORs headers to '*'.
@@ -250,7 +253,7 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
250253
},
251254
regResp.DERPForceWebSockets,
252255
s.DialCoordinator,
253-
false, // TODO: this will be covered in a subsequent pr.
256+
opts.BlockDirect,
254257
s.TracerProvider,
255258
)
256259
if err != nil {

enterprise/wsproxy/wsproxy_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,73 @@ func TestWorkspaceProxyWorkspaceApps(t *testing.T) {
498498
}
499499
})
500500
}
501+
502+
func TestWorkspaceProxyWorkspaceApps_BlockDirect(t *testing.T) {
503+
t.Parallel()
504+
505+
apptest.Run(t, false, func(t *testing.T, opts *apptest.DeploymentOptions) *apptest.Deployment {
506+
deploymentValues := coderdtest.DeploymentValues(t)
507+
deploymentValues.DisablePathApps = clibase.Bool(opts.DisablePathApps)
508+
deploymentValues.Dangerous.AllowPathAppSharing = clibase.Bool(opts.DangerousAllowPathAppSharing)
509+
deploymentValues.Dangerous.AllowPathAppSiteOwnerAccess = clibase.Bool(opts.DangerousAllowPathAppSiteOwnerAccess)
510+
deploymentValues.Experiments = []string{
511+
"*",
512+
}
513+
514+
proxyStatsCollectorFlushCh := make(chan chan<- struct{}, 1)
515+
flushStats := func() {
516+
proxyStatsCollectorFlushDone := make(chan struct{}, 1)
517+
proxyStatsCollectorFlushCh <- proxyStatsCollectorFlushDone
518+
<-proxyStatsCollectorFlushDone
519+
}
520+
521+
if opts.PrimaryAppHost == "" {
522+
opts.PrimaryAppHost = "*.primary.test.coder.com"
523+
}
524+
client, closer, api, user := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
525+
Options: &coderdtest.Options{
526+
DeploymentValues: deploymentValues,
527+
AppHostname: opts.PrimaryAppHost,
528+
IncludeProvisionerDaemon: true,
529+
RealIPConfig: &httpmw.RealIPConfig{
530+
TrustedOrigins: []*net.IPNet{{
531+
IP: net.ParseIP("127.0.0.1"),
532+
Mask: net.CIDRMask(8, 32),
533+
}},
534+
TrustedHeaders: []string{
535+
"CF-Connecting-IP",
536+
},
537+
},
538+
WorkspaceAppsStatsCollectorOptions: opts.StatsCollectorOptions,
539+
},
540+
LicenseOptions: &coderdenttest.LicenseOptions{
541+
Features: license.Features{
542+
codersdk.FeatureWorkspaceProxy: 1,
543+
},
544+
},
545+
})
546+
t.Cleanup(func() {
547+
_ = closer.Close()
548+
})
549+
550+
// Create the external proxy
551+
if opts.DisableSubdomainApps {
552+
opts.AppHost = ""
553+
}
554+
proxyAPI := coderdenttest.NewWorkspaceProxy(t, api, client, &coderdenttest.ProxyOptions{
555+
Name: "best-proxy",
556+
AppHostname: opts.AppHost,
557+
DisablePathApps: opts.DisablePathApps,
558+
FlushStats: proxyStatsCollectorFlushCh,
559+
BlockDirect: true,
560+
})
561+
562+
return &apptest.Deployment{
563+
Options: opts,
564+
SDKClient: client,
565+
FirstUser: user,
566+
PathAppBaseURL: proxyAPI.Options.AccessURL,
567+
FlushStats: flushStats,
568+
}
569+
})
570+
}

0 commit comments

Comments
 (0)