-
Notifications
You must be signed in to change notification settings - Fork 25
186 lines (167 loc) · 7.03 KB
/
e2e.container-based.schedule.main.gcp-workload-identity.slsa3.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
on:
schedule:
# Twice a month scheduled cron for rebuilding the base builder image.
- cron: "0 3 1,15 * *"
# Verify container-based workflow with the base builder image daily.
- cron: "0 3 * * *"
workflow_dispatch:
inputs:
trigger_build:
description: "Trigger a build"
required: false
default: false
type: boolean
permissions: read-all
concurrency: "e2e.container-based.schedule.main.gcp-workload-identity.slsa3"
env:
# TODO: Replace this token.
GH_TOKEN: ${{ secrets.E2E_CONTAINER_TOKEN }}
ISSUE_REPOSITORY: slsa-framework/slsa-github-generator
PROVENANCE_NAME: attestation.intoto
IMAGE_NAME: slsa-tooling/example-package-repo/e2e.container-based.schedule.main.gcp-workload-identity.slsa3
IMAGE_REGISTRY: us-west2-docker.pkg.dev
SERVICE_ACCOUNT: [email protected]
PROVIDER_NAME: projects/819720953812/locations/global/workloadIdentityPools/example-package-pool/providers/example-package-provider
jobs:
# Rebuild the base image
base-build:
runs-on: ubuntu-latest
if: inputs.trigger_build || (github.event_name == 'schedule' && github.event.schedule == '0 3 1,15 * *')
permissions:
contents: read # For reading repository contents.
packages: write # For writing container images.
id-token: write # For authenticating to Google Cloud Workload Identity
steps:
- id: auth
name: "Authenticate to Google Cloud"
uses: google-github-actions/auth@35b0e87d162680511bf346c299f71c9c5c379033 # v1.1.1
with:
token_format: "access_token"
service_account: ${{ env.SERVICE_ACCOUNT }}
workload_identity_provider: ${{ env.PROVIDER_NAME }}
- name: Checkout the repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2.9.1
- name: Authenticate Docker
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0
with:
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
id: build
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
base:
runs-on: ubuntu-latest
if: ${{ !inputs.trigger_build }}
permissions:
contents: read # For reading repository contents.
packages: write # For writing container images.
id-token: write # For authenticating to Google Cloud Workload Identity
outputs:
image: ${{ steps.image.outputs.image }}
digest: ${{ steps.image.outputs.digest }}
steps:
- id: auth
name: "Authenticate to Google Cloud"
uses: google-github-actions/auth@35b0e87d162680511bf346c299f71c9c5c379033 # v1.1.1
with:
token_format: "access_token"
service_account: ${{ env.SERVICE_ACCOUNT }}
workload_identity_provider: ${{ env.PROVIDER_NAME }}
- name: Authenticate Docker
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Output image
id: image
run: |
# NOTE: We need to use the image and digest in order to make sure
# that the image we attest has not been modified.
full_image_name="${IMAGE_REGISTRY}/${IMAGE_NAME}"
docker pull "${full_image_name}:main"
repo_digest=$(docker inspect --format='{{index .RepoDigests 0}}' "${full_image_name}:main")
echo "$repo_digest"
{
echo "image=$full_image_name"
echo "digest=${repo_digest#*@}"
echo "service_account=${SERVICE_ACCOUNT}"
echo "provider_name=${PROVIDER_NAME}"
} >> "${GITHUB_OUTPUT}"
build:
permissions:
id-token: write # For signing
actions: read
contents: write # For asset uploads
needs: [base]
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_container-based_slsa3.yml@main
with:
builder-image: ${{ needs.base.outputs.image }}
builder-digest: ${{ needs.base.outputs.digest }}
config-path: ".github/configs-docker/app-config.toml"
provenance-name: attestation.intoto
compile-builder: true
verify:
runs-on: ubuntu-latest
needs: [base, build]
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/download-artifact@e9ef242655d12993efdcda9058dee2db83a2cb9b
with:
name: ${{ needs.build.outputs.build-outputs-name }}
path: outputs
- name: Get build artifact
id: build
run: |
name=$(find outputs/ -type f | head -1)
cp "${name}" .
echo "name=$(basename "${name}")" >> "${GITHUB_OUTPUT}"
- uses: actions/download-artifact@e9ef242655d12993efdcda9058dee2db83a2cb9b
with:
name: ${{ needs.build.outputs.attestations-download-name }}
path: attestations
- name: Get attestation
id: att
env:
FOLDER: attestations
run: |
name=$(find "${FOLDER}"/ -type f | head -1)
cp "${name}" .
echo "name=$(basename "${name}")" >> "${GITHUB_OUTPUT}"
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version: "1.20"
- env:
BINARY: ${{ steps.build.outputs.name }}
PROVENANCE: ${{ steps.att.outputs.name }}
run: ./.github/workflows/scripts/e2e.container-based.default.verify.sh
if-succeeded:
runs-on: ubuntu-latest
needs: [build, verify]
# NOTE: The workflow is allowed to run for other event types but don't post
# to issues unless it's a schedule event.
if: github.event_name == 'schedule' && needs.build.result == 'success' && needs.verify.result == 'success'
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: ./.github/workflows/scripts/e2e-report-success.sh
if-failed:
runs-on: ubuntu-latest
needs: [build, verify]
# NOTE: The workflow is allowed to run for other event types but don't post
# to issues unless it's a schedule event.
if: always() && github.event_name == 'schedule' && (needs.build.result == 'failure' || needs.verify.result == 'failure')
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: ./.github/workflows/scripts/e2e-report-failure.sh