Skip to content

Commit 14c7585

Browse files
authored
fix(security): harden GitHub Actions workflows against expression injection (#407)
Move `${{ }}` expressions from `run:` blocks into step-level `env:` blocks, then reference them as properly-quoted shell variables. Part of cloudnative-pg/cloudnative-pg#10113 Assisted-by: Claude Opus 4.6 Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
1 parent 3321b8a commit 14c7585

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

.github/workflows/bake_targets.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ jobs:
7171

7272
- name: Filter by versions
7373
id: extract_targets
74+
env:
75+
TARGETS_MATRIX: ${{ steps.targets.outputs.matrix }}
76+
PG_VERSION: ${{ inputs.postgresql_version }}
7477
run: |
75-
target=$(echo '${{ steps.targets.outputs.matrix }}' | jq -r '.[] | .[] | select(match("${{ inputs.postgresql_version }}"))' | xargs echo | sed 's/ /,/g')
76-
echo "Targets for PostgreSQL ${{ inputs.postgresql_version }}: $target"
78+
target=$(echo "${TARGETS_MATRIX}" | jq -r --arg v "${PG_VERSION}" '.[] | .[] | select(match($v))' | xargs echo | sed 's/ /,/g')
79+
echo "Targets for PostgreSQL ${PG_VERSION}: $target"
7780
echo "filtered_targets=$target" >> "$GITHUB_OUTPUT"
7881
7982
- name: Log in to the GitHub Container registry
@@ -113,8 +116,10 @@ jobs:
113116
# Get a list of the images that were built and pushed. We only care about a single tag for each image.
114117
- name: Generated images
115118
id: images
119+
env:
120+
BUILD_METADATA: ${{ steps.build.outputs.metadata }}
116121
run: |
117-
echo "images=$(echo '${{ steps.build.outputs.metadata }}' | jq -c '[ .[]."image.name" | sub(",.*";"") ]')" >> "$GITHUB_OUTPUT"
122+
echo "images=$(echo "${BUILD_METADATA}" | jq -c '[ .[]."image.name" | sub(",.*";"") ]')" >> "$GITHUB_OUTPUT"
118123
119124
# Even if we're testing we sign the images, so we can push them to production later if that's required
120125
- name: Install cosign
@@ -123,8 +128,10 @@ jobs:
123128
# and https://github.com/actions/starter-workflows/blob/main/ci/docker-publish.yml for more details on
124129
# how to use cosign.
125130
- name: Sign images
131+
env:
132+
BUILD_METADATA: ${{ steps.build.outputs.metadata }}
126133
run: |
127-
echo '${{ steps.build.outputs.metadata }}' | \
134+
echo "${BUILD_METADATA}" | \
128135
jq '.[] | (."image.name" | sub(",.*";"" )) + "@" + ."containerimage.digest"' | \
129136
xargs cosign sign --yes
130137

0 commit comments

Comments
 (0)