Skip to content

Commit a7dbb73

Browse files
committed
ci: CI hardening
* ci: Bump actions/checkout to v7.0.0 * ci: Add explicit permissions to jobs * ci: Conditionally install host dependencies without cache * ci: Conditionally set rust-cache lookup-only * ci: Skip publish jobs for forks * ci: Remove checkout step from notify job
1 parent 1cc39b7 commit a7dbb73

8 files changed

Lines changed: 71 additions & 39 deletions

File tree

.github/workflows/generate_prs.yml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ permissions: {}
2525
jobs:
2626
create-prs:
2727
runs-on: ubuntu-latest
28+
permissions:
29+
contents: read
2830
strategy:
2931
fail-fast: ${{ inputs.fail-fast }}
3032
matrix:
@@ -48,7 +50,7 @@ jobs:
4850
- trino-operator
4951
- zookeeper-operator
5052
steps:
51-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
53+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
5254
with:
5355
persist-credentials: false
5456
- uses: cachix/install-nix-action@fd24c48048070c1be9acd18c9d369a83f0fe94d7 # v31.8.1
@@ -76,33 +78,35 @@ jobs:
7678
- name: Install jinja2
7779
run: pip install -r requirements.txt
7880

79-
# Create commit message depending on whether this is run manually or due to a scheduled run
80-
- name: Set commit message for manual dispatch
81-
if: ${{ github.event_name == 'workflow_dispatch' }}
82-
env:
83-
REASON: ${{ github.event.inputs.message }}
84-
AUTHOR: ${{ github.event.sender.login }}
85-
run: |
86-
echo "AUTHOR=$AUTHOR" >> "$GITHUB_ENV"
87-
echo "REASON=$REASON" >> "$GITHUB_ENV"
88-
- name: Set commit message for schedule
89-
if: ${{ github.event_name == 'schedule' }}
90-
run: |
91-
echo "AUTHOR=stackabletech/developers"
92-
echo "REASON=Daily run triggered" >> "$GITHUB_ENV"
93-
81+
# Create commit message and run the playbook
9482
- name: Run playbook
9583
env:
9684
CUSTOM_PR_TITLE: ${{ inputs.custom-pr-title }}
9785
GH_ACCESS_TOKEN: ${{ secrets.gh_access_token }}
9886
REPOSITORY: ${{ matrix.repository }}
99-
# tags local excludes all actions that actually generate PRs
100-
DRY_RUN_FLAGS: ${{ inputs.dry-run && '--tags=local' || '' }}
101-
# shellsheck disable=SC2086
87+
DRY_RUN_FLAGS: ${{ (github.event_name != 'schedule' && inputs.dry-run != false) && '--tags=local' || '' }}
88+
# Safely pass inputs/context via environment variables to prevent injection
89+
INPUT_MESSAGE: ${{ github.event.inputs.message }}
90+
SENDER_LOGIN: ${{ github.event.sender.login }}
91+
EVENT_NAME: ${{ github.event_name }}
10292
run: |
103-
echo '{}' | jq '{commit_hash: $ENV.GITHUB_SHA, author: $ENV.AUTHOR, reason: $ENV.REASON, custom_pr_title: $ENV.CUSTOM_PR_TITLE, base_dir: $pwd, gh_access_token: $ENV.GH_ACCESS_TOKEN, shard_repositories: [$ENV.REPOSITORY]} | with_entries(select(.value != null and .value != ""))' --arg pwd "$(pwd)" > vars.json
104-
# $DRY_RUN_FLAGS is intentionally not quoted, since we need to avoid
105-
# passing an argument if we're not in dry mode.
106-
# This is safe, since it always has one of two hard-coded values.
107-
# shellcheck disable=SC2086
93+
if [ "$EVENT_NAME" = "schedule" ]; then
94+
AUTHOR="stackabletech/developers"
95+
REASON="Weekly run triggered"
96+
else
97+
AUTHOR="$SENDER_LOGIN"
98+
REASON="$INPUT_MESSAGE"
99+
fi
100+
101+
# Encode parameters safely using jq, without serializing the GH_ACCESS_TOKEN
102+
jq -n \
103+
--arg commit_hash "$GITHUB_SHA" \
104+
--arg author "$AUTHOR" \
105+
--arg reason "$REASON" \
106+
--arg custom_pr_title "$CUSTOM_PR_TITLE" \
107+
--arg base_dir "$(pwd)" \
108+
--arg repository "$REPOSITORY" \
109+
'{commit_hash: $commit_hash, author: $author, reason: $reason, custom_pr_title: $custom_pr_title, base_dir: $base_dir, shard_repositories: [$repository]} | with_entries(select(.value != null and .value != ""))' > vars.json
110+
111+
# Run the Ansible playbook. The token is read directly from the GH_ACCESS_TOKEN environment variable.
108112
ansible-playbook playbook/playbook.yaml --extra-vars "@vars.json" $DRY_RUN_FLAGS

.github/workflows/pr_prek.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ permissions: {}
1212
jobs:
1313
prek:
1414
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
1517
steps:
16-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
18+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
1719
with:
1820
persist-credentials: false
1921
fetch-depth: 0

playbook/playbook.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
- name: Synchronize operator template files with operator repositories
33
hosts: localhost
44
connection: local
5+
vars:
6+
gh_access_token: "{{ lookup('env', 'GH_ACCESS_TOKEN') }}"
57

68
tasks:
79
- name: Include data which repositories to check

template/.github/workflows/build.yaml.j2

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ jobs:
3939
detect-changes:
4040
name: Detect relevant changed files
4141
runs-on: ubuntu-latest
42+
permissions:
43+
contents: read
4244
steps:
4345
- name: Checkout Repository
44-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
46+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
4547
with:
4648
persist-credentials: false
4749
fetch-depth: 0
@@ -67,6 +69,8 @@ jobs:
6769
if: needs.detect-changes.outputs.detected == 'true'
6870
needs: [detect-changes]
6971
runs-on: ubuntu-latest
72+
permissions:
73+
contents: read
7074
env:
7175
RUSTC_BOOTSTRAP: 1
7276
steps:
@@ -77,7 +81,7 @@ jobs:
7781
version: ubuntu-latest
7882

7983
- name: Checkout Repository
80-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
84+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
8185
with:
8286
persist-credentials: false
8387
submodules: recursive
@@ -91,6 +95,7 @@ jobs:
9195
with:
9296
cache-all-crates: "true"
9397
key: udeps
98+
lookup-only: ${{ github.event_name == 'pull_request' }}
9499

95100
- name: Install cargo-udeps
96101
uses: stackabletech/cargo-install-action@8f7dbbcd2ebe22717efc132d0dd61e80841994b9 # cargo-udeps
@@ -103,6 +108,7 @@ jobs:
103108
if: (github.event_name != 'merge_group') && needs.detect-changes.outputs.detected == 'true'
104109
needs: [detect-changes]
105110
permissions:
111+
contents: read
106112
id-token: write
107113
strategy:
108114
fail-fast: false
@@ -114,14 +120,25 @@ jobs:
114120
outputs:
115121
operator-version: ${{ steps.version.outputs.OPERATOR_VERSION }}
116122
steps:
123+
# Use cached apt packages on PRs.
124+
# For merges to main and releases, bypass the cache and install fresh package to ensure we have the absolute latest versions.
117125
- name: Install host dependencies
126+
if: github.event_name == 'pull_request'
118127
uses: awalsh128/cache-apt-pkgs-action@2c09a5e66da6c8016428a2172bd76e5e4f14bb17 # v1.5.3
119128
with:
120129
packages: protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config apt-transport-https
121130
version: ${{ matrix.runner.name }}
122131

132+
- name: Install host dependencies (no cache)
133+
if: github.event_name != 'pull_request'
134+
run: |
135+
sudo apt-get update
136+
sudo apt-get install -y protobuf-compiler krb5-user libkrb5-dev \
137+
libclang-dev liblzma-dev libssl-dev pkg-config apt-transport-https
138+
139+
123140
- name: Checkout Repository
124-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
141+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
125142
with:
126143
persist-credentials: false
127144
submodules: recursive
@@ -203,14 +220,15 @@ jobs:
203220
- detect-changes
204221
- build-container-image
205222
permissions:
223+
contents: read
206224
id-token: write
207225
runs-on: ubuntu-latest
208226
outputs:
209227
oci-index-digest: ${{ steps.publish-oci.outputs.image-index-manifest-digest }}
210228
quay-index-digest: ${{ steps.publish-quay.outputs.image-index-manifest-digest }}
211229
steps:
212230
- name: Checkout Repository
213-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
231+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
214232
with:
215233
persist-credentials: false
216234

@@ -297,15 +315,17 @@ jobs:
297315
if: |
298316
(github.event_name != 'merge_group')
299317
&& needs.detect-changes.outputs.detected == 'true'
318+
&& !github.event.pull_request.head.repo.fork
300319
needs:
301320
- detect-changes
302321
- build-container-image
303322
permissions:
323+
contents: read
304324
id-token: write
305325
runs-on: ubuntu-latest
306326
steps:
307327
- name: Checkout Repository
308-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
328+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
309329
with:
310330
persist-credentials: false
311331
submodules: recursive
@@ -394,13 +414,9 @@ jobs:
394414
- provenance-oci
395415
- provenance-quay
396416
- publish-helm-chart
417+
- finished
397418
runs-on: ubuntu-latest
398419
steps:
399-
- name: Checkout Repository
400-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
401-
with:
402-
persist-credentials: false
403-
404420
- name: Send Notification
405421
uses: stackabletech/actions/send-slack-notification@a8af17a19bdcc3b5da0065f76e73827ba0c072ce # v0.16.0
406422
with:

template/.github/workflows/general_daily_security.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ permissions: {}
1515
jobs:
1616
audit:
1717
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
checks: write
21+
issues: write
1822
steps:
19-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
2024
with:
2125
persist-credentials: false
2226
- uses: rustsec/audit-check@69366f33c96575abad1ee0dba8212993eecbe998 # v2.0.0

template/.github/workflows/integration-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ jobs:
2929
test:
3030
name: Run Integration Test
3131
runs-on: ubuntu-latest
32+
permissions:
33+
contents: read
3234
# services:
3335
# otel-collector:
3436
# image: ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-k8s:0.131.1
3537
# volumes:
3638
# - .:/mnt
3739
steps:
38-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
40+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
3941
with:
4042
persist-credentials: false
4143
submodules: recursive

template/.github/workflows/pr_prek.yaml.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ env:
1717
jobs:
1818
prek:
1919
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
2022
steps:
2123
- name: Install host dependencies
2224
uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0
2325
with:
2426
packages: protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config apt-transport-https
2527
version: ubuntu-latest
26-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
28+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
2729
with:
2830
persist-credentials: false
2931
submodules: recursive

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
rm -fr work || true
44
mkdir -p work
5-
ansible-playbook playbook/playbook.yaml --tags="local" --extra-vars "gh_access_token=unneeded base_dir=$(pwd) commit_hash=12345 reason='original message'" "$@"
5+
GH_ACCESS_TOKEN=unneeded ansible-playbook playbook/playbook.yaml --tags="local" --extra-vars "base_dir=$(pwd) commit_hash=12345 reason='original message'" "$@"

0 commit comments

Comments
 (0)