Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rcfiles
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
rcfiles
Commits
cede124f
Commit
cede124f
authored
8 months ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
assume-role: Add MFA support.
parent
da9e72c5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Documents/bin/assume-role
+27
-0
27 additions, 0 deletions
Documents/bin/assume-role
with
27 additions
and
0 deletions
Documents/bin/assume-role
+
27
−
0
View file @
cede124f
...
...
@@ -20,6 +20,33 @@ fi
role
=
"
$1
"
shift
if
[
"
$(
aws iam list-mfa-devices
--query
'length(MFADevices)'
)
"
-gt
0
]
then
printf
"Enter the MFA token: "
read
-r
mfa_token
for
mfa_dev
in
$(
aws iam list-mfa-devices
--query
'MFADevices[].SerialNumber'
--output
text
)
do
credentials
=
"
$(
aws sts get-session-token
--output
text
--token-code
"
$mfa_token
"
--serial-number
"
$mfa_dev
"
2>/dev/null
)
"
||
continue
break
done
if
[
-z
"
$credentials
"
]
then
echo
'Failed to get a temporary token.'
>
&2
exit
1
fi
AWS_ACCESS_KEY_ID
=
"
$(
echo
"
$credentials
"
|
awk
'{print $2}'
)
"
AWS_SECRET_ACCESS_KEY
=
"
$(
echo
"
$credentials
"
|
awk
'{print $4}'
)
"
AWS_SESSION_TOKEN
=
"
$(
echo
"
$credentials
"
|
awk
'{print $5}'
)
"
export
AWS_ACCESS_KEY_ID
export
AWS_SECRET_ACCESS_KEY
export
AWS_SESSION_TOKEN
unset
AWS_SECURITY_TOKEN
fi
if
[
"
$role
"
=
"
${
role
##arn
:
}
"
]
then
role_arn
=
"
$(
aws iam list-roles
--query
"Roles[?RoleName==
\`
${
role
}
\`
].Arn"
--output
text
)
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment