Skip to content

Commit 12cacad

Browse files
ci: update CI config to use secret manager integration for credentials (#166)
* ci(java): switch to secret manager from keystore * ci(java): switch to secret manager from keystore, use java-docs-samples user for samples tests * fix: we don't need to supply a service account Source-Author: Jeff Ching <chingor@google.com> Source-Date: Mon Jun 15 11:45:21 2020 -0700 Source-Repo: googleapis/synthtool Source-Sha: d1addcdf80aa9ddef8c932c89c919024bbad7af3 Source-Link: googleapis/synthtool@d1addcd * samples(java): fix bad character in samples.cfg from copy/paste Somehow an invisible character was copy/pasted into the file and Kokoro cannot parse the file. Source-Author: Jeff Ching <chingor@google.com> Source-Date: Mon Jun 15 15:42:10 2020 -0700 Source-Repo: googleapis/synthtool Source-Sha: 6d3eed67a45fd58f9c7bfa173c32e4fd4fed058f Source-Link: googleapis/synthtool@6d3eed6 * ci(java): switch integration test secrets to secret manager Source-Author: Jeff Ching <chingor@google.com> Source-Date: Tue Jun 16 09:26:06 2020 -0700 Source-Repo: googleapis/synthtool Source-Sha: 6eb80fa9f96433af8dbeb1c8323aa80cda49b374 Source-Link: googleapis/synthtool@6eb80fa * ci(java): fix typo in java integration test secret name Source-Author: BenWhitehead <BenWhitehead@users.noreply.github.com> Source-Date: Tue Jun 16 13:32:19 2020 -0400 Source-Repo: googleapis/synthtool Source-Sha: c4f3059c27591eb24d6942a0e357ec94c80459f2 Source-Link: googleapis/synthtool@c4f3059
1 parent f1874f1 commit 12cacad

File tree

8 files changed

+67
-38
lines changed

8 files changed

+67
-38
lines changed

.kokoro/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ retry_with_backoff 3 10 \
3939

4040
# if GOOGLE_APPLICATION_CREDIENTIALS is specified as a relative path prepend Kokoro root directory onto it
4141
if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then
42-
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_ROOT}/src/${GOOGLE_APPLICATION_CREDENTIALS})
42+
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_GFILE_DIR}/${GOOGLE_APPLICATION_CREDENTIALS})
4343
fi
4444

4545
RETURN_CODE=0

.kokoro/nightly/integration.cfg

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ env_vars: {
2828

2929
env_vars: {
3030
key: "GOOGLE_APPLICATION_CREDENTIALS"
31-
value: "keystore/73713_java_it_service_account"
31+
value: "secret_manager/java-it-service-account"
3232
}
3333

34-
before_action {
35-
fetch_keystore {
36-
keystore_resource {
37-
keystore_config_id: 73713
38-
keyname: "java_it_service_account"
39-
}
40-
}
34+
env_vars: {
35+
key: "SECRET_MANAGER_KEYS"
36+
value: "java-it-service-account"
4137
}

.kokoro/nightly/samples.cfg

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,15 @@ env_vars: {
2424

2525
env_vars: {
2626
key: "GOOGLE_APPLICATION_CREDENTIALS"
27-
value: "keystore/73713_java_it_service_account"
27+
value: "secret_manager/java-docs-samples-service-account"
2828
}
2929

3030
env_vars: {
31-
key: "ENABLE_BUILD_COP"
32-
value: "true"
31+
key: "SECRET_MANAGER_KEYS"
32+
value: "java-docs-samples-service-account"
3333
}
3434

35-
before_action {
36-
fetch_keystore {
37-
keystore_resource {
38-
keystore_config_id: 73713
39-
keyname: "java_it_service_account"
40-
}
41-
}
35+
env_vars: {
36+
key: "ENABLE_BUILD_COP"
37+
value: "true"
4238
}

.kokoro/populate-secrets.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# Copyright 2020 Google LLC.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eo pipefail
17+
18+
function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;}
19+
function msg { println "$*" >&2 ;}
20+
function println { printf '%s\n' "$(now) $*" ;}
21+
22+
23+
# Populates requested secrets set in SECRET_MANAGER_KEYS from service account:
24+
# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com
25+
SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
26+
msg "Creating folder on disk for secrets: ${SECRET_LOCATION}"
27+
mkdir -p ${SECRET_LOCATION}
28+
for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g")
29+
do
30+
msg "Retrieving secret ${key}"
31+
docker run --entrypoint=gcloud \
32+
--volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \
33+
gcr.io/google.com/cloudsdktool/cloud-sdk \
34+
secrets versions access latest \
35+
--project cloud-devrel-kokoro-resources \
36+
--secret ${key} > \
37+
"${SECRET_LOCATION}/${key}"
38+
if [[ $? == 0 ]]; then
39+
msg "Secret written to ${SECRET_LOCATION}/${key}"
40+
else
41+
msg "Error retrieving secret ${key}"
42+
fi
43+
done

.kokoro/presubmit/integration.cfg

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ env_vars: {
2424

2525
env_vars: {
2626
key: "GOOGLE_APPLICATION_CREDENTIALS"
27-
value: "keystore/73713_java_it_service_account"
27+
value: "secret_manager/java-it-service-account"
2828
}
2929

30-
before_action {
31-
fetch_keystore {
32-
keystore_resource {
33-
keystore_config_id: 73713
34-
keyname: "java_it_service_account"
35-
}
36-
}
30+
env_vars: {
31+
key: "SECRET_MANAGER_KEYS"
32+
value: "java-it-service-account"
3733
}

.kokoro/presubmit/samples.cfg

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ env_vars: {
2424

2525
env_vars: {
2626
key: "GOOGLE_APPLICATION_CREDENTIALS"
27-
value: "keystore/73713_java_it_service_account"
27+
value: "secret_manager/java-docs-samples-service-account"
2828
}
2929

30-
before_action {
31-
fetch_keystore {
32-
keystore_resource {
33-
keystore_config_id: 73713
34-
keyname: "java_it_service_account"
35-
}
36-
}
37-
}
30+
env_vars: {
31+
key: "SECRET_MANAGER_KEYS"
32+
value: "java-docs-samples-service-account"
33+
}

.kokoro/trampoline.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ function cleanup() {
2121
echo "cleanup";
2222
}
2323
trap cleanup EXIT
24+
25+
$(dirname $0)/populate-secrets.sh # Secret Manager secrets.
2426
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"

synth.metadata

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"git": {
55
"name": ".",
66
"remote": "https://github.com/googleapis/java-datastore.git",
7-
"sha": "39c8d723b318d08ca494b71167eaa80b1df6423d"
7+
"sha": "f1874f1b2745724ccc2345f35b65fb577f53683e"
88
}
99
},
1010
{
@@ -19,7 +19,7 @@
1919
"git": {
2020
"name": "synthtool",
2121
"remote": "https://github.com/googleapis/synthtool.git",
22-
"sha": "987270824bd26f6a8c716d5e2022057b8ae7b26e"
22+
"sha": "c4f3059c27591eb24d6942a0e357ec94c80459f2"
2323
}
2424
}
2525
],

0 commit comments

Comments
 (0)