Skip to content

Commit

Permalink
retrieving config from identity service
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian-Nara committed Jul 23, 2024
1 parent e4007e0 commit 98be93a
Showing 1 changed file with 7 additions and 37 deletions.
44 changes: 7 additions & 37 deletions scripts/aws/eks/enclave/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,17 @@ echo "Starting vsock proxy..."
echo "Starting syslog-ng..."
/usr/sbin/syslog-ng --verbose

# -- load env vars via proxy
echo "Loading env vars via proxy..."
# -- load config from identity service
echo "Loading config from identity service via proxy..."
IDENTITY_SERVICE_CONFIG=$(curl -s -x socks5h://127.0.0.1:3305 http://127.0.0.1:27016/getConfig)
echo "${IDENTITY_SERVICE_CONFIG}"

TOKEN=$(curl -x socks5h://127.0.0.1:3305 --request PUT "http://169.254.169.254/latest/api/token" --header "X-aws-ec2-metadata-token-ttl-seconds: 3600")
USER_DATA=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/user-data --header "X-aws-ec2-metadata-token: $TOKEN")
if [ "${IDENTITY_SCOPE}" = "UID2" ]; then
UID2_CONFIG_SECRET_KEY=$([[ "$(echo "${USER_DATA}" | grep UID2_CONFIG_SECRET_KEY=)" =~ ^export\ UID2_CONFIG_SECRET_KEY=\"(.*)\"$ ]] && echo "${BASH_REMATCH[1]}" || echo "uid2-operator-config-key")
elif [ "${IDENTITY_SCOPE}" = "EUID" ]; then
UID2_CONFIG_SECRET_KEY=$([[ "$(echo "${USER_DATA}" | grep EUID_CONFIG_SECRET_KEY=)" =~ ^export\ EUID_CONFIG_SECRET_KEY=\"(.*)\"$ ]] && echo "${BASH_REMATCH[1]}" || echo "euid-operator-config-key")
else
echo "Unrecognized IDENTITY_SCOPE ${IDENTITY_SCOPE}"
exit 1
fi
CORE_BASE_URL=$([[ "$(echo "${USER_DATA}" | grep CORE_BASE_URL=)" =~ ^export\ CORE_BASE_URL=\"(.*)\"$ ]] && echo "${BASH_REMATCH[1]}" || echo "")
OPTOUT_BASE_URL=$([[ "$(echo "${USER_DATA}" | grep OPTOUT_BASE_URL=)" =~ ^export\ OPTOUT_BASE_URL=\"(.*)\"$ ]] && echo "${BASH_REMATCH[1]}" || echo "")

echo "UID2_CONFIG_SECRET_KEY=${UID2_CONFIG_SECRET_KEY}"
echo "CORE_BASE_URL=${CORE_BASE_URL}"
echo "OPTOUT_BASE_URL=${OPTOUT_BASE_URL}"

export AWS_REGION_NAME=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/dynamic/instance-identity/document/ --header "X-aws-ec2-metadata-token: $TOKEN" | jq -r ".region")
echo "AWS_REGION_NAME=${AWS_REGION_NAME}"
echo "127.0.0.1 secretsmanager.${AWS_REGION_NAME}.amazonaws.com" >> /etc/hosts

IAM_ROLE=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/meta-data/iam/security-credentials/ --header "X-aws-ec2-metadata-token: $TOKEN")
echo "IAM_ROLE=${IAM_ROLE}"

SECURITY_CREDS=$(curl -s -x socks5h://127.0.0.1:3305 "http://169.254.169.254/latest/meta-data/iam/security-credentials/${IAM_ROLE}" --header "X-aws-ec2-metadata-token: $TOKEN")
export AWS_ACCESS_KEY_ID=$(echo $SECURITY_CREDS | jq -r ".AccessKeyId")
export AWS_SECRET_KEY=$(echo $SECURITY_CREDS | jq -r ".SecretAccessKey")
export AWS_SESSION_TOKEN=$(echo $SECURITY_CREDS | jq -r ".Token")

# -- load configs via proxy
echo "Loading config overrides..."
export OVERRIDES_CONFIG="/app/conf/config-overrides.json"
python3 /app/load_config.py > "${OVERRIDES_CONFIG}"
echo "${IDENTITY_SERVICE_CONFIG}" > "${OVERRIDES_CONFIG}"

export DEPLOYMENT_ENVIRONMENT=$(jq -r ".environment" < "${OVERRIDES_CONFIG}")
export CORE_BASE_URL=$(jq -r ".core_base_url" < "${OVERRIDES_CONFIG}")
export OPTOUT_BASE_URL=$(jq -r ".optout_base_url" < "${OVERRIDES_CONFIG}")
echo "DEPLOYMENT_ENVIRONMENT=${DEPLOYMENT_ENVIRONMENT}"
if [ -z "${DEPLOYMENT_ENVIRONMENT}" ]; then
echo "DEPLOYMENT_ENVIRONMENT cannot be empty"
Expand Down Expand Up @@ -96,9 +69,6 @@ fi

cat "${FINAL_CONFIG}"

HOSTNAME=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/meta-data/local-hostname --header "X-aws-ec2-metadata-token: $TOKEN")
echo "HOSTNAME=${HOSTNAME}"

# -- set pwd to /app so we can find default configs
cd /app

Expand Down

0 comments on commit 98be93a

Please sign in to comment.