Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#17 - Write aws config file to a temporary directory #20

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ set -u
set -o pipefail

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

# Delete the temporary file when this script finishes running, is interrupted, or exits abnormally
trap "rm -f $config" 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