@@ -25,16 +25,34 @@ failed=0
25
25
required=(" S3_BUCKET_NAME" " S3_SERVER" " S3_SERVER_PORT" " S3_SERVER_PROTO"
26
26
" S3_REGION" " S3_STYLE" " ALLOW_DIRECTORY_LIST" " AWS_SIGS_VERSION" )
27
27
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
29
34
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.
30
39
elif curl --output /dev/null --silent --head --fail --connect-timeout 2 " http://169.254.169.254" ; then
31
40
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.
32
50
else
33
51
required+=(" S3_ACCESS_KEY_ID" " S3_SECRET_KEY" )
34
52
fi
35
53
36
54
for name in ${required[@]} ; do
37
- if [ -z ${ ! name+x} ]; then
55
+ if [[ ! -v name ] ]; then
38
56
>&2 echo " Required ${name} environment variable missing"
39
57
failed=1
40
58
fi
0 commit comments