Skip to content

Commit 1dee373

Browse files
committed
Improve security of GitHub Actions workflows
Signed-off-by: Caleb Xu <caxu@redhat.com>
1 parent 2423138 commit 1dee373

File tree

9 files changed

+140
-49
lines changed

9 files changed

+140
-49
lines changed

.github/workflows/add-release-info-to-pyxis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ jobs:
4141
--key '${{ env.KEY_FILE_LOCATION }}' \
4242
--pass '${{ secrets.certificatePassword }}' \
4343
-H 'Content-Type: application/json' \
44-
-d '{"commit":"${{ inputs.commit }}","enabled_for_testing":true,"name":"github.com/redhat-openshift-ecosystem/openshift-preflight","version":"${{ inputs.tag }}"}' \
44+
-d ${DATA_PAYLOAD} \
4545
-X POST \
46-
'https://${{ inputs.host }}/v1/tools' | jq
46+
${PYXIS_ENDPOINT} | jq
47+
env:
48+
DATA_PAYLOAD: '{"commit":"${{ inputs.commit }}","enabled_for_testing":true,"name":"github.com/redhat-openshift-ecosystem/openshift-preflight","version":"${{ inputs.tag }}"}'
49+
PYXIS_ENDPOINT: 'https://${{ inputs.host }}/v1/tools'
4750

4851
- name: Cleanup
4952
if: always()

.github/workflows/build-main.yml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,39 @@ on:
66

77
env:
88
IMAGE_NAME: preflight
9-
9+
1010
jobs:
1111
build-main:
12+
# TODO: Set explicit permissions for this job.
13+
# zizmor: ignore[excessive-permissions]
1214
name: Build and push main snapshot images
1315
strategy:
1416
matrix:
1517
architecture: [amd64,ppc64le,arm64,s390x]
1618
platform: [linux]
1719
runs-on: ubuntu-latest
1820
steps:
19-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
with:
23+
persist-credentials: false
24+
2025
- name: Fetch latest release version
21-
uses: reloc8/action-latest-release-version@1.0.0
26+
uses: reloc8/action-latest-release-version@b8d6337f30390558e7874a044d6a3c1314314bab # 1.0.0
2227
id: fetch-latest-release
23-
- name: Set Env Tags
24-
run: echo RELEASE_TAG=${{ steps.fetch-latest-release.outputs.latest-release }} >> $GITHUB_ENV
25-
- name: set short sha
26-
run: echo SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV
28+
29+
- name: Set release tag and short SHA
30+
run: |
31+
echo RELEASE_TAG=${RELEASE_TAG} >> $GITHUB_ENV
32+
echo SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV
33+
env:
34+
RELEASE_TAG: ${{ steps.fetch-latest-release.outputs.latest-release }}
2735

2836
- name: Set up QEMU
29-
uses: docker/setup-qemu-action@v3
37+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
3038

3139
- name: Build Image
3240
id: build-image
33-
uses: redhat-actions/buildah-build@v2
41+
uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2.13
3442
with:
3543
image: ${{ secrets.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
3644
tags: ${{ env.SHA_SHORT }}-${{ matrix.platform }}-${{ matrix.architecture }}
@@ -44,7 +52,7 @@ jobs:
4452
4553
- name: Push Image
4654
id: push-image
47-
uses: redhat-actions/push-to-registry@v2
55+
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8
4856
with:
4957
image: ${{ env.IMAGE_NAME }}
5058
tags: ${{ env.SHA_SHORT }}-${{ matrix.platform }}-${{ matrix.architecture }}
@@ -53,22 +61,28 @@ jobs:
5361
password: ${{ secrets.REGISTRY_PASSWORD }}
5462

5563
- name: Print image url
56-
run: echo "Image pushed to ${{ steps.push-image.outputs.registry-paths }}"
64+
run: echo "Image pushed to ${REGISTRY_PATHS}"
65+
env:
66+
REGISTRY_PATHS: ${{ steps.push-image.outputs.registry-paths }}
5767

5868
outputs:
5969
imageName: ${{ env.IMAGE_NAME }}
6070
imageVersion: ${{ env.SHA_SHORT }}
6171

6272
build-coverage:
73+
# TODO: Set explicit permissions for this job.
74+
# zizmor: ignore[excessive-permissions]
6375
runs-on: ubuntu-latest
6476
steps:
65-
- uses: actions/checkout@v4
77+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
78+
with:
79+
persist-credentials: false
6680

6781
- name: Install system deps
6882
run: 'sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev'
6983

7084
- name: Set up Go
71-
uses: actions/setup-go@v5
85+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
7286
with:
7387
go-version-file: go.mod
7488

@@ -85,12 +99,14 @@ jobs:
8599
run: make cover
86100

87101
- name: Coveralls
88-
uses: coverallsapp/github-action@v2
102+
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6
89103
with:
90104
github-token: ${{ secrets.GITHUB_TOKEN }}
91105
file: coverage.out
92106

93107
build-multiarch:
108+
# TODO: Set explicit permissions for this job.
109+
# zizmor: ignore[excessive-permissions]
94110
needs: build-main
95111
uses: ./.github/workflows/build-multiarch.yml
96112
with:

.github/workflows/build-multiarch.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,49 @@ jobs:
5555

5656
# Authenticate to container image registry to push the image
5757
- name: Podman Login
58-
uses: redhat-actions/podman-login@v1
58+
uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1.7
5959
with:
6060
registry: ${{ secrets.registry }}
6161
username: ${{ secrets.user }}
6262
password: ${{ secrets.password }}
6363

6464
- name: Create and add to manifest
6565
run: |
66-
buildah manifest create ${{ inputs.name }}
67-
buildah manifest add ${{ inputs.name }} ${{ secrets.registry }}/${{ inputs.name }}:${{ inputs.tag }}-linux-amd64
68-
buildah manifest add ${{ inputs.name }} ${{ secrets.registry }}/${{ inputs.name }}:${{ inputs.tag }}-linux-ppc64le
69-
buildah manifest add ${{ inputs.name }} ${{ secrets.registry }}/${{ inputs.name }}:${{ inputs.tag }}-linux-arm64
70-
buildah manifest add ${{ inputs.name }} ${{ secrets.registry }}/${{ inputs.name }}:${{ inputs.tag }}-linux-s390x
66+
buildah manifest create ${INPUT_NAME}
67+
buildah manifest add ${INPUT_NAME} ${{ secrets.registry }}/${INPUT_NAME}:${INPUT_TAG}-linux-amd64
68+
buildah manifest add ${INPUT_NAME} ${{ secrets.registry }}/${INPUT_NAME}:${INPUT_TAG}-linux-ppc64le
69+
buildah manifest add ${INPUT_NAME} ${{ secrets.registry }}/${INPUT_NAME}:${INPUT_TAG}-linux-arm64
70+
buildah manifest add ${INPUT_NAME} ${{ secrets.registry }}/${INPUT_NAME}:${INPUT_TAG}-linux-s390x
71+
env:
72+
INPUT_NAME: ${{ inputs.name }}
73+
INPUT_TAG: ${{ inputs.tag }}
7174

7275
- name: Push manifest
7376
id: push-manifest
7477
run: |
75-
podman manifest push --digestfile imagedigest ${{ inputs.name }} ${{ secrets.registry }}/${{ inputs.name }}:${{ inputs.tag }} --all
78+
podman manifest push --digestfile imagedigest ${INPUT_NAME} ${{ secrets.registry }}/${INPUT_NAME}:${INPUT_TAG} --all
7679
echo "digest=$(cat imagedigest)" | tee -a $GITHUB_OUTPUT
80+
env:
81+
INPUT_NAME: ${{ inputs.name }}
82+
INPUT_TAG: ${{ inputs.tag }}
7783

7884
- name: Sign the published manifest
7985
# only sign if release is published, not for ghactions branch push
8086
# which is used for testing and development.
8187
if: ${{ inputs.sign == true && github.event.release && github.event.action == 'published' }}
8288
run: |
83-
cosign sign --yes --recursive ${{ secrets.registry }}/${{ inputs.name }}@${{ steps.push-manifest.outputs.digest }}
89+
cosign sign --yes --recursive ${{ secrets.registry }}/${INPUT_NAME}@${DIGEST}
90+
env:
91+
DIGEST: ${{ steps.push-manifest.outputs.digest }}
92+
INPUT_NAME: ${{ inputs.name }}
8493

8594
- name: Verify the image signature
8695
if: ${{ inputs.sign == true && github.event.release && github.event.action == 'published' }}
8796
run: |
8897
cosign verify \
89-
--certificate-identity https://github.com/${{ github.repository }}/.github/workflows/build-multiarch.yml@refs/tags/${{ inputs.tag }} \
98+
--certificate-identity https://github.com/${{ github.repository }}/.github/workflows/build-multiarch.yml@refs/tags/${INPUT_TAG} \
9099
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
91-
${{ secrets.registry }}/${{ inputs.name }}:${{ inputs.tag }}
100+
${{ secrets.registry }}/${INPUT_NAME}:${INPUT_TAG}
101+
env:
102+
INPUT_NAME: ${{ inputs.name }}
103+
INPUT_TAG: ${{ inputs.tag }}

.github/workflows/build-release.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@ env:
1212

1313
jobs:
1414
build-release:
15+
# TODO: Set explicit permissions for this job.
16+
# zizmor: ignore[excessive-permissions]
1517
name: Build and push tag images
1618
strategy:
1719
matrix:
1820
architecture: [amd64,ppc64le,arm64,s390x]
1921
platform: [linux]
2022
runs-on: ubuntu-latest
2123
steps:
22-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
with:
26+
persist-credentials: false
27+
2328
- name: Set Env Tags
2429
run: echo RELEASE_TAG=$(echo $GITHUB_REF | cut -d '/' -f 3) >> $GITHUB_ENV
2530

2631
- name: Set up QEMU
27-
uses: docker/setup-qemu-action@v3
32+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
2833

2934
- name: Build Image
3035
id: build-image
31-
uses: redhat-actions/buildah-build@v2
36+
uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2.13
3237
with:
3338
image: ${{ secrets.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
3439
tags: ${{ env.RELEASE_TAG }}-${{ matrix.platform }}-${{ matrix.architecture }}
@@ -41,7 +46,7 @@ jobs:
4146
4247
- name: Push Image
4348
id: push-image
44-
uses: redhat-actions/push-to-registry@v2
49+
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8
4550
with:
4651
image: ${{ env.IMAGE_NAME }}
4752
tags: ${{ env.RELEASE_TAG }}-${{ matrix.platform }}-${{ matrix.architecture }}
@@ -50,7 +55,9 @@ jobs:
5055
password: ${{ secrets.REGISTRY_PASSWORD }}
5156

5257
- name: Print image url
53-
run: echo "Image pushed to ${{ steps.push-image.outputs.registry-paths }}"
58+
run: echo "Image pushed to ${REGISTRY_PATHS}"
59+
env:
60+
REGISTRY_PATHS: ${{ steps.push-image.outputs.registry-paths }}
5461

5562
outputs:
5663
imageName: ${{ env.IMAGE_NAME }}
@@ -78,6 +85,8 @@ jobs:
7885
token: ${{ secrets.GITHUB_TOKEN }}
7986

8087
extract-assets:
88+
# TODO: Set explicit permissions for this job.
89+
# zizmor: ignore[excessive-permissions]
8190
needs: build-release
8291
uses: ./.github/workflows/release-artifacts.yml
8392
with:
@@ -90,6 +99,8 @@ jobs:
9099
token: ${{ secrets.GITHUB_TOKEN }}
91100

92101
add-release-info-to-pyxis:
102+
# TODO: Set explicit permissions for this job.
103+
# zizmor: ignore[excessive-permissions]
93104
needs: [build-release, extract-assets]
94105
uses: ./.github/workflows/add-release-info-to-pyxis.yml
95106
if: "!github.event.release.prerelease"
@@ -103,6 +114,8 @@ jobs:
103114
certificatePassword: ${{ secrets.PREFLIGHT_RELEASE_PASSWORD }}
104115

105116
copy-to-rhisv:
117+
# TODO: Set explicit permissions for this job.
118+
# zizmor: ignore[excessive-permissions]
106119
needs: [build-release, build-multiarch]
107120
uses: ./.github/workflows/copy-to-rhisv.yml
108121
with:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Analyze GitHub Actions security
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
permissions: {}
10+
11+
jobs:
12+
zizmor:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
with:
18+
persist-credentials: false
19+
20+
- name: Run zizmor
21+
uses: zizmorcore/zizmor-action@f52a838cfabf134edcbaa7c8b3677dde20045018 # v0.1.1
22+
with:
23+
advanced-security: false

.github/workflows/code-review.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
name: Gemini AI Code Review
22

3-
on:
3+
# pull_request_target is needed to access the Gemini key and modify (set/remove labels, comment on)
4+
# the pull request.
5+
on: # zizmor: ignore[dangerous-triggers]
46
pull_request_target:
57
types: [opened, synchronize, reopened, labeled]
68

9+
# TODO: Assign permissions in individual jobs rather than at the
10+
# workflow level to avoid blindly handing out `pull-requests: write`
11+
# at the workflow level to all jobs (particularly if new jobs are
12+
# added in this workflow in the future).
713
permissions:
814
contents: read
9-
pull-requests: write
15+
pull-requests: write # zizmor: ignore[excessive-permissions]
1016

1117
concurrency:
1218
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
@@ -21,15 +27,19 @@ jobs:
2127
pull-requests: write
2228
steps:
2329
- name: Checkout repository
24-
uses: actions/checkout@v4
30+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
31+
with:
32+
persist-credentials: false
33+
2534
- name: Handle review label
2635
id: prep
2736
env:
2837
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2938
PR_NUMBER: ${{ github.event.pull_request.number }}
39+
LABEL_JSON: ${{ toJSON(github.event.pull_request.labels.*.name) }}
40+
EVENT_ACTION: ${{ github.event.action }}
3041
run: |
31-
HAS_LABEL=$(echo '${{ toJSON(github.event.pull_request.labels.*.name) }}' | jq 'any(. == "gemini-review")')
32-
EVENT_ACTION="${{ github.event.action }}"
42+
HAS_LABEL=$(jq -n 'env.LABEL_JSON | fromjson | any(. == "gemini-review")')
3343
3444
if [[ "$HAS_LABEL" == "true" && "$EVENT_ACTION" != "labeled" ]]; then
3545
echo "gemini-review label found on a '${EVENT_ACTION}' event. Removing label and skipping review."
@@ -52,10 +62,11 @@ jobs:
5262
uses: actions/checkout@v4
5363
with:
5464
ref: refs/pull/${{ github.event.pull_request.number }}/merge
65+
persist-credentials: false
5566
fetch-depth: 0
5667

5768
- name: Gemini AI Code Review
58-
uses: sshnaidm/gemini-code-review-action@d4ccdaf0e2cad5cb79f80f6db07857c0e7fff28f
69+
uses: sshnaidm/gemini-code-review-action@d4ccdaf0e2cad5cb79f80f6db07857c0e7fff28f # v1
5970
with:
6071
gemini-key: ${{ secrets.GEMINI_API_KEY }}
6172
model: 'gemini-2.5-flash'

.github/workflows/copy-to-rhisv.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,24 @@ jobs:
2828
runs-on: ubuntu-latest
2929
steps:
3030
- name: Podman Login
31-
uses: redhat-actions/podman-login@v1
31+
uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1.7
3232
with:
33-
registry: ${{ secrets.destImageRegistry }}
33+
registry: ${DEST_IMAGE_REGISTRY}
3434
username: ${{ secrets.destRegistryUser }}
3535
password: ${{ secrets.destRegistryPassword }}
3636

3737
- name: Copy Images from Source to Dest
3838
id: skopeo-copy-image
3939
run: |
4040
skopeo -v
41-
skopeo copy --all --preserve-digests docker://${{ secrets.sourceImageRegistry }}/${{ inputs.sourceImageName }}:${{ inputs.sourceImageTag }}-linux-amd64 docker://${{ secrets.destImageRegistry }}/${{ inputs.destImageName }}:${{ inputs.sourceImageTag }}-linux-amd64
42-
skopeo copy --all --preserve-digests docker://${{ secrets.sourceImageRegistry }}/${{ inputs.sourceImageName }}:${{ inputs.sourceImageTag }}-linux-ppc64le docker://${{ secrets.destImageRegistry }}/${{ inputs.destImageName }}:${{ inputs.sourceImageTag }}-linux-ppc64le
43-
skopeo copy --all --preserve-digests docker://${{ secrets.sourceImageRegistry }}/${{ inputs.sourceImageName }}:${{ inputs.sourceImageTag }}-linux-arm64 docker://${{ secrets.destImageRegistry }}/${{ inputs.destImageName }}:${{ inputs.sourceImageTag }}-linux-arm64
44-
skopeo copy --all --preserve-digests docker://${{ secrets.sourceImageRegistry }}/${{ inputs.sourceImageName }}:${{ inputs.sourceImageTag }}-linux-s390x docker://${{ secrets.destImageRegistry }}/${{ inputs.destImageName }}:${{ inputs.sourceImageTag }}-linux-s390x
45-
skopeo copy --all --preserve-digests docker://${{ secrets.sourceImageRegistry }}/${{ inputs.sourceImageName }}:${{ inputs.sourceImageTag }} docker://${{ secrets.destImageRegistry }}/${{ inputs.destImageName }}:${{ inputs.sourceImageTag }}
41+
skopeo copy --all --preserve-digests docker://${SOURCE_IMAGE_REGISTRY}/${SOURCE_IMAGE_NAME}:${SOURCE_IMAGE_TAG}-linux-amd64 docker://${DEST_IMAGE_REGISTRY}/${DEST_IMAGE_NAME}:${SOURCE_IMAGE_TAG}-linux-amd64
42+
skopeo copy --all --preserve-digests docker://${SOURCE_IMAGE_REGISTRY}/${SOURCE_IMAGE_NAME}:${SOURCE_IMAGE_TAG}-linux-ppc64le docker://${DEST_IMAGE_REGISTRY}/${DEST_IMAGE_NAME}:${SOURCE_IMAGE_TAG}-linux-ppc64le
43+
skopeo copy --all --preserve-digests docker://${SOURCE_IMAGE_REGISTRY}/${SOURCE_IMAGE_NAME}:${SOURCE_IMAGE_TAG}-linux-arm64 docker://${DEST_IMAGE_REGISTRY}/${DEST_IMAGE_NAME}:${SOURCE_IMAGE_TAG}-linux-arm64
44+
skopeo copy --all --preserve-digests docker://${SOURCE_IMAGE_REGISTRY}/${SOURCE_IMAGE_NAME}:${SOURCE_IMAGE_TAG}-linux-s390x docker://${DEST_IMAGE_REGISTRY}/${DEST_IMAGE_NAME}:${SOURCE_IMAGE_TAG}-linux-s390x
45+
skopeo copy --all --preserve-digests docker://${SOURCE_IMAGE_REGISTRY}/${SOURCE_IMAGE_NAME}:${SOURCE_IMAGE_TAG} docker://${DEST_IMAGE_REGISTRY}/${DEST_IMAGE_NAME}:${SOURCE_IMAGE_TAG}
46+
env:
47+
SOURCE_IMAGE_REGISTRY: ${{ secrets.sourceImageRegistry }}
48+
SOURCE_IMAGE_NAME: ${{ inputs.sourceImageName }}
49+
SOURCE_IMAGE_TAG: ${{ inputs.sourceImageTag }}
50+
DEST_IMAGE_REGISTRY: ${{ secrets.destImageRegistry }}
51+
DEST_IMAGE_NAME: ${{ inputs.destImageName }}

.github/workflows/go.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ on:
88

99
jobs:
1010
build:
11+
# TODO: Set explicit permissions for this job.
12+
# zizmor: ignore[excessive-permissions]
1113
runs-on: ubuntu-latest
1214
steps:
13-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
16+
with:
17+
persist-credentials: false
1418

1519
- name: Install system deps
1620
run: 'sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev'
@@ -36,7 +40,7 @@ jobs:
3640
run: make cover
3741

3842
- name: Coveralls
39-
uses: coverallsapp/github-action@v2
43+
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6
4044
with:
4145
github-token: ${{ secrets.GITHUB_TOKEN }}
4246
file: coverage.out

0 commit comments

Comments
 (0)