Repository navigation
Expand file tree
/
Copy pathkms_encryption_integration_tests.yml
More file actions
264 lines (230 loc) · 10.7 KB
/
Copy pathkms_encryption_integration_tests.yml
File metadata and controls
264 lines (230 loc) · 10.7 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
name: KMS Encryption Integration Tests
# The LocalStack job needs no AWS account and no secrets, so it also runs on pull requests from forks.
# The real-key and Aurora jobs read the key ARN, its region and the roles from repository variables,
# which an administrator sets up once; CI never creates or changes KMS keys.
# On a push to main they run only when the variables they need are set, so main stays green until then;
# a manual run of either fails when KMS_KEY_ARN is missing.
on:
pull_request:
paths:
- 'aws_advanced_python_wrapper/**'
- 'tests/integration/**'
- 'pyproject.toml'
- 'poetry.lock'
- '.github/workflows/kms_encryption_integration_tests.yml'
push:
branches: [ main ]
paths:
- 'aws_advanced_python_wrapper/**'
- 'tests/integration/**'
- 'pyproject.toml'
- 'poetry.lock'
- '.github/workflows/kms_encryption_integration_tests.yml'
workflow_dispatch:
inputs:
lane:
description: 'Which KMS environment to run'
type: choice
options: [ localstack, real-kms, aurora ]
default: localstack
permissions:
contents: read
concurrency:
# Each push has its own group, so a long Aurora job never holds back or cancels a later push's other jobs.
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.lane }}-${{ github.event_name == 'push' && github.sha || '' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
kms-localstack:
name: Run KMS Encryption Tests with LocalStack
if: github.event_name != 'workflow_dispatch' || inputs.lane == 'localstack'
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
include:
- { engine: pg, skip: mysql }
- { engine: mysql, skip: pg }
steps:
- name: 'Clone repository'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: 'Set up JDK 8'
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
distribution: 'corretto'
java-version: 8
- name: 'Set up Python 3.12'
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.12'
- name: Install poetry
shell: bash
run: |
pipx install poetry==1.8.2
poetry config virtualenvs.prefer-active-python true
- name: Install dependencies
run: poetry install
- name: 'Run the KMS tests on Docker with LocalStack'
run: |
DB_PASSWORD="$(openssl rand -hex 16)"
echo "::add-mask::${DB_PASSWORD}"
export DB_PASSWORD DB_USERNAME=test_user DB_DATABASE_NAME=test_db
./gradlew --no-parallel --no-daemon test-kms-encryption-docker \
-Dexclude-${{ matrix.skip }}-engine=true -Dexclude-${{ matrix.skip }}-driver=true
# pytest exits 0 when every test is skipped, so count the KMS test cases that ran.
- name: 'Fail when no KMS test ran'
run: |
python3 -c 'import glob,sys,xml.etree.ElementTree as E; c=[t for f in glob.glob("tests/integration/container/reports/*.xml") for t in E.parse(f).iter("testcase") if "kms_encryption" in t.get("classname","") and t.find("skipped") is None]; print("KMS tests run:", len(c)); sys.exit(0 if c else 1)'
- name: 'Archive results'
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: kms-localstack-${{ matrix.engine }}
path: ./tests/integration/container/reports
retention-days: 5
kms-real-key:
name: Run KMS Encryption Tests with a real KMS key
if: >-
(github.event_name == 'push' && github.ref == 'refs/heads/main'
&& vars.KMS_KEY_ARN != '' && vars.KMS_REGION != '' && vars.KMS_DECRYPT_ONLY_ROLE_ARN != '' && vars.KMS_IT_ROLE_ARN != '')
|| inputs.lane == 'real-kms'
runs-on: ubuntu-latest
timeout-minutes: 45
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
strategy:
fail-fast: false
matrix:
include:
- { engine: pg, skip: mysql }
- { engine: mysql, skip: pg }
steps:
- name: 'Clone repository'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: 'Set up JDK 8'
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
distribution: 'corretto'
java-version: 8
- name: 'Set up Python 3.12'
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.12'
- name: Install poetry
shell: bash
run: |
pipx install poetry==1.8.2
poetry config virtualenvs.prefer-active-python true
- name: Install dependencies
run: poetry install
- name: 'Configure AWS Credentials'
uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6
with:
role-to-assume: ${{ vars.KMS_IT_ROLE_ARN }}
role-session-name: python_kms_integration_tests
role-duration-seconds: 3600
aws-region: ${{ vars.KMS_REGION }}
- name: 'Run the KMS tests on Docker with a real KMS key'
run: |
test -n "${KMS_KEY_ARN}" || { echo "::error::Set the KMS_KEY_ARN repository variable: CI uses the administrator's key and never makes one."; exit 1; }
DB_PASSWORD="$(openssl rand -hex 16)"
echo "::add-mask::${DB_PASSWORD}"
export DB_PASSWORD DB_USERNAME=test_user DB_DATABASE_NAME=test_db
./gradlew --no-parallel --no-daemon test-kms-encryption-docker-kms \
-Dexclude-${{ matrix.skip }}-engine=true -Dexclude-${{ matrix.skip }}-driver=true
env:
KMS_KEY_ARN: ${{ vars.KMS_KEY_ARN }}
KMS_REGION: ${{ vars.KMS_REGION }}
KMS_DECRYPT_ONLY_ROLE_ARN: ${{ vars.KMS_DECRYPT_ONLY_ROLE_ARN }}
- name: 'Fail when no KMS test ran'
run: |
python3 -c 'import glob,sys,xml.etree.ElementTree as E; c=[t for f in glob.glob("tests/integration/container/reports/*.xml") for t in E.parse(f).iter("testcase") if "kms_encryption" in t.get("classname","") and t.find("skipped") is None]; print("KMS tests run:", len(c)); sys.exit(0 if c else 1)'
- name: 'Archive results'
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: kms-real-key-${{ matrix.engine }}
path: ./tests/integration/container/reports
retention-days: 5
kms-aurora:
name: Run KMS Encryption Tests on Aurora
if: >-
(github.event_name == 'push' && github.ref == 'refs/heads/main' && vars.KMS_KEY_ARN != '' && vars.KMS_REGION != '')
|| inputs.lane == 'aurora'
runs-on: ubuntu-latest
timeout-minutes: 150
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
strategy:
fail-fast: false
matrix:
include:
- { engine: pg, skip: mysql }
- { engine: mysql, skip: pg }
concurrency:
group: kms-aurora-${{ matrix.engine }}
cancel-in-progress: false
env:
# The harness doesn't delete its cluster when a run is cancelled, so the last step deletes this one by name.
RDS_DB_NAME: kms-it-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.engine }}
steps:
- name: 'Clone repository'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: 'Set up JDK 8'
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
distribution: 'corretto'
java-version: 8
- name: 'Set up Python 3.12'
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.12'
- name: Install poetry
shell: bash
run: |
pipx install poetry==1.8.2
poetry config virtualenvs.prefer-active-python true
- name: Install dependencies
run: poetry install
- name: 'Configure AWS Credentials'
uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }}
role-session-name: python_integration_tests
role-duration-seconds: 21600
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: 'Run the KMS tests on Aurora'
run: |
test -n "${KMS_KEY_ARN}" || { echo "::error::Set the KMS_KEY_ARN repository variable: CI uses the administrator's key and never makes one."; exit 1; }
DB_PASSWORD="$(openssl rand -hex 16)"
echo "::add-mask::${DB_PASSWORD}"
export DB_PASSWORD DB_USERNAME=test_user DB_DATABASE_NAME=test_db
./gradlew --no-parallel --no-daemon test-kms-encryption-aurora \
-Dexclude-${{ matrix.skip }}-engine=true -Dexclude-${{ matrix.skip }}-driver=true
env:
NUM_INSTANCES: 2
RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
KMS_KEY_ARN: ${{ vars.KMS_KEY_ARN }}
KMS_REGION: ${{ vars.KMS_REGION }}
- name: 'Fail when no KMS test ran'
run: |
python3 -c 'import glob,sys,xml.etree.ElementTree as E; c=[t for f in glob.glob("tests/integration/container/reports/*.xml") for t in E.parse(f).iter("testcase") if "kms_encryption" in t.get("classname","") and t.find("skipped") is None]; print("KMS tests run:", len(c)); sys.exit(0 if c else 1)'
- name: 'Archive results'
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: kms-aurora-${{ matrix.engine }}
path: ./tests/integration/container/reports
retention-days: 5
# Deletes the cluster named RDS_DB_NAME and its member instances, never clusters matched by a name prefix.
- name: 'Delete the cluster of this run'
if: always()
run: |
instances="$(aws rds describe-db-clusters --db-cluster-identifier "${RDS_DB_NAME}" \
--query 'DBClusters[0].DBClusterMembers[].DBInstanceIdentifier' --output text 2>/dev/null)" || exit 0
for instance in ${instances}; do
aws rds delete-db-instance --db-instance-identifier "${instance}" --skip-final-snapshot > /dev/null || true
done
aws rds delete-db-cluster --db-cluster-identifier "${RDS_DB_NAME}" --skip-final-snapshot > /dev/null || true