Skip to content

Commit 6bc6ec3

Browse files
committed
ci: reduce workflow permissions
Decrease security exposure by restricting what the code executing in the actions is allowed to do (in terms of GitHub operations).
1 parent e2567a6 commit 6bc6ec3

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

.github/workflows/main.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ on:
1313
branches:
1414
- main
1515
- "[0-9]+.[0-9]+.x"
16+
1617
env:
1718
PYTEST_ADDOPTS: "--color=yes"
1819

20+
# Set permissions at the job level.
21+
permissions: {}
22+
1923
jobs:
2024
build:
2125
runs-on: ${{ matrix.os }}
2226
timeout-minutes: 30
27+
permissions:
28+
contents: read
2329

2430
strategy:
2531
fail-fast: false
@@ -139,10 +145,13 @@ jobs:
139145
- uses: actions/checkout@v2
140146
with:
141147
fetch-depth: 0
148+
persist-credentials: false
149+
142150
- name: Set up Python ${{ matrix.python }}
143151
uses: actions/setup-python@v2
144152
with:
145153
python-version: ${{ matrix.python }}
154+
146155
- name: Install dependencies
147156
run: |
148157
python -m pip install --upgrade pip
@@ -164,49 +173,67 @@ jobs:
164173

165174
linting:
166175
runs-on: ubuntu-latest
176+
permissions:
177+
contents: read
178+
167179
steps:
168180
- uses: actions/checkout@v2
181+
with:
182+
persist-credentials: false
183+
169184
- uses: actions/setup-python@v2
185+
170186
- name: set PY
171187
run: echo "name=PY::$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
188+
172189
- uses: actions/cache@v2
173190
with:
174191
path: ~/.cache/pre-commit
175192
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
193+
176194
- name: Install dependencies
177195
run: |
178196
python -m pip install --upgrade pip
179197
pip install tox
198+
180199
- run: tox -e linting
181200

182201
deploy:
183202
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && github.repository == 'pytest-dev/pytest'
184203

185204
runs-on: ubuntu-latest
186205
timeout-minutes: 30
206+
permissions:
207+
contents: read
187208

188209
needs: [build]
189210

190211
steps:
191212
- uses: actions/checkout@v2
192213
with:
193214
fetch-depth: 0
215+
persist-credentials: false
216+
194217
- name: Set up Python
195218
uses: actions/setup-python@v2
196219
with:
197220
python-version: "3.7"
221+
198222
- name: Install dependencies
199223
run: |
200224
python -m pip install --upgrade pip
201225
pip install --upgrade wheel setuptools tox
226+
202227
- name: Build package
203228
run: |
204229
python setup.py sdist bdist_wheel
230+
205231
- name: Publish package to PyPI
206232
uses: pypa/gh-action-pypi-publish@master
207233
with:
208234
user: __token__
209235
password: ${{ secrets.pypi_token }}
236+
210237
- name: Publish GitHub release notes
211238
env:
212239
GH_RELEASE_NOTES_TOKEN: ${{ secrets.release_notes }}

.github/workflows/prepare-release-pr.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ on:
1212
required: true
1313
default: 'no'
1414

15+
# Set permissions at the job level.
16+
permissions: {}
17+
1518
jobs:
1619
build:
1720
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
1823

1924
steps:
2025
- uses: actions/checkout@v2
2126
with:
2227
fetch-depth: 0
28+
persist-credentials: false
2329

2430
- name: Set up Python
2531
uses: actions/setup-python@v2

.github/workflows/release-on-comment.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,33 @@ on:
77
issue_comment:
88
types: [created, edited]
99

10+
# Set permissions at the job level.
11+
permissions: {}
12+
1013
jobs:
1114
build:
1215
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
1318

1419
if: (github.event.comment && startsWith(github.event.comment.body, '@pytestbot please')) || (github.event.issue && !github.event.comment && startsWith(github.event.issue.body, '@pytestbot please'))
1520

1621
steps:
1722
- uses: actions/checkout@v2
1823
with:
1924
fetch-depth: 0
25+
persist-credentials: false
2026

2127
- name: Set up Python
2228
uses: actions/setup-python@v2
2329
with:
2430
python-version: "3.8"
31+
2532
- name: Install dependencies
2633
run: |
2734
python -m pip install --upgrade pip
2835
pip install --upgrade setuptools tox
36+
2937
- name: Prepare release
3038
run: |
3139
tox -e release-on-comment -- $GITHUB_EVENT_PATH ${{ secrets.chatops }}

.github/workflows/update-plugin-list.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,35 @@ on:
77
- cron: '0 0 * * 0'
88
workflow_dispatch:
99

10+
# Set permissions at the job level.
11+
permissions: {}
12+
1013
jobs:
1114
createPullRequest:
1215
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
1320
steps:
1421
- name: Checkout
1522
uses: actions/checkout@v2
23+
with:
24+
fetch-depth: 0
25+
1626
- name: Setup Python
1727
uses: actions/setup-python@v2
1828
with:
1929
python-version: 3.8
30+
2031
- name: Install dependencies
2132
run: |
2233
python -m pip install --upgrade pip
2334
pip install packaging requests tabulate[widechars]
35+
2436
- name: Update Plugin List
2537
run: python scripts/update-plugin-list.py
38+
2639
- name: Create Pull Request
2740
uses: peter-evans/create-pull-request@2455e1596942c2902952003bbb574afbbe2ab2e6
2841
with:

0 commit comments

Comments
 (0)