Skip to content

Commit 3d9dacd

Browse files
mergify[bot]v1v
andauthored
buildkite: use GCP OIDC (#13856) (#13912)
(cherry picked from commit 47b4432) Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
1 parent c78b69b commit 3d9dacd

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
@@ -29,8 +29,6 @@ export TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX"
2929
REPO_BUILD_TAG="${REPO_NAME}/$(buildkite_pr_branch_build_id)"
3030
export REPO_BUILD_TAG
3131

32-
PRIVATE_CI_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/gcp-platform-ingest-ci-service-account
33-
3432
BUILDKITE_API_TOKEN_PATH=kv/ci-shared/platform-ingest/buildkite_token
3533

3634
EC_TOKEN_PATH=kv/ci-shared/platform-ingest/platform-ingest-ec-qa
@@ -40,6 +38,8 @@ EC_DATA_PATH=secret/ci/elastic-integrations/ec_data
4038
export ENVIRONMENT="ci"
4139
export REPO="${REPO_NAME}"
4240

41+
export JOB_GCS_BUCKET_INTERNAL="ecosystem-ci-internal"
42+
4343
branch_name_label() {
4444
local branch="$1"
4545

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

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

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

125115
BUILDKITE_API_TOKEN=$(retry 5 vault kv get -field buildkite_token "${BUILDKITE_API_TOKEN_PATH}")
126116
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/"
@@ -253,34 +252,6 @@ with_github_cli() {
253252
gh version
254253
}
255254

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

892+
echo "--- Uploading safe logs to GCP bucket ${bucket}"
893+
921894
if ! ls ${source} 2>&1 > /dev/null ; then
922895
echo "upload_safe_logs: artifacts files not found, nothing will be archived"
923896
return
924897
fi
925898

926-
google_cloud_auth_safe_logs
927-
928-
gsutil cp ${source} "gs://${bucket}/buildkite/${REPO_BUILD_TAG}/${target}"
899+
gcloud storage cp ${source} "gs://${bucket}/buildkite/${REPO_BUILD_TAG}/${target}"
929900

930-
google_cloud_logout_active_account
901+
echo "GCP logout is not required, the BK plugin will do it for us"
931902
}
932903

933904
clean_safe_logs() {

.buildkite/scripts/trigger_integrations_in_parallel.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ for package in ${PACKAGE_LIST}; do
7474
# This plugin creates the environment variables required by the service deployer (AWS_SECRET_ACCESS_KEY and AWS_SECRET_KEY_ID)
7575
- elastic/oblt-aws-auth#v0.1.0:
7676
duration: 10800 # seconds
77+
# See https://github.com/elastic/oblt-infra/blob/main/conf/resources/repos/integrations/01-gcp-buildkite-oidc.tf
78+
# This plugin authenticates to Google Cloud using the OIDC token.
79+
- elastic/oblt-google-auth#v1.3.0:
80+
lifetime: 10800 # seconds
81+
project-id: "elastic-observability-ci"
82+
project-number: "911195782929"
7783
artifact_paths:
7884
- build/test-results/*.xml
7985
- build/test-coverage/*.xml

0 commit comments

Comments
 (0)