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

Feature: add argument --ghe-hostname for GHE Servers #362

Closed
2 tasks done
runjivu opened this issue Dec 26, 2024 · 6 comments
Closed
2 tasks done

Feature: add argument --ghe-hostname for GHE Servers #362

runjivu opened this issue Dec 26, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@runjivu
Copy link

runjivu commented Dec 26, 2024

Pre-submission checks

  • I am not reporting a bug (crash, false positive/negative, etc). These must be filed via the bug report template.
  • I have looked through the open issues for a duplicate request.

What's the problem this feature will solve?

I'm trying zizmor out with GHE Server repos, but for now github_api client's api_base is fixed to "https://api.github.com".

Describe the solution you'd like

by adding additional parameter --ghe-hostname, i can run something like
zizmor --gh-token {token} --ghe-hostname {github.example.com} example/repos,
which would be nice

Additional context

I am new to GitHub Actions security hardening.
In a GHE Server / self-hosted runner environments, it seems/feels inherently safer against many attacks..
Are they really?
I’d love to hear some advice on what specific things I should focus on to keep things secure in these environments! 😃

@woodruffw
Copy link
Owner

Hi @runjivu, thanks for the feature request!

Overall, this sounds like a good idea to me -- supporting both hosted and on-prem GHE is something we should do.

A couple of thoughts:

  1. How does this interact across multiple instances/hosts? For example, if a repo on a GHE host references actions/checkout, how do we ensure that the user's GH_TOKEN works for both the GHE host and the normal GH host, e.g. for the impostor-commit audit?
  2. How does GitHub's own gh CLI handle these cases? IMO we should closely mirror their own flags/behavior here.

In a GHE Server / self-hosted runner environments, it seems/feels inherently safer against many attacks..
Are they really?

It depends 🙂: self-hosted runners come in a large variety of configurations, some of which are less secure than GitHub-hosted runners. In general, GitHub recommends only using self-hosted runners on private repos, regardless of whether the repo is on a GH or GHE host.

In general however, my understanding is that the "best practice" for self-hosted runners is to never use persistent runners (only use ephemeral runners), and to manage your runners at whatever organizational level makes sense for your use case (e.g. repo/org/enterprise level) and not allow deviations from that level.

Some more docs here: https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners#self-hosted-runner-security

@runjivu
Copy link
Author

runjivu commented Dec 27, 2024

Hi @woodruffw , thank you for the quick response!

my initial thoughts on your points :

  1. How does GitHub's own gh CLI handle these cases?

when logging in with gh auth login,
gh cli seems to store and use hostnames under ~/.config/gh/hosts.yml , and set corresponding tokens to keychain.
example :

github.com:
    git_protocol: https
    users:
        runjivu:
    user: runjivu
github.example.com:
    git_protocol: https
    users:
        haneul:
    user: haneul

so as long as zizmor intends to get token directly with --gh-token , i think just passing --ghe-hostname may be sufficient enough ( fyi the flag for gh auth login is --hostname )

  1. How does this interact across multiple instances/hosts?

As far as I know, forks between github instances are prohibited, as github not does not provide a direct way to fork between separate instances . (I might be wrong, but i couldn't find related docs 😢)

According to reference doc, actions for GHE server first looks for repos in GHE instance, and then for actions in github.com.
(only if github connect is turned on)

reference : https://docs.github.com/en/enterprise-server@3.11/admin/managing-github-actions-for-your-enterprise/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#about-resolution-for-actions-using-github-connect

Since my organization does not enable github connect,
gh_token for GHE server was sufficient enough to do impostor-commit.

image

But for broader coverage impostor_commit.rs should also check for public actions for github.com also!

Lastly thank you for the advice, I'll start from there! and thanks for building this project!
It's great to be able to scan for workflow security holistlicly with zizmor 😀

@woodruffw
Copy link
Owner

i think just passing --ghe-hostname may be sufficient enough ( fyi the flag for gh auth login is --hostname )

Thanks, makes sense!

To bikeshed a bit: how do you feel about making it --gh-hostname? IMO that would be more consistent with the existing --gh-token flag. We could also allow GH_HOST to override it in the environment, which would be consistent with gh.

According to reference doc, actions for GHE server first looks for repos in GHE instance, and then for actions in github.com.

TIL, thanks for finding that!

@runjivu
Copy link
Author

runjivu commented Dec 28, 2024

Yes that makes sense, will do!
Should i work on PR #363 ?

@woodruffw
Copy link
Owner

Yes that makes sense, will do! Should i work on PR #363 ?

Yes, thanks!

@woodruffw
Copy link
Owner

Completed with #363 and #371.

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

No branches or pull requests

2 participants