Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also run the output based auto port forwarding #114424

Merged
merged 2 commits into from Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/vs/platform/remote/common/tunnel.ts
Expand Up @@ -5,7 +5,7 @@

import { Emitter, Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { isWindows } from 'vs/base/common/platform';
import { isWindows, OperatingSystem } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
Expand Down Expand Up @@ -85,8 +85,12 @@ function getOtherLocalhost(host: string): string | undefined {
return (host === 'localhost') ? '127.0.0.1' : ((host === '127.0.0.1') ? 'localhost' : undefined);
}

export function isPortPrivileged(port: number): boolean {
return !isWindows && (port < 1024);
export function isPortPrivileged(port: number, os?: OperatingSystem): boolean {
if (os) {
return os !== OperatingSystem.Windows && (port < 1024);
} else {
return !isWindows && (port < 1024);
}
}

export abstract class AbstractTunnelService implements ITunnelService {
Expand Down
19 changes: 13 additions & 6 deletions src/vs/workbench/contrib/remote/browser/remoteExplorer.ts
Expand Up @@ -212,10 +212,12 @@ export class AutomaticPortForwarding extends Disposable implements IWorkbenchCon

remoteAgentService.getEnvironment().then(environment => {
if (environment?.os === OperatingSystem.Windows) {
this._register(new WindowsAutomaticPortForwarding(terminalService, notificationService, openerService,
remoteExplorerService, configurationService, debugService, tunnelService));
this._register(new OutputAutomaticPortForwarding(terminalService, notificationService, openerService,
remoteExplorerService, configurationService, debugService, tunnelService, remoteAgentService, false));
} else if (environment?.os === OperatingSystem.Linux) {
this._register(new LinuxAutomaticPortForwarding(configurationService, remoteExplorerService, notificationService, openerService, tunnelService));
this._register(new ProcAutomaticPortForwarding(configurationService, remoteExplorerService, notificationService, openerService, tunnelService));
this._register(new OutputAutomaticPortForwarding(terminalService, notificationService, openerService,
remoteExplorerService, configurationService, debugService, tunnelService, remoteAgentService, true));
}
});
}
Expand Down Expand Up @@ -355,7 +357,7 @@ class OnAutoForwardedAction extends Disposable {
}
}

class WindowsAutomaticPortForwarding extends Disposable {
class OutputAutomaticPortForwarding extends Disposable {
private portsFeatures?: IDisposable;
private urlFinder?: UrlFinder;
private notifier: OnAutoForwardedAction;
Expand All @@ -368,7 +370,9 @@ class WindowsAutomaticPortForwarding extends Disposable {
private readonly remoteExplorerService: IRemoteExplorerService,
private readonly configurationService: IConfigurationService,
private readonly debugService: IDebugService,
readonly tunnelService: ITunnelService
readonly tunnelService: ITunnelService,
private readonly remoteAgentService: IRemoteAgentService,
readonly privilegedOnly: boolean
) {
super();
this.portsAttributes = new PortsAttributes(configurationService);
Expand Down Expand Up @@ -408,6 +412,9 @@ class WindowsAutomaticPortForwarding extends Disposable {
if (this.portsAttributes.getAttributes(localUrl.port)?.onAutoForward === OnPortForward.Ignore) {
return;
}
if (this.privilegedOnly && !isPortPrivileged(localUrl.port, (await this.remoteAgentService.getEnvironment())?.os)) {
return;
}
const forwarded = await this.remoteExplorerService.forward(localUrl);
if (forwarded) {
this.notifier.doAction([forwarded]);
Expand All @@ -423,7 +430,7 @@ class WindowsAutomaticPortForwarding extends Disposable {
}
}

class LinuxAutomaticPortForwarding extends Disposable {
class ProcAutomaticPortForwarding extends Disposable {
private candidateListener: IDisposable | undefined;
private autoForwarded: Set<string> = new Set();
private notifier: OnAutoForwardedAction;
Expand Down
4 changes: 3 additions & 1 deletion src/vs/workbench/contrib/remote/browser/urlFinder.ts
Expand Up @@ -18,6 +18,7 @@ export class UrlFinder extends Disposable {
* http://0.0.0.0:4000 - Elixir Phoenix
*/
private static readonly localUrlRegex = /\b\w{2,20}:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|:\d{2,5})[\w\-\.\~:\/\?\#[\]\@!\$&\(\)\*\+\,\;\=]*/gim;
private static readonly extractPortRegex = /(localhost|127\.0\.0\.1|0\.0\.0\.0):(\d{1,5})/;
/**
* https://github.com/microsoft/vscode-remote-release/issues/3949
*/
Expand Down Expand Up @@ -106,7 +107,8 @@ export class UrlFinder extends Disposable {
const serverUrl = new URL(match);
if (serverUrl) {
// check if the port is a valid integer value
const port = parseFloat(serverUrl.port!);
const portMatch = match.match(UrlFinder.extractPortRegex);
const port = parseFloat(serverUrl.port ? serverUrl.port : (portMatch ? portMatch[2] : 'NaN'));
if (!isNaN(port) && Number.isInteger(port) && port > 0 && port <= 65535) {
// normalize the host name
let host = serverUrl.hostname;
Expand Down