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

Use dbcmd.WithPrintFormat only for preview of teleterm gateway command #39906

Merged
merged 4 commits into from
Mar 29, 2024

Conversation

ravicious
Copy link
Member

@ravicious ravicious commented Mar 27, 2024

Fixes #39836.

Changelog: Fixed "Invalid URI" error when starting mongosh from database connection tab in Teleport Connect

Currently lib/teleterm uses dbcmd.WithPrintFormat when generating db commands. This option is meant to be used when the command is printed rather than executed, i.e. tsh db config --format cmd. It wraps connection strings in quotes. This way when the user copies a command and tries to execute it in a shell, the shell doesn't interpret certain characters in the connection string as special characters.

This worked in Connect because for a long time we did put those commands directly into a shell. However, in #26441 we switched to spawning CLI clients directly, which means that the quotes are at best unnecessary and at worst cause problems like the one described in #39836.

To fix this, daemon.Service.GetGatewayCLICommand returns two exec.Cmds: one that doesn't use the print format and one that does. The one that does use the print format should be used for api.GatewayCLICommand.Preview, while other fields should come from the exec.Cmd that doesn't use the print format.

This way when the user clicks "Run", we execute the command without the quotes. But in the UI we display the version with the quotes, so that the user can simply copy and paste the command somewhere outside of Teleport Connect.

At the moment it mostly affects Mongodb. Looking at dbcmd, I don't think other protocols were affected.

mongo-gateway

@ravicious ravicious force-pushed the r7s/dbcmd-print-format branch from 1549626 to 17944a2 Compare March 28, 2024 11:36
lib/teleterm/cmd/db_test.go Outdated Show resolved Hide resolved
@ravicious
Copy link
Member Author

@probakowski Ping, we have a customer waiting for this fix.

@ravicious ravicious enabled auto-merge March 29, 2024 14:29
@ravicious ravicious added this pull request to the merge queue Mar 29, 2024
Merged via the queue into master with commit 584fd5d Mar 29, 2024
38 checks passed
@ravicious ravicious deleted the r7s/dbcmd-print-format branch March 29, 2024 15:53
@public-teleport-github-review-bot

@ravicious See the table below for backport results.

Branch Result
branch/v13 Failed
branch/v14 Failed
branch/v15 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error reported attempting to connect to MongoDB resources via Teleport Connect
3 participants