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

GitHub proxy part 6.5: tsh git ssh/clone/config #50044

Merged
merged 7 commits into from
Jan 9, 2025
Merged

Conversation

greedy52
Copy link
Contributor

@greedy52 greedy52 commented Dec 11, 2024

related:

examples:

$ tsh git config
The current Git directory is configured with Teleport for GitHub organization "goteleport-core-test".

$ tsh git config reset
Teleport configuration removed.

$ tsh git config
The current Git directory is not configured with Teleport.
Run 'tsh git config update' to configure it.

$ tsh git config update
Teleport configuration added.
The current Git directory is configured with Teleport for GitHub organization "goteleport-core-test".

@greedy52 greedy52 mentioned this pull request Dec 10, 2024
17 tasks
@greedy52 greedy52 force-pushed the STeve/48762_ssh_tsh branch from 4aeabc8 to fd571b3 Compare December 11, 2024 03:32
@greedy52 greedy52 force-pushed the STeve/48762_ssh branch 2 times, most recently from a5cb9a6 to 97bbddf Compare December 12, 2024 01:33
@greedy52 greedy52 force-pushed the STeve/48762_ssh_tsh branch 3 times, most recently from fc0459d to 0e0f74f Compare December 16, 2024 18:04
go.mod Outdated
@@ -100,6 +100,7 @@ require (
github.com/fxamacker/cbor/v2 v2.7.0
github.com/ghodss/yaml v1.0.0
github.com/gizak/termui/v3 v3.1.0
github.com/go-git/go-git/v5 v5.12.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

go-git will be used for the teleport as well.

local mac build tsh increased about 200k (out of 106MB) after importing it.

@greedy52 greedy52 force-pushed the STeve/48762_ssh_tsh branch from 0e0f74f to f21c24c Compare December 17, 2024 15:37
@greedy52 greedy52 changed the base branch from STeve/48762_ssh to master December 17, 2024 15:37
@greedy52 greedy52 requested a review from Tener December 17, 2024 15:37
@greedy52 greedy52 marked this pull request as ready for review December 17, 2024 15:37
@github-actions github-actions bot added size/lg tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Dec 17, 2024
@greedy52 greedy52 force-pushed the STeve/48762_ssh_tsh branch from f21c24c to 9d38794 Compare December 17, 2024 15:46
Copy link

🤖 Vercel preview here: https://docs-1vdax8b5f-goteleport.vercel.app/docs

@greedy52 greedy52 added the no-changelog Indicates that a PR does not require a changelog entry label Dec 17, 2024
Copy link
Contributor

@Tener Tener left a comment

Choose a reason for hiding this comment

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

Can you add some context to the implementation choice, i.e, shelling out to git binaries versus using go-git? There are some pros and cons to both and it would be beneficial to hear your reasoning; perhaps worth documenting it in the package itself, too?

On that note, I wonder if we should start splitting the tsh subcommands into their own packages.

We are using git command line interface as the API, which makes it hard to spot any potential mistakes. We don't have infrastructure for this yet, but having an end-to-end suite of tests (including a real github repo and docker image with git) would be amazing.

All those shell invocations makes me wonder about Windows. Can you check if tsh.exe works as intended? (My build command: BUILDDIR=build-win FIDO2=no ARCH=amd64 OS=windows make build-win/tsh && mv build-win/tsh build-win/tsh.exe)

tool/tsh/common/git.go Show resolved Hide resolved
tool/tsh/common/git.go Show resolved Hide resolved
tool/tsh/common/git.go Show resolved Hide resolved
tool/tsh/common/git.go Outdated Show resolved Hide resolved
tool/tsh/common/git_clone.go Outdated Show resolved Hide resolved
tool/tsh/common/git_config.go Outdated Show resolved Hide resolved
tool/tsh/common/git_config.go Outdated Show resolved Hide resolved
@greedy52
Copy link
Contributor Author

greedy52 commented Jan 2, 2025

Can you add some context to the implementation choice, i.e, shelling out to git binaries versus using go-git? There are some pros and cons to both and it would be beneficial to hear your reasoning; perhaps worth documenting it in the package itself, too?

using go-git is an afterthought. By design, we use git under the hood. I've changed the commant to a TODO to investigating the option to use go-git. but overall i feel git binary is more stable (in all platforms) than go-git. And for things like tsh git clone --some-flag (which yet to be implemented), it will be easier to pass extra args directly to git binary then re-implementing the flags through go-git.

On that note, I wonder if we should start splitting the tsh subcommands into their own packages.

It still relies on CLIConf, so would require quite some refactoring to have its own package.

We are using git command line interface as the API, which makes it hard to spot any potential mistakes. We don't have infrastructure for this yet, but having an end-to-end suite of tests (including a real github repo and docker image with git) would be amazing.

Added to TODO list (#48762).

All those shell invocations makes me wonder about Windows. Can you check if tsh.exe works as intended? (My build command: BUILDDIR=build-win FIDO2=no ARCH=amd64 OS=windows make build-win/tsh && mv build-win/tsh build-win/tsh.exe)

I think it should work without issue. I will give it a shot later and submit a separate issue to track it if it doesn't work.

@greedy52
Copy link
Contributor Author

greedy52 commented Jan 9, 2025

friendly ping @smallinsky @r0mant


func (c *gitConfigCommand) run(cf *CLIConf) error {
// Make sure we are in a Git dir.
err := execGitWithStdoutAndStderr(cf, io.Discard, io.Discard, "rev-parse", "--is-inside-work-tree")
Copy link
Contributor

Choose a reason for hiding this comment

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

The --is-inside-work-tree return true or false:

  --is-inside-work-tree
           When the current working directory is inside the work tree of the repository print "true", otherwise "false".

Just want to ensure that we want to rely on command error and not handle the "false" case ?

Copy link
Contributor Author

@greedy52 greedy52 Jan 9, 2025

Choose a reason for hiding this comment

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

I don't see the false getting printed:

stevehuang@mac ~ $ git rev-parse --is-inside-work-tree
fatal: not a git repository (or any of the parent directories): .git

The fatal error is sent to stderr. Same on my mac or my ec2 linux machine.

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from r0mant January 9, 2025 16:15
@greedy52 greedy52 force-pushed the STeve/48762_ssh_tsh branch from 55f3f8e to 683d82a Compare January 9, 2025 16:32
@greedy52 greedy52 enabled auto-merge January 9, 2025 16:42
@greedy52 greedy52 added this pull request to the merge queue Jan 9, 2025
Merged via the queue into master with commit 5eee08d Jan 9, 2025
44 checks passed
@greedy52 greedy52 deleted the STeve/48762_ssh_tsh branch January 9, 2025 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Indicates that a PR does not require a changelog entry size/lg tsh tsh - Teleport's command line tool for logging into nodes running Teleport.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants