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

added files for module 00 #39

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions 00-dev-environment/answers.md
@@ -0,0 +1,8 @@
# This file holds all answers and reference to scripts for module 00

## Exercise 0.1.1: MFA Script

- The script "creds.sh" helps reduce the manual effort of gathering and assigning of the temporary AWS MFA credentials

- All you need to do is run the script like this below:
- ./creds.sh -e <profile_name> -t <token-code>
46 changes: 46 additions & 0 deletions 00-dev-environment/creds.sh
@@ -0,0 +1,46 @@
#!/bin/bash
# inputs needed - environment (ENV) and code (TOKEN)
echo $@
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
-e|--env)
ENV="$2"
shift # past argument
shift # past value
;;
-t|--token)
TOKEN="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters

if [ "${ENV}" = "lab" ]; then
SERIAL='arn:aws:iam::324320755747:mfa/fidelis.ogunsanmi.labs'
fi

echo "Configuring $ENV with token $TOKEN"
CREDJSON="$(aws sts get-session-token --serial-number $SERIAL --profile $ENV --token-code $TOKEN)"

ACCESSKEY="$(echo $CREDJSON | jq '.Credentials.AccessKeyId' | sed 's/"//g')"
SECRETKEY="$(echo $CREDJSON | jq '.Credentials.SecretAccessKey' | sed 's/"//g')"
SESSIONTOKEN="$(echo $CREDJSON | jq '.Credentials.SessionToken' | sed 's/"//g')"
PROFILENAME="$ENV"mfa

# echo "Profile $PROFILENAME AccessKey $ACCESSKEY SecretKey $SECRETKEY"
# echo "SessionToken $SESSIONTOKEN"

aws configure set aws_access_key_id $ACCESSKEY --profile $PROFILENAME
aws configure set aws_secret_access_key $SECRETKEY --profile $PROFILENAME
aws configure set aws_session_token $SESSIONTOKEN --profile $PROFILENAME