Skip to content

Commit 86f9d43

Browse files
gotmax23oraNodwebknjaz
authored
Lint Github Actions workflows with zizmor (#3188)
* ci: fix issues indentified by zizmor GHA linter This fixes issues identified by the zizmor linter which checks for Github Actions security best practicies. Summary of changes: - Remove possibilities for shell injection. These can all only be activated by workflow_dispatch input provided by people who already have access to the repository but still a good idea to tidy this up. Many of these occur in the build-package-docs actions. We should test everything to make sure nothing is broken by these changes. - Explicitly set permissions. This is not strictly required, because we already enforce a limited set of default permissions in the repo's GHA settings, but zizmor wants us to be explicit. - Use `persist-credentials: false` with the checkout action. Also, when rebasing this commit, I added back the manual `nox -s clone-core` step to keep the outputs separate. * ci: run zizmor in CI and noxfile - Adds lockfile - Adds nox session - Adds nox session to CI matrix * ci: fix additional issues identified by zizmor - Add default permissions to new workflows - Add cooldown to dependabot * ci: add zizmor configuration for unpinned-uses We could configure dependabot to pin shared workflow commit SHA hashes, but for now, let's relax the unpinned-uses relax * ci: restore secrets: inheirt for pip-compile workflows See comment for more details. * ci: fix token auth for pip-compile workflow * README: mention that lint session runs GHA checks * Update noxfile.py Co-authored-by: Don Naro <[email protected]> * nox zizmor: allow overriding persona * nox: actually run zizmor as part of lint session * ci: use GHA expression instead of shell test Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]> * ci: use Python to avoid shell+json quoting issues --------- Co-authored-by: Don Naro <[email protected]> Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
1 parent cda50f3 commit 86f9d43

19 files changed

+138
-29
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ updates:
99
directory: "/"
1010
schedule:
1111
interval: "weekly"
12+
cooldown:
13+
default-days: 4

.github/workflows/build-devel-docs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ name: Scheduled build for devel docs
55
# Run at 05:22 daily
66
- cron: '22 5 * * *'
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
build-package-docs:
1013
name: 📝 Build

.github/workflows/build-latest-docs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ name: Scheduled build for latest docs
55
# Run at 05:41 on Monday
66
- cron: '41 5 * * 1'
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
build-package-docs:
1013
name: 📝 Build

.github/workflows/build-package-docs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ name: Build and deploy docs
5151
- production
5252
- test
5353

54+
permissions:
55+
contents: read
56+
5457
jobs:
5558
build-package-docs:
5659
name: 📝 Build

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ name: Ansible Docsite CI
1616
- ready_for_review # used in PRs created from GitHub Actions workflows
1717
workflow_dispatch:
1818

19+
permissions:
20+
contents: read
21+
1922
jobs:
2023
nox:
2124
uses: ./.github/workflows/reusable-nox.yml

.github/workflows/labeler.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

55
"on":
6-
pull_request_target:
6+
# This workflow does not execute untrusted code from pull requests and all
7+
# inputs are properly sanitized,
8+
pull_request_target: # zizmor: ignore[dangerous-triggers]
79
types:
810
- opened # default
911
- synchronize # default
@@ -29,6 +31,9 @@
2931

3032
name: "Triage Issues and PRs"
3133

34+
permissions:
35+
contents: read
36+
3237
jobs:
3338
label_prs:
3439
runs-on: ubuntu-latest
@@ -48,6 +53,8 @@ jobs:
4853
private-key: ${{ secrets.BOT_APP_KEY }}
4954
- name: Checkout parent repository
5055
uses: actions/checkout@v6
56+
with:
57+
persist-credentials: false
5158
- name: Install Python 3.12
5259
uses: actions/setup-python@v6
5360
with:

.github/workflows/pip-compile-dev.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ name: "Refresh dev dependencies"
1313
required: false
1414
type: string
1515

16+
permissions:
17+
contents: read
18+
1619
jobs:
1720
refresh:
1821
strategy:
@@ -63,4 +66,9 @@ jobs:
6366
python-versions: "${{ matrix.python-versions }}"
6467
reset-branch: "${{ inputs.reset-branch || false }}"
6568
labels: "${{ inputs.labels || 'no_backport,tooling' }}"
66-
secrets: inherit
69+
# Pass using inherit, as this seems to be the only possible way to access
70+
# secrets defined in an enviornment when using nested workflows.
71+
secrets: inherit # zizmor: ignore[secrets-inherit]
72+
# secrets:
73+
# BOT_APP_ID: "${{ secrets.BOT_APP_ID }}"
74+
# BOT_APP_KEY: "${{ secrets.BOT_APP_KEY }}"

.github/workflows/pip-compile-docs.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ name: "Refresh docs build dependencies"
2525
type: string
2626
default: "3.12"
2727

28+
permissions:
29+
contents: read
30+
2831
jobs:
2932
refresh:
3033
name: "Refresh docs build dependencies"
@@ -39,4 +42,9 @@ jobs:
3942
reset-branch: "${{ inputs.reset-branch || false }}"
4043
labels: "${{ inputs.labels || 'doc builds,no_backport' }}"
4144
python-versions: "${{ inputs.python-version }}"
42-
secrets: inherit
45+
# Pass using inherit, as this seems to be the only possible way to access
46+
# secrets defined in an enviornment when using nested workflows.
47+
secrets: inherit # zizmor: ignore[secrets-inherit]
48+
# secrets:
49+
# BOT_APP_ID: "${{ secrets.BOT_APP_ID }}"
50+
# BOT_APP_KEY: "${{ secrets.BOT_APP_KEY }}"

.github/workflows/release-porting-guide.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
description: >-
1313
Exact release version. For example, 12.1.0
1414
required: true
15+
permissions:
16+
contents: read
1517

1618
jobs:
1719
upload-porting-guide:
@@ -40,13 +42,15 @@ jobs:
4042
uses: actions/checkout@v6
4143
with:
4244
token: ${{ steps.create_token.outputs.token }}
45+
persist-credentials: true # Needed to push to the repo
4346

4447
- name: Check out ansible-build-data
4548
uses: actions/checkout@v6
4649
with:
4750
repository: ansible-community/ansible-build-data
4851
ref: ${{ inputs.ansible-build-data-branch }}
4952
path: ansible-build-data
53+
persist-credentials: false
5054

5155
- name: Copy the RST file to the correct path
5256
run: >-

.github/workflows/reusable-build-docs.yaml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ name: Build docs
3232
DOCS_BOT_TOKEN:
3333
required: true
3434

35-
env:
36-
PACKAGE_VERSION: ${{ inputs.ansible-package-version }}
37-
3835
jobs:
3936
build-package-docs:
4037
runs-on: ubuntu-latest
@@ -50,26 +47,35 @@ jobs:
5047
}}
5148
ref: ${{ inputs.repository-branch }}
5249
path: build-directory
50+
persist-credentials: false
5351

5452
- name: Setup nox
5553
uses: wntrblm/[email protected]
5654

5755
- name: Output Python info
5856
run: python --version --version && which python
5957

60-
- name: Set the VERSION variable
61-
run: echo VERSION="${PACKAGE_VERSION}" >> "${GITHUB_ENV}"
58+
- name: Graft ansible-core
59+
run: nox -s clone-core
60+
working-directory: build-directory
6261

6362
- name: Build the Ansible community package docs
63+
env:
64+
PACKAGE_VERSION: >-
65+
${{
66+
inputs.ansible-package-version != 'devel'
67+
&& inputs.ansible-package-version
68+
|| ''
69+
}}
6470
run: >-
65-
nox -e make -- webdocs ${{
71+
nox -e make -- webdocs ANSIBLE_VERSION="${PACKAGE_VERSION}" ${{
6672
inputs.generate-redirects && 'EXTRA_TAGS="-t redirects"' || ''
67-
}} ANSIBLE_VERSION="${{
68-
env.PACKAGE_VERSION != 'devel' && env.PACKAGE_VERSION || ''
69-
}}"
73+
}}
7074
working-directory: build-directory
7175

7276
- name: Create a tarball with the build contents
77+
env:
78+
PACKAGE_VERSION: "${{ inputs.ansible-package-version }}"
7379
run: >-
7480
tar -czvf
7581
ansible-package-docs-html-"${PACKAGE_VERSION}"-"$(date '+%Y-%m-%d')"-${{
@@ -106,7 +112,17 @@ jobs:
106112

107113
- name: Notify the DaWGs in Matrix
108114
run: |
109-
curl -X PUT "${{ env.ROOM_URL }}/${TX_ID}" \
115+
body="$(python3 -c '
116+
import json
117+
import os
118+
import sys
119+
120+
json.dump({
121+
"msgtype": "m.text",
122+
"body": os.environ["FAIL_MESSAGE"],
123+
}, sys.stdout)'
124+
)"
125+
curl -X PUT "${ROOM_URL}/${TX_ID}" \
110126
-H "Authorization: Bearer ${{ secrets.DOCS_BOT_TOKEN }}" \
111127
-H "Content-Type: application/json" \
112-
-d '{"msgtype": "m.text", "body": "${{ env.FAIL_MESSAGE }}"}'
128+
-d "${body}"

0 commit comments

Comments
 (0)