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

Added GitHub Enterprise and Private GitHub support #83

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

Conversation

chp9-u
Copy link

@chp9-u chp9-u commented Aug 6, 2020

A naive and working attempt to support both Github Enterprise Private and GitHub Private Repositories

@welcome
Copy link

welcome bot commented Aug 6, 2020

Welcome! Congrats on your first pull request to Jekyll Remote Theme. If you haven't already, please be sure to check out the contributing guidelines.

@chp9-u
Copy link
Author

chp9-u commented Aug 6, 2020

resolves #81

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Dec 25, 2020
Copy link
Owner

@benbalter benbalter left a comment

Choose a reason for hiding this comment

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

I'd be curious to learn more about what workflow you're trying to solve for here. Enterprise Server support was added in #53.

```
Where the personal autorization token is the token provided by the github repo setting page.

> :warning: **Storing credentials can lead to security issues** - As stated in the [Creating a personal access token on GitHub guides](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) Treat your tokens like passwords and keep them secret. When working with the API, use tokens as environment variables instead of hardcoding them into your programs.
Copy link
Owner

Choose a reason for hiding this comment

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

Given that this is explicitly called out in the documentation, I'd be hesitant to create a workflow that requires committing the secret to the repository. Could we use an environmental variable as suggested?

Copy link
Author

Choose a reason for hiding this comment

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

I fully agree that specifying an environment variable here would prevent "hardcoding" any credentials which can be a security hazard. Unfortunately, unless some changes are done on the server side to allow the GitHub Pages to specify credentials for a privately hosted themes, this was the easiest way to solve the issue.

Copy link

Choose a reason for hiding this comment

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

So does this mean that there is no way for GitHub Secrets to be accessed in the GitHub Pages environment?

CONFIG_KEY = "remote_theme"
CONFIG_REPOSITORY_KEY = "repository"
CONFIG_THEME_KEY = "remote_theme"
CONFIG_HEADERS_KEY = "remote_headers"
Copy link
Owner

Choose a reason for hiding this comment

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

Why would a user need to be able to specify custom headers?

Copy link
Author

Choose a reason for hiding this comment

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

To allow downloading a private hosted theme and additional headers required in a large organization.

end
end

def fetch(uri_str, limit = 10)
Copy link
Owner

Choose a reason for hiding this comment

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

Can you describe the change here? I'm having trouble following.

Copy link
Author

Choose a reason for hiding this comment

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

It takes the remote_headers from the configuration file and ensures that the custom headers are passed to the request of the download of the remote_theme. I had to reorganize the download function code for readability and usability.

More details are provided with additional comments of the relevant code.

ENV["PAGES_GITHUB_HOSTNAME"],
ENV["GITHUB_HOSTNAME"],
host,
default_host,
Copy link
Owner

Choose a reason for hiding this comment

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

As currently written, this is an anti-abuse mechanism, which it looks like this change removes. In an untrusted environment, a malicious actor could request a remote theme from a malicious Git server, leading to a denial of service or other attack. How would we limit hosts in untrusted environments?

Copy link
Author

Choose a reason for hiding this comment

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

The problem for us is that since we are using custom DNS, privately hosted repos, the themes are not hosted on any of theses endpoints.

@stale stale bot removed wontfix labels Jan 4, 2021
@chp9-u
Copy link
Author

chp9-u commented Jan 4, 2021

I'd be curious to learn more about what workflow you're trying to solve for here. Enterprise Server support was added in #53.

We are hosting our GitHub Enterprise Server (2.21) with a custom internal DNS so it is not using the default github.<enterprise>.com. Our themes repos are also hosted internally and forced to be private by the administrators. Since we can't access anything on the server side, including the process of generating jekyll pages (we are a large organization), we can't rely on environment variables to pass the token to download the theme.

:host => "codeload.#{theme.host}",
:path => [theme.owner, theme.name, "zip", theme.git_ref].join("/")
:host => theme.host,
:path => [theme.owner, theme.name, "archive", theme.git_ref + ".zip"].join("/")
Copy link
Author

Choose a reason for hiding this comment

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

According to the GitHub API documentation, host "api.github.com" and rest endpoint "zipball" is the proper endpoint for getting the repository archive zip file. As per the documentation, this requires support for redirections.

Using "archive" should extend the the support to other git private repository such as gitlab and still work for github repos.

raise_unless_sucess(response)
enforce_max_file_size(response.content_length)
response.read_body do |chunk|
zip_file.write chunk
Copy link
Author

Choose a reason for hiding this comment

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

Reorganizing code for better readability and usability

end

req
end
Copy link
Author

Choose a reason for hiding this comment

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

Create a request including the remote_headers configuration provided to the downloader

response.read_body do |chunk|
zip_file.write chunk
end
end
Copy link
Author

Choose a reason for hiding this comment

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

Reading the archive file from the server as per the download code above

when Net::HTTPSuccess
handle_response(response)
when Net::HTTPRedirection
fetch(response["location"], limit - 1)
Copy link
Author

Choose a reason for hiding this comment

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

Our organization is using a custom DNS, and the REST Api are creating some redirections. This new download code supports HTTP Redirections to a maximum of 10 hops.

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

Successfully merging this pull request may close these issues.

3 participants