Skip to content

Commit f8fc946

Browse files
authored
[ws-proxy] remove cors settings (#20198)
1 parent 02b4952 commit f8fc946

File tree

6 files changed

+0
-104
lines changed

6 files changed

+0
-104
lines changed

components/ws-proxy/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ require (
3030

3131
require (
3232
github.com/beorn7/perks v1.0.1 // indirect
33-
github.com/blang/semver v3.5.1+incompatible // indirect
3433
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
3534
github.com/cespare/xxhash/v2 v2.2.0 // indirect
36-
github.com/configcat/go-sdk/v7 v7.6.0 // indirect
3735
github.com/davecgh/go-spew v1.1.1 // indirect
3836
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
3937
github.com/evanphx/json-patch/v5 v5.8.0 // indirect

components/ws-proxy/go.sum

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/ws-proxy/pkg/config/config.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55
package config
66

77
import (
8-
"context"
98
"encoding/json"
109
"os"
11-
"time"
1210

1311
"golang.org/x/xerrors"
1412

15-
"github.com/gitpod-io/gitpod/common-go/experiments"
16-
"github.com/gitpod-io/gitpod/common-go/log"
1713
"github.com/gitpod-io/gitpod/ws-proxy/pkg/proxy"
1814
)
1915

20-
const experimentsCorsEnabled = "ws_proxy_cors_enabled"
21-
2216
// Config configures this service.
2317
type Config struct {
2418
Ingress proxy.HostBasedIngressConfig `json:"ingress"`
@@ -69,32 +63,5 @@ func GetConfig(fn string) (*Config, error) {
6963
if err != nil {
7064
return nil, xerrors.Errorf("config validation error: %w", err)
7165
}
72-
73-
timeout := time.Second * 45
74-
log.WithField("timeout", timeout).Info("waiting for Feature Flag")
75-
experimentsClient := experiments.NewClient(experiments.WithPollInterval(time.Second * 3))
76-
ctx, cancel := context.WithTimeout(context.Background(), timeout)
77-
defer cancel()
78-
ffValue := waitExperimentsStringValue(ctx, experimentsClient, experimentsCorsEnabled, "nope", experiments.Attributes{})
79-
corsEnabled := ffValue == "true"
80-
cfg.Proxy.CorsEnabled = corsEnabled
81-
log.WithField("ffValue", ffValue).WithField("corsEnabled", cfg.Proxy.CorsEnabled).Info("feature flag final value")
82-
8366
return &cfg, nil
8467
}
85-
86-
func waitExperimentsStringValue(ctx context.Context, client experiments.Client, experimentName, nopeValue string, attributes experiments.Attributes) string {
87-
ticker := time.NewTicker(1 * time.Second)
88-
defer ticker.Stop()
89-
for {
90-
select {
91-
case <-ctx.Done():
92-
return nopeValue
93-
case <-ticker.C:
94-
value := client.GetStringValue(ctx, experimentName, nopeValue, attributes)
95-
if value != nopeValue {
96-
return value
97-
}
98-
}
99-
}
100-
}

components/ws-proxy/pkg/proxy/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type Config struct {
2929

3030
BuiltinPages BuiltinPagesConfig `json:"builtinPages"`
3131
SSHGatewayCAKeyFile string `json:"sshCAKeyFile"`
32-
CorsEnabled bool
3332
}
3433

3534
// Validate validates the configuration to catch issues during startup and not at runtime.

components/ws-proxy/pkg/proxy/routes.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
type RouteHandlerConfig struct {
4646
Config *Config
4747
DefaultTransport http.RoundTripper
48-
CorsHandler mux.MiddlewareFunc
4948
WorkspaceAuthHandler mux.MiddlewareFunc
5049
}
5150

@@ -61,14 +60,9 @@ func WithDefaultAuth(infoprov common.WorkspaceInfoProvider) RouteHandlerConfigOp
6160

6261
// NewRouteHandlerConfig creates a new instance.
6362
func NewRouteHandlerConfig(config *Config, opts ...RouteHandlerConfigOpt) (*RouteHandlerConfig, error) {
64-
corsHandler, err := corsHandler(config.CorsEnabled, config.GitpodInstallation.Scheme, config.GitpodInstallation.HostName)
65-
if err != nil {
66-
return nil, err
67-
}
6863
cfg := &RouteHandlerConfig{
6964
Config: config,
7065
DefaultTransport: createDefaultTransport(config.TransportConfig),
71-
CorsHandler: corsHandler,
7266
WorkspaceAuthHandler: func(h http.Handler) http.Handler { return h },
7367
}
7468
for _, o := range opts {
@@ -185,7 +179,6 @@ func (ir *ideRoutes) HandleSSHHostKeyRoute(route *mux.Route, hostKeyList []ssh.S
185179
}
186180
r := route.Subrouter()
187181
r.Use(logRouteHandlerHandler("HandleSSHHostKeyRoute"))
188-
r.Use(ir.Config.CorsHandler)
189182
r.NewRoute().HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
190183
rw.Header().Add("Content-Type", "application/json")
191184
rw.Write(byt)
@@ -195,7 +188,6 @@ func (ir *ideRoutes) HandleSSHHostKeyRoute(route *mux.Route, hostKeyList []ssh.S
195188
func (ir *ideRoutes) HandleCreateKeyRoute(route *mux.Route, hostKeyList []ssh.Signer) {
196189
r := route.Subrouter()
197190
r.Use(logRouteHandlerHandler("HandleCreateKeyRoute"))
198-
r.Use(ir.Config.CorsHandler)
199191

200192
r.Use(ir.workspaceMustExistHandler)
201193
r.Use(ir.Config.WorkspaceAuthHandler)
@@ -260,7 +252,6 @@ func extractCloseErrorCode(errStr string) string {
260252
func (ir *ideRoutes) HandleSSHOverWebsocketTunnel(route *mux.Route, sshGatewayServer *sshproxy.Server) {
261253
r := route.Subrouter()
262254
r.Use(logRouteHandlerHandler("HandleSSHOverWebsocketTunnel"))
263-
r.Use(ir.Config.CorsHandler)
264255
r.Use(ir.workspaceMustExistHandler)
265256
r.Use(ir.Config.WorkspaceAuthHandler)
266257

@@ -304,7 +295,6 @@ func (ir *ideRoutes) HandleSSHOverWebsocketTunnel(route *mux.Route, sshGatewaySe
304295
func (ir *ideRoutes) HandleDirectSupervisorRoute(route *mux.Route, authenticated bool, proxyPassOpts ...proxyPassOpt) {
305296
r := route.Subrouter()
306297
r.Use(logRouteHandlerHandler(fmt.Sprintf("HandleDirectSupervisorRoute (authenticated: %v)", authenticated)))
307-
r.Use(ir.Config.CorsHandler)
308298
r.Use(ir.workspaceMustExistHandler)
309299
if authenticated {
310300
r.Use(ir.Config.WorkspaceAuthHandler)
@@ -389,7 +379,6 @@ type BlobserveInlineVars struct {
389379
func (ir *ideRoutes) HandleRoot(route *mux.Route) {
390380
r := route.Subrouter()
391381
r.Use(logRouteHandlerHandler("handleRoot"))
392-
r.Use(ir.Config.CorsHandler)
393382
r.Use(ir.workspaceMustExistHandler)
394383

395384
proxyPassWoSensitiveCookies := sensitiveCookieHandler(ir.Config.Config.GitpodInstallation.HostName)(proxyPass(ir.Config, ir.InfoProvider, workspacePodResolver))
@@ -523,7 +512,6 @@ func installDebugWorkspaceRoutes(r *mux.Router, config *RouteHandlerConfig, info
523512
}
524513

525514
r.Use(logHandler)
526-
r.Use(config.CorsHandler)
527515
r.Use(config.WorkspaceAuthHandler)
528516
// filter all session cookies
529517
r.Use(sensitiveCookieHandler(config.Config.GitpodInstallation.HostName))
@@ -661,54 +649,6 @@ func buildWorkspacePodURL(protocol api.PortProtocol, ipAddress string, port stri
661649
return url.Parse(fmt.Sprintf("%v://%v:%v", portProtocol, ipAddress, port))
662650
}
663651

664-
// corsHandler produces the CORS handler for workspaces.
665-
func corsHandler(enabled bool, scheme, hostname string) (mux.MiddlewareFunc, error) {
666-
if !enabled {
667-
// empty handler
668-
return func(h http.Handler) http.Handler {
669-
return h
670-
}, nil
671-
}
672-
origin := fmt.Sprintf("%s://%s", scheme, hostname)
673-
674-
domainRegex := strings.ReplaceAll(hostname, ".", "\\.")
675-
originRegex, err := regexp.Compile(".*" + domainRegex)
676-
if err != nil {
677-
return nil, err
678-
}
679-
680-
return handlers.CORS(
681-
handlers.AllowedOriginValidator(func(origin string) bool {
682-
// Is the origin a subdomain of the installations hostname?
683-
matches := originRegex.Match([]byte(origin))
684-
return matches
685-
}),
686-
// TODO(gpl) For domain-based workspace access with authentication (for accessing the IDE) we need to respond with the precise Origin header that was sent
687-
handlers.AllowedOrigins([]string{origin}),
688-
handlers.AllowedMethods([]string{
689-
"GET",
690-
"POST",
691-
"OPTIONS",
692-
}),
693-
handlers.AllowedHeaders([]string{
694-
// "Accept", "Accept-Language", "Content-Language" are allowed per default
695-
"Cache-Control",
696-
"Content-Type",
697-
"DNT",
698-
"If-Modified-Since",
699-
"Keep-Alive",
700-
"Origin",
701-
"User-Agent",
702-
"X-Requested-With",
703-
}),
704-
handlers.AllowCredentials(),
705-
// required to be able to read Authorization header in frontend
706-
handlers.ExposedHeaders([]string{"Authorization"}),
707-
handlers.MaxAge(60),
708-
handlers.OptionStatusCode(200),
709-
), nil
710-
}
711-
712652
type wsproxyContextKey struct{}
713653

714654
var (

components/ws-proxy/pkg/proxy/routes_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ var (
9595
BuiltinPages: BuiltinPagesConfig{
9696
Location: "../../public",
9797
},
98-
CorsEnabled: false,
9998
}
10099
)
101100

0 commit comments

Comments
 (0)