Skip to content

Commit 1d63fa1

Browse files
committed
Address PR review feedback from linglp and jaymedina
- Fix push jobs to load scanned tar instead of rebuilding (build.yml) - Pin trivy-action to SHA for v0.35.0 to address supply chain attack - Fix env.repo_name output using $GITHUB_OUTPUT (trivy_periodic_scan.yml) - Pin all third-party actions to commit SHAs - Remove unnecessary permissions on get-image-reference job - Use !cancelled() for SARIF upload condition (trivy.yml) - Use LOCAL_IMAGE_TAG env var instead of hardcoded string (docker_build.yml) - Fix IMAGE_REFERENCES YAML line continuation
1 parent 0497f30 commit 1d63fa1

4 files changed

Lines changed: 46 additions & 45 deletions

File tree

.github/workflows/build.yml

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ jobs:
593593
file: ./Dockerfile
594594
platforms: linux/amd64
595595
cache-from: type=registry,ref=ghcr.io/sage-bionetworks/synapsepythonclient:build-cache
596+
cache-to: type=registry,mode=max,ref=ghcr.io/sage-bionetworks/synapsepythonclient:build-cache
596597
- name: Save Docker image to tar
597598
run: docker save synapsepythonclient-release:local -o ${{ env.TARFILE_NAME }}
598599
- name: Upload tar artifact
@@ -624,28 +625,31 @@ jobs:
624625
contents: read
625626
packages: write
626627

628+
env:
629+
TARFILE_NAME: synapsepythonclient-release.tar
630+
627631
steps:
628-
- name: Check out the repo
629-
uses: actions/checkout@v4
630-
- name: Set up Docker Buildx
631-
uses: docker/setup-buildx-action@v2
632+
- name: Download scanned tar
633+
uses: actions/download-artifact@v4
634+
with:
635+
name: ${{ env.TARFILE_NAME }}
636+
path: /tmp
637+
- name: Load Docker image from tar
638+
run: docker load -i /tmp/${{ env.TARFILE_NAME }}
632639
- name: Log in to GitHub Container Registry
633640
uses: docker/login-action@v2
634641
with:
635642
registry: ghcr.io
636643
username: ${{ github.actor }}
637644
password: ${{ secrets.GITHUB_TOKEN }}
638-
- name: Build and push Docker image
639-
uses: docker/build-push-action@v5
640-
with:
641-
context: .
642-
push: true
643-
provenance: false
644-
tags: ${{ needs.ghcr-build-on-release.outputs.image-tags }}
645-
file: ./Dockerfile
646-
platforms: linux/amd64
647-
cache-from: type=registry,ref=ghcr.io/sage-bionetworks/synapsepythonclient:build-cache
648-
cache-to: type=registry,mode=max,ref=ghcr.io/sage-bionetworks/synapsepythonclient:build-cache
645+
- name: Tag and push Docker image
646+
shell: bash
647+
run: |
648+
IFS=',' read -ra TAGS <<< "${{ needs.ghcr-build-on-release.outputs.image-tags }}"
649+
for TAG in "${TAGS[@]}"; do
650+
docker tag synapsepythonclient-release:local "$TAG"
651+
docker push "$TAG"
652+
done
649653
650654
# containerize the package and upload to the GHCR upon commit in develop
651655
# Step 1: Build the Docker image and save as tar for scanning
@@ -677,6 +681,7 @@ jobs:
677681
file: ./Dockerfile
678682
platforms: linux/amd64
679683
cache-from: type=registry,ref=ghcr.io/sage-bionetworks/synapsepythonclient:build-cache
684+
cache-to: type=inline
680685
- name: Save Docker image to tar
681686
run: docker save synapsepythonclient-develop:local -o ${{ env.TARFILE_NAME }}
682687
- name: Upload tar artifact
@@ -709,25 +714,24 @@ jobs:
709714
contents: read
710715
packages: write
711716

717+
env:
718+
TARFILE_NAME: synapsepythonclient-develop.tar
719+
712720
steps:
713-
- name: Check out the repo
714-
uses: actions/checkout@v4
715-
- name: Set up Docker Buildx
716-
uses: docker/setup-buildx-action@v2
721+
- name: Download scanned tar
722+
uses: actions/download-artifact@v4
723+
with:
724+
name: ${{ env.TARFILE_NAME }}
725+
path: /tmp
726+
- name: Load Docker image from tar
727+
run: docker load -i /tmp/${{ env.TARFILE_NAME }}
717728
- name: Log in to GitHub Container Registry
718729
uses: docker/login-action@v2
719730
with:
720731
registry: ghcr.io
721732
username: ${{ github.actor }}
722733
password: ${{ secrets.GITHUB_TOKEN }}
723-
- name: Build and push Docker image
724-
uses: docker/build-push-action@v5
725-
with:
726-
context: .
727-
push: true
728-
provenance: false
729-
tags: ghcr.io/sage-bionetworks/synapsepythonclient:develop-${{ github.sha }}
730-
file: ./Dockerfile
731-
platforms: linux/amd64
732-
cache-from: type=registry,ref=ghcr.io/sage-bionetworks/synapsepythonclient:build-cache
733-
cache-to: type=inline
734+
- name: Tag and push Docker image
735+
run: |
736+
docker tag synapsepythonclient-develop:local "${{ needs.ghcr-build-on-develop.outputs.image-tag }}"
737+
docker push "${{ needs.ghcr-build-on-develop.outputs.image-tag }}"

.github/workflows/docker_build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ jobs:
4040
context: .
4141
push: false
4242
load: true
43-
tags: rebuild-image:local
43+
tags: ${{ env.LOCAL_IMAGE_TAG }}
4444
file: ./Dockerfile
4545
platforms: linux/amd64
4646

4747
- name: Save Docker image to tar
48-
run: docker save rebuild-image:local -o ${{ env.TARFILE_NAME }}
48+
run: docker save ${{ env.LOCAL_IMAGE_TAG }} -o ${{ env.TARFILE_NAME }}
4949

5050
- name: Upload tarball for use by Trivy job
5151
uses: actions/upload-artifact@v4
@@ -98,6 +98,6 @@ jobs:
9898
run: |
9999
IFS=',' read -ra TAGS <<< "${{ inputs.IMAGE_REFERENCES }}"
100100
for TAG in "${TAGS[@]}"; do
101-
docker tag rebuild-image:local "$TAG"
101+
docker tag ${{ env.LOCAL_IMAGE_TAG }} "$TAG"
102102
docker push "$TAG"
103103
done

.github/workflows/trivy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
run: docker load -i ${{ steps.tar-download.outputs.download-path }}/${{ inputs.TARFILE_NAME }}
6363

6464
- name: Run Trivy vulnerability scanner for any major issues
65-
uses: aquasecurity/trivy-action@0.32.0
65+
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
6666
id: trivy
6767
with:
6868
image-ref: ${{ inputs.IMAGE_NAME }}
@@ -75,14 +75,14 @@ jobs:
7575

7676
- name: Upload Trivy scan results to GitHub Security tab
7777
uses: github/codeql-action/upload-sarif@v3.25.12
78-
if: ${{ success() || steps.trivy.conclusion == 'failure' }}
78+
if: ${{ !cancelled() }}
7979
with:
8080
sarif_file: ${{ env.sarif_file_name }}
8181
wait-for-processing: true
8282

8383
- name: Upload Trivy output
8484
uses: actions/upload-artifact@v4
85-
if: ${{ success() || steps.trivy.conclusion == 'failure' }}
85+
if: ${{ !cancelled() }}
8686
with:
8787
name: ${{ env.sarif_file_name }}
8888
path: ${{ env.sarif_file_name }}

.github/workflows/trivy_periodic_scan.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ jobs:
2222
# While GitHub repos can be mixed case,
2323
# Docker images can only be lower case
2424
repo_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
25-
echo "repo_name=$repo_name" >> $GITHUB_ENV
25+
echo "repo_name=$repo_name" >> $GITHUB_OUTPUT
2626
- name: Find current version
2727
id: find_version
28-
uses: mathieudutour/github-tag-action@v6.2
28+
uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b # v6.2
2929
with:
3030
github_token: ${{ secrets.GITHUB_TOKEN }}
3131
dry_run: true # setting to 'true' means no new version is created
3232
outputs:
33-
image_repo: ghcr.io/${{ env.repo_name }}
33+
image_repo: ghcr.io/${{ steps.to_lower_case.outputs.repo_name }}
3434
image_tag: ${{ steps.find_version.outputs.previous_version }}
3535
permissions:
3636
contents: read
37-
deployments: write
38-
security-events: write
3937

4038
periodic-scan:
4139
needs: get-image-reference
@@ -57,12 +55,12 @@ jobs:
5755
steps:
5856
- name: Bump version and push tag
5957
id: tag_version
60-
uses: mathieudutour/github-tag-action@v6.2
58+
uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b # v6.2
6159
with:
6260
github_token: ${{ secrets.GITHUB_TOKEN }}
6361
- name: Parse new version
6462
id: parsed
65-
uses: booxmedialtd/ws-action-parse-semver@v1
63+
uses: booxmedialtd/ws-action-parse-semver@7784200024d6b3fc01253e617ec0168daf603de3 # v1.4.7
6664
with:
6765
input_string: ${{ steps.tag_version.outputs.new_version }}
6866
outputs:
@@ -80,8 +78,7 @@ jobs:
8078
uses: "./.github/workflows/docker_build.yml"
8179
with:
8280
REF_TO_CHECKOUT: ${{ needs.bump-tag.outputs.new_tag }}
83-
IMAGE_REFERENCES: "${{ needs.get-image-reference.outputs.image_repo }}:${{ needs.bump-tag.outputs.new_version }},\
84-
${{ needs.get-image-reference.outputs.image_repo }}:${{ needs.bump-tag.outputs.new_major_minor }}"
81+
IMAGE_REFERENCES: "${{ needs.get-image-reference.outputs.image_repo }}:${{ needs.bump-tag.outputs.new_version }},${{ needs.get-image-reference.outputs.image_repo }}:${{ needs.bump-tag.outputs.new_major_minor }}"
8582
permissions:
8683
contents: read
8784
deployments: write

0 commit comments

Comments
 (0)