-
Notifications
You must be signed in to change notification settings - Fork 10
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
docs: preview in PRs from forks #194
Comments
Apparently this is by design to prevent security risks from malicious PRs.
A safe alternative would be to create a separate repository - something like score-previews where only the previews from PR are pushed. The https://eclipse-score.github.io/score would only hold main and releases. This would avoid cluttering the gh-pages ( although in theory they are deleted when the PR is merged). Nevertheless, we could still try the following:
|
Fine grained PATs do not allow branch restrictions sadly. So we could in theory create a DEPLOY_PREVIEW_TOKEN, but GH doesn't allow for it to be restricted to a specific branch ( gh-pages for us) |
The github-pages-deploy-action also allows ssh-key usage So, one could:
2, add the public key to GH
|
Is an Environment secret also a viable alternative? With review by "trusted contributors" before the action starts. Just collecting ideas. |
@AlexanderLanin yes, using a combination of environment secrets with manual approval is definitely an alternative, which would require a trusteed reviewer ( not a big problem from my pov, considering the PRs have to be reviewed in any case). So the steps would be to store a GH Actions secret in an Env and require manual approval before the workflow can access the secret. Afterwards, the secret will be used to authenticate and push changes to the gh-pages branch. StepsCreate an env with a secret
Modify Your GitHub Actions Workflow The documentation workflow should be modified to: -Use pull_request_target to ensure it runs with main repository permissions.
|
I will test the behavior on some dummy repos to see how these work |
Since pull_request_target runs in the context of the base repository, it does not automatically check out the PR's code. This is why no changes are detected and it is not a viable option. |
Tried with a PAT (configured as secret). That's why my secret is never available in forked PRs, even after approval. |
Tried also configuring a separate env, which required manual approval and triggering. Sadly the secrets are still obfuscated by GitHub for the PRs coming from forks.
|
Both env variables and secrets are not accessible from forked PRs. Also, trying to embed a private key in the workflow doens't do the trick, as GH protection pick-up on it
|
I attempted to use a workflow_run that triggers upon the completion of a doc build workflow to publish documentation. The doc build workflow successfully uploads an artifact containing the documentation. However, the workflow_run (which would run in the context of the source repo, and not the fork) fails to access this artifact because GitHub Actions does not support sharing artifacts between workflows, even if they belong to the same repository. Artifacts are scoped to the workflow that created them and workflow_run workflows cannot directly access them. This limitation makes the workflow_run approach unsuitable for artifact-dependent tasks across workflows. The idea was that when a PR (from a fork was triggered)
the artifact is uploaded and there is a workflow_run that executes in the context of the source repo (not the forked one) and publishes the GH Pages
|
After exploring multiple approaches, including workflow_run triggers and artifact sharing between workflows, the only viable solution to publish GitHub Pages from pull requests originating from forks is to use a separate repository (score-preview) dedicated to hosting preview pages. To mitigate these risks:
For official releases and the primary documentation, the original repository ( score) will continue to host and manage them with branch protection and other safeguards in place. This ensures the integrity of the main documentation while enabling a workaround for PR previews from forks. |
Went over the documentation again https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token It appears that The problem with my earlier attempts was that we need to manually checkout the code from the forked branch/PR. |
Pushing to GitHub Pages from a Forked Pull Request (conclusions)When working with GitHub Pages in repositories where contributors submit changes via forks, special considerations must be taken due to security restrictions imposed by GitHub Actions. This comment covers how to safely publish content to GitHub Pages from a pull request originating from a fork, based on previous research and try-outs on dummy repos. Why Use
|
Thanks for that! It is a nice read! How about converting it to @everyone: if you know any github experts, please ask them for a review! |
@dcalavrezo-qorix would it make sense to implement 1-3 and then revisit 4? Or is it too much overhead? |
@AlexanderLanin it makes sense. The overhead would be low. |
Problem Description
Currently PRs from forks do not have any kind of preview for the generated documentation.
The workflow is established, but it has insufficient access rights when the PR stems from a fork. Detailed explanation and potential solution at eclipse-score/.eclipsefdn#11
Task:
The text was updated successfully, but these errors were encountered: