Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

gerrit: Add support for SSH cloning#61537

Merged
eseliger merged 2 commits intomainfrom
es/gerrit-ssh
Apr 4, 2024
Merged

gerrit: Add support for SSH cloning#61537
eseliger merged 2 commits intomainfrom
es/gerrit-ssh

Conversation

@eseliger
Copy link
Member

@eseliger eseliger commented Apr 3, 2024

To bring Gerrit support more in line with other code hosts and because a customer recently ran into this limitation, this PR adds support for the SSH flag.

The diff is mostly straightforward, with two things to watch out for:

  • The clone URL construction in makeRepo was wrong previously, it missed the /a/. This is only used for visuals, but still annoying. So I moved the whole construction into here from the gitserver cloneURL package.
  • The SSH hostname and port are configurable in Gerrit, so to construct the right URL we need to fetch some instance metadata. This would be costly to do in the gitserver method, so we persist all the info needed to construct clone URLs "offline" during the cloning process by storing all the data for HTTP and SSH clones on the repo metadata column. This is mostly in line with other code hosts as well, see GitLab right above in the gitserver/cloneurl package.

Closes https://github.com/sourcegraph/sourcegraph/issues/60597

Test plan

Added tests for the various stages, recreated recorded responses, and tried both HTTP and SSH cloning locally, both worked with out Gerrit instance.

@cla-bot cla-bot bot added the cla-signed label Apr 3, 2024
@github-actions github-actions bot added team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all labels Apr 3, 2024
To bring Gerrit support more in line with other code hosts and because a customer recently ran into this limitation, this PR adds support for the SSH flag.

The diff is mostly straightforward, with two things to watch out for:
- The clone URL construction in makeRepo was wrong previously, it missed the `/a/`. This is only used for visuals, but still annoying. So I moved the whole construction into here from the gitserver cloneURL package.
- The SSH hostname and port are configurable in Gerrit, so to construct the right URL we need to fetch some instance metadata. This would be costly to do in the gitserver method, so we persist all the info needed to construct clone URLs "offline" during the cloning process by storing all the data for HTTP and SSH clones on the repo metadata column. This is mostly in line with other code hosts as well, see GitLab right above in the gitserver/cloneurl package.

Closes https://github.com/sourcegraph/sourcegraph/issues/60597

## Test plan

Added tests for the various stages, recreated recorded responses, and tried both HTTP and SSH cloning locally, both worked with out Gerrit instance.
@eseliger eseliger marked this pull request as ready for review April 3, 2024 12:21
@eseliger eseliger requested a review from a team April 3, 2024 12:21
- Auth providers now support a `noSignIn` option that, when set to true, will hide the auth provider from the sign in page, but still allow users to connect the external account from their Account Security page for permissions syncing. [#60722](https://github.com/sourcegraph/sourcegraph/pull/60722)
- Added a "Commits" button to the folders in repos that shows commits for the items in that folder. [#60909](https://github.com/sourcegraph/sourcegraph/pull/60909)
- The frontend Grafana dashboard has a new Prometheus metric that tracks the rate of requests that Sourcegraph issues to external services. [#61348](https://github.com/sourcegraph/sourcegraph/pull/61348)
- Added support for the `gitURLType` setting for Gerrit, Sourcegraph now supports cloning from Gerrit via SSH. Note: Not on Cloud yet, like for all code hosts. [#61537](https://github.com/sourcegraph/sourcegraph/pull/61537)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we support SSH on cloud?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we have no way of configuring known_hosts and ssh keypairs in-app right now (that's one of the things on our potential roadmap), it requires a deployment change where you mount those files into gitserver. Since customers on cloud cannot modify the deployment, they cannot do that -> not supported.

https://sourcegraph.com/docs/admin/deploy/kubernetes/configure#ssh-for-cloning

u, err := url.Parse(cfg.Url)
if err != nil {
logger.Warn("Error adding authentication to Gerrit project remote URL.", log.String("url", cfg.Url), log.Error(err))
return cfg.Url
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is an error why doesnt this return an error ?

Copy link
Member Author

Choose a reason for hiding this comment

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

To be honest, I'm not entirely sure, I followed what we do for all other code host types in this file. Might be good to clean that up though and return proper errors?

Copy link
Contributor

Choose a reason for hiding this comment

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

The function where this is called returns string, error anyways, so we could just have these return errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll push this as a separate PR to make pinpointing potential issues easier, but agree that handling errors is probably better than logging which customers on Cloud have no insight to!

Copy link
Member Author

Choose a reason for hiding this comment

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

u := *instanceHTTPURL
u.User = nil
// Gerrit encodes slashes in IDs, so need to decode them.
decodedName := strings.ReplaceAll(p.ID, "%2F", "/")
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use a more general urldecode type method?

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this code over from the clone_url package unmodified - I'm not sure why this was picked and if there's some other things in gerrit that might break (can you have names in gerrit that need to be URL encoded but will not be here?)

I can make the change, but felt slightly risky. WDYT? Worth it?

Copy link
Contributor

Choose a reason for hiding this comment

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

No not worth it

@eseliger eseliger merged commit 5a370f2 into main Apr 4, 2024
@eseliger eseliger deleted the es/gerrit-ssh branch April 4, 2024 13:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for SSH cloning in Gerrit

3 participants