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

Connect: Make sure tsh auto-updates are turned off #49180

Merged
merged 3 commits into from
Nov 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The env vars available in the launch daemon process are just these:

TELEPORT_TOOLS_VERSION=off XPC_SERVICE_NAME=com.goteleport.tshdev.vnetd PATH=/usr/bin:/bin:/usr/sbin:/sbin XPC_FLAGS=1

</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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gzdunek I added this folder so we can start sorting shared files. I imagine we'd also want to create a folder called "universal" for files that are used both in the browser and in Node.js.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

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
Loading