Skip to content

Commit a56c874

Browse files
committed
ci: resolve zizmor security findings in github actions workflows
1 parent 3617943 commit a56c874

4 files changed

Lines changed: 48 additions & 14 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ concurrency:
5656
cancel-in-progress: true
5757
group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}}
5858

59-
permissions: read-all
59+
# Declare default permissions as read only.
60+
permissions:
61+
contents: read
6062

6163
jobs:
6264
python-checks:
@@ -68,6 +70,7 @@ jobs:
6870
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
6971
with:
7072
fetch-depth: 0
73+
persist-credentials: false
7174

7275
- name: Set up Python and restore cache
7376
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
@@ -112,6 +115,8 @@ jobs:
112115
steps:
113116
- name: Check out a copy of the git repository
114117
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
118+
with:
119+
persist-credentials: false
115120

116121
- name: Set up Python and restore cache
117122
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
@@ -144,6 +149,8 @@ jobs:
144149
steps:
145150
- name: Check out a copy of the git repository
146151
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
152+
with:
153+
persist-credentials: false
147154

148155
- name: Set up Python and restore cache
149156
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
@@ -173,6 +180,8 @@ jobs:
173180
steps:
174181
- name: Check out a copy of the git repository
175182
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
183+
with:
184+
persist-credentials: false
176185

177186
# Note: deliberately not using our Python cache here b/c this runs
178187
# a different version of Python.
@@ -202,6 +211,7 @@ jobs:
202211
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
203212
with:
204213
fetch-depth: 0
214+
persist-credentials: false
205215

206216
- name: Set up Python and restore cache
207217
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
@@ -228,6 +238,8 @@ jobs:
228238
steps:
229239
- name: Check out a copy of the git repository
230240
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
241+
with:
242+
persist-credentials: false
231243

232244
- name: Install yamllint
233245
run: |
@@ -248,6 +260,8 @@ jobs:
248260
steps:
249261
- name: Check out a copy of the git repository
250262
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
263+
with:
264+
persist-credentials: false
251265

252266
- name: Run hadolint on Dockerfiles
253267
env:
@@ -258,7 +272,7 @@ jobs:
258272
files=(**/[Dd]ockerfile*)
259273
if [[ ${#files[@]} -gt 0 ]]; then
260274
docker run --rm -v "${PWD}:/app" -w /app \
261-
ghcr.io/hadolint/hadolint@${{env.sha}} /bin/hadolint "${files[@]}"
275+
"ghcr.io/hadolint/hadolint@${sha}" /bin/hadolint "${files[@]}"
262276
fi
263277
264278
workflow-lint:
@@ -268,6 +282,8 @@ jobs:
268282
steps:
269283
- name: Check out a copy of the git repository
270284
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
285+
with:
286+
persist-credentials: false
271287

272288
- name: Run actionlint
273289
uses: raven-actions/actionlint@3d39aea434753780c3b3d4a1a31c854b4dbf49d7 # v2.2.0
@@ -283,6 +299,8 @@ jobs:
283299
steps:
284300
- name: Check out a copy of the git repository
285301
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
302+
with:
303+
persist-credentials: false
286304

287305
- name: Run shellcheck on shell scripts
288306
run: |
@@ -296,6 +314,8 @@ jobs:
296314
steps:
297315
- name: Check out a copy of the git repository
298316
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
317+
with:
318+
persist-credentials: false
299319

300320
- name: Set up Python and restore cache
301321
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0

.github/workflows/nightly-pytest.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ on:
3535
# Allow manual invocation.
3636
workflow_dispatch:
3737

38+
concurrency:
39+
cancel-in-progress: true
40+
group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}}
41+
3842
# Declare default workflow permissions as read only.
39-
permissions: read-all
43+
permissions:
44+
contents: read
4045

4146
jobs:
4247
Pytest:
@@ -75,6 +80,8 @@ jobs:
7580
steps:
7681
- name: Check out a copy of the OpenFermion git repository
7782
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
83+
with:
84+
persist-credentials: false
7885

7986
- name: Set up Python ${{matrix.python-version}}
8087
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
@@ -89,7 +96,11 @@ jobs:
8996
run: pip install -r dev_tools/requirements/envs/pytest.env.txt
9097

9198
- name: Install cirq-core (current stable version)
92-
run: pip install -U cirq-core ${{inputs.args}}
99+
env:
100+
INSTALL_ARGS: ${{inputs.args}}
101+
run: |
102+
# shellcheck disable=SC2086
103+
pip install -U cirq-core $INSTALL_ARGS
93104
94105
- name: Set up Pytest output problem matcher
95106
run: echo '::add-matcher::.github/problem-matchers/pytest.json'

.github/workflows/nightly.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,20 @@ on:
2929
workflow_dispatch:
3030

3131
# Declare default permissions as read only.
32-
permissions: read-all
32+
permissions:
33+
contents: read
3334

3435
jobs:
3536
cirq-stable:
3637
name: Nightly Pytest Cirq stable
37-
uses: ./.github/workflows/nightly-pytest.yaml
38+
uses: $/.github/workflows/nightly-pytest.yaml
3839
with:
3940
args: ''
4041
reason: '(nightly)'
4142

4243
cirq-pre:
4344
name: Nightly Pytest Cirq pre-release
44-
uses: ./.github/workflows/nightly-pytest.yaml
45+
uses: $/.github/workflows/nightly-pytest.yaml
4546
with:
4647
args: '--pre'
4748
reason: '(nightly)'

.github/workflows/scorecard-scanner.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@ concurrency:
3939
group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}}
4040

4141
# Declare default workflow permissions as read only.
42-
permissions: read-all
42+
permissions:
43+
contents: read
4344

4445
jobs:
4546
run-scorecard:
4647
# Skip fork PRs to avoid "Analysis configuration not found" errors.
4748
if: >-
4849
github.repository_owner == 'quantumlib' &&
4950
(github.event_name != 'pull_request' ||
50-
github.event.pull_request.head.repo.fork == false)
51+
github.event.pull_request.head.repo.full_name == github.repository)
5152
name: Scorecard analyzer
5253
runs-on: ubuntu-24.04
5354
permissions:
54-
security-events: write
55-
id-token: write
55+
security-events: write # Needed to upload SARIF results to GitHub Code Scanning dashboard.
56+
id-token: write # Needed to sign and publish Scorecard results.
5657
timeout-minutes: 15
5758
steps:
5859
- name: Check out a copy of the git repository
@@ -83,10 +84,11 @@ jobs:
8384
timeout-minutes: 5
8485
steps:
8586
- name: Write the Scorecard report page link to the workflow summary
87+
env:
88+
REPO: ${{github.repository}}
8689
run: |
87-
repo="${{github.repository}}"
88-
url="https://scorecard.dev/viewer/?uri=github.com/${repo}"
90+
url="https://scorecard.dev/viewer/?uri=github.com/${REPO}"
8991
{
9092
echo -n "The results are available on the OpenSSF Scorecard "
91-
echo "[report page for ${{github.repository}}]($url)."
93+
echo "[report page for ${REPO}]($url)."
9294
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)