-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (51 loc) · 2.2 KB
/
attest-images.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
name: Attest Images
on: [workflow_call]
jobs:
binary-auth:
runs-on: ubuntu-latest
defaults:
run:
working-directory: .
steps:
# checkout@v4 is the latest version
- uses: actions/checkout@v4
- id: gcloud-auth
name: Authenticate with gcloud
# auth@v2 is the latest version
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Set up Cloud SDK
id: setup-gcloud-sdk
# setup-gcloud@v2 is the latest version
uses: 'google-github-actions/setup-gcloud@v2'
- name: Install gcloud beta
id: install-gcloud-beta
run: gcloud components install beta
- name: Attest Images
run: |
grep -ir "image:" ./manifests/blog-app/ | awk {'print $3'} | sort -t: -u -k1,1 > ./images
for image in $(cat ./images); do
no_of_slash=$(echo $image | tr -cd '/' | wc -c)
prefix=""
if [ $no_of_slash -eq 1 ]; then
prefix="docker.io/"
fi
if [ $no_of_slash -eq 0 ]; then
prefix="docker.io/library/"
fi
image_to_attest=$image
if [[ $image =~ "@" ]]; then
echo "Image $image has DIGEST"
image_to_attest="${prefix}${image}"
else
echo "All images should be in the SHA256 digest format"
exit 1
fi
echo "Processing $image"
attestation_present=$(gcloud beta container binauthz attestations list --attestor-project="${{ secrets.PROJECT_ID }}" --attestor="${{ secrets.ATTESTOR_NAME }}" --artifact-url="${image_to_attest}")
# If the attestation is not present, then attestation should be done
if [ -z "${attestation_present// }" ]; then
gcloud beta container binauthz attestations sign-and-create --artifact-url="${image_to_attest}" --attestor="${{ secrets.ATTESTOR_NAME }}" --attestor-project="${{ secrets.PROJECT_ID }}" --keyversion-project="${{ secrets.PROJECT_ID }}" --keyversion-location="${{ secrets.KMS_KEY_LOCATION }}" --keyversion-keyring="${{ secrets.KMS_KEYRING_NAME }}" --keyversion-key="${{ secrets.KMS_KEY_NAME }}" --keyversion="${{ secrets.KMS_KEY_VERSION }}"
fi
done