Skip to content

Commit

Permalink
mrchief#17 - Write aws config file to a temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeyers99 committed Aug 17, 2021
1 parent 12ba236 commit f608423
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ set -u
set -o pipefail

awsDir="${HOME}/.aws"
config="${awsDir}/config"
configDir="$(mktemp -d)"
config="${configDir}/config"
credentials="${awsDir}/credentials"

# Delete the temporary file when this script finishes running, is interrupted, or exits abnormally
trap "rm -Rf $configDir" 0 2 3 15

mkdir -p "${awsDir}"
echo -e "[profile default]\noutput = json" >>"$config"
echo -e "[profile default]\noutput = json" >"$config"

# Attempt to get aws credentials via tokendito
max_attempts=10
totp_time=30
totp_error='Each code can only be used once. Please wait for a new code and try again.'
for ((attempts = 1; attempts <= $max_attempts; attempts++)); do
echo "Requesting AWS credentials via Tokendito."
t_error=$(tokendito --aws-profile default -ou $INPUT_OKTA_APP_URL -R $INPUT_AWS_ROLE_ARN --username $INPUT_OKTA_USERNAME --password $INPUT_OKTA_PASSWORD --mfa-method ${INPUT_OKTA_MFA_METHOD:=token:software:totp} --mfa-response $(echo $INPUT_OKTA_MFA_SEED | mintotp ${totp_time}) 2>&1 1>/dev/null)
t_error=$(tokendito --config-file $config --aws-profile default -ou $INPUT_OKTA_APP_URL -R $INPUT_AWS_ROLE_ARN --username $INPUT_OKTA_USERNAME --password $INPUT_OKTA_PASSWORD --mfa-method ${INPUT_OKTA_MFA_METHOD:=token:software:totp} --mfa-response $(echo $INPUT_OKTA_MFA_SEED | mintotp ${totp_time}) 2>&1 1>/dev/null)

if [[ $? == 0 ]]; then
echo "Succeeded getting credentials in attempt #${attempts}."
Expand Down

0 comments on commit f608423

Please sign in to comment.