Skip to content

Commit 9813864

Browse files
authored
Merge branch 'main' into onboarding-card-design
2 parents 682fb91 + f136782 commit 9813864

File tree

970 files changed

+9296
-2575
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

970 files changed

+9296
-2575
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
source "$(dirname "${BASH_SOURCE[0]}")/vault_fns.sh"
6+
7+
BUCKET_OR_EMAIL="${1:-}"
8+
GCLOUD_EMAIL_POSTFIX="elastic-kibana-ci.iam.gserviceaccount.com"
9+
GCLOUD_SA_PROXY_EMAIL="kibana-ci-sa-proxy@$GCLOUD_EMAIL_POSTFIX"
10+
11+
if [[ -z "$BUCKET_OR_EMAIL" ]]; then
12+
echo "Usage: $0 <bucket_name|email>"
13+
exit 1
14+
elif [[ "$BUCKET_OR_EMAIL" == "--unset-impersonation" ]]; then
15+
echo "Unsetting impersonation"
16+
gcloud config unset auth/impersonate_service_account
17+
exit 0
18+
elif [[ "$BUCKET_OR_EMAIL" == "--logout-gcloud" ]]; then
19+
echo "Logging out of gcloud"
20+
if [[ -x "$(command -v gcloud)" ]] && [[ "$(gcloud auth list 2>/dev/null | grep $GCLOUD_SA_PROXY_EMAIL)" != "" ]]; then
21+
gcloud auth revoke $GCLOUD_SA_PROXY_EMAIL --no-user-output-enabled
22+
fi
23+
exit 0
24+
fi
25+
26+
CURRENT_GCLOUD_USER=$(gcloud auth list --filter="status=ACTIVE" --format="value(account)")
27+
28+
# Verify that the service account proxy is activated
29+
if [[ "$CURRENT_GCLOUD_USER" != "$GCLOUD_SA_PROXY_EMAIL" ]]; then
30+
if [[ -x "$(command -v gcloud)" ]]; then
31+
if [[ -z "${KIBANA_SERVICE_ACCOUNT_PROXY_KEY:-}" ]]; then
32+
echo "KIBANA_SERVICE_ACCOUNT_PROXY_KEY is not set, cannot activate service account $GCLOUD_SA_PROXY_EMAIL."
33+
exit 1
34+
fi
35+
36+
AUTH_RESULT=$(gcloud auth activate-service-account --key-file="$KIBANA_SERVICE_ACCOUNT_PROXY_KEY" || "FAILURE")
37+
if [[ "$AUTH_RESULT" == "FAILURE" ]]; then
38+
echo "Failed to activate service account $GCLOUD_SA_PROXY_EMAIL."
39+
exit 1
40+
else
41+
echo "Activated service account $GCLOUD_SA_PROXY_EMAIL"
42+
fi
43+
else
44+
echo "gcloud is not installed, cannot activate service account $GCLOUD_SA_PROXY_EMAIL."
45+
exit 1
46+
fi
47+
fi
48+
49+
# Check if the arg is a service account e-mail or a bucket name
50+
EMAIL=""
51+
if [[ "$BUCKET_OR_EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
52+
EMAIL="$BUCKET_OR_EMAIL"
53+
elif [[ "$BUCKET_OR_EMAIL" =~ ^gs://* ]]; then
54+
BUCKET_NAME="${BUCKET_OR_EMAIL:5}"
55+
else
56+
BUCKET_NAME="$BUCKET_OR_EMAIL"
57+
fi
58+
59+
if [[ -z "$EMAIL" ]]; then
60+
case "$BUCKET_NAME" in
61+
"elastic-kibana-coverage-live")
62+
EMAIL="kibana-ci-access-coverage@$GCLOUD_EMAIL_POSTFIX"
63+
;;
64+
"kibana-ci-es-snapshots-daily")
65+
EMAIL="kibana-ci-access-es-snapshots@$GCLOUD_EMAIL_POSTFIX"
66+
;;
67+
"kibana-so-types-snapshots")
68+
EMAIL="kibana-ci-access-so-snapshots@$GCLOUD_EMAIL_POSTFIX"
69+
;;
70+
"kibana-performance")
71+
EMAIL="kibana-ci-access-perf-stats@$GCLOUD_EMAIL_POSTFIX"
72+
;;
73+
"ci-artifacts.kibana.dev")
74+
EMAIL="kibana-ci-access-artifacts@$GCLOUD_EMAIL_POSTFIX"
75+
;;
76+
*)
77+
EMAIL="$BUCKET_NAME@$GCLOUD_EMAIL_POSTFIX"
78+
;;
79+
esac
80+
fi
81+
82+
# Activate the service account
83+
echo "Impersonating $EMAIL"
84+
gcloud config set auth/impersonate_service_account "$EMAIL"
85+
echo "Activated service account $EMAIL"

.buildkite/scripts/common/setup_bazel.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
source .buildkite/scripts/common/util.sh
44

5+
echo '--- Setting up bazel'
6+
57
echo "[bazel] writing .bazelrc"
68
cat <<EOF > $KIBANA_DIR/.bazelrc
79
# Generated by .buildkite/scripts/common/setup_bazel.sh
@@ -27,16 +29,16 @@ if [[ "$BAZEL_CACHE_MODE" == "gcs" ]]; then
2729

2830
echo "[bazel] using GCS bucket: $BAZEL_BUCKET"
2931

30-
cat <<EOF >> $KIBANA_DIR/.bazelrc
32+
cat <<EOF >> $KIBANA_DIR/.bazelrc
3133
build --remote_cache=https://storage.googleapis.com/$BAZEL_BUCKET
32-
build --google_default_credentials
34+
build --google_credentials=$BAZEL_REMOTE_CACHE_CREDENTIALS_FILE
3335
EOF
3436
fi
3537

3638
if [[ "$BAZEL_CACHE_MODE" == "populate-local-gcs" ]]; then
3739
echo "[bazel] enabling caching with GCS buckets for local dev"
3840

39-
cat <<EOF >> $KIBANA_DIR/.bazelrc
41+
cat <<EOF >> $KIBANA_DIR/.bazelrc
4042
build --remote_cache=https://storage.googleapis.com/kibana-local-bazel-remote-cache
4143
build --google_credentials=$BAZEL_LOCAL_DEV_CACHE_CREDENTIALS_FILE
4244
EOF

.buildkite/scripts/common/util.sh

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
source "$(dirname "${BASH_SOURCE[0]}")/vault_fns.sh"
4+
35
is_pr() {
46
[[ "${GITHUB_PR_NUMBER-}" ]] && return
57
false
@@ -170,48 +172,3 @@ npm_install_global() {
170172
download_artifact() {
171173
retry 3 1 timeout 3m buildkite-agent artifact download "$@"
172174
}
173-
174-
# TODO: remove after https://github.com/elastic/kibana-operations/issues/15 is done
175-
if [[ "${VAULT_ADDR:-}" == *"secrets.elastic.co"* ]]; then
176-
VAULT_PATH_PREFIX="secret/kibana-issues/dev"
177-
VAULT_KV_PREFIX="secret/kibana-issues/dev"
178-
IS_LEGACY_VAULT_ADDR=true
179-
else
180-
VAULT_PATH_PREFIX="secret/ci/elastic-kibana"
181-
VAULT_KV_PREFIX="kv/ci-shared/kibana-deployments"
182-
IS_LEGACY_VAULT_ADDR=false
183-
fi
184-
export IS_LEGACY_VAULT_ADDR
185-
186-
vault_get() {
187-
key_path=$1
188-
field=$2
189-
190-
fullPath="$VAULT_PATH_PREFIX/$key_path"
191-
192-
if [[ -z "${2:-}" || "${2:-}" =~ ^-.* ]]; then
193-
retry 5 5 vault read "$fullPath" "${@:2}"
194-
else
195-
retry 5 5 vault read -field="$field" "$fullPath" "${@:3}"
196-
fi
197-
}
198-
199-
vault_set() {
200-
key_path=$1
201-
shift
202-
fields=("$@")
203-
204-
205-
fullPath="$VAULT_PATH_PREFIX/$key_path"
206-
207-
# shellcheck disable=SC2068
208-
retry 5 5 vault write "$fullPath" ${fields[@]}
209-
}
210-
211-
vault_kv_set() {
212-
kv_path=$1
213-
shift
214-
fields=("$@")
215-
216-
vault kv put "$VAULT_KV_PREFIX/$kv_path" "${fields[@]}"
217-
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
# TODO: remove after https://github.com/elastic/kibana-operations/issues/15 is done
4+
if [[ "${VAULT_ADDR:-}" == *"secrets.elastic.co"* ]]; then
5+
VAULT_PATH_PREFIX="secret/kibana-issues/dev"
6+
VAULT_KV_PREFIX="secret/kibana-issues/dev"
7+
IS_LEGACY_VAULT_ADDR=true
8+
else
9+
VAULT_PATH_PREFIX="secret/ci/elastic-kibana"
10+
VAULT_KV_PREFIX="kv/ci-shared/kibana-deployments"
11+
IS_LEGACY_VAULT_ADDR=false
12+
fi
13+
export IS_LEGACY_VAULT_ADDR
14+
15+
retry() {
16+
local retries=$1; shift
17+
local delay=$1; shift
18+
local attempts=1
19+
20+
until "$@"; do
21+
retry_exit_status=$?
22+
echo "Exited with $retry_exit_status" >&2
23+
if (( retries == "0" )); then
24+
return $retry_exit_status
25+
elif (( attempts == retries )); then
26+
echo "Failed $attempts retries" >&2
27+
return $retry_exit_status
28+
else
29+
echo "Retrying $((retries - attempts)) more times..." >&2
30+
attempts=$((attempts + 1))
31+
sleep "$delay"
32+
fi
33+
done
34+
}
35+
36+
vault_get() {
37+
key_path=${1:-}
38+
field=${2:-}
39+
40+
fullPath="$VAULT_PATH_PREFIX/$key_path"
41+
42+
if [[ -z "$field" || "$field" =~ ^-.* ]]; then
43+
retry 5 5 vault read "$fullPath" "${@:2}"
44+
else
45+
retry 5 5 vault read -field="$field" "$fullPath" "${@:3}"
46+
fi
47+
}
48+
49+
vault_set() {
50+
key_path=$1
51+
shift
52+
fields=("$@")
53+
54+
55+
fullPath="$VAULT_PATH_PREFIX/$key_path"
56+
57+
# shellcheck disable=SC2068
58+
retry 5 5 vault write "$fullPath" ${fields[@]}
59+
}
60+
61+
vault_kv_set() {
62+
kv_path=$1
63+
shift
64+
fields=("$@")
65+
66+
vault kv put "$VAULT_KV_PREFIX/$kv_path" "${fields[@]}"
67+
}

.buildkite/scripts/lifecycle/post_command.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
set -euo pipefail
44

5+
echo '--- Log out of gcloud'
6+
./.buildkite/scripts/common/activate_service_account.sh --unset-impersonation || echo "Failed to unset impersonation"
7+
./.buildkite/scripts/common/activate_service_account.sh --logout-gcloud || echo "Failed to log out of gcloud"
8+
59
echo '--- Agent Debug Info'
610
ts-node .buildkite/scripts/lifecycle/print_agent_links.ts || true
711

.buildkite/scripts/lifecycle/pre_command.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ BAZEL_LOCAL_DEV_CACHE_CREDENTIALS_FILE="$HOME/.kibana-ci-bazel-remote-cache-loca
167167
export BAZEL_LOCAL_DEV_CACHE_CREDENTIALS_FILE
168168
vault_get kibana-ci-bazel-remote-cache-local-dev service_account_json > "$BAZEL_LOCAL_DEV_CACHE_CREDENTIALS_FILE"
169169

170+
# Export key for accessing bazel remote cache's GCS bucket
171+
BAZEL_REMOTE_CACHE_CREDENTIALS_FILE="$HOME/.kibana-ci-bazel-remote-cache-gcs.json"
172+
export BAZEL_REMOTE_CACHE_CREDENTIALS_FILE
173+
vault_get kibana-ci-bazel-remote-cache-sa-key key | base64 -d > "$BAZEL_REMOTE_CACHE_CREDENTIALS_FILE"
174+
175+
# Setup GCS Service Account Proxy for CI
176+
KIBANA_SERVICE_ACCOUNT_PROXY_KEY="$(mktemp -d)/kibana-gcloud-service-account.json"
177+
export KIBANA_SERVICE_ACCOUNT_PROXY_KEY
178+
vault_get kibana-ci-sa-proxy-key key | base64 -d > "$KIBANA_SERVICE_ACCOUNT_PROXY_KEY"
179+
170180
PIPELINE_PRE_COMMAND=${PIPELINE_PRE_COMMAND:-".buildkite/scripts/lifecycle/pipelines/$BUILDKITE_PIPELINE_SLUG/pre_command.sh"}
171181
if [[ -f "$PIPELINE_PRE_COMMAND" ]]; then
172182
source "$PIPELINE_PRE_COMMAND"

.buildkite/scripts/steps/archive_so_migration_snapshot.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ set -euo pipefail
33

44
.buildkite/scripts/bootstrap.sh
55

6-
SO_MIGRATIONS_SNAPSHOT_FOLDER=kibana-so-types-snapshots
6+
SO_MIGRATIONS_SNAPSHOT_BUCKET="gs://kibana-so-types-snapshots"
77
SNAPSHOT_FILE_PATH="${1:-target/plugin_so_types_snapshot.json}"
88

99
echo "--- Creating snapshot of Saved Object migration info"
1010
node scripts/snapshot_plugin_types snapshot --outputPath "$SNAPSHOT_FILE_PATH"
1111

1212
echo "--- Uploading as ${BUILDKITE_COMMIT}.json"
13-
SNAPSHOT_PATH="${SO_MIGRATIONS_SNAPSHOT_FOLDER}/${BUILDKITE_COMMIT}.json"
14-
gsutil cp "$SNAPSHOT_FILE_PATH" "gs://$SNAPSHOT_PATH"
13+
SNAPSHOT_PATH="${SO_MIGRATIONS_SNAPSHOT_BUCKET}/${BUILDKITE_COMMIT}.json"
14+
.buildkite/scripts/common/activate_service_account.sh "$SO_MIGRATIONS_SNAPSHOT_BUCKET"
15+
gsutil cp "$SNAPSHOT_FILE_PATH" "$SNAPSHOT_PATH"
1516

1617
buildkite-agent annotate --context so_migration_snapshot --style success \
1718
'Saved Object type snapshot is available at <a href="https://storage.cloud.google.com/'"$SNAPSHOT_PATH"'">'"$SNAPSHOT_PATH"'</a>'

.buildkite/scripts/steps/code_coverage/reporting/downloadPrevSha.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set -euo pipefail
66
gsutil -m cp -r gs://elastic-bekitzur-kibana-coverage-live/previous_pointer/previous.txt . || echo "### Previous Pointer NOT FOUND?"
77

88
# TODO: Activate after the above is removed
9+
#.buildkite/scripts/common/activate_service_account.sh gs://elastic-kibana-coverage-live
910
#gsutil -m cp -r gs://elastic-kibana-coverage-live/previous_pointer/previous.txt . || echo "### Previous Pointer NOT FOUND?"
1011

1112
if [ -e ./previous.txt ]; then

.buildkite/scripts/steps/code_coverage/reporting/uploadPrevSha.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ collectPrevious
1212
# TODO: Safe to remove this after 2024-03-01 (https://github.com/elastic/kibana/issues/175904)
1313
gsutil cp previous.txt gs://elastic-bekitzur-kibana-coverage-live/previous_pointer/
1414

15+
.buildkite/scripts/common/activate_service_account.sh gs://elastic-kibana-coverage-live
1516
gsutil cp previous.txt gs://elastic-kibana-coverage-live/previous_pointer/

.buildkite/scripts/steps/code_coverage/reporting/uploadStaticSite.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ uploadRest() {
2727

2828
echo "--- Uploading static site"
2929

30+
.buildkite/scripts/common/activate_service_account.sh gs://elastic-kibana-coverage-live
3031
uploadBase
3132
uploadRest

0 commit comments

Comments
 (0)