Skip to content

Commit 3b00da9

Browse files
axisofentropyLinkinStars
authored andcommitted
Sanitize input from contributor fork workflows.
Signed-off-by: Adam Vollrath <[email protected]>
1 parent 152934c commit 3b00da9

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

.github/workflows/uffizzi-build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ jobs:
3636

3737
- name: Generate UUID image name
3838
id: uuid
39-
run: echo "UUID_WORKER=$(uuidgen)" >> $GITHUB_ENV
39+
run: echo "UUID_WORKER=answer-$(uuidgen --time)" >> $GITHUB_ENV
4040

4141
- name: Docker metadata
4242
id: meta
4343
uses: docker/metadata-action@v4
4444
with:
4545
images: registry.uffizzi.com/${{ env.UUID_WORKER }}
4646
tags: |
47-
type=raw,value=60d
47+
type=raw,value=30d
4848
4949
- name: Build and Push Image to registry.uffizzi.com - Uffizzi's ephemeral Registry
5050
uses: docker/build-push-action@v3

.github/workflows/uffizzi-preview.yml

+25-16
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ jobs:
3030
runs-on: ubuntu-latest
3131
if: ${{ github.event.workflow_run.conclusion == 'success' }}
3232
outputs:
33-
compose-file-cache-key: ${{ env.HASH }}
34-
pr-number: ${{ env.PR_NUMBER }}
33+
compose-file-cache-key: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}
34+
git-ref: ${{ steps.event.outputs.GIT_REF }}
35+
pr-number: ${{ steps.event.outputs.PR_NUMBER }}
36+
action: ${{ steps.event.outputs.ACTION }}
3537
steps:
3638
- name: Download artifacts
3739
# Fetch output (zip archive) from the workflow run that triggered this workflow.
@@ -46,6 +48,9 @@ jobs:
4648
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
4749
return artifact.name == "preview-spec"
4850
})[0];
51+
if (matchArtifact === undefined) {
52+
throw TypeError('Build Artifact not found!');
53+
}
4954
let download = await github.rest.actions.downloadArtifact({
5055
owner: context.repo.owner,
5156
repo: context.repo.repo,
@@ -55,34 +60,38 @@ jobs:
5560
let fs = require('fs');
5661
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/preview-spec.zip`, Buffer.from(download.data));
5762
58-
- name: Unzip artifact
59-
run: unzip preview-spec.zip
63+
- name: 'Accept event from first stage'
64+
run: unzip preview-spec.zip event.json
65+
6066
- name: Read Event into ENV
67+
id: event
6168
run: |
62-
echo 'EVENT_JSON<<EOF' >> $GITHUB_ENV
63-
cat event.json >> $GITHUB_ENV
64-
echo 'EOF' >> $GITHUB_ENV
69+
echo PR_NUMBER=$(jq '.number | tonumber' < event.json) >> $GITHUB_OUTPUT
70+
echo ACTION=$(jq --raw-output '.action | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT
71+
echo GIT_REF=$(jq --raw-output '.pull_request.head.sha | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT
6572
6673
- name: Hash Rendered Compose File
6774
id: hash
6875
# If the previous workflow was triggered by a PR close event, we will not have a compose file artifact.
69-
if: ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
70-
run: echo "HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_ENV
76+
if: ${{ steps.event.outputs.ACTION != 'closed' }}
77+
run: |
78+
unzip preview-spec.zip docker-compose.rendered.yml
79+
echo "COMPOSE_FILE_HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_OUTPUT
80+
7181
- name: Cache Rendered Compose File
72-
if: ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
82+
if: ${{ steps.event.outputs.ACTION != 'closed' }}
7383
uses: actions/cache@v3
7484
with:
7585
path: docker-compose.rendered.yml
76-
key: ${{ env.HASH }}
86+
key: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}
7787

78-
- name: Read PR Number From Event Object
79-
id: pr
80-
run: echo "PR_NUMBER=${{ fromJSON(env.EVENT_JSON).number }}" >> $GITHUB_ENV
8188
- name: DEBUG - Print Job Outputs
8289
if: ${{ runner.debug }}
8390
run: |
84-
echo "PR number: ${{ env.PR_NUMBER }}"
85-
echo "Compose file hash: ${{ env.HASH }}"
91+
echo "PR number: ${{ steps.event.outputs.PR_NUMBER }}"
92+
echo "Git Ref: ${{ steps.event.outputs.GIT_REF }}"
93+
echo "Action: ${{ steps.event.outputs.ACTION }}"
94+
echo "Compose file hash: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}"
8695
cat event.json
8796
8897
deploy-uffizzi-preview:

0 commit comments

Comments
 (0)