Skip to content

Commit 68bbd91

Browse files
committed
feat(image): Sign image with cosign
1 parent b150f42 commit 68bbd91

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

.github/workflows/main.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
push_images:
1010
name: Test and Push Images
1111
runs-on: ubuntu-latest
12+
permissions:
13+
id-token: write # needed for signing the images with GitHub OIDC Token
1214
strategy:
1315
matrix:
1416
# "{0}" will be replaced by the latest pushed nginx version
@@ -44,6 +46,8 @@ jobs:
4446
nginx-tag: "${{ steps.target_nginx_tag.outputs.tag }}"
4547
matrix-nginx: "${{ matrix.nginx }}"
4648
docker-repository: "${{ vars.DOCKER_REPOSITORY }}"
49+
- name: Install Cosign
50+
uses: sigstore/cosign-installer@v3
4751
- uses: docker/setup-qemu-action@v3
4852
name: Set up QEMU
4953
- uses: docker/setup-buildx-action@v3
@@ -55,6 +59,7 @@ jobs:
5559
password: ${{ secrets.DOCKER_PASSWORD }}
5660
- uses: docker/build-push-action@v6
5761
name: Build and push
62+
id: build-and-push
5863
if: ${{ steps.target_tags.outputs.tags != '' }}
5964
with:
6065
context: .
@@ -65,3 +70,15 @@ jobs:
6570
build-args: NGINX_TAG=${{ steps.target_nginx_tag.outputs.tag }}
6671
provenance: mode=max
6772
sbom: true
73+
- name: Sign the images with GitHub OIDC Token
74+
if: ${{ steps.target_tags.outputs.tags != '' }}
75+
env:
76+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
77+
TAGS: ${{ steps.target_tags.outputs.tags }}
78+
run: |
79+
images=""
80+
for tag in ${TAGS//,/ }; do
81+
images+="${tag}@${DIGEST} "
82+
done
83+
echo '${{ secrets.DOCKER_PASSWORD }}' | cosign login ${{ vars.HELM_REGISTRY }} --username '${{ secrets.DOCKER_USERNAME }}' --password-stdin
84+
cosign sign --yes ${images}

.github/workflows/update.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
rebase_images:
1212
name: Update Images
1313
runs-on: ubuntu-latest
14+
permissions:
15+
id-token: write # needed for signing the images with GitHub OIDC Token
1416
strategy:
1517
matrix:
1618
spa_server_major_version: [ "latest", "1" ]
@@ -81,6 +83,7 @@ jobs:
8183
password: ${{ secrets.DOCKER_PASSWORD }}
8284
- uses: docker/build-push-action@v6
8385
name: Build and push
86+
id: build-and-push
8487
if: ${{ steps.check_if_update_is_necessary.outputs.needs_update == 'true' && steps.target_image_name.outputs.tags != '' }}
8588
with:
8689
context: .
@@ -91,3 +94,15 @@ jobs:
9194
build-args: NGINX_TAG=${{ steps.target_nginx_tag.outputs.tag }}
9295
provenance: mode=max
9396
sbom: true
97+
- name: Sign the images with GitHub OIDC Token
98+
if: ${{ steps.target_tags.outputs.tags != '' }}
99+
env:
100+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
101+
TAGS: ${{ steps.target_image_name.outputs.tags }}
102+
run: |
103+
images=""
104+
for tag in ${TAGS//,/ }; do
105+
images+="${tag}@${DIGEST} "
106+
done
107+
echo '${{ secrets.DOCKER_PASSWORD }}' | cosign login ${{ vars.HELM_REGISTRY }} --username '${{ secrets.DOCKER_USERNAME }}' --password-stdin
108+
cosign sign --yes ${images}

0 commit comments

Comments
 (0)