Skip to content

Commit 337c1c3

Browse files
committed
Sign deployment image.
1 parent ace073f commit 337c1c3

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

.github/workflows/docker.yaml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ jobs:
2020
name: Build
2121
runs-on: ubuntu-latest
2222
permissions:
23-
packages: write
24-
contents: read
23+
contents: 'read'
24+
id-token: 'write'
25+
packages: 'write'
2526

2627
steps:
2728
- name: Check out code into the Go module directory
@@ -40,6 +41,9 @@ jobs:
4041
[ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true
4142
[ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true
4243
44+
- name: Install Cosign
45+
uses: sigstore/cosign-installer@v3
46+
4347
- name: Set up Docker Buildx
4448
uses: docker/setup-buildx-action@v3
4549

@@ -59,6 +63,7 @@ jobs:
5963

6064
- name: Build and push minimal image
6165
uses: docker/build-push-action@v6
66+
id: build_minimal
6267
with:
6368
context: .
6469
push: true
@@ -68,9 +73,35 @@ jobs:
6873

6974
- name: Build and push image
7075
uses: docker/build-push-action@v6
76+
id: build
7177
with:
7278
context: .
7379
push: true
7480
sbom: true
7581
tags: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.tag }}
7682
target: withcloudproviders
83+
84+
- uses: google-github-actions/auth@v2
85+
id: auth
86+
with:
87+
workload_identity_provider: projects/723287855471/locations/global/workloadIdentityPools/github/providers/github-actions
88+
service_account: [email protected]
89+
token_format: id_token
90+
id_token_audience: sigstore
91+
id_token_include_email: true
92+
93+
- name: Sign image
94+
run: |
95+
cosign sign --yes --key env://COSIGN_PRIVATE_KEY \
96+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.tag }} \
97+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.tag }}-minimal \
98+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}@${{ steps.build_minimal.outputs.digest }} \
99+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}
100+
cosign sign --yes --identity-token=${{ steps.auth.outputs.id_token }} \
101+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.tag }} \
102+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.tag }}-minimal \
103+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}@${{ steps.build_minimal.outputs.digest }} \
104+
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}
105+
env:
106+
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
107+
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}

0 commit comments

Comments
 (0)