Skip to content

Commit bba94a6

Browse files
sawkaesimkowitz
andauthored
add jwt token back to wsl connections (#1841)
Co-authored-by: Evan Simkowitz <[email protected]>
1 parent 3c7f4d2 commit bba94a6

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

cmd/wsh/cmd/wshcmd-setbg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func setBgRun(cmd *cobra.Command, args []string) (rtnErr error) {
140140
}
141141

142142
// Create URL-safe path
143-
escapedPath := strings.ReplaceAll(absPath, "\\", "\\\\")
143+
escapedPath := filepath.ToSlash(absPath)
144144
escapedPath = strings.ReplaceAll(escapedPath, "'", "\\'")
145145
bgStyle = fmt.Sprintf("url('%s')", escapedPath)
146146

frontend/app/app-bg.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function processBackgroundUrls(cssText: string): string {
5454
return;
5555
}
5656
// allow absolute paths
57-
if (originalUrl.startsWith("/") || originalUrl.startsWith("~/")) {
57+
if (originalUrl.startsWith("/") || originalUrl.startsWith("~/") || /^[a-zA-Z]:(\/|\\)/.test(originalUrl)) {
5858
const newUrl = encodeFileURL(originalUrl);
5959
node.value = newUrl;
6060
return;

pkg/remote/connparse/connparse.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
)
2424

2525
var windowsDriveRegex = regexp.MustCompile(`^[a-zA-Z]:`)
26+
var wslConnRegex = regexp.MustCompile(`^wsl://[^/]+`)
2627

2728
type Connection struct {
2829
Scheme string
@@ -117,12 +118,17 @@ func ParseURI(uri string) (*Connection, error) {
117118
remotePath = rest
118119
}
119120
} else {
120-
split = strings.SplitN(rest, "/", 2)
121-
host = split[0]
122-
if len(split) > 1 {
123-
remotePath = split[1]
121+
if strings.HasPrefix(rest, "wsl://") {
122+
host = wslConnRegex.FindString(rest)
123+
remotePath = strings.TrimPrefix(rest, host)
124124
} else {
125-
remotePath = "/"
125+
split = strings.SplitN(rest, "/", 2)
126+
host = split[0]
127+
if len(split) > 1 {
128+
remotePath = split[1]
129+
} else {
130+
remotePath = "/"
131+
}
126132
}
127133
}
128134

pkg/shellexec/shellexec.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ func StartWslShellProc(ctx context.Context, termSize waveobj.TermSize, cmdStr st
262262
conn.Debugf(ctx, "packed swaptoken %s\n", packedToken)
263263
cmdCombined = fmt.Sprintf(`%s=%s %s`, wavebase.WaveSwapTokenVarName, packedToken, cmdCombined)
264264
}
265+
jwtToken := cmdOpts.SwapToken.Env[wavebase.WaveJwtTokenVarName]
266+
if jwtToken != "" {
267+
cmdCombined = fmt.Sprintf(`%s=%s %s`, wavebase.WaveJwtTokenVarName, jwtToken, cmdCombined)
268+
}
265269
log.Printf("full combined command: %s", cmdCombined)
266270
ecmd := exec.Command("wsl.exe", "~", "-d", client.Name(), "--", "sh", "-c", cmdCombined)
267271
if termSize.Rows == 0 || termSize.Cols == 0 {

pkg/util/shellutil/tokenswap.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type TokenSwapEntry struct {
2020
Token string `json:"token"`
2121
SockName string `json:"sockname,omitempty"`
2222
RpcContext *wshrpc.RpcContext `json:"rpccontext,omitempty"`
23-
JwtToken string `json:"jwttoken,omitempty"`
2423
Env map[string]string `json:"env,omitempty"`
2524
ScriptText string `json:"scripttext,omitempty"`
2625
Exp time.Time `json:"-"`

pkg/wshrpc/wshserver/wshserver.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/wavetermdev/waveterm/pkg/remote/fileshare"
2929
"github.com/wavetermdev/waveterm/pkg/telemetry"
3030
"github.com/wavetermdev/waveterm/pkg/util/envutil"
31+
"github.com/wavetermdev/waveterm/pkg/util/shellutil"
3132
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
3233
"github.com/wavetermdev/waveterm/pkg/util/wavefileutil"
3334
"github.com/wavetermdev/waveterm/pkg/waveai"
@@ -51,6 +52,19 @@ func (*WshServer) WshServerImpl() {}
5152

5253
var WshServerImpl = WshServer{}
5354

55+
// TODO remove this after implementing in multiproxy, just for wsl
56+
func (ws *WshServer) AuthenticateTokenCommand(ctx context.Context, data wshrpc.CommandAuthenticateTokenData) (wshrpc.CommandAuthenticateRtnData, error) {
57+
entry := shellutil.GetAndRemoveTokenSwapEntry(data.Token)
58+
if entry == nil {
59+
return wshrpc.CommandAuthenticateRtnData{}, fmt.Errorf("invalid token")
60+
}
61+
rtn := wshrpc.CommandAuthenticateRtnData{
62+
Env: entry.Env,
63+
InitScriptText: entry.ScriptText,
64+
}
65+
return rtn, nil
66+
}
67+
5468
func (ws *WshServer) TestCommand(ctx context.Context, data string) error {
5569
defer func() {
5670
panichandler.PanicHandler("TestCommand", recover())

0 commit comments

Comments
 (0)