Skip to content

Commit 3f4e9f6

Browse files
Venefilynxlionjuan
andcommitted
feat: Verify upstream image
If the upstream image is tampered with we should automatically fail the image build and prevent any futher security breaches. This is not foolproof as the implementation grabs the public key from a git repository instead of locally, but it will ensure that the key from the git repository did sign the image. Fixes: #25 Co-authored-by: XLion <xlion@xlion.tw> Signed-off-by: Freya Gustavsson <freya@venefilyn.se>
1 parent c33279c commit 3f4e9f6

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ on:
55
branches:
66
- main
77
schedule:
8-
- cron: '05 10 * * *' # 10:05am UTC everyday
8+
- cron: "05 10 * * *" # 10:05am UTC everyday
99
push:
1010
branches:
1111
- main
1212
paths-ignore:
13-
- '**/README.md'
13+
- "**/README.md"
1414
workflow_dispatch:
1515

1616
env:
17-
IMAGE_NAME: "${{ github.event.repository.name }}" # the name of the image produced by this build, matches repo names
17+
IMAGE_NAME: "${{ github.event.repository.name }}" # the name of the image produced by this build, matches repo names
1818
IMAGE_DESC: "My Customized Universal Blue Image"
19-
IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}" # do not edit
20-
ARTIFACTHUB_LOGO_URL: "https://avatars.githubusercontent.com/u/120078124?s=200&v=4" # You should put your own image here so that you get a fancy profile image on https://artifacthub.io/!
19+
IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}" # do not edit
20+
ARTIFACTHUB_LOGO_URL: "https://avatars.githubusercontent.com/u/120078124?s=200&v=4" # You should put your own image here so that you get a fancy profile image on https://artifacthub.io/!
2121

2222
concurrency:
2323
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}-${{ inputs.brand_name}}-${{ inputs.stream_name }}
@@ -43,7 +43,7 @@ jobs:
4343
# uses: ublue-os/remove-unwanted-software@517622d6452028f266b7ba4cc9a123b5f58a6b53 # v7
4444
# with:
4545
# remove-codeql: true
46-
46+
4747
- name: Get current date
4848
id: date
4949
run: |
@@ -86,6 +86,27 @@ jobs:
8686
sep-tags: " "
8787
sep-annotations: " "
8888

89+
- name: Install Cosign
90+
uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2
91+
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
92+
93+
# With cosign we can verify the authenticity of the upstream image.
94+
# This is highly recommended to ensure the upstream wasn't tampered with.
95+
# This can fail through a key mismatch or upstream image not being signed.
96+
#
97+
# We find the upstream image by checking the 'FROM' field.
98+
- name: Verify upstream container image
99+
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
100+
shell: bash
101+
run: |
102+
set -oue pipefail
103+
echo "Get upstream image tag"
104+
image=$(grep -i '^FROM.*:\S*' "./Containerfile" | awk '{print $2}')
105+
echo "Using Cosign to verify image"
106+
cosign verify \
107+
--key https://raw.githubusercontent.com/ublue-os/main/main/cosign.pub \
108+
"${image}"
109+
89110
- name: Build Image
90111
id: build_image
91112
uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2
@@ -165,9 +186,6 @@ jobs:
165186
# your project for others to consume. You will need to create a public and private key
166187
# using Cosign and save the private key as a repository secret in Github for this workflow
167188
# to consume. For more details, review the image signing section of the README.
168-
- name: Install Cosign
169-
uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2
170-
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
171189

172190
- name: Sign container image
173191
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)

0 commit comments

Comments
 (0)