Skip to content

Commit 41027f4

Browse files
jnodorp-jaconidekobon
authored andcommitted
Fix startup when using IAM roles for service accounts
Closes #70
1 parent 535d6a2 commit 41027f4

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

common/docker-entrypoint.d/00-check-for-required-env.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,34 @@ failed=0
2525
required=("S3_BUCKET_NAME" "S3_SERVER" "S3_SERVER_PORT" "S3_SERVER_PROTO"
2626
"S3_REGION" "S3_STYLE" "ALLOW_DIRECTORY_LIST" "AWS_SIGS_VERSION")
2727

28-
if [ ! -z ${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI+x} ]; then
28+
# Require some form of authentication to be configured.
29+
30+
# a) Using container credentials. This is indicated by AWS_CONTAINER_CREDENTIALS_RELATIVE_URI being set.
31+
# See https://docs.aws.amazon.com/sdkref/latest/guide/feature-container-credentials.html
32+
# Example: We are running inside an ECS task.
33+
if [[ -v AWS_CONTAINER_CREDENTIALS_RELATIVE_URI ]]; then
2934
echo "Running inside an ECS task, using container credentials"
35+
36+
# b) Using Instance Metadata Service (IMDS) credentials, if IMDS is present at http://169.254.169.254.
37+
# See https://docs.aws.amazon.com/sdkref/latest/guide/feature-imds-credentials.html.
38+
# Example: We are running inside an EC2 instance.
3039
elif curl --output /dev/null --silent --head --fail --connect-timeout 2 "http://169.254.169.254"; then
3140
echo "Running inside an EC2 instance, using IMDS for credentials"
41+
42+
# c) Using assume role credentials. This is indicated by AWS_WEB_IDENTITY_TOKEN_FILE being set.
43+
# See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html.
44+
# Example: We are running inside an EKS cluster with IAM roles for service accounts enabled.
45+
elif [[ -v AWS_WEB_IDENTITY_TOKEN_FILE ]]; then
46+
echo "Running inside EKS with IAM roles for service accounts"
47+
48+
# If none of the options above is used, require static credentials.
49+
# See https://docs.aws.amazon.com/sdkref/latest/guide/feature-static-credentials.html.
3250
else
3351
required+=("S3_ACCESS_KEY_ID" "S3_SECRET_KEY")
3452
fi
3553

3654
for name in ${required[@]}; do
37-
if [ -z ${!name+x} ]; then
55+
if [[ ! -v name ]]; then
3856
>&2 echo "Required ${name} environment variable missing"
3957
failed=1
4058
fi

0 commit comments

Comments
 (0)