Skip to content

Commit ffb8835

Browse files
authored
docs: harden GITHUB_TOKEN permissions in gitStream workflow templates (#850)
* docs: harden GITHUB_TOKEN permissions in gitStream workflow templates Add `permissions: contents: read` to the generated gitStream workflow templates and all inline snippets in the installation + troubleshooting docs. Add a dedicated section explaining the two-token split (workflow GITHUB_TOKEN vs. gitStream App installation token) and why scoping to contents: read does not affect any feature. Covers: - docs/downloads/gitstream.yml - docs/downloads/gitstream-lite.yml - docs/github-installation.md (inline snippets + new section) - docs/troubleshooting.md (dependabot + lite snippets) - tutorials/basic-usage-python-repo/.github/workflows/gitstream.yml - .github/workflows/gitstream.yml (dogfood) Follows https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/ * chore: retrigger CI
1 parent eba47d0 commit ffb8835

6 files changed

Lines changed: 50 additions & 4 deletions

File tree

.github/workflows/gitstream.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ on:
3030
required: false
3131
default: ''
3232

33+
permissions:
34+
contents: read
35+
3336
jobs:
3437
gitStream:
35-
timeout-minutes: 5
38+
timeout-minutes: 15
3639
runs-on: ubuntu-latest
3740
name: gitStream workflow automation
3841
steps:

docs/downloads/gitstream-lite.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ on:
3030
required: false
3131
default: ''
3232

33+
permissions:
34+
contents: read
35+
3336
jobs:
3437
gitStream:
3538
timeout-minutes: 15

docs/downloads/gitstream.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ on:
3030
required: false
3131
default: ''
3232

33+
permissions:
34+
contents: read
35+
3336
jobs:
3437
gitStream:
3538
timeout-minutes: 15

docs/github-installation.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ You can set up gitStream for a single repo or your entire GitHub organization. S
6868
If you're working with a large repository (typically monorepos) and experience timeout issues during GitHub Actions execution, you can use the lite version of gitStream that performs a shallow clone to reduce execution time:
6969

7070
```yaml
71+
permissions:
72+
contents: read
73+
7174
jobs:
7275
gitStream:
7376
timeout-minutes: 15
@@ -135,6 +138,9 @@ You can set up gitStream for a single repo or your entire GitHub organization. S
135138
If you're working with large repositories in your organization (typically monorepos) and experience timeout issues during GitHub Actions execution, you can use the lite version of gitStream that performs a shallow clone to reduce execution time:
136139

137140
```yaml
141+
permissions:
142+
contents: read
143+
138144
jobs:
139145
gitStream:
140146
timeout-minutes: 15
@@ -186,6 +192,25 @@ You can set up gitStream for a single repo or your entire GitHub organization. S
186192
| Read and write access to actions, checks, pull requests, and workflows | Trigger workflows, create and update pull requests and their checks, and modify workflow files |
187193
| User email | Used to identify users |
188194

195+
### Hardening the Workflow `GITHUB_TOKEN`
196+
197+
The generated `.github/workflows/gitstream.yml` declares an explicit `permissions:` block that scopes the workflow's built-in `GITHUB_TOKEN` to the minimum required:
198+
199+
```yaml
200+
permissions:
201+
contents: read
202+
```
203+
204+
This follows GitHub's [least-privilege guidance for `GITHUB_TOKEN`](https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/). All remaining scopes default to `none` once any key is set.
205+
206+
!!! info "Why `contents: read` is sufficient"
207+
The gitStream action uses two distinct tokens:
208+
209+
- **`GITHUB_TOKEN`** (built into the workflow runner) — used only to clone the repository via `actions/checkout`. Needs `contents: read` on private repos.
210+
- **gitStream App installation token** — passed through `client_payload` and used by the action for all PR comments, labels, approvals, and checks. Governed by the **GitHub App permissions** documented above, independent of the workflow `permissions:` block.
211+
212+
Scoping `GITHUB_TOKEN` down to `contents: read` does not affect any gitStream feature — writes flow through the App token.
213+
189214
### Configure gitStream to Block Merges <a name="github-merge-block"></a>
190215
You can configure GitHub to require gitStream checks to pass before PRs can be merged using [branch protection rules](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches).
191216

@@ -221,6 +246,9 @@ Follow these steps to ensure gitStream runs on self-hosted GitHub Actions runner
221246
- Modify the gitStream GitHub Actions workflow file (`.github/workflows/gitstream.yml`) to specify self-hosted runners:
222247

223248
```yaml
249+
permissions:
250+
contents: read
251+
224252
jobs:
225253
gitStream:
226254
runs-on: self-hosted

docs/troubleshooting.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ When using repository level rules, you can edit the `.github/workflows/gitstream
9595

9696
This will not work for org level rules
9797

98-
```yaml+jinja title=".github/workflows/gitstream.yml" hl_lines="5"
98+
```yaml+jinja title=".github/workflows/gitstream.yml" hl_lines="8"
99+
permissions:
100+
contents: read
101+
99102
jobs:
100103
gitStream:
101-
timeout-minutes: 5
104+
timeout-minutes: 15
102105
# uncomment this condition, if you don't want any automation on dependabot PRs
103106
if: github.actor != 'dependabot[bot]'
104107
runs-on: ubuntu-latest
@@ -180,6 +183,9 @@ If you're experiencing timeout issues during GitHub Actions execution, particula
180183
You can resolve this by using the **lite version** of the gitStream GitHub Action, which performs a shallow clone to reduce execution time:
181184

182185
```yaml
186+
permissions:
187+
contents: read
188+
183189
jobs:
184190
gitStream:
185191
timeout-minutes: 15

tutorials/basic-usage-python-repo/.github/workflows/gitstream.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ on:
2828
required: false
2929
default: ''
3030

31+
permissions:
32+
contents: read
33+
3134
jobs:
3235
gitStream:
33-
timeout-minutes: 5
36+
timeout-minutes: 15
3437
# uncomment this condition, if you dont want any automation on dependabot PRs
3538
# if: github.actor != 'dependabot[bot]'
3639
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)