{"id":308885,"date":"2020-08-23T15:00:30","date_gmt":"2020-08-23T15:00:30","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308885"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-08-23T15:00:30","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308885","title":{"rendered":"AWS CLI \u0447\u0435\u0440\u0435\u0437 MFA"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516262\/\">\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 AWS MFA, \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u044e\u0449\u0435\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 AWS CLI.<\/p>\n<p>  <\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0443 \u043c\u0435\u043d\u044f \u043d\u0430 \u044d\u0442\u0443 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0443\u0448\u043b\u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u0434\u043d\u044f. \u0427\u0442\u043e\u0431\u044b \u0434\u0440\u0443\u0433\u0438\u043c \u043d\u0435\u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c AWS \ud83d\ude09 \u043a\u0430\u043a \u0438 \u044f \u0441\u0430\u043c, \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0434\u0440\u0430\u0433\u043e\u0446\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u044d\u0442\u0443 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e\u0435, \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0414\u0430\u0436\u0435 \u0434\u043b\u044f sandbox \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Multi-factor_authentication\" rel=\"nofollow\">MFA<\/a> \u2014 \u044d\u0442\u043e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435. \u0423 \u043d\u0430\u0441 \u044d\u0442\u043e \u0442\u0430\u043a.<\/p>\n<p>  <\/p>\n<h2 id=\"nastroyka-mfa\">\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MFA<\/h2>\n<p>  <\/p>\n<ol>\n<li>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 <a href=\"https:\/\/aws.amazon.com\/ru\/iam\/features\/mfa\/\" rel=\"nofollow\">\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0435 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/a><\/li>\n<li>\u0417\u0430\u0439\u0434\u0438\u0442\u0435 \u0432 <a href=\"https:\/\/console.aws.amazon.com\/iam\/home?region=us-east-1#\/security_credentials\" rel=\"nofollow\">AWS \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/a><\/li>\n<li><a href=\"https:\/\/console.aws.amazon.com\/iam\/home?region=us-east-1#\/security_credentials\" rel=\"nofollow\">My Security Credentials<\/a> -&gt; Assign MFA Device<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/8x\/fp\/vx\/8xfpvxycy4mfdecdbbc1jicjc5s.png\"><\/li>\n<li>Virtual MFA Device<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/bo\/jp\/zn\/bojpznvqpcc6_y8_-pcddmmcxek.png\"><\/li>\n<li>\u0421\u043b\u0435\u0434\u0443\u0439\u0442\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/3h\/lv\/uq\/3hlvuqvudtawzzsassfsfps9udw.png\"><br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ow\/hn\/u0\/owhnu0_xk3x82doarf4trayqq70.png\"><\/li>\n<li>\u0412\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0433\u043e\u0442\u043e\u0432\u043e<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/iz\/nj\/fw\/iznjfwmdltubodcjqncio4ub5vg.png\"><\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"ustanovka-aws-cli\">\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 AWS CLI<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/install-cliv2.html\" rel=\"nofollow\">https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/install-cliv2.html<\/a><\/p>\n<p>  <\/p>\n<h2 id=\"nastroyka-imenovannogo-profilya\">\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/cli-configure-profiles.html\" rel=\"nofollow\">https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/cli-configure-profiles.html<\/a><\/p>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/console.aws.amazon.com\/iam\/home?region=us-east-1#\/security_credentials\" rel=\"nofollow\">My Security Credentials<\/a> -&gt; Create access key<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/6r\/ew\/dz\/6rewdzjbu5kvxqhfuthnwckhih0.png\"><\/li>\n<li>\u0421\u043a\u043e\u043f\u0438\u0440\u0443\u0439\u0442\u0435 \u043a\u043b\u044e\u0447 \u0432 \u0431\u0443\u0444\u0435\u0440 \u043e\u0431\u043c\u0435\u043d\u0430. \u041e\u043d \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435<\/li>\n<li><code>$ aws configure --profile &lt;your profile name&gt;<\/code><\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"aws-cli-cherez-mfa\">AWS CLI \u0447\u0435\u0440\u0435\u0437 MFA<\/h2>\n<p>  <\/p>\n<ol>\n<li>\u0421\u043a\u043e\u043f\u0438\u0440\u0443\u0439\u0442\u0435 ARN \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dx\/n5\/a1\/dxn5a1bvzyt-fkyn31mxtowbb-4.png\"><\/li>\n<li><code>aws sts get-session-token --profile &lt;\u0438\u043c\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u044f&gt; --serial-number &lt;ARN \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430&gt; --token-code &lt;\u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c&gt;<\/code><br \/>  \u041e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0437\u044f\u0442\u044c \u0438\u0437 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435.<\/li>\n<li>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 JSON, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0436\u0443\u0435\u043d\u0438\u044f AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u042f \u0440\u0435\u0448\u0438\u043b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <code>~\/.bash_profile<\/code><br \/>  \u0414\u043b\u044f \u0440\u0430\u0437\u0431\u043e\u0440\u0430 JSON \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 <a href=\"https:\/\/stedolan.github.io\/jq\/download\/\" rel=\"nofollow\">jq<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#!\/usr\/bin\/env bash  aws_login() {     session=$(aws sts get-session-token &quot;$@&quot;)     echo &quot;${session}&quot;     AWS_ACCESS_KEY_ID=$(echo &quot;${session}&quot; | jq -r '.Credentials.AccessKeyId')     export AWS_ACCESS_KEY_ID     AWS_SECRET_ACCESS_KEY=$(echo &quot;${session}&quot; | jq -r '.Credentials.SecretAccessKey')     export AWS_SECRET_ACCESS_KEY     AWS_SESSION_TOKEN=$(echo &quot;${session}&quot; | jq -r '.Credentials.SessionToken')     export AWS_SESSION_TOKEN }  alias aws-login-dev='aws_login --profile &lt;\u0438\u043c\u044f dev \u043f\u0440\u043e\u0444\u0438\u043b\u044f&gt; --serial-number &lt;ARN \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430&gt; --token-code ' alias aws-login-prod='aws_login --profile &lt;\u0438\u043c\u044f prod \u043f\u0440\u043e\u0444\u0438\u043b\u044f&gt; --serial-number &lt;ARN \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430&gt; --token-code '<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ aws-login-dev &lt;\u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c \u0434\u0430\u043d\u043d\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445 \u0431\u043b\u0443\u0436\u0434\u0430\u043d\u0438\u0439 \u043f\u043e \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \ud83d\ude09<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/516262\/\"> https:\/\/habr.com\/ru\/post\/516262\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516262\/\">\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 AWS MFA, \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u044e\u0449\u0435\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 AWS CLI.<\/p>\n<p>  <\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0443 \u043c\u0435\u043d\u044f \u043d\u0430 \u044d\u0442\u0443 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0443\u0448\u043b\u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u0434\u043d\u044f. \u0427\u0442\u043e\u0431\u044b \u0434\u0440\u0443\u0433\u0438\u043c \u043d\u0435\u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c AWS \ud83d\ude09 \u043a\u0430\u043a \u0438 \u044f \u0441\u0430\u043c, \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0434\u0440\u0430\u0433\u043e\u0446\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u044d\u0442\u0443 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e\u0435, \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308885","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308885","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308885"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308885\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}