-
Notifications
You must be signed in to change notification settings - Fork 73
421 lines (388 loc) · 19.1 KB
/
Copy pathgoogle.yml
File metadata and controls
421 lines (388 loc) · 19.1 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Google Cloud Test
on:
push:
branches:
- main
pull_request:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
env:
RUST_LOG: DEBUG
RUST_BACKTRACE: full
permissions: {}
jobs:
# Unit tests - always run, no secrets needed
unit_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Run unit tests
working-directory: ./services/google
run: |
echo "::group::Running unit tests"
cargo test --lib --no-fail-fast
cargo test --doc --no-fail-fast
echo "::endgroup::"
# Check if we can run integration tests
check_secrets:
runs-on: ubuntu-latest
outputs:
has_secrets: ${{ steps.check.outputs.has_secrets }}
steps:
- name: Check if secrets are available
id: check
run: |
if [[ "${{ github.event_name }}" == "push" || ( "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.fork }}" == "false" && "${{ github.actor }}" != "dependabot[bot]" ) ]]; then
echo "has_secrets=true" >> $GITHUB_OUTPUT
echo "::notice::Integration tests will be executed (base repository and non-dependabot PR)"
else
echo "has_secrets=false" >> $GITHUB_OUTPUT
echo "::warning::Integration tests will be skipped (forked repository, dependabot PR, or no secrets available)"
fi
# Signing tests - test signature algorithm with static credentials
signing_test:
needs: check_secrets
if: needs.check_secrets.outputs.has_secrets == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup 1Password Connect
uses: 1Password/load-secrets-action/configure@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
with:
connect-host: ${{ secrets.OP_CONNECT_HOST }}
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
- name: Load secrets
uses: 1Password/load-secrets-action@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
with:
export-env: true
env:
REQSIGN_GOOGLE_TEST: on
REQSIGN_GOOGLE_CREDENTIAL: op://reqsign/google/credential_base64
REQSIGN_GOOGLE_CLOUD_STORAGE_SCOPE: op://reqsign/google/storage_scope
REQSIGN_GOOGLE_CLOUD_STORAGE_URL: op://reqsign/google/storage_url
- name: Test signing
working-directory: ./services/google
run: |
echo "::group::Running signing tests"
cargo test signing:: --no-fail-fast -- --no-capture
echo "::endgroup::"
# DefaultCredentialProvider test
test_default_provider:
needs: check_secrets
if: needs.check_secrets.outputs.has_secrets == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup 1Password Connect
uses: 1Password/load-secrets-action/configure@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
with:
connect-host: ${{ secrets.OP_CONNECT_HOST }}
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
- name: Load secrets
id: load_secrets
uses: 1Password/load-secrets-action@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
env:
REQSIGN_GOOGLE_TEST_DEFAULT: on
GOOGLE_APPLICATION_CREDENTIALS_BASE64: op://reqsign/google/credential_base64
- name: Setup test credentials file
run: |
echo "${STEPS_LOAD_SECRETS_OUTPUTS_GOOGLE_APPLICATION_CREDENTIALS_BASE64}" | base64 -d > /tmp/gcp_credentials.json
echo "GOOGLE_APPLICATION_CREDENTIALS=/tmp/gcp_credentials.json" >> $GITHUB_ENV
env:
STEPS_LOAD_SECRETS_OUTPUTS_GOOGLE_APPLICATION_CREDENTIALS_BASE64: ${{ steps.load_secrets.outputs.GOOGLE_APPLICATION_CREDENTIALS_BASE64 }}
- name: Test DefaultCredentialProvider
working-directory: ./services/google
run: |
echo "::group::Testing DefaultCredentialProvider"
cargo test test_default_credential_provider --no-fail-fast -- --no-capture
echo "::endgroup::"
# StaticCredentialProvider test
test_static_provider:
needs: check_secrets
if: needs.check_secrets.outputs.has_secrets == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup 1Password Connect
uses: 1Password/load-secrets-action/configure@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
with:
connect-host: ${{ secrets.OP_CONNECT_HOST }}
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
- name: Load secrets
uses: 1Password/load-secrets-action@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
with:
export-env: true
env:
REQSIGN_GOOGLE_TEST_STATIC: on
REQSIGN_GOOGLE_CREDENTIAL: op://reqsign/google/credential_base64
REQSIGN_GOOGLE_CLOUD_STORAGE_SCOPE: op://reqsign/google/storage_scope
- name: Test StaticCredentialProvider
working-directory: ./services/google
run: |
echo "::group::Testing StaticCredentialProvider"
cargo test test_static_credential_provider --no-fail-fast -- --no-capture
echo "::endgroup::"
# AuthorizedUserCredentialProvider test
test_authorized_user_provider:
needs: check_secrets
if: needs.check_secrets.outputs.has_secrets == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup 1Password Connect
uses: 1Password/load-secrets-action/configure@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
with:
connect-host: ${{ secrets.OP_CONNECT_HOST }}
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
- name: Load secrets
id: load_secrets
uses: 1Password/load-secrets-action@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
env:
REQSIGN_GOOGLE_TEST_AUTHORIZED_USER: on
AUTHORIZED_USER_CREDENTIALS_BASE64: op://reqsign/google/authorized_user_base64
- name: Setup test credentials file
run: |
echo "${STEPS_LOAD_SECRETS_OUTPUTS_AUTHORIZED_USER_CREDENTIALS_BASE64}" | base64 -d > /tmp/authorized_user.json
echo "REQSIGN_GOOGLE_AUTHORIZED_USER_CREDENTIALS=/tmp/authorized_user.json" >> $GITHUB_ENV
env:
STEPS_LOAD_SECRETS_OUTPUTS_AUTHORIZED_USER_CREDENTIALS_BASE64: ${{ steps.load_secrets.outputs.AUTHORIZED_USER_CREDENTIALS_BASE64 }}
- name: Test AuthorizedUserCredentialProvider
working-directory: ./services/google
run: |
echo "::group::Testing AuthorizedUserCredentialProvider"
cargo test test_authorized_user_credential_provider --no-fail-fast -- --no-capture
echo "::endgroup::"
# ExternalAccountCredentialProvider test (Workload Identity)
test_external_account_provider:
needs: check_secrets
if: needs.check_secrets.outputs.has_secrets == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup 1Password Connect
uses: 1Password/load-secrets-action/configure@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
with:
connect-host: ${{ secrets.OP_CONNECT_HOST }}
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
- name: Load secrets
uses: 1Password/load-secrets-action@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
with:
export-env: true
env:
REQSIGN_GOOGLE_TEST_WORKLOAD_IDENTITY: on
GOOGLE_WORKLOAD_IDENTITY_PROVIDER: op://reqsign/google/workload_identity_provider
GOOGLE_SERVICE_ACCOUNT: op://reqsign/google/service_account_email
- name: Setup Workload Identity with Google Auth
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0
with:
create_credentials_file: true
workload_identity_provider: ${{ env.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.GOOGLE_SERVICE_ACCOUNT }}
- name: Test ExternalAccountCredentialProvider
working-directory: ./services/google
run: |
echo "::group::Testing ExternalAccountCredentialProvider"
# The google-github-actions/auth action sets GOOGLE_APPLICATION_CREDENTIALS
# reqsign should be able to use this external_account configuration
cargo test test_external_account_with_workload_identity --no-fail-fast -- --no-capture
echo "::endgroup::"
# ImpersonatedServiceAccountCredentialProvider test
test_impersonated_service_account_provider:
needs: check_secrets
if: needs.check_secrets.outputs.has_secrets == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup 1Password Connect
uses: 1Password/load-secrets-action/configure@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
with:
connect-host: ${{ secrets.OP_CONNECT_HOST }}
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}
- name: Load secrets
id: load_secrets
uses: 1Password/load-secrets-action@3a12b0ab99d9cd590a3e9b5a90ea017210ed9556 # v4.0.1
env:
REQSIGN_GOOGLE_TEST_IMPERSONATED_SERVICE_ACCOUNT: on
IMPERSONATED_SA_CREDENTIALS_BASE64: op://reqsign/google/impersonated_sa_base64
- name: Setup test credentials file
run: |
echo "${STEPS_LOAD_SECRETS_OUTPUTS_IMPERSONATED_SA_CREDENTIALS_BASE64}" | base64 -d > /tmp/impersonated_sa.json
echo "REQSIGN_GOOGLE_IMPERSONATED_SERVICE_ACCOUNT_CREDENTIALS=/tmp/impersonated_sa.json" >> $GITHUB_ENV
env:
STEPS_LOAD_SECRETS_OUTPUTS_IMPERSONATED_SA_CREDENTIALS_BASE64: ${{ steps.load_secrets.outputs.IMPERSONATED_SA_CREDENTIALS_BASE64 }}
- name: Test ImpersonatedServiceAccountCredentialProvider
working-directory: ./services/google
run: |
echo "::group::Testing ImpersonatedServiceAccountCredentialProvider"
cargo test test_impersonated_service_account_credential_provider --no-fail-fast -- --no-capture
echo "::endgroup::"
# VmMetadataCredentialProvider test
test_vm_metadata_provider:
needs: check_secrets
if: needs.check_secrets.outputs.has_secrets == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Start mock metadata server
run: |
python3 services/google/tests/mocks/vm_metadata_mock_server.py 8080 &
echo "MOCK_PID=$!" >> $GITHUB_ENV
sleep 2
# Verify the mock server is running
curl -f -H "Metadata-Flavor: Google" http://127.0.0.1:8080/computeMetadata/v1/instance/service-accounts/ || exit 1
- name: Test VmMetadataCredentialProvider with mock
working-directory: ./services/google
run: |
echo "::group::Testing VmMetadataCredentialProvider with mock"
export REQSIGN_GOOGLE_TEST_VM_METADATA_MOCK=on
export GCE_METADATA_HOST=127.0.0.1:8080
cargo test test_vm_metadata_credential_provider_with_mock --no-fail-fast -- --no-capture
echo "::endgroup::"
- name: Stop mock server
if: always()
run: |
if [ ! -z "$MOCK_PID" ]; then
kill $MOCK_PID || true
fi
# Summary
test_summary:
needs:
[
unit_test,
signing_test,
test_default_provider,
test_static_provider,
test_authorized_user_provider,
test_external_account_provider,
test_impersonated_service_account_provider,
test_vm_metadata_provider,
]
if: always()
runs-on: ubuntu-latest
steps:
- name: Test Summary
run: |
echo "## Google Cloud Test Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Unit tests status
if [[ "${NEEDS_UNIT_TEST_RESULT}" == "success" ]]; then
echo "✅ Unit tests passed" >> $GITHUB_STEP_SUMMARY
elif [[ "${NEEDS_UNIT_TEST_RESULT}" == "skipped" ]]; then
echo "⏭️ Unit tests skipped" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Unit tests failed" >> $GITHUB_STEP_SUMMARY
fi
# Integration tests status
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Integration Tests" >> $GITHUB_STEP_SUMMARY
if [[ "${NEEDS_SIGNING_TEST_RESULT}" == "success" ]]; then
echo "✅ Signing tests passed" >> $GITHUB_STEP_SUMMARY
elif [[ "${NEEDS_SIGNING_TEST_RESULT}" == "skipped" ]]; then
echo "⏭️ Signing tests skipped (no secrets)" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Signing tests failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${NEEDS_TEST_DEFAULT_PROVIDER_RESULT}" == "success" ]]; then
echo "✅ DefaultCredentialProvider tests passed" >> $GITHUB_STEP_SUMMARY
elif [[ "${NEEDS_TEST_DEFAULT_PROVIDER_RESULT}" == "skipped" ]]; then
echo "⏭️ DefaultCredentialProvider tests skipped (no secrets)" >> $GITHUB_STEP_SUMMARY
else
echo "❌ DefaultCredentialProvider tests failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${NEEDS_TEST_STATIC_PROVIDER_RESULT}" == "success" ]]; then
echo "✅ StaticCredentialProvider tests passed" >> $GITHUB_STEP_SUMMARY
elif [[ "${NEEDS_TEST_STATIC_PROVIDER_RESULT}" == "skipped" ]]; then
echo "⏭️ StaticCredentialProvider tests skipped (no secrets)" >> $GITHUB_STEP_SUMMARY
else
echo "❌ StaticCredentialProvider tests failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${NEEDS_TEST_AUTHORIZED_USER_PROVIDER_RESULT}" == "success" ]]; then
echo "✅ AuthorizedUserCredentialProvider tests passed" >> $GITHUB_STEP_SUMMARY
elif [[ "${NEEDS_TEST_AUTHORIZED_USER_PROVIDER_RESULT}" == "skipped" ]]; then
echo "⏭️ AuthorizedUserCredentialProvider tests skipped (no secrets)" >> $GITHUB_STEP_SUMMARY
else
echo "❌ AuthorizedUserCredentialProvider tests failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${NEEDS_TEST_EXTERNAL_ACCOUNT_PROVIDER_RESULT}" == "success" ]]; then
echo "✅ ExternalAccountCredentialProvider tests passed" >> $GITHUB_STEP_SUMMARY
elif [[ "${NEEDS_TEST_EXTERNAL_ACCOUNT_PROVIDER_RESULT}" == "skipped" ]]; then
echo "⏭️ ExternalAccountCredentialProvider tests skipped (no secrets)" >> $GITHUB_STEP_SUMMARY
else
echo "❌ ExternalAccountCredentialProvider tests failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${NEEDS_TEST_IMPERSONATED_SERVICE_ACCOUNT_PROVIDER_RESULT}" == "success" ]]; then
echo "✅ ImpersonatedServiceAccountCredentialProvider tests passed" >> $GITHUB_STEP_SUMMARY
elif [[ "${NEEDS_TEST_IMPERSONATED_SERVICE_ACCOUNT_PROVIDER_RESULT}" == "skipped" ]]; then
echo "⏭️ ImpersonatedServiceAccountCredentialProvider tests skipped (no secrets)" >> $GITHUB_STEP_SUMMARY
else
echo "❌ ImpersonatedServiceAccountCredentialProvider tests failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${NEEDS_TEST_VM_METADATA_PROVIDER_RESULT}" == "success" ]]; then
echo "✅ VmMetadataCredentialProvider tests passed" >> $GITHUB_STEP_SUMMARY
elif [[ "${NEEDS_TEST_VM_METADATA_PROVIDER_RESULT}" == "skipped" ]]; then
echo "⏭️ VmMetadataCredentialProvider tests skipped (no secrets)" >> $GITHUB_STEP_SUMMARY
else
echo "❌ VmMetadataCredentialProvider tests failed" >> $GITHUB_STEP_SUMMARY
fi
# Overall status
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${NEEDS_UNIT_TEST_RESULT}" == "success" ]] && \
( [[ "${NEEDS_SIGNING_TEST_RESULT}" == "success" ]] || [[ "${NEEDS_SIGNING_TEST_RESULT}" == "skipped" ]] ) && \
( [[ "${NEEDS_TEST_DEFAULT_PROVIDER_RESULT}" == "success" ]] || [[ "${NEEDS_TEST_DEFAULT_PROVIDER_RESULT}" == "skipped" ]] ) && \
( [[ "${NEEDS_TEST_STATIC_PROVIDER_RESULT}" == "success" ]] || [[ "${NEEDS_TEST_STATIC_PROVIDER_RESULT}" == "skipped" ]] ) && \
( [[ "${NEEDS_TEST_AUTHORIZED_USER_PROVIDER_RESULT}" == "success" ]] || [[ "${NEEDS_TEST_AUTHORIZED_USER_PROVIDER_RESULT}" == "skipped" ]] ) && \
( [[ "${NEEDS_TEST_EXTERNAL_ACCOUNT_PROVIDER_RESULT}" == "success" ]] || [[ "${NEEDS_TEST_EXTERNAL_ACCOUNT_PROVIDER_RESULT}" == "skipped" ]] ) && \
( [[ "${NEEDS_TEST_IMPERSONATED_SERVICE_ACCOUNT_PROVIDER_RESULT}" == "success" ]] || [[ "${NEEDS_TEST_IMPERSONATED_SERVICE_ACCOUNT_PROVIDER_RESULT}" == "skipped" ]] ) && \
( [[ "${NEEDS_TEST_VM_METADATA_PROVIDER_RESULT}" == "success" ]] || [[ "${NEEDS_TEST_VM_METADATA_PROVIDER_RESULT}" == "skipped" ]] ); then
echo "### ✅ All tests completed successfully" >> $GITHUB_STEP_SUMMARY
else
echo "### ❌ Some tests failed" >> $GITHUB_STEP_SUMMARY
exit 1
fi
env:
NEEDS_UNIT_TEST_RESULT: ${{ needs.unit_test.result }}
NEEDS_SIGNING_TEST_RESULT: ${{ needs.signing_test.result }}
NEEDS_TEST_DEFAULT_PROVIDER_RESULT: ${{ needs.test_default_provider.result }}
NEEDS_TEST_STATIC_PROVIDER_RESULT: ${{ needs.test_static_provider.result }}
NEEDS_TEST_AUTHORIZED_USER_PROVIDER_RESULT: ${{ needs.test_authorized_user_provider.result }}
NEEDS_TEST_EXTERNAL_ACCOUNT_PROVIDER_RESULT: ${{ needs.test_external_account_provider.result }}
NEEDS_TEST_IMPERSONATED_SERVICE_ACCOUNT_PROVIDER_RESULT: ${{ needs.test_impersonated_service_account_provider.result }}
NEEDS_TEST_VM_METADATA_PROVIDER_RESULT: ${{ needs.test_vm_metadata_provider.result }}