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

Skip to content

Commit 23d0a4c

Browse files
committed
Comments and import cleanup
1 parent 391fe74 commit 23d0a4c

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

enterprise/coderd/workspaceproxy.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"database/sql"
77
"fmt"
88
"net/http"
9-
"net/http/httptest"
109
"net/url"
1110
"strings"
1211

@@ -257,16 +256,23 @@ func (api *API) issueSignedAppToken(rw http.ResponseWriter, r *http.Request) {
257256
return
258257
}
259258

260-
// HACK: the CreateToken code reads the session token from the request, but
261-
// since the session token is in a header, we need to make a fake request.
259+
// userReq is a http request from the user on the other side of the proxy.
260+
// Although the workspace proxy is making this call, we want to use the user's
261+
// authorization context to create the token.
262262
//
263-
// TODO(@dean): fix this hack. This could be fixed by providing the token as
264-
// a param to CreateToken instead of the whole request.
265-
fakeReq := httptest.NewRequest("GET", req.AppRequest.BasePath, nil)
266-
fakeReq.Header.Set(codersdk.SessionTokenHeader, req.SessionToken)
263+
// We can use the existing request context for all tracing/logging purposes.
264+
// Any workspace proxy auth uses different context keys so we don't need to
265+
// worry about that.
266+
userReq, err := http.NewRequestWithContext(ctx, "GET", req.AppRequest.BasePath, nil)
267+
if err != nil {
268+
// This should never happen
269+
httpapi.InternalServerError(rw, xerrors.Errorf("[DEV ERROR] new request: %w", err))
270+
return
271+
}
272+
userReq.Header.Set(codersdk.SessionTokenHeader, req.SessionToken)
267273

268274
// Exchange the token.
269-
token, tokenStr, ok := api.AGPL.WorkspaceAppsProvider.CreateToken(ctx, rw, fakeReq, req.AppRequest)
275+
token, tokenStr, ok := api.AGPL.WorkspaceAppsProvider.CreateToken(ctx, rw, userReq, req.AppRequest)
270276
if !ok {
271277
return
272278
}

enterprise/externalproxy/proxy.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,18 @@ import (
77
"regexp"
88
"time"
99

10+
"github.com/go-chi/chi/v5"
1011
"github.com/google/uuid"
11-
12-
"github.com/coder/coder/codersdk"
13-
14-
"github.com/coder/coder/buildinfo"
15-
1612
"github.com/prometheus/client_golang/prometheus"
17-
1813
"go.opentelemetry.io/otel/trace"
1914

20-
"github.com/coder/coder/coderd/tracing"
21-
22-
"github.com/go-chi/chi/v5"
23-
24-
"github.com/coder/coder/coderd/wsconncache"
25-
26-
"github.com/coder/coder/coderd/httpmw"
27-
2815
"cdr.dev/slog"
16+
"github.com/coder/coder/buildinfo"
17+
"github.com/coder/coder/coderd/httpmw"
18+
"github.com/coder/coder/coderd/tracing"
2919
"github.com/coder/coder/coderd/workspaceapps"
20+
"github.com/coder/coder/coderd/wsconncache"
21+
"github.com/coder/coder/codersdk"
3022
)
3123

3224
type Options struct {

0 commit comments

Comments
 (0)