Skip to content

Commit 9e3e157

Browse files
jc-clarkSiaraMist
andauthoredMay 16, 2024··
add pull_request_target information to caching example (#50658)
Co-authored-by: Siara <108543037+SiaraMist@users.noreply.github.com>
1 parent 60eec9d commit 9e3e157

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed
 

‎content/actions/using-workflows/caching-dependencies-to-speed-up-workflows.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ Caches have branch scope restrictions in place, which means some caches have lim
339339

340340
For example, a repository could have many new pull requests opened, each with their own caches that are restricted to that branch. These caches could take up the majority of the cache storage for that repository. {% data reusables.actions.cache-eviction-policy %} In order to prevent cache thrashing when this happens, you can set up workflows to delete caches on a faster cadence than the cache eviction policy will. You can use the [`gh-actions-cache`](https://github.com/actions/gh-actions-cache/) CLI extension to delete caches for specific branches.
341341

342-
This example workflow uses `gh-actions-cache` to delete up to 100 caches created by a branch once a pull request is closed.
342+
The following example workflow uses `gh-actions-cache` to delete up to 100 caches created by a branch once a pull request is closed.
343+
344+
To run the following example on cross-repository pull requests or pull requests from forks, you can trigger the workflow with the `pull_request_target` event. If you do use `pull_request_target` to trigger the workflow, there are security considerations to keep in mind. For more information, see "[AUTOTITLE](/actions/using-workflows/events-that-trigger-workflows#pull_request_target)."
343345

344346
```yaml
345347
name: cleanup caches by a branch

‎content/actions/using-workflows/events-that-trigger-workflows.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,7 @@ This event runs in the context of the base of the pull request, rather than in t
814814

815815
To ensure repository security, branches with names that match certain patterns (such as those which look similar to SHAs) may not trigger workflows with the `pull_request_target` event.
816816

817-
{% warning %}
818-
819-
**Warning:** For workflows that are triggered by the `pull_request_target` event, the `GITHUB_TOKEN` is granted read/write repository permission unless the `permissions` key is specified and the workflow can access secrets, even when it is triggered from a fork. Although the workflow runs in the context of the base of the pull request, you should make sure that you do not check out, build, or run untrusted code from the pull request with this event. Additionally, any caches share the same scope as the base branch. To help prevent cache poisoning, you should not save the cache if there is a possibility that the cache contents were altered. For more information, see "[Keeping your GitHub Actions and workflows secure: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests)" on the GitHub Security Lab website.
820-
821-
{% endwarning %}
817+
{% data reusables.actions.pull-request-target-permissions-warning %}
822818

823819
For example, you can run a workflow when a pull request has been `assigned`, `opened`, `synchronize`, or `reopened`.
824820

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% warning %}
2+
3+
**Warning:** For workflows that are triggered by the `pull_request_target` event, the `GITHUB_TOKEN` is granted read/write repository permission unless the `permissions` key is specified and the workflow can access secrets, even when it is triggered from a fork. Although the workflow runs in the context of the base of the pull request, you should make sure that you do not check out, build, or run untrusted code from the pull request with this event. Additionally, any caches share the same scope as the base branch. To help prevent cache poisoning, you should not save the cache if there is a possibility that the cache contents were altered. For more information, see "[Keeping your GitHub Actions and workflows secure: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests)" on the GitHub Security Lab website.
4+
5+
{% endwarning %}

0 commit comments

Comments
 (0)
Please sign in to comment.