Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3f9af6f

Browse files
authored
chore: Allow cors requests to workspace proxies for latency checks (#7484)
* CSP addition for web requests* chore: Add cors to workspace proxies to allow for latency checks
1 parentd17ea84 commit3f9af6f

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

‎coderd/httpmw/csp.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ func CSPHeaders(websocketHosts func() []string) func(next http.Handler) http.Han
104104
iflen(extraConnect)>0 {
105105
for_,extraHost:=rangeextraConnect {
106106
cspSrcs.Append(cspDirectiveConnectSrc,fmt.Sprintf("wss://%[1]s ws://%[1]s",extraHost))
107+
// We also require this to make http/https requests to the workspace proxy for latency checking.
108+
cspSrcs.Append(cspDirectiveConnectSrc,fmt.Sprintf("https://%[1]s http://%[1]s",extraHost))
107109
}
108110
}
109111

‎enterprise/wsproxy/wsproxy.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/go-chi/chi/v5"
14+
"github.com/go-chi/cors"
1415
"github.com/google/uuid"
1516
"github.com/prometheus/client_golang/prometheus"
1617
"go.opentelemetry.io/otel/trace"
@@ -197,6 +198,20 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
197198
httpmw.ExtractRealIP(s.Options.RealIPConfig),
198199
httpmw.Logger(s.Logger),
199200
httpmw.Prometheus(s.PrometheusRegistry),
201+
// The primary coderd dashboard needs to make some GET requests to
202+
// the workspace proxies to check latency.
203+
cors.Handler(cors.Options{
204+
AllowedOrigins: []string{
205+
// Allow the dashboard to make requests to the proxy for latency
206+
// checks.
207+
opts.DashboardURL.String(),
208+
},
209+
// Only allow GET requests for latency checks.
210+
AllowedMethods: []string{http.MethodGet},
211+
AllowedHeaders: []string{"Accept","Content-Type"},
212+
// Do not send any cookies
213+
AllowCredentials:false,
214+
}),
200215

201216
// HandleSubdomain is a middleware that handles all requests to the
202217
// subdomain-based workspace apps.

‎go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ require (
174174
tailscale.comv1.32.2
175175
)
176176

177-
requiregithub.com/armon/go-radixv1.0.0// indirect
177+
require (
178+
github.com/armon/go-radixv1.0.0// indirect
179+
github.com/go-chi/corsv1.2.1// indirect
180+
)
178181

179182
require (
180183
cloud.google.com/go/computev1.18.0// indirect

‎go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,8 @@ github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs=
599599
github.com/go-chi/chiv1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg=
600600
github.com/go-chi/chi/v5v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
601601
github.com/go-chi/chi/v5v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
602+
github.com/go-chi/corsv1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
603+
github.com/go-chi/corsv1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
602604
github.com/go-chi/httpratev0.7.1 h1:d5kXARdms2PREQfU4pHvq44S6hJ1hPu4OXLeBKmCKWs=
603605
github.com/go-chi/httpratev0.7.1/go.mod h1:6GOYBSwnpra4CQfAKXu8sQZg+nZ0M1g9QnyFvxrAB8A=
604606
github.com/go-chi/renderv1.0.1 h1:4/5tis2cKaNdnv9zFLfXzcquC9HbeZgCnxGnKrltBS8=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp