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

Skip to content

Commit 243b6af

Browse files
committed
fix: ignore https redirect for DERP meshing
1 parent bd17290 commit 243b6af

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

cli/cliutil/sink_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestDiscardAfterClose(t *testing.T) {
1313
t.Parallel()
14-
exErr := errors.New("test")
14+
exErr := xerrors.New("test")
1515
fwc := &fakeWriteCloser{err: exErr}
1616
uut := cliutil.DiscardAfterClose(fwc)
1717

cli/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
897897
// the request is not to a local IP.
898898
var handler http.Handler = coderAPI.RootHandler
899899
if vals.RedirectToAccessURL {
900-
handler = redirectToAccessURL(handler, vals.AccessURL.Value(), tunnel != nil, appHostnameRegex)
900+
handler = redirectToAccessURL(handler, vals.AccessURL.Value(), tunnel != nil, appHostnameRegex, options.IgnoreRedirectHostnames...)
901901
}
902902

903903
// ReadHeaderTimeout is purposefully not enabled. It caused some
@@ -1916,7 +1916,7 @@ func ConfigureHTTPClient(ctx context.Context, clientCertFile, clientKeyFile stri
19161916
}
19171917

19181918
// nolint:revive
1919-
func redirectToAccessURL(handler http.Handler, accessURL *url.URL, tunnel bool, appHostnameRegex *regexp.Regexp) http.Handler {
1919+
func redirectToAccessURL(handler http.Handler, accessURL *url.URL, tunnel bool, appHostnameRegex *regexp.Regexp, ignoreHosts ...string) http.Handler {
19201920
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
19211921
redirect := func() {
19221922
http.Redirect(w, r, accessURL.String(), http.StatusTemporaryRedirect)
@@ -1945,6 +1945,13 @@ func redirectToAccessURL(handler http.Handler, accessURL *url.URL, tunnel bool,
19451945
return
19461946
}
19471947

1948+
for _, ignore := range ignoreHosts {
1949+
if r.Host == ignore {
1950+
handler.ServeHTTP(w, r)
1951+
return
1952+
}
1953+
}
1954+
19481955
redirect()
19491956
})
19501957
}

coderd/coderd.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ type Options struct {
120120
RealIPConfig *httpmw.RealIPConfig
121121
TrialGenerator func(ctx context.Context, email string) error
122122
// TLSCertificates is used to mesh DERP servers securely.
123-
TLSCertificates []tls.Certificate
124-
TailnetCoordinator tailnet.Coordinator
125-
DERPServer *derp.Server
123+
TLSCertificates []tls.Certificate
124+
TailnetCoordinator tailnet.Coordinator
125+
IgnoreRedirectHostnames []string
126+
DERPServer *derp.Server
126127
// BaseDERPMap is used as the base DERP map for all clients and agents.
127128
// Proxies are added to this list.
128129
BaseDERPMap *tailcfg.DERPMap

enterprise/cli/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func (r *RootCmd) Server(_ func()) *clibase.Cmd {
7575

7676
CheckInactiveUsersCancelFunc: dormancy.CheckInactiveUsers(ctx, options.Logger, options.Database),
7777
}
78+
if o.DERPServerRelayAddress != "" {
79+
o.Options.IgnoreRedirectHostnames = append(o.Options.IgnoreRedirectHostnames, o.DERPServerRelayAddress)
80+
}
7881

7982
if encKeys := options.DeploymentValues.ExternalTokenEncryptionKeys.Value(); len(encKeys) != 0 {
8083
keys := make([][]byte, 0, len(encKeys))

enterprise/coderd/coderd.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import (
1414
"sync"
1515
"time"
1616

17-
"golang.org/x/xerrors"
18-
"tailscale.com/tailcfg"
19-
2017
"github.com/cenkalti/backoff/v4"
2118
"github.com/go-chi/chi/v5"
2219
"github.com/prometheus/client_golang/prometheus"
20+
"golang.org/x/xerrors"
21+
"tailscale.com/tailcfg"
2322

2423
"cdr.dev/slog"
2524
"github.com/coder/coder/v2/coderd"

enterprise/replicasync/replicasync.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ type Options struct {
3636
TLSConfig *tls.Config
3737
}
3838

39-
// New registers the replica with the database and periodically updates to ensure
40-
// it's healthy. It contacts all other alive replicas to ensure they are reachable.
39+
// New registers the replica with the database and periodically updates to
40+
// ensure it's healthy. It contacts all other alive replicas to ensure they are
41+
// reachable.
4142
func New(ctx context.Context, logger slog.Logger, db database.Store, ps pubsub.Pubsub, options *Options) (*Manager, error) {
4243
if options == nil {
4344
options = &Options{}

0 commit comments

Comments
 (0)