Skip to content

Commit

Permalink
Replace tailscale binary with tailscaled unix socket (#83)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marwan-at-work committed Jun 28, 2023
1 parent cdfd327 commit cf36726
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 158 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ If the extension isn't working, we recommend following these steps to troublesho
- If you have signed in to multiple Tailscale accounts on your device, ensure that the correct account is active.
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.
3. Ensure that [magicDNS and HTTPS Certificates are enabled](https://tailscale.com/kb/1153/enabling-https/) on your tailnet.
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.
4. If you are running `tailscaled` in a non-default path, you can set its path via the `tailscale.socketPath` setting in VS Code.

## Configuration

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

## Contribute

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@
"type": "object",
"title": "Tailscale",
"properties": {
"tailscale.path": {
"tailscale.socketPath": {
"type": "string",
"default": null,
"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.",
"markdownDescription": "An absolute path to the `tailscaled` unix socket. By default, the extension looks for the default path based on the platform.",
"scope": "window",
"examples": [
"/usr/bin/tailscale",
"C:\\Program Files\\Tailscale\\tailscale.exe"
"/var/run/tailscaled.socket",
"\\\\.\\pipe\\ProtectedPrefix\\Administrators\\Tailscale\\tailscaled"
]
}
}
Expand Down
38 changes: 3 additions & 35 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,23 @@
import * as vscode from 'vscode';

import { ServePanelProvider } from './serve-panel-provider';
import { getTailscaleCommandPath } from './tailscale';
import { downloadLinkForPlatform, ADMIN_CONSOLE } from './utils/url';
import { ADMIN_CONSOLE } from './utils/url';
import { Tailscale } from './tailscale';
import { fileExists } from './utils';
import { EXTENSION_ID } from './constants';
import { Logger } from './logger';
import { errorForType } from './tailscale/error';

let tailscaleInstance: Tailscale;

export async function activate(context: vscode.ExtensionContext) {
const commandPath = await getTailscaleCommandPath();

Logger.info(`CLI path: ${commandPath}`);
vscode.commands.executeCommand('setContext', 'tailscale.env', process.env.NODE_ENV);

if (commandPath && !(await fileExists(commandPath))) {
vscode.window
.showErrorMessage(
`Tailscale CLI not found at ${commandPath}. Set tailscale.path`,
'Open Settings'
)
.then(() => {
vscode.commands.executeCommand('workbench.action.openSettings', `@ext:${EXTENSION_ID}`);
});
}

if (!commandPath) {
vscode.window
.showErrorMessage(
'Tailscale CLI not found. Install Tailscale or set tailscale.path',
'Install Tailscale',
'Open Settings'
)
.then((selection) => {
if (selection === 'Install Tailscale') {
vscode.env.openExternal(vscode.Uri.parse(downloadLinkForPlatform(process.platform)));
} else if (selection === 'Open Settings') {
vscode.commands.executeCommand('workbench.action.openSettings', `@ext:${EXTENSION_ID}`);
}
});
}

tailscaleInstance = await Tailscale.withInit(vscode);

// walkthrough completion
tailscaleInstance.serveStatus().then((status) => {
// assume if we have any BackendState we are installed
vscode.commands.executeCommand('setContext', 'tailscale.walkthroughs.installed', !!commandPath);
const isInstalled = status.BackendState !== '';
vscode.commands.executeCommand('setContext', 'tailscale.walkthroughs.installed', isInstalled);

// Funnel check
const isFunnelOn = !status?.Errors?.some((e) => e.Type === 'FUNNEL_OFF');
Expand Down
9 changes: 9 additions & 0 deletions src/tailscale/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Logger } from '../logger';
import * as path from 'node:path';
import { LogLevel } from 'vscode';
import { trimSuffix } from '../utils';
import { EXTENSION_NS } from '../constants';

const LOG_COMPONENT = 'tsrelay';

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

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

async init(port?: string, nonce?: string) {
return new Promise<null>((resolve) => {
this.socket = vscode.workspace.getConfiguration(EXTENSION_NS).get<string>('socketPath');
let binPath = this.tsrelayPath();
let args = [];
if (this._vscode.env.logLevel === LogLevel.Debug) {
Expand All @@ -61,6 +64,9 @@ export class Tailscale {
if (nonce) {
args.push(`-nonce=${this.nonce}`);
}
if (this.socket) {
args.push(`-socket=${this.socket}`);
}
Logger.debug(`path: ${binPath}`, LOG_COMPONENT);
Logger.debug(`args: ${args.join(' ')}`, LOG_COMPONENT);

Expand Down Expand Up @@ -142,6 +148,9 @@ export class Tailscale {
if (this._vscode.env.logLevel === LogLevel.Debug) {
args.push('-v');
}
if (this.socket) {
args.push(`-socket=${this.socket}`);
}
Logger.info(`path: ${binPath}`, LOG_COMPONENT);
this.notifyExit = () => {
Logger.info('starting sudo tsrelay');
Expand Down
87 changes: 0 additions & 87 deletions src/tailscale/command-path.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/tailscale/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './command-path';
export * from './cli';
export * from './analytics';
5 changes: 0 additions & 5 deletions src/utils/fs.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './fs';
export * from './string';
20 changes: 0 additions & 20 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,3 @@ export const ADMIN_CONSOLE_DNS = `${ADMIN_CONSOLE}/admin/dns`;
export const KB_FUNNEL_SETUP = 'https://tailscale.com/kb/1223/tailscale-funnel/#setup';
export const KB_FUNNEL_USE_CASES = 'https://tailscale.com/kb/1247/funnel-serve-use-cases';
export const KB_ENABLE_HTTPS = 'https://tailscale.com/kb/1153/enabling-https/#configure-https';

export function downloadLinkForPlatform(platform?: string) {
let page = '';

switch (platform) {
case 'darwin':
page = 'mac';
break;

case 'win32':
page = 'windows';
break;

case 'linux':
page = 'linux';
break;
}

return `https://tailscale.com/download/${page}`;
}

0 comments on commit cf36726

Please sign in to comment.