Skip to content

Commit 510ddb5

Browse files
committed
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.
1 parent 3603994 commit 510ddb5

File tree

10 files changed

+74
-27
lines changed

10 files changed

+74
-27
lines changed

.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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
name: "Triage Issues and PRs"
3131

32+
permissions:
33+
contents: read
34+
3235
jobs:
3336
label_prs:
3437
runs-on: ubuntu-latest
@@ -48,6 +51,8 @@ jobs:
4851
private-key: ${{ secrets.BOT_APP_KEY }}
4952
- name: Checkout parent repository
5053
uses: actions/checkout@v5
54+
with:
55+
persist-credentials: false
5156
- name: Install Python 3.12
5257
uses: actions/setup-python@v6
5358
with:

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

Lines changed: 6 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:
@@ -71,4 +74,6 @@ jobs:
7174
python-versions: "${{ matrix.python-versions }}"
7275
reset-branch: "${{ inputs.reset-branch || false }}"
7376
labels: "${{ inputs.labels || 'no_backport,tooling' }}"
74-
secrets: inherit
77+
secrets:
78+
BOT_APP_ID: "${{ secrets.BOT_APP_ID }}"
79+
BOT_APP_KEY: "${{ secrets.BOT_APP_KEY }}"

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ name: "Refresh docs build dependencies"
1919
required: false
2020
type: string
2121

22+
permissions:
23+
contents: read
24+
2225
jobs:
2326
refresh:
2427
name: "Refresh docs build dependencies"
@@ -33,4 +36,6 @@ jobs:
3336
reset-branch: "${{ inputs.reset-branch || false }}"
3437
labels: "${{ inputs.labels || 'doc builds,no_backport' }}"
3538
python-versions: "3.12"
36-
secrets: inherit
39+
secrets:
40+
BOT_APP_ID: "${{ secrets.BOT_APP_ID }}"
41+
BOT_APP_KEY: "${{ secrets.BOT_APP_KEY }}"

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

Lines changed: 12 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,6 +47,7 @@ jobs:
5047
}}
5148
ref: ${{ inputs.repository-branch }}
5249
path: build-directory
50+
persist-credentials: false
5351

5452
- name: Setup nox
5553
uses: wntrblm/nox@2025.10.16
@@ -68,19 +66,22 @@ jobs:
6866
-c tests/requirements.txt
6967
working-directory: build-directory
7068

71-
- name: Set the VERSION variable
72-
run: echo VERSION="${PACKAGE_VERSION}" >> "${GITHUB_ENV}"
73-
7469
- name: Build the Ansible community package docs
75-
run: >-
76-
make webdocs ${{
70+
env:
71+
PACKAGE_VERSION: "${{ inputs.ansible-package-version }}"
72+
run: |
73+
# Clear PACKAGE_VERSION if it's set to devel
74+
if [ "${PACKAGE_VERSION}" = "devel" ]; then
75+
PACKAGE_VERSION=""
76+
fi
77+
make webdocs ANSIBLE_VERSION="${PACKAGE_VERSION}" ${{
7778
inputs.generate-redirects && 'EXTRA_TAGS="-t redirects"' || ''
78-
}} ANSIBLE_VERSION="${{
79-
env.PACKAGE_VERSION != 'devel' && env.PACKAGE_VERSION || ''
80-
}}"
79+
}}
8180
working-directory: build-directory/docs/docsite
8281

8382
- name: Create a tarball with the build contents
83+
env:
84+
PACKAGE_VERSION: "${{ inputs.ansible-package-version }}"
8485
run: >-
8586
tar -czvf
8687
ansible-package-docs-html-"${PACKAGE_VERSION}"-"$(date '+%Y-%m-%d')"-${{

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@ jobs:
3333
runs-on: ubuntu-latest
3434
steps:
3535
- name: Log the workflow inputs if deployed
36+
env:
37+
deployment_environment: "${{ inputs.deployment-environment }}"
38+
package_version: "${{ inputs.ansible-package-version }}"
39+
owner: "${{ inputs.repository-owner }}"
40+
branch: "${{ inputs.repository-branch }}"
3641
run: |
3742
{
3843
echo "## Deployment details :shipit:";
39-
echo "Publish to: ${{ inputs.deployment-environment }}";
40-
echo "Package version: ${{ inputs.ansible-package-version }}";
41-
echo "Owner: ${{ inputs.repository-owner }}";
42-
echo "Branch: ${{ inputs.repository-branch }}";
44+
echo "Publish to: ${deployment_environment}";
45+
echo "Package version: ${package_version}";
46+
echo "Owner: ${owner}";
47+
echo "Branch: ${branch}";
4348
} >> "${GITHUB_STEP_SUMMARY}"
4449
4550
deploy-package-docs:

.github/workflows/reusable-nox.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
steps:
3939
- name: Check out repo
4040
uses: actions/checkout@v5
41+
with:
42+
persist-credentials: false
4143
- name: Setup nox
4244
uses: wntrblm/nox@2025.10.16
4345
with:
@@ -46,7 +48,8 @@ jobs:
4648
run: |
4749
nox -e clone-core
4850
- name: "Run nox -e ${{ matrix.session }}"
51+
# Using GHA expression interpolation is fine here,
52+
# as we control all the inputs.
53+
# zizmor: ignore[template-injection]
4954
run: |
50-
# Using GHA expression interpolation is fine here,
51-
# as we control all the inputs.
5255
nox -e "${{ matrix.session }}" -- ${{ matrix.extra-args }}

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,21 @@ name: "Refresh pinned dependencies"
3535
python-versions:
3636
type: string
3737
required: true
38+
39+
permissions:
40+
contents: read
41+
3842
jobs:
3943
refresh:
4044
runs-on: ubuntu-latest
4145
environment: github-bot
4246
steps:
43-
- name: Generate temp GITHUB_TOKEN
44-
id: create_token
45-
uses: actions/create-github-app-token@v2
46-
with:
47-
app-id: ${{ secrets.BOT_APP_ID }}
48-
private-key: ${{ secrets.BOT_APP_KEY }}
4947
- name: Check out repo
5048
uses: actions/checkout@v5
5149
with:
5250
fetch-depth: 0
5351
ref: "${{ inputs.base-branch }}"
54-
token: "${{ steps.create_token.outputs.token }}"
52+
persist-credentials: false
5553
- name: Fetch required contents of ansible-core
5654
run: |
5755
python docs/bin/clone-core.py
@@ -78,11 +76,25 @@ jobs:
7876
echo "branch-exists=false" >> "${GITHUB_OUTPUT}"
7977
git switch -c "${pr_branch}"
8078
fi
79+
- name: Generate temp GITHUB_TOKEN
80+
id: create_token
81+
uses: actions/create-github-app-token@v2
82+
with:
83+
app-id: ${{ secrets.BOT_APP_ID }}
84+
private-key: ${{ secrets.BOT_APP_KEY }}
85+
# We could rely on the checkout action to persist the token in the
86+
# repository config, but this way, we can prevent the previous steps
87+
# from having unnecessary access.
88+
- name: "Set up token authentication"
89+
run: gh auth setup-git --hostname github.com
8190
- name: "Run nox ${{ inputs.nox-args }}"
8291
env:
8392
# Ensure the latest pip version is used
8493
VIRTUALENV_DOWNLOAD: '1'
85-
#
94+
# nox-args is defined statically in the calling workflows and passing it
95+
# as a shell variable presents quoting issues, so ignore zizmor error
96+
# for now.
97+
# zizmor: ignore[template-injection]
8698
run: |
8799
nox ${{ inputs.nox-args }}
88100
- name: Push new dependency versions and create a PR

.github/workflows/tag.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ name: Sync tags with ansible-core releases
1111
schedule:
1212
- cron: "0 * * * *" # Hourly
1313

14+
permissions:
15+
contents: read # read-only because we use bot token to push
16+
1417
jobs:
1518
tag:
1619
runs-on: "ubuntu-latest"
@@ -30,12 +33,14 @@ jobs:
3033
path: ansible-documentation
3134
fetch-depth: 0
3235
token: "${{ steps.create_token.outputs.token }}"
36+
persist-credentials: true
3337
- name: Check out core
3438
uses: actions/checkout@v5
3539
with:
3640
repository: ansible/ansible
3741
path: ansible
3842
fetch-depth: 0
43+
persist-credentials: false
3944
- name: Setup nox
4045
uses: wntrblm/nox@2025.10.16
4146
with:

0 commit comments

Comments
 (0)