Skip to content

Commit 47b4432

Browse files
authored
buildkite: use GCP OIDC (elastic#13856)
1 parent 1bfe66c commit 47b4432

File tree

5 files changed

+18
-55
lines changed

5 files changed

+18
-55
lines changed

.buildkite/hooks/pre-command

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ export TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX"
3131
REPO_BUILD_TAG="${REPO_NAME}/$(buildkite_pr_branch_build_id)"
3232
export REPO_BUILD_TAG
3333

34-
PRIVATE_CI_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/gcp-platform-ingest-ci-service-account
35-
3634
BUILDKITE_API_TOKEN_PATH=kv/ci-shared/platform-ingest/buildkite_token
3735

3836
EC_TOKEN_PATH=kv/ci-shared/platform-ingest/platform-ingest-ec-qa
@@ -42,6 +40,8 @@ EC_DATA_PATH=secret/ci/elastic-integrations/ec_data
4240
export ENVIRONMENT="ci"
4341
export REPO="${REPO_NAME}"
4442

43+
export JOB_GCS_BUCKET_INTERNAL="ecosystem-ci-internal"
44+
4545
branch_name_label() {
4646
local branch="$1"
4747

@@ -106,23 +106,13 @@ if [[ "${BUILDKITE_PIPELINE_SLUG}" =~ ^(integrations|integrations-test-stack)$ ]
106106
fi
107107

108108
if [[ "${BUILDKITE_STEP_KEY}" =~ ^test-integrations- ]]; then
109-
PRIVATE_CI_GCS_CREDENTIALS_SECRET=$(retry 5 vault kv get -field plaintext -format=json "${PRIVATE_CI_GCS_CREDENTIALS_PATH}")
110-
export PRIVATE_CI_GCS_CREDENTIALS_SECRET
111-
export JOB_GCS_BUCKET_INTERNAL="ingest-buildkite-ci"
112-
113109
BUILDKITE_API_TOKEN=$(retry 5 vault kv get -field buildkite_token "${BUILDKITE_API_TOKEN_PATH}")
114110
export BUILDKITE_API_TOKEN
115111
fi
116112
fi
117113

118114
if [[ "${BUILDKITE_PIPELINE_SLUG}" == "integrations-serverless" ]]; then
119115
if [[ "${BUILDKITE_STEP_KEY}" == "test-integrations-serverless-project" ]]; then
120-
# Currently, system tests are not run when testing with an Elastic Serverless project, so it is not required to
121-
# add the AWS credentials as in the integrations pipeline.
122-
123-
PRIVATE_CI_GCS_CREDENTIALS_SECRET=$(retry 5 vault kv get -field plaintext -format=json "${PRIVATE_CI_GCS_CREDENTIALS_PATH}")
124-
export PRIVATE_CI_GCS_CREDENTIALS_SECRET
125-
export JOB_GCS_BUCKET_INTERNAL="ingest-buildkite-ci"
126116

127117
BUILDKITE_API_TOKEN=$(retry 5 vault kv get -field buildkite_token "${BUILDKITE_API_TOKEN_PATH}")
128118
export BUILDKITE_API_TOKEN

.buildkite/hooks/pre-exit

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ set -euo pipefail
77
if [[ "$BUILDKITE_PIPELINE_SLUG" =~ ^(integrations|integrations-test-stack)$ ]]; then
88
# FIXME: update condition depending on the pipeline steps triggered
99
if [[ "$BUILDKITE_STEP_KEY" =~ ^test-integrations- ]]; then
10-
unset ELASTIC_PACKAGE_AWS_ACCESS_KEY
11-
unset ELASTIC_PACKAGE_AWS_SECRET_KEY
12-
unset AWS_ACCESS_KEY_ID
13-
unset AWS_SECRET_ACCESS_KEY
1410

1511
# Ensure that kind cluster is deleted
1612
delete_kind_cluster
@@ -25,10 +21,6 @@ fi
2521

2622
if [[ "$BUILDKITE_PIPELINE_SLUG" == "integrations-serverless" ]]; then
2723
if [[ "$BUILDKITE_STEP_KEY" == "test-integrations-serverless-project" ]]; then
28-
unset ELASTIC_PACKAGE_AWS_ACCESS_KEY
29-
unset ELASTIC_PACKAGE_AWS_SECRET_KEY
30-
unset AWS_ACCESS_KEY_ID
31-
unset AWS_SECRET_ACCESS_KEY
3224

3325
# Ensure that kind cluster is deleted
3426
delete_kind_cluster
@@ -44,8 +36,6 @@ fi
4436
unset_secrets
4537
cleanup
4638

47-
google_cloud_logout_active_account
48-
4939
if [[ "$BUILDKITE_PIPELINE_SLUG" == "integrations-backport" && "$BUILDKITE_STEP_KEY" == "create-backport-branch" ]]; then
5040
cd "${WORKSPACE}"
5141
git config remote.origin.url "https://github.com/elastic/integrations.git"

.buildkite/pipeline.serverless.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ steps:
7272
# This plugin creates the environment variables required by the service deployer (AWS_SECRET_ACCESS_KEY and AWS_SECRET_KEY_ID)
7373
- elastic/oblt-aws-auth#v0.1.0:
7474
duration: 10800 # seconds
75+
# See https://github.com/elastic/oblt-infra/blob/main/conf/resources/repos/integrations/01-gcp-buildkite-oidc.tf
76+
# This plugin authenticates to Google Cloud using the OIDC token.
77+
- elastic/oblt-google-auth#v1.3.0:
78+
lifetime: 10800 # seconds
79+
project-id: "elastic-observability-ci"
80+
project-number: "911195782929"
7581
artifact_paths:
7682
- "build/test-results/*.xml"
7783
- "build/elastic-stack-dump/*/logs/*.log"

.buildkite/scripts/common.sh

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ platform_type_lowercase="${platform_type,,}"
1010

1111
SCRIPTS_BUILDKITE_PATH="${WORKSPACE}/.buildkite/scripts"
1212

13-
GOOGLE_CREDENTIALS_FILENAME="google-cloud-credentials.json"
1413
export ELASTIC_PACKAGE_BIN=${WORKSPACE}/build/elastic-package
1514

1615
API_BUILDKITE_PIPELINES_URL="https://api.buildkite.com/v2/organizations/elastic/pipelines/"
@@ -255,34 +254,6 @@ with_github_cli() {
255254
gh version
256255
}
257256

258-
## Logging and logout from Google Cloud
259-
google_cloud_auth_safe_logs() {
260-
local gsUtilLocation
261-
gsUtilLocation=$(mktemp -d -p "${WORKSPACE}" -t "${TMP_FOLDER_TEMPLATE}")
262-
local secretFileLocation=${gsUtilLocation}/${GOOGLE_CREDENTIALS_FILENAME}
263-
264-
echo "${PRIVATE_CI_GCS_CREDENTIALS_SECRET}" > "${secretFileLocation}"
265-
266-
gcloud auth activate-service-account --key-file "${secretFileLocation}" 2> /dev/null
267-
export GOOGLE_APPLICATION_CREDENTIALS=${secretFileLocation}
268-
}
269-
270-
google_cloud_logout_active_account() {
271-
local active_account
272-
active_account=$(gcloud auth list --filter=status:ACTIVE --format="value(account)" 2>/dev/null || true)
273-
if [[ -n "$active_account" && -n "${GOOGLE_APPLICATION_CREDENTIALS+x}" ]]; then
274-
echo "Logging out from GCP for active account"
275-
gcloud auth revoke "$active_account" > /dev/null 2>&1
276-
else
277-
echo "No active GCP accounts found."
278-
fi
279-
280-
if [ -n "${GOOGLE_APPLICATION_CREDENTIALS+x}" ]; then
281-
rm -rf "${GOOGLE_APPLICATION_CREDENTIALS}"
282-
unset GOOGLE_APPLICATION_CREDENTIALS
283-
fi
284-
}
285-
286257
## Helpers for integrations pipelines
287258
check_git_diff() {
288259
cd "${WORKSPACE}"
@@ -983,16 +954,16 @@ upload_safe_logs() {
983954
local source="$2"
984955
local target="$3"
985956

957+
echo "--- Uploading safe logs to GCP bucket ${bucket}"
958+
986959
if ! ls ${source} 2>&1 > /dev/null ; then
987960
echo "upload_safe_logs: artifacts files not found, nothing will be archived"
988961
return
989962
fi
990963

991-
google_cloud_auth_safe_logs
992-
993-
gsutil cp ${source} "gs://${bucket}/buildkite/${REPO_BUILD_TAG}/${target}"
964+
gcloud storage cp ${source} "gs://${bucket}/buildkite/${REPO_BUILD_TAG}/${target}"
994965

995-
google_cloud_logout_active_account
966+
echo "GCP logout is not required, the BK plugin will do it for us"
996967
}
997968

998969
clean_safe_logs() {

.buildkite/scripts/trigger_integrations_in_parallel.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ for package in ${PACKAGE_LIST}; do
9393
# This plugin creates the environment variables required by the service deployer (AWS_SECRET_ACCESS_KEY and AWS_SECRET_KEY_ID)
9494
- elastic/oblt-aws-auth#v0.1.0:
9595
duration: 10800 # seconds
96+
# See https://github.com/elastic/oblt-infra/blob/main/conf/resources/repos/integrations/01-gcp-buildkite-oidc.tf
97+
# This plugin authenticates to Google Cloud using the OIDC token.
98+
- elastic/oblt-google-auth#v1.3.0:
99+
lifetime: 10800 # seconds
100+
project-id: "elastic-observability-ci"
101+
project-number: "911195782929"
96102
artifact_paths:
97103
- build/test-results/*.xml
98104
- build/test-coverage/*.xml

0 commit comments

Comments
 (0)