Skip to content

Commit

Permalink
Merge pull request #7361 from rancher-sandbox/remove-vtunnel
Browse files Browse the repository at this point in the history
Remove vtunnel
  • Loading branch information
Nino-K authored Aug 20, 2024
2 parents d122567 + f78888d commit 12e8f84
Show file tree
Hide file tree
Showing 24 changed files with 6 additions and 1,387 deletions.
4 changes: 2 additions & 2 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ corepack
coreutils
crds
credfwd
credhelper
CREDHELPER
cri
crond
crt
Expand Down Expand Up @@ -204,7 +204,6 @@ doclink
dompurify
donotuse
dotfile
Dowloading
dport
dri
DSL
Expand Down Expand Up @@ -694,6 +693,7 @@ Runas
runbook
runc
rundir
runlevels
RUnlock
runtimeclass
runtimeclasses
Expand Down
8 changes: 0 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ updates:
labels: ["component/dependencies"]
reviewers: [ "jandubois" ]

- package-ecosystem: "gomod"
directory: "/src/go/vtunnel"
schedule:
interval: "daily"
open-pull-requests-limit: 1
labels: ["component/dependencies"]
reviewers: [ "Nino-K" ]

- package-ecosystem: "gomod"
directory: "/src/go/wsl-helper"
schedule:
Expand Down
1 change: 0 additions & 1 deletion build/signing-config-win.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ resources/resources/win32/internal:
- host-switch.exe
- privileged-service.exe
- steve.exe
- vtunnel.exe
- wsl-helper.exe
32 changes: 1 addition & 31 deletions e2e/credentials-server.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ import { expect, test } from '@playwright/test';
import fetch from 'node-fetch';

import { NavPage } from './pages/nav-page';
import {
getFullPathForTool, retry, startSlowerDesktop, teardown, tool,
} from './utils/TestUtils';
import { getFullPathForTool, startSlowerDesktop, teardown, tool } from './utils/TestUtils';

import { defaultSettings } from '@pkg/config/settings';
import { ServerState } from '@pkg/main/commandServer/httpCommandServer';
import { spawnFile } from '@pkg/utils/childProcess';
import paths from '@pkg/utils/paths';
Expand Down Expand Up @@ -109,7 +106,6 @@ function haveCredentialServerHelper(): boolean {

const describeWithCreds = haveCredentialServerHelper() ? test.describe : test.describe.skip;
const describeCredHelpers = credStore === 'none' ? test.describe.skip : test.describe;
const testWin32 = os.platform() === 'win32' ? test : test.skip;
const testUnix = os.platform() === 'win32' ? test.skip : test;

describeWithCreds('Credentials server', () => {
Expand Down Expand Up @@ -334,32 +330,6 @@ describeWithCreds('Credentials server', () => {
// behavior is all over the place. Fails with osxkeychain, succeeds with wincred.
});

// On Windows, we need to wait for the vtunnel proxy to be established.
testWin32('ensure vtunnel proxy is ready', () => {
const isTunnel = defaultSettings.experimental.virtualMachine.networkingTunnel;

test.skip(isTunnel, 'vtunnel process is not needed when network tunnel is enabled');
const args = ['--distribution', 'rancher-desktop', '--exec',
'curl', '--verbose', '--user', `${ serverState.user }:${ serverState.password }`,
'http://localhost:3030/'];

return retry(async() => {
try {
await spawnFile('wsl.exe', args);
} catch (ex: any) {
const curlExitReason = {
7: 'Failed to connect to host',
56: 'Failure in receiving network data',
};

if (!curlExitReason) {
throw ex;
}
throw new Error(`curl failed with ${ ex } (${ curlExitReason })`);
}
});
});

test('it should complain about an unrecognized command', async() => {
const badCommand = 'gazornaanplatt';
const stdout = await doRequest(badCommand);
Expand Down
1 change: 0 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ use (
./src/go/networking
./src/go/privileged-service
./src/go/rdctl
./src/go/vtunnel
./src/go/wsl-helper
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# shellcheck shell=ksh

depend() {
after vtunnel-peer
after network-online
}

Expand Down
16 changes: 0 additions & 16 deletions pkg/rancher-desktop/assets/scripts/service-vtunnel-peer.initd

This file was deleted.

61 changes: 3 additions & 58 deletions pkg/rancher-desktop/backend/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import SERVICE_GUEST_AGENT_INIT from '@pkg/assets/scripts/rancher-desktop-guesta
import SERVICE_SCRIPT_CRI_DOCKERD from '@pkg/assets/scripts/service-cri-dockerd.initd';
import SERVICE_SCRIPT_HOST_RESOLVER from '@pkg/assets/scripts/service-host-resolver.initd';
import SERVICE_SCRIPT_K3S from '@pkg/assets/scripts/service-k3s.initd';
import SERVICE_VTUNNEL_PEER from '@pkg/assets/scripts/service-vtunnel-peer.initd';
import SERVICE_SCRIPT_DOCKERD from '@pkg/assets/scripts/service-wsl-dockerd.initd';
import SCRIPT_DATA_WSL_CONF from '@pkg/assets/scripts/wsl-data.conf';
import WSL_EXEC from '@pkg/assets/scripts/wsl-exec';
Expand All @@ -46,7 +45,6 @@ import WSL_INIT_RD_NETWORKING_SCRIPT from '@pkg/assets/scripts/wsl-init-rd-netwo
import { ContainerEngine } from '@pkg/config/settings';
import { getServerCredentialsPath, ServerState } from '@pkg/main/credentialServer/httpCredentialHelperServer';
import mainEvents from '@pkg/main/mainEvents';
import { getVtunnelInstance, getVtunnelConfigPath } from '@pkg/main/networking/vtunnel';
import BackgroundProcess from '@pkg/utils/backgroundProcess';
import * as childProcess from '@pkg/utils/childProcess';
import clone from '@pkg/utils/clone';
Expand Down Expand Up @@ -147,18 +145,6 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
shouldRun: () => Promise.resolve([State.STARTING, State.STARTED, State.DISABLED].includes(this.state)),
});

if (!this.cfg?.experimental.virtualMachine.networkingTunnel) {
// Register a new tunnel for RD Guest Agent
this.vtun.addTunnel({
name: 'Rancher Desktop Privileged Service',
handshakePort: 17382,
vsockHostPort: 17381,
peerAddress: '127.0.0.1',
peerPort: 3040,
upstreamServerAddress: 'npipe:////./pipe/rancher_desktop/privileged_service',
});
}

this.kubeBackend = kubeFactory(this);
}

Expand Down Expand Up @@ -244,9 +230,6 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
this.#noModalDialogs = value;
}

/** Vtunnel Proxy management singleton. */
protected vtun = getVtunnelInstance();

/**
* The current operation underway; used to avoid responding to state changes
* when we're in the process of doing a different one.
Expand Down Expand Up @@ -807,43 +790,18 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
const credsPath = getServerCredentialsPath();

try {
const vtunnelPeerServerAddr = '127.0.0.1:3030';
const credentialServerAddr = '192.168.127.254:6109';
// When networkTunnel is enabled we talk directly to the host which is assigned
// with 192.168.127.254 static address. Otherwise, we talk to the vtunnel peer
// which is listening in the WSL VM on 127.0.0.1:3030.
const credForwarderURL = this.cfg?.experimental.virtualMachine.networkingTunnel ? credentialServerAddr : vtunnelPeerServerAddr;
const stateInfo: ServerState = JSON.parse(await fs.promises.readFile(credsPath, { encoding: 'utf-8' }));
const escapedPassword = stateInfo.password.replace(/\\/g, '\\\\')
.replace(/'/g, "\\'");
// leading `$` is needed to escape single-quotes, as : $'abc\'xyz'
const leadingDollarSign = stateInfo.password.includes("'") ? '$' : '';
const fileContents = `CREDFWD_AUTH=${ leadingDollarSign }'${ stateInfo.user }:${ escapedPassword }'
CREDFWD_URL='http://${ credForwarderURL }'
CREDFWD_URL='http://${ credentialServerAddr }'
`;
const defaultConfig = { credsStore: 'rancher-desktop' };
let existingConfig: Record<string, any>;

const OldCredHelperService = '/etc/init.d/credhelper-vtunnel-peer';
const OldCredHelperConfd = '/etc/conf.d/credhelper-vtunnel-peer';

await this.handleUpgrade([OldCredHelperService, OldCredHelperConfd]);

await this.writeFile('/etc/init.d/vtunnel-peer', SERVICE_VTUNNEL_PEER, 0o755);
await this.writeConf('vtunnel-peer', {
VTUNNEL_PEER_BINARY: await this.getVtunnelPeerPath(),
LOG_DIR: await this.wslify(paths.logs),
CONFIG_PATH: await this.wslify(getVtunnelConfigPath()),
});
await this.execCommand('/sbin/rc-update', 'add', 'vtunnel-peer', 'default');

// Stop the service if RD Networking is enabled. We need to add it
// first as rc-service del … fails if the service is not enabled,
// but rc-service add … handles an already-enabled service fine.
if (this.cfg?.experimental.virtualMachine.networkingTunnel) {
await this.execCommand('/sbin/rc-update', 'del', 'vtunnel-peer', 'default');
}

await this.execCommand('mkdir', '-p', ETC_RANCHER_DESKTOP_DIR);
await this.writeFile(CREDENTIAL_FORWARDER_SETTINGS_PATH, fileContents, 0o644);
await this.writeFile(DOCKER_CREDENTIAL_PATH, DOCKER_CREDENTIAL_SCRIPT, 0o755);
Expand Down Expand Up @@ -1333,10 +1291,6 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend

this.privilegedServiceEnabled = rdNetworking ? false : await this.invokePrivilegedService('start');

if (!rdNetworking) {
await this.vtun.start();
}

if (config.kubernetes.enabled) {
prepActions.push((async() => {
[kubernetesVersion] = await this.kubeBackend.download(config);
Expand Down Expand Up @@ -1478,6 +1432,8 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
await this.execCommand({ root: true }, 'rm', '-f', obsoleteImageAllowListConf);
}),
await this.progressTracker.action('Rancher Desktop guest agent', 50, this.installGuestAgent(kubernetesVersion, this.cfg)),
// Remove any residual rc artifacts from previous versions when vtunnel was installed
await this.execCommand({ root: true }, 'rm', '-f', '/etc/init.d/vtunnel-peer', '/etc/runlevels/default/vtunnel-peer'),
]);

await this.writeFile('/usr/local/bin/wsl-exec', WSL_EXEC, 0o755);
Expand Down Expand Up @@ -1731,7 +1687,6 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
}
}
if (!this.cfg?.experimental.virtualMachine.networkingTunnel) {
await this.vtun.stop();
await this.resolverHostProcess.stop();
await this.invokePrivilegedService('stop');
}
Expand Down Expand Up @@ -1821,16 +1776,6 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
return this.wslify(executable('wsl-helper-linux'), distro);
}

/**
* Return the Linux path to the vtunnel peer executable.
*/
protected getVtunnelPeerPath(): Promise<string> {
// We need to get the Linux path to our helper executable; it is easier to
// just get WSL to do the transformation for us.

return this.wslify(path.join(paths.resources, 'linux', 'internal', 'vtunnel'));
}

async getFailureDetails(exception: any): Promise<FailureDetails> {
const loglines = (await fs.promises.readFile(console.path, 'utf-8')).split('\n').slice(-10);

Expand Down
15 changes: 0 additions & 15 deletions pkg/rancher-desktop/main/commandServer/httpCommandServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { TransientSettings } from '@pkg/config/transientSettings';
import type { DiagnosticsResultCollection } from '@pkg/main/diagnostics/diagnostics';
import { ExtensionMetadata } from '@pkg/main/extensions/types';
import mainEvents from '@pkg/main/mainEvents';
import { getVtunnelInstance } from '@pkg/main/networking/vtunnel';
import * as serverHelper from '@pkg/main/serverHelper';
import { Snapshot } from '@pkg/main/snapshots/types';
import Logging from '@pkg/utils/logging';
Expand Down Expand Up @@ -47,7 +46,6 @@ const SERVER_FILE_BASENAME = 'rd-engine.json';
const MAX_REQUEST_BODY_LENGTH = 4194304; // 4MiB

export class HttpCommandServer {
protected vtun = getVtunnelInstance();
protected server = http.createServer();
protected app = express();
protected readonly externalState: ServerState = {
Expand Down Expand Up @@ -117,19 +115,6 @@ export class HttpCommandServer {

async init() {
const localHost = '127.0.0.1';

// The peerPort and upstreamServerAddress port will need to match
// this is crucial if we ever pick dynamic ports for upstreamServerAddress
if (process.platform === 'win32') {
this.vtun.addTunnel({
name: 'CLI Server',
handshakePort: 17372,
vsockHostPort: 17371,
peerAddress: localHost,
peerPort: SERVER_PORT,
upstreamServerAddress: `${ localHost }:${ SERVER_PORT }`,
});
}
const statePath = path.join(paths.appHome, SERVER_FILE_BASENAME);

await fs.promises.mkdir(paths.appHome, { recursive: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { URL } from 'url';

import runCredentialHelper from './credentialUtils';

import { getVtunnelInstance } from '@pkg/main/networking/vtunnel';
import * as serverHelper from '@pkg/main/serverHelper';
import Logging from '@pkg/utils/logging';
import paths from '@pkg/utils/paths';
Expand Down Expand Up @@ -54,7 +53,6 @@ function ensureEndsWithNewline(s: string) {
}

export class HttpCredentialHelperServer {
protected vtun = getVtunnelInstance();
protected server = http.createServer();
protected password = serverHelper.randomStr();
protected stateInfo: ServerState = {
Expand All @@ -67,16 +65,6 @@ export class HttpCredentialHelperServer {
protected listenAddr = '127.0.0.1';

async init() {
if (process.platform === 'win32') {
this.vtun.addTunnel({
name: 'Credential Server',
handshakePort: 17362,
vsockHostPort: 17361,
peerAddress: this.listenAddr,
peerPort: 3030,
upstreamServerAddress: `${ this.listenAddr }:${ SERVER_PORT }`,
});
}
const statePath = getServerCredentialsPath();

await fs.promises.writeFile(statePath,
Expand Down
Loading

0 comments on commit 12e8f84

Please sign in to comment.