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

feat: Add https auth #748

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

jonathanmorley
Copy link
Contributor

@jonathanmorley jonathanmorley commented Apr 5, 2024

Shepherd currently uses ssh git urls to clone repositories.
This assumes that ssh auth is available in the environment for all repositories being cloned.

We are trying to use GitHub Actions to run Shepherd, with a GitHub App providing authentication.
This works for the API (we can have the GitHub App's API token get used by shepherd), but GitHub Apps do not have SSH keys associated with them to allow git pushes over ssh.

They can however use http authentication with their GitHub token to perform git pushes, which this PR allows for using (SHEPHERD_GITHUB_ENTERPRISE_BASE_URL=x-access-token:${GITHUB_PAT}@github.com)

@aorinevo aorinevo added the enhancement New feature or request label Apr 5, 2024
@aorinevo aorinevo requested review from kavitha186 and aorinevo April 5, 2024 20:27
@@ -26,7 +26,7 @@ npm install -g @nerdwallet/shepherd
If using GitHub Enterprise, ensure the following environment variables are exported:

```
export SHEPHERD_GITHUB_ENTERPRISE_BASE_URL={company_github_enterprise_base_url} # e.g., api.github.com
export SHEPHERD_GITHUB_ENTERPRISE_BASE_URL={company_github_enterprise_base_url} # e.g., github.com
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add both as example Github enterprise server (github.com) and api.github.com (Cloud github enterprise)? @jonathanmorley

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im not sure api.github.com is ever appropriate here.
I am using GitHub Enterprise Cloud, and github.com is the right value for this setting.
I would expect GitHub Enterprise Server to be installation-dependent.

Copy link
Collaborator

@aorinevo aorinevo Apr 10, 2024

Choose a reason for hiding this comment

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

When working with GitHub, the API endpoints differ based on whether you are using GitHub's public cloud service, GitHub Enterprise Cloud, or GitHub Enterprise Server (on-premises). Here’s how the endpoints vary:

In each case, the API functionality and how you interact with it are largely the same, but the base URL changes based on where your GitHub instance is hosted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think what you are describing is the API endpoint for GitHub, which is configurable in shepherd with SHEPHERD_GITHUB_ENTERPRISE_URL.

However, this environment variable is SHEPHERD_GITHUB_ENTERPRISE_BASE_URL, which appears to only be used as a hostname to generate git clone URLs.
I have observed both public github.com and github enterprise cloud using github.com for these values.

Copy link

Choose a reason for hiding this comment

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

I've observed this as well using Enterprise Cloud

@@ -309,7 +305,16 @@ class GithubAdapter extends GitAdapter {
}

protected getRepositoryUrl(repo: IRepo): string {
return `git@${gitHubEnterpriseBaseUrl}:${repo.owner}/${repo.name}.git`;
const gitHubEnterpriseBaseUrl = process.env.SHEPHERD_GITHUB_ENTERPRISE_BASE_URL ?? 'github.com';
Copy link
Collaborator

Choose a reason for hiding this comment

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

How moving the gitHubEnterpriseBaseUrl initialized outside class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is moved for a couple of reasons:

  1. Having it here improves testability (the tests would otherwise need to reimport the file within the tests)
  2. This reduces the scope of the variable (from file, to method), without loss, since the variable is only used in this method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As per my other comment, we should default to api.github.com. Additionally, as this has already been rolled out to consumers, we would want to avoid breaking consumers that depend on it being defaulted to api.github.com.

Copy link

Choose a reason for hiding this comment

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

Yeah I like having the callout in the readme

@@ -309,7 +305,16 @@ class GithubAdapter extends GitAdapter {
}

protected getRepositoryUrl(repo: IRepo): string {
return `git@${gitHubEnterpriseBaseUrl}:${repo.owner}/${repo.name}.git`;
const gitHubEnterpriseBaseUrl = process.env.SHEPHERD_GITHUB_ENTERPRISE_BASE_URL ?? 'github.com';
const githubProtocol = process.env.SHEPHERD_GITHUB_PROTOCOL ?? 'ssh';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious, what's the reasoning for defaulting to ssh instead of https?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only option right now is ssh. Setting the default to ssh maintains the backwards compatability

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @jonathanmorley, I've finally got some time to circle back on this. Changes make sense and you're correct that as the code currently exists, it only supports ssh, though it's rather odd as I've certainly used it for https without making any changes.

That said, the changes in this PR explicitly support https protocol and I'll work to land these changes this week.

At the moment I'm working through some dependency upgrades and ESM/CommonJS transpilation issues. Once complete, this will be a fast follow.

@@ -26,7 +26,7 @@ npm install -g @nerdwallet/shepherd
If using GitHub Enterprise, ensure the following environment variables are exported:

```
export SHEPHERD_GITHUB_ENTERPRISE_BASE_URL={company_github_enterprise_base_url} # e.g., api.github.com
export SHEPHERD_GITHUB_ENTERPRISE_BASE_URL={company_github_enterprise_base_url} # e.g., github.com
Copy link
Collaborator

@aorinevo aorinevo Apr 10, 2024

Choose a reason for hiding this comment

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

When working with GitHub, the API endpoints differ based on whether you are using GitHub's public cloud service, GitHub Enterprise Cloud, or GitHub Enterprise Server (on-premises). Here’s how the endpoints vary:

In each case, the API functionality and how you interact with it are largely the same, but the base URL changes based on where your GitHub instance is hosted.

@@ -309,7 +305,16 @@ class GithubAdapter extends GitAdapter {
}

protected getRepositoryUrl(repo: IRepo): string {
return `git@${gitHubEnterpriseBaseUrl}:${repo.owner}/${repo.name}.git`;
const gitHubEnterpriseBaseUrl = process.env.SHEPHERD_GITHUB_ENTERPRISE_BASE_URL ?? 'github.com';
Copy link
Collaborator

Choose a reason for hiding this comment

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

As per my other comment, we should default to api.github.com. Additionally, as this has already been rolled out to consumers, we would want to avoid breaking consumers that depend on it being defaulted to api.github.com.

@aorinevo
Copy link
Collaborator

aorinevo commented Apr 10, 2024

@jonathanmorley, thank you for contributing. When you get a chance, can you update the PR description with context for these changes?

@jonathanmorley jonathanmorley changed the title Add https auth feat: Add https auth Apr 16, 2024
Copy link

@cal4 cal4 Jul 26, 2024

Choose a reason for hiding this comment

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

Think it'd be useful to add a blurb to the Environment Variables table describing the new option for more exposure, something like:
| SHEPHERD_GITHUB_PROTOCOL | ssh | (github adapter) is the protocol to use when cloning repos. Can be https or ssh. https is useful when ssh is firewalled. |

@cal4
Copy link

cal4 commented Jul 26, 2024

Thanks for contributing this!

@aorinevo aorinevo closed this Oct 3, 2024
@aorinevo aorinevo reopened this Oct 3, 2024
@aorinevo aorinevo changed the base branch from main to feat/add-https-auth October 3, 2024 05:48
@aorinevo
Copy link
Collaborator

aorinevo commented Oct 3, 2024

While CI failures are valid, landing on feature branch so that we can collaborate on upstream branch to resolve them.

@aorinevo aorinevo self-requested a review October 3, 2024 05:50
@aorinevo aorinevo merged commit 0dd67d6 into NerdWalletOSS:feat/add-https-auth Oct 3, 2024
0 of 7 checks passed
@aorinevo
Copy link
Collaborator

aorinevo commented Oct 3, 2024

Please refer to #847 to track progress towards landing on upstream.

aorinevo added a commit that referenced this pull request Oct 3, 2024
* feat: Add https auth (#748)

---------

Co-authored-by: Jonathan Morley <morley.jonathan@gmail.com>
aorinevo pushed a commit that referenced this pull request Oct 3, 2024
# [2.6.0](v2.5.0...v2.6.0) (2024-10-03)

### Features

* **auth:** add support for https protocol ([#748](#748)) ([#847](#847)) ([c0e0596](c0e0596))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants