Skip to content

Commit

Permalink
Merge pull request #11 from soemeier/master
Browse files Browse the repository at this point in the history
Allow to use aws ec2 roles for authentication
  • Loading branch information
mqasimsarfraz authored Jun 15, 2020
2 parents 5b3d8b3 + 6740ad7 commit 2fad57e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ The proxy is packaged in a docker container and can be configured with following
| Environment Variable | Description | Status | Default |
| :---------------------------------: | :--------------------------------------------: | :-------------------------------: | :--------: |
| `AWS_REGION` | AWS Region for AWS ECR | Required | |
| `AWS_ACCESS_KEY_ID` | AWS Account Access Key ID | Required | |
| `AWS_SECRET_ACCESS_KEY` | AWS Account Secret Access Key | Required | |
| `AWS_ACCESS_KEY_ID` | AWS Account Access Key ID | Optional | |
| `AWS_SECRET_ACCESS_KEY` | AWS Account Secret Access Key | Optional | |
| `AWS_USE_EC2_ROLE_FOR_AUTH` | Set this to true if we do want to use aws roles for authentication instead of providing the secret and access keys explicitly | Optional | |
| `UPSTREAM` | URL for AWS ECR | Required | |
| `RESOLVER` | DNS server to be used by proxy | Required | |
| `PORT` | Port on which proxy listens | Required | |
Expand Down
17 changes: 11 additions & 6 deletions files/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ if [ -z "$AWS_REGION" ] ; then
exit 1
fi

if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY not set."
exit 1
if [ -z "$AWS_USE_EC2_ROLE_FOR_AUTH" ] || [ "$AWS_USE_EC2_ROLE_FOR_AUTH" != "true" ]; then
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY not set."
exit 1
fi
fi

UPSTREAM_WITHOUT_PORT=$( echo ${UPSTREAM} | sed -r "s/.*:\/\/(.*):.*/\1/g")
Expand Down Expand Up @@ -64,9 +66,12 @@ AWS_FOLDER='/root/.aws'
mkdir -p ${AWS_FOLDER}
echo "[default]" > ${AWS_FOLDER}/config
echo "region = $AWS_REGION" >> ${AWS_FOLDER}/config
echo "[default]" > ${AWS_FOLDER}/credentials
echo "aws_access_key_id=$AWS_ACCESS_KEY_ID" >> ${AWS_FOLDER}/credentials
echo "aws_secret_access_key=$AWS_SECRET_ACCESS_KEY" >> ${AWS_FOLDER}/credentials

if [ -z "$AWS_USE_EC2_ROLE_FOR_AUTH" ] || [ "$AWS_USE_EC2_ROLE_FOR_AUTH" != "true" ]; then
echo "[default]" > ${AWS_FOLDER}/credentials
echo "aws_access_key_id=$AWS_ACCESS_KEY_ID" >> ${AWS_FOLDER}/credentials
echo "aws_secret_access_key=$AWS_SECRET_ACCESS_KEY" >> ${AWS_FOLDER}/credentials
fi
chmod 600 -R ${AWS_FOLDER}

# add the auth token in default.conf
Expand Down

0 comments on commit 2fad57e

Please sign in to comment.