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: proxing Git using SSH transport #49980

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

greedy52
Copy link
Contributor

Related:

will stack another PR for tsh git ssh/config/clone commands on top of this

@greedy52 greedy52 mentioned this pull request Dec 10, 2024
17 tasks
Base automatically changed from STeve/48762_github_oauth_flow to master December 10, 2024 17:50
@greedy52 greedy52 changed the base branch from master to STeve/48762_audit_log December 11, 2024 02:53
@greedy52 greedy52 changed the base branch from STeve/48762_audit_log to master December 11, 2024 02:53
@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 marked this pull request as ready for review December 12, 2024 01:59
Copy link
Contributor

@espadolini espadolini left a comment

Choose a reason for hiding this comment

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

Are you sure that hooking into lib/srv/forward.Server to essentially add a completely separate mode gated by a flag (or like three different and potentially conflicting flags) is easier than writing something new that's going to be structurally guaranteed to work as intended just for the purpose of forwarding the ssh git protocol?

Comment on lines +1901 to +1902
// GitServerGetter defines a service to get Git servers.
services.GitServerGetter
Copy link
Contributor

Choose a reason for hiding this comment

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

If ClientI already has a way to get a gitserver.Client which has GetGitServer and ListGitServers, why do we need to extend ClientI with methods at the top level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are casting ClientI to ProxyAccessPoint in a few places, which forces authclient to have same interface as Cache. Also gitserver.Client is not suitable for "AccessPoint".

one other option is to have a gitserver.ReadOnlyClient or decouple ClientI from ProxyAccessPoint somehow. any recommendation is welcome.

lib/proxy/router.go Outdated Show resolved Hide resolved
lib/proxy/router.go Show resolved Hide resolved
lib/srv/forward/sshserver.go Outdated Show resolved Hide resolved
lib/srv/forward/sshserver.go Outdated Show resolved Hide resolved
lib/reversetunnel/remotesite.go Outdated Show resolved Hide resolved
lib/srv/authhandlers.go Outdated Show resolved Hide resolved
lib/srv/git/git.go Outdated Show resolved Hide resolved
lib/srv/git/github.go Outdated Show resolved Hide resolved
lib/srv/git/github.go Outdated Show resolved Hide resolved
@greedy52
Copy link
Contributor Author

greedy52 commented Dec 16, 2024

Are you sure that hooking into lib/srv/forward.Server to essentially add a completely separate mode gated by a flag (or like three different and potentially conflicting flags) is easier than writing something new that's going to be structurally guaranteed to work as intended just for the purpose of forwarding the ssh git protocol?

will do 👍

@greedy52
Copy link
Contributor Author

i am splitting out some parts of this PR to separate ones like

@public-teleport-github-review-bot

@greedy52 - this PR will require admin approval to merge due to its size. Consider breaking it up into a series smaller changes.

@greedy52 greedy52 requested a review from espadolini January 2, 2025 14:19
@greedy52 greedy52 requested review from Tener and GavinFrazar and removed request for flyinghermit January 2, 2025 15:09
@greedy52
Copy link
Contributor Author

greedy52 commented Jan 7, 2025

@espadolini PTAL

lib/cryptosuites/suites.go Outdated Show resolved Hide resolved
lib/proxy/router.go Outdated Show resolved Hide resolved
lib/reversetunnel/localsite.go Outdated Show resolved Hide resolved
lib/srv/forward/sshserver.go Outdated Show resolved Hide resolved
lib/srv/forward/sshserver.go Outdated Show resolved Hide resolved
lib/sshutils/reply.go Outdated Show resolved Hide resolved
lib/srv/git/forward.go Outdated Show resolved Hide resolved
}

// Use auth.UserKeyAuth to verify user cert is signed by UserCA.
permissions, err := s.auth.UserKeyAuth(conn, key)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will also do regular RBAC on the TargetServer unless you also change the check for h.c.Component == teleport.ComponentForwardingNode in authhandlers.go

Copy link
Contributor Author

@greedy52 greedy52 Jan 8, 2025

Choose a reason for hiding this comment

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

there is a check to avoid that:

if h.isProxy() || h.c.Component == teleport.ComponentForwardingGit {
return permissions, nil
}

but in the long run, we should do some refactoring to have dedicated auth handler for each type.

lib/srv/git/forward.go Outdated Show resolved Hide resolved
return true, nil
case sshutils.ExecRequest:
return true, trace.Wrap(s.handleExec(ctx, ch, req, remoteSession))
case sshutils.EnvRequest:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we ever want and/or need envvars in the ssh git protocol?

Copy link
Contributor Author

@greedy52 greedy52 Jan 8, 2025

Choose a reason for hiding this comment

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

openssh sends LANG and GIT_PROTOCOL (when using v2 protocol). they are optional but it would be nice to forward them.

@greedy52 greedy52 added the no-changelog Indicates that a PR does not require a changelog entry label Jan 8, 2025
@greedy52 greedy52 requested a review from espadolini January 9, 2025 03:15
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.

A few comments.

In general, I wonder about the decision to reuse ssh connection functionality for this. If we ever want to support other protocols then suddenly we need to reinvent a lot of things. The implementation ends up rather intrusive as we need to hijack a number of bits, e.g. the routing to nodes.

I assume this point was discussed before, so I'm keen to learn the rationale behind this vs e.g. reusing the infrastructure for TCP apps.

api/types/server.go Outdated Show resolved Hide resolved
lib/proxy/router.go Show resolved Hide resolved
lib/srv/authhandlers.go Show resolved Hide resolved
@espadolini
Copy link
Contributor

In general, I wonder about the decision to reuse ssh connection functionality for this. If we ever want to support other protocols then suddenly we need to reinvent a lot of things.

I can't speak for the decision to use the git ssh protocol vs the git http protocol, but if we're going to use the git ssh protocol, reusing our existing SSH transport makes sense IMO. My initial recommendation was to actually make the configuration bits real static nodes in a similar fashion to the openssh ones, but we've decided to use a dedicated configuration type for git servers.

@greedy52
Copy link
Contributor Author

greedy52 commented Jan 9, 2025

In general, I wonder about the decision to reuse ssh connection functionality for this. If we ever want to support other protocols then suddenly we need to reinvent a lot of things.

I can't speak for the decision to use the git ssh protocol vs the git http protocol, but if we're going to use the git ssh protocol, reusing our existing SSH transport makes sense IMO. My initial recommendation was to actually make the configuration bits real static nodes in a similar fashion to the openssh ones, but we've decided to use a dedicated configuration type for git servers.

The very first git proxy poc is actually http-based for AWS CodeCommit using AWS app access. But AWS CodeCommit is dead now.

Like Edoardo said, this is what we end up with after a few iterations of poc and RFD discussions. GitLab supports SSH CA as well. Even if we have to do HTTP later, I don't think it's that difficult.

@greedy52 greedy52 requested a review from Tener January 9, 2025 21:52
@greedy52
Copy link
Contributor Author

@espadolini @Tener could you take another look? thanks!

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants