Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions ci/get_secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,72 @@
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2023 Datadog, Inc.

# Loads secrets for CI jobs from Vault (gitlab-runner path below).
#
# Full mode (default): requires EXTERNAL_ID_NAME, ROLE_TO_ASSUME, and AWS_ACCOUNT.
# Fetches the external ID and DD API key, then assumes the AWS deployer role.
#
# API-key-only mode: set GET_SECRETS_API_KEY_ONLY=1 when sourcing.
# Loads DD_API_KEY only (e.g. unit-test Test Optimization). Uses DD_API_KEY from
# the environment when set; otherwise reads from Vault. Installs the vault CLI
# on slim images that do not include it.

set -e

VAULT_SECRETS_PATH="kv/k8s/gitlab-runner/datadog-lambda-python/secrets"
VAULT_CLI_VERSION="${VAULT_CLI_VERSION:-1.18.5}"

_ensure_vault_cli() {
command -v vault >/dev/null 2>&1 && return

local arch install_dir
case "$(uname -m)" in
x86_64 | amd64) arch=amd64 ;;
aarch64 | arm64) arch=arm64 ;;
*) printf "[Error] Unsupported architecture: %s\n" "$(uname -m)" >&2; exit 1 ;;
esac

install_dir="${TMPDIR:-/tmp}/vault-cli-${VAULT_CLI_VERSION}-${arch}"
if [ -x "${install_dir}/vault" ]; then
export PATH="${install_dir}:${PATH}"
return
fi

apt-get update -qq && apt-get install -y -qq curl unzip
printf "Installing vault CLI %s (%s)...\n" "$VAULT_CLI_VERSION" "$arch"
mkdir -p "$install_dir"
curl -fsSL \
"https://releases.hashicorp.com/vault/${VAULT_CLI_VERSION}/vault_${VAULT_CLI_VERSION}_linux_${arch}.zip" \
-o "${install_dir}/vault.zip"
unzip -qo "${install_dir}/vault.zip" -d "$install_dir"
rm -f "${install_dir}/vault.zip"
export PATH="${install_dir}:${PATH}"
}

_get_dd_api_key() {
if [ -n "${DD_API_KEY:-}" ]; then
printf "Using DD_API_KEY from environment.\n"
else
printf "Getting DD API KEY...\n"
_ensure_vault_cli
DD_API_KEY=$(vault kv get -field=dd-api-key "$VAULT_SECRETS_PATH")
if [ -z "$DD_API_KEY" ]; then
printf "[Error] DD_API_KEY is empty after Vault lookup.\n" >&2
return 1 2>/dev/null || exit 1
fi
export DD_API_KEY
fi

if [ -n "${GITLAB_ENV:-}" ]; then
echo "DD_API_KEY=${DD_API_KEY}" >>"$GITLAB_ENV"
fi
}

if [ -n "${GET_SECRETS_API_KEY_ONLY:-}" ]; then
_get_dd_api_key
return 0 2>/dev/null || exit 0
fi

if [ -z "$EXTERNAL_ID_NAME" ]; then
printf "[Error] No EXTERNAL_ID_NAME found.\n"
printf "Exiting script...\n"
Expand All @@ -19,13 +83,13 @@ if [ -z "$ROLE_TO_ASSUME" ]; then
exit 1
fi

printf "Getting AWS External ID...\n"
_ensure_vault_cli

EXTERNAL_ID=$(vault kv get -field="$EXTERNAL_ID_NAME" kv/k8s/gitlab-runner/datadog-lambda-python/secrets)
printf "Getting AWS External ID...\n"

printf "Getting DD API KEY...\n"
EXTERNAL_ID=$(vault kv get -field="$EXTERNAL_ID_NAME" "$VAULT_SECRETS_PATH")

export DD_API_KEY=$(vault kv get -field=dd-api-key kv/k8s/gitlab-runner/datadog-lambda-python/secrets)
_get_dd_api_key

printf "Assuming role...\n"

Expand Down
9 changes: 8 additions & 1 deletion ci/input_files/build.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,18 @@ unit-test ({{ $runtime.name }}-{{ $runtime.arch }}):
{{ end }}
image: registry.ddbuild.io/images/mirror/python:{{ $runtime.image }}
cache: &{{ $runtime.name }}-{{ $runtime.arch }}-cache
variables:
DD_CIVISIBILITY_AGENTLESS_ENABLED: "true"
DD_SERVICE: "datadog-lambda-python-{{ $runtime.python_version }}-{{ $runtime.arch }}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should runtime and arch be tags?

DD_ENV: "ci"
before_script:
- GET_SECRETS_API_KEY_ONLY=1 source ./ci/get_secrets.sh
- PYTHON_VERSION={{ $runtime.python_version }} ARCH={{ $runtime.arch }} ./scripts/setup_python_env.sh
script:
- set -e
- GET_SECRETS_API_KEY_ONLY=1 source ./ci/get_secrets.sh
- source venv/bin/activate
- pytest -vv
- pytest -vv --ddtrace
retry: 2

integration-test ({{ $runtime.name }}-{{ $runtime.arch }}):
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/snapshots/logs/async-metrics_python310.log
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -160,6 +161,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down Expand Up @@ -267,6 +269,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -295,6 +298,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down Expand Up @@ -483,6 +487,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -512,6 +517,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down Expand Up @@ -651,6 +657,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -680,6 +687,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down Expand Up @@ -834,6 +842,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -863,6 +872,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down Expand Up @@ -1010,6 +1020,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -1039,6 +1050,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down Expand Up @@ -1195,6 +1207,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -1224,6 +1237,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down Expand Up @@ -1369,6 +1383,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -1398,6 +1413,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down Expand Up @@ -1542,6 +1558,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -1571,6 +1588,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down Expand Up @@ -1723,6 +1741,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "datadoghq.com",
Expand Down Expand Up @@ -1752,6 +1771,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"component": "requests",
"http.method": "GET",
"http.status_code": "200",
"http.status_msg": "OK",
"http.url": "https://www.datadoghq.com/",
"http.useragent": "python-requests/X.X.X",
"out.host": "www.datadoghq.com",
Expand Down
Loading
Loading