Skip to content

Commit

Permalink
Connect: Make sure tsh auto-updates are turned off (#49180)
Browse files Browse the repository at this point in the history
* Add dir for code shared between Node.js processes

* Connect: Make sure tsh auto-updates are turned off

* Pass TELEPORT_TOOLS_VERSION=off to tsh vnet-daemon
  • Loading branch information
ravicious committed Nov 19, 2024
1 parent 34a9b14 commit 49d109a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@
<string>/var/log/vnet.log</string>
<key>ThrottleInterval</key>
<integer>5</integer>
<key>EnvironmentVariables</key>
<dict>
<!-- Auto-updates are disabled because $HOME isn't available,
but let's also disable them explicitly anyway. -->
<key>TELEPORT_TOOLS_VERSION</key>
<string>off</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@
<string>/var/log/vnet.log</string>
<key>ThrottleInterval</key>
<integer>5</integer>
<key>EnvironmentVariables</key>
<dict>
<!-- Auto-updates are disabled because $HOME isn't available,
but let's also disable them explicitly anyway. -->
<key>TELEPORT_TOOLS_VERSION</key>
<string>off</string>
</dict>
</dict>
</plist>
5 changes: 5 additions & 0 deletions web/packages/teleterm/src/mainProcess/mainProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ import * as grpcCreds from 'teleterm/services/grpcCredentials';
import { createTshdClient, TshdClient } from 'teleterm/services/tshd';
import { loggingInterceptor } from 'teleterm/services/tshd/interceptors';
import { staticConfig } from 'teleterm/staticConfig';
import {
TSH_AUTOUPDATE_ENV_VAR,
TSH_AUTOUPDATE_OFF,
} from 'teleterm/node/tshAutoupdate';

import {
ConfigService,
Expand Down Expand Up @@ -188,6 +192,7 @@ export default class MainProcess {
env: {
...process.env,
TELEPORT_HOME: homeDir,
[TSH_AUTOUPDATE_ENV_VAR]: TSH_AUTOUPDATE_OFF,
},
}
);
Expand Down
2 changes: 2 additions & 0 deletions web/packages/teleterm/src/node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Files in this directory are executed within a Node.js process, be it the main process or the shared
process.
27 changes: 27 additions & 0 deletions web/packages/teleterm/src/node/tshAutoupdate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* An env var which controls whether tsh is going to download an up-to-date version of itself
* to ~/.tsh/bin and re-execute itself. In Connect, we always want it to be set to 'off', as Connect
* needs to use the bundled tsh where the version of tsh matches exactly the version of Connect.
*
* See RFD 144 for more details.
*/
export const TSH_AUTOUPDATE_ENV_VAR = 'TELEPORT_TOOLS_VERSION';
export const TSH_AUTOUPDATE_OFF = 'off';
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ describe('buildPtyOptions', () => {
});

expect(processOptions.env.WSLENV).toBe(
'CUSTOM_VAR:TERM_PROGRAM:TERM_PROGRAM_VERSION:TELEPORT_CLUSTER:TELEPORT_PROXY:TELEPORT_HOME/p:KUBECONFIG/p'
'CUSTOM_VAR:KUBECONFIG/p:TERM_PROGRAM:TERM_PROGRAM_VERSION:TELEPORT_CLUSTER:TELEPORT_PROXY:TELEPORT_HOME/p:TELEPORT_TOOLS_VERSION'
);
});
});
12 changes: 10 additions & 2 deletions web/packages/teleterm/src/services/pty/ptyHost/buildPtyOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ import path, { delimiter } from 'path';
import { RuntimeSettings } from 'teleterm/mainProcess/types';
import { PtyProcessOptions } from 'teleterm/sharedProcess/ptyHost';
import { assertUnreachable } from 'teleterm/ui/utils';

import { Shell, makeCustomShellFromPath } from 'teleterm/mainProcess/shell';
import { CUSTOM_SHELL_ID } from 'teleterm/services/config/appConfigSchema';
import {
TSH_AUTOUPDATE_ENV_VAR,
TSH_AUTOUPDATE_OFF,
} from 'teleterm/node/tshAutoupdate';

import {
PtyCommand,
Expand Down Expand Up @@ -92,6 +95,9 @@ export async function buildPtyOptions({
throw error;
})
.then(({ shellEnv, creationStatus }) => {
// combinedEnv is going to be used as env by every command coming out of buildPtyOptions. Some
// commands might add extra variables, but they shouldn't remove any of the env vars that are
// added here.
const combinedEnv = {
...processEnv,
...shellEnv,
Expand All @@ -100,6 +106,7 @@ export async function buildPtyOptions({
TELEPORT_HOME: settings.tshd.homeDir,
TELEPORT_CLUSTER: cmd.clusterName,
TELEPORT_PROXY: cmd.proxyHost,
[TSH_AUTOUPDATE_ENV_VAR]: TSH_AUTOUPDATE_OFF,
};

// The regular env vars are not available in WSL,
Expand All @@ -108,12 +115,13 @@ export async function buildPtyOptions({
// https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
if (settings.platform === 'win32' && shell.binName === 'wsl.exe') {
const wslEnv = [
'KUBECONFIG/p',
'TERM_PROGRAM',
'TERM_PROGRAM_VERSION',
'TELEPORT_CLUSTER',
'TELEPORT_PROXY',
'TELEPORT_HOME/p',
'KUBECONFIG/p',
TSH_AUTOUPDATE_ENV_VAR,
];
// Preserve the user defined WSLENV and add ours (ours takes precedence).
combinedEnv[WSLENV_VAR] = [combinedEnv[WSLENV_VAR], wslEnv]
Expand Down

0 comments on commit 49d109a

Please sign in to comment.