- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathset-temp-fle-aws-creds.sh
58 lines (49 loc) · 2.11 KB
/
set-temp-fle-aws-creds.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
# Obtains temporary AWS credentials for CSFLE testing.
#
# Run with a . to add environment variables to the current shell:
# . ./set-temp-fle-aws-creds.sh
#
# Requires the python AWS SDK boto3. This can be installed with: pip install boto3
# The path to python in a virtual environment may be passed with the PYTHON
# environment variable.
#
# Environment variables used as input:
# FLE_AWS_KEY Set to access for global FLE_AWS_KEY
# FLE_AWS_SECRET Set to access for global FLE_AWS_SECRET
# FLE_AWS_DEFAULT_REGION Set default AWS region for FLE_AWS_KEY
#
# Environment variables produced as output:
# FLE_AWS_TEMP_ACCESS_KEY_ID Temporary AWS_ACCESS_KEY_ID
# FLE_AWS_TEMP_SECRET_ACCESS_KEY Temporary AWS_SECRET_ACCESS_KEY
# FLE_AWS_TEMP_SESSION_TOKEN Temporary AWS_SESSION_TOKEN
set +o xtrace # Disable tracing.
if [ -f"$DRIVERS_TOOLS/.evergreen/csfle/secrets-export.sh" ];then
source$DRIVERS_TOOLS/.evergreen/csfle/secrets-export.sh
else
echo"$DRIVERS_TOOLS/.evergreen/csfle/secrets-export.sh does not exists."
exit 2
fi
#boto3 expects env variables in a bit different form than we use
export AWS_ACCESS_KEY_ID=$FLE_AWS_KEY
export AWS_SECRET_ACCESS_KEY=$FLE_AWS_SECRET
export AWS_DEFAULT_REGION=$FLE_AWS_DEFAULT_REGION
echo"Triggering temporary CSFLE credentials"
get_creds() {
$PYTHON - "$@"<< 'EOF'
import sys
import boto3
client = boto3.client("sts")
credentials = client.get_session_token()["Credentials"]
sys.stdout.write(credentials["AccessKeyId"] + " " + credentials["SecretAccessKey"] + " " + credentials["SessionToken"])
EOF
}
PYTHON=${PYTHON:-python}
$PYTHON -m pip install boto3
CREDS=$(get_creds)
export FLE_AWS_TEMP_ACCESS_KEY_ID=$(echo $CREDS| awk '{print $1}')
export FLE_AWS_TEMP_SECRET_ACCESS_KEY=$(echo $CREDS| awk '{print $2}')
export FLE_AWS_TEMP_SESSION_TOKEN=$(echo $CREDS| awk '{print $3}')
#enable related tests in the driver
export FLE_AWS_TEMPORARY_CREDS_ENABLED=true
echo"CSFLE credentials have been exported"