-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36788b2
commit 8e55401
Showing
6 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tools/cert-update → terraform/tools/cert-update
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#/bin/bash | ||
# This script assumes the hst_reprocessing_admin_role, runs a given command using that role, and then switches back to original role | ||
|
||
# Set region | ||
export AWS_DEFAULT_REGION="us-east-1" | ||
|
||
# Role to assume | ||
ACCOUNT_ID=`aws sts get-caller-identity --output=text | awk '{ print $1 }'` | ||
HST_ADMIN_ARN="arn:aws:iam::${ACCOUNT_ID}:role/hst_reprocessing_admin_role" | ||
|
||
# Grab parameters | ||
COMMAND_TO_RUN=$* | ||
|
||
# Save current AWS credentials | ||
CURRENT_AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID | ||
CURRENT_AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY | ||
CURRENT_AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN | ||
|
||
#Assume role, run command, and switch back | ||
printf "\n Assuming role..." | ||
if CREDENTIALS=`aws sts assume-role --role-arn $HST_ADMIN_ARN --role-session-name temp_admin_session --duration-seconds 3599` ; then | ||
|
||
export AWS_ACCESS_KEY_ID=`echo ${CREDENTIALS} | python -c "import sys, json, os; temp=json.load(sys.stdin)['Credentials']['AccessKeyId'];print(temp)"` | ||
export AWS_SECRET_ACCESS_KEY=`echo ${CREDENTIALS} | python -c "import sys, json, os; temp=json.load(sys.stdin)['Credentials']['SecretAccessKey'];print(temp)"` | ||
export AWS_SESSION_TOKEN=`echo ${CREDENTIALS} | python -c "import sys, json, os; temp=json.load(sys.stdin)['Credentials']['SessionToken'];print(temp)"` | ||
|
||
printf "\n Role assumed:" | ||
aws sts get-caller-identity | ||
|
||
printf "\n Running command\n" | ||
$COMMAND_TO_RUN | ||
|
||
printf "\n Switching back to original role" | ||
export AWS_ACCESS_KEY_ID=$CURRENT_AWS_ACCESS_KEY_ID | ||
export AWS_SECRET_ACCESS_KEY=$CURRENT_AWS_SECRET_ACCESS_KEY | ||
export AWS_SESSION_TOKEN=$CURRENT_AWS_SESSION_TOKEN | ||
|
||
printf "\n Role switched back:" | ||
aws sts get-caller-identity | ||
|
||
else | ||
printf "\n==========================\n\n - Error assuming role. Aborting execution\n\n" | ||
exit 1 | ||
fi |