Skip to content

Commit cf36726

Browse files
Replace tailscale binary with tailscaled unix socket (#83)
We currently check for existence of the `tailscale` binary just for guessing at whether you have tailscale installed. However, we already show a similar message when tsrelay returns a NOT_RUNNING state. Furthermore, showing those pop ups on first install when we already have a walkthrough to show you how to install Tailscale is not a pleasant experience. Therefore, this PR removes the manual checks for the binary and switches the VSCode configuration to be for setting the unix socket Updates #76
1 parent cdfd327 commit cf36726

File tree

9 files changed

+19
-158
lines changed

9 files changed

+19
-158
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,12 @@ If the extension isn't working, we recommend following these steps to troublesho
8181
- If you have signed in to multiple Tailscale accounts on your device, ensure that the correct account is active.
8282
2. Ensure that your Tailnet access controls (ACLs) are [configured to allow Tailscale Funnel](https://tailscale.com/kb/1223/tailscale-funnel/#setup) on your device.
8383
3. Ensure that [magicDNS and HTTPS Certificates are enabled](https://tailscale.com/kb/1153/enabling-https/) on your tailnet.
84-
4. Ensure `tailscale` is available in the environment path. You can check this by running `tailscale status` in your CLI; if no command is found, you may need to add the Tailscale executable to your path. Alternatively, you can set its path via the `tailscale.path` setting in VS Code.
84+
4. If you are running `tailscaled` in a non-default path, you can set its path via the `tailscale.socketPath` setting in VS Code.
8585

8686
## Configuration
8787

88-
- `tailscale.path`: A path to the `tailscale` executable. If unset, the extension will use
89-
the environment path to resolve the `tailscale` executable. If set, the extension
90-
will use the supplied path. The path should include the executable name (e.g.
91-
`/usr/bin/tailscale`, `C:\Program Files\tailscale\tailscale.exe`).
88+
- `tailscale.socketPath`: A path to the `tailscaled` unix socket. If unset, the extension will use
89+
the default path based on the platform. If set, the extension will use the supplied path.
9290

9391
## Contribute
9492

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@
189189
"type": "object",
190190
"title": "Tailscale",
191191
"properties": {
192-
"tailscale.path": {
192+
"tailscale.socketPath": {
193193
"type": "string",
194194
"default": null,
195-
"markdownDescription": "An absolute path to the `tailscale` CLI executable. By default, the extension looks for `tailscale` in the `PATH`, but if set, will use the path specified instead.",
195+
"markdownDescription": "An absolute path to the `tailscaled` unix socket. By default, the extension looks for the default path based on the platform.",
196196
"scope": "window",
197197
"examples": [
198-
"/usr/bin/tailscale",
199-
"C:\\Program Files\\Tailscale\\tailscale.exe"
198+
"/var/run/tailscaled.socket",
199+
"\\\\.\\pipe\\ProtectedPrefix\\Administrators\\Tailscale\\tailscaled"
200200
]
201201
}
202202
}

src/extension.ts

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,23 @@
11
import * as vscode from 'vscode';
22

33
import { ServePanelProvider } from './serve-panel-provider';
4-
import { getTailscaleCommandPath } from './tailscale';
5-
import { downloadLinkForPlatform, ADMIN_CONSOLE } from './utils/url';
4+
import { ADMIN_CONSOLE } from './utils/url';
65
import { Tailscale } from './tailscale';
7-
import { fileExists } from './utils';
8-
import { EXTENSION_ID } from './constants';
96
import { Logger } from './logger';
107
import { errorForType } from './tailscale/error';
118

129
let tailscaleInstance: Tailscale;
1310

1411
export async function activate(context: vscode.ExtensionContext) {
15-
const commandPath = await getTailscaleCommandPath();
16-
17-
Logger.info(`CLI path: ${commandPath}`);
1812
vscode.commands.executeCommand('setContext', 'tailscale.env', process.env.NODE_ENV);
1913

20-
if (commandPath && !(await fileExists(commandPath))) {
21-
vscode.window
22-
.showErrorMessage(
23-
`Tailscale CLI not found at ${commandPath}. Set tailscale.path`,
24-
'Open Settings'
25-
)
26-
.then(() => {
27-
vscode.commands.executeCommand('workbench.action.openSettings', `@ext:${EXTENSION_ID}`);
28-
});
29-
}
30-
31-
if (!commandPath) {
32-
vscode.window
33-
.showErrorMessage(
34-
'Tailscale CLI not found. Install Tailscale or set tailscale.path',
35-
'Install Tailscale',
36-
'Open Settings'
37-
)
38-
.then((selection) => {
39-
if (selection === 'Install Tailscale') {
40-
vscode.env.openExternal(vscode.Uri.parse(downloadLinkForPlatform(process.platform)));
41-
} else if (selection === 'Open Settings') {
42-
vscode.commands.executeCommand('workbench.action.openSettings', `@ext:${EXTENSION_ID}`);
43-
}
44-
});
45-
}
46-
4714
tailscaleInstance = await Tailscale.withInit(vscode);
4815

4916
// walkthrough completion
5017
tailscaleInstance.serveStatus().then((status) => {
5118
// assume if we have any BackendState we are installed
52-
vscode.commands.executeCommand('setContext', 'tailscale.walkthroughs.installed', !!commandPath);
19+
const isInstalled = status.BackendState !== '';
20+
vscode.commands.executeCommand('setContext', 'tailscale.walkthroughs.installed', isInstalled);
5321

5422
// Funnel check
5523
const isFunnelOn = !status?.Errors?.some((e) => e.Type === 'FUNNEL_OFF');

src/tailscale/cli.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Logger } from '../logger';
77
import * as path from 'node:path';
88
import { LogLevel } from 'vscode';
99
import { trimSuffix } from '../utils';
10+
import { EXTENSION_NS } from '../constants';
1011

1112
const LOG_COMPONENT = 'tsrelay';
1213

@@ -31,6 +32,7 @@ export class Tailscale {
3132
public authkey?: string;
3233
private childProcess?: cp.ChildProcess;
3334
private notifyExit?: () => void;
35+
private socket?: string;
3436

3537
constructor(vscode: vscodeModule) {
3638
this._vscode = vscode;
@@ -44,6 +46,7 @@ export class Tailscale {
4446

4547
async init(port?: string, nonce?: string) {
4648
return new Promise<null>((resolve) => {
49+
this.socket = vscode.workspace.getConfiguration(EXTENSION_NS).get<string>('socketPath');
4750
let binPath = this.tsrelayPath();
4851
let args = [];
4952
if (this._vscode.env.logLevel === LogLevel.Debug) {
@@ -61,6 +64,9 @@ export class Tailscale {
6164
if (nonce) {
6265
args.push(`-nonce=${this.nonce}`);
6366
}
67+
if (this.socket) {
68+
args.push(`-socket=${this.socket}`);
69+
}
6470
Logger.debug(`path: ${binPath}`, LOG_COMPONENT);
6571
Logger.debug(`args: ${args.join(' ')}`, LOG_COMPONENT);
6672

@@ -142,6 +148,9 @@ export class Tailscale {
142148
if (this._vscode.env.logLevel === LogLevel.Debug) {
143149
args.push('-v');
144150
}
151+
if (this.socket) {
152+
args.push(`-socket=${this.socket}`);
153+
}
145154
Logger.info(`path: ${binPath}`, LOG_COMPONENT);
146155
this.notifyExit = () => {
147156
Logger.info('starting sudo tsrelay');

src/tailscale/command-path.ts

Lines changed: 0 additions & 87 deletions
This file was deleted.

src/tailscale/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export * from './command-path';
21
export * from './cli';
32
export * from './analytics';

src/utils/fs.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
export * from './fs';
21
export * from './string';

src/utils/url.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,3 @@ export const ADMIN_CONSOLE_DNS = `${ADMIN_CONSOLE}/admin/dns`;
33
export const KB_FUNNEL_SETUP = 'https://tailscale.com/kb/1223/tailscale-funnel/#setup';
44
export const KB_FUNNEL_USE_CASES = 'https://tailscale.com/kb/1247/funnel-serve-use-cases';
55
export const KB_ENABLE_HTTPS = 'https://tailscale.com/kb/1153/enabling-https/#configure-https';
6-
7-
export function downloadLinkForPlatform(platform?: string) {
8-
let page = '';
9-
10-
switch (platform) {
11-
case 'darwin':
12-
page = 'mac';
13-
break;
14-
15-
case 'win32':
16-
page = 'windows';
17-
break;
18-
19-
case 'linux':
20-
page = 'linux';
21-
break;
22-
}
23-
24-
return `https://tailscale.com/download/${page}`;
25-
}

0 commit comments

Comments
 (0)