ããã«ã¡ã¯ãAWS CLIã好ããªç¦å³¶ã§ãã
ä»åã¯ãAWS SSOé¢é£ã®æ
å ±ãåå¾ããã³ãã³ãããç´¹ä»ãããã¾ãã
ååã®ããã°ã§æ¬¡åã¯ãIAM権éã«ã¤ãã¦ããç´¹ä»ããã¨è¨è¼ããã®ã§ããã ã¡ãã£ã¨å¯ãéããã¦ãAWS SSOé¢é£ã®æ å ±åå¾ãå ã«ãç´¹ä»ãããã¾ãã
- AWS SSOã®ã¤ã³ã¹ã¿ã³ã¹ARNã®ç¢ºèª
- ã¢ã¯ã»ã¹æ¨©éã»ããã®ç¢ºèª
- ã¢ã¯ã»ã¹æ¨©éã»ããã®åºæ¬æ å ±
- ã¢ã¯ã»ã¹æ¨©éã»ããã«ç´ã¥ãããã¼ã¸ãããªã·ã¼
- ã¢ã¯ã»ã¹æ¨©éã»ããã®ã¤ã³ã©ã¤ã³ããªã·ã¼
- ã¢ã¯ã»ã¹æ¨©éã»ãããç´ã¥ãã¦ããã¢ã«ã¦ã³ãä¸è¦§
- ã¢ã«ã¦ã³ãã«ç´ã¥ãã¢ã¯ã»ã¹æ¨©éã»ãã
- å ¨ã¢ã«ã¦ã³ãã«ç´ã¥ãã¢ã¯ã»ã¹æ¨©éã»ããã®è¡¨ç¤º1
- å ¨ã¢ã«ã¦ã³ãã«ç´ã¥ãã¢ã¯ã»ã¹æ¨©éã»ããã®è¡¨ç¤º2
- å ¨ã¢ã¯ã»ã¹æ¨©éã»ããã®è©³ç´°
- ãããã«
å ã«è¨è¼ãã¦ããã¨ã
- å ¨ã¢ã«ã¦ã³ãã«ç´ã¥ãã¢ã¯ã»ã¹æ¨©éã»ããã®è¡¨ç¤º
- å ¨ã¢ã¯ã»ã¹æ¨©éã»ããã®è©³ç´°
ãä¸çªä½¿ããã¨æãã¾ãã
AWS SSOã®ã¤ã³ã¹ã¿ã³ã¹ARNã®ç¢ºèª
ã¤ã³ã¹ã¿ã³ã¹ã®ARNã¯ãä»å¾ç´¹ä»ããã³ãã³ãã§çµæ§ä½¿ãã¾ãã
ã³ãã³ã
aws sso-admin list-instances
- å®è¡çµæ
{ "Instances": [ { "InstanceArn": "arn:aws:sso:::instance/ssoins-7758faff83b26bbb", "IdentityStoreId": "d-9567180725" } ] }
ã¢ã¯ã»ã¹æ¨©éã»ããã®ç¢ºèª
ã¤ã³ã¹ã¿ã³ã¹ã®ARNãå©ç¨ãã¾ãããã³ãã³ãã§èªåã§åå¾ããããã«ãã¦ã¾ãã®ã§ãã³ããã§OKã§ãã
ã³ãã³ã
aws sso-admin list-permission-sets \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text)
- å®è¡çµæ
{ "PermissionSets": [ "arn:aws:sso:::permissionSet/ssoins-7758faff83b26bbb/ps-82a2d3c9ca6398a4", "arn:aws:sso:::permissionSet/ssoins-7758faff83b26bbb/ps-82c9d5e2c3d089ec" ] }
ã¢ã¯ã»ã¹æ¨©éã»ããã®åºæ¬æ å ±
ã³ãã³ã
PERMISSION="" â PermissionSetsã®Arnãå ¥åãã¾ãã aws sso-admin describe-permission-set \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --permission-set-arn ${PERMISSION}
- å®è¡çµæ
{ "PermissionSet": { "Name": "AdministratorAccess", "PermissionSetArn": "arn:aws:sso:::permissionSet/ssoins-7758faff83b26bbb/ps-82a2d3c9ca6398a4", "CreatedDate": "2020-10-09T09:53:33.521000+09:00", "SessionDuration": "PT1H" } }
ã¢ã¯ã»ã¹æ¨©éã»ããã«ç´ã¥ãããã¼ã¸ãããªã·ã¼
ã³ãã³ã
PERMISSION="" â PermissionSetsã®Arnãå ¥åãã¾ãã aws sso-admin list-managed-policies-in-permission-set \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --permission-set-arn ${PERMISSION}
- å®è¡çµæ
{ "AttachedManagedPolicies": [ { "Name": "AdministratorAccess", "Arn": "arn:aws:iam::aws:policy/AdministratorAccess" } ] }
ã¢ã¯ã»ã¹æ¨©éã»ããã®ã¤ã³ã©ã¤ã³ããªã·ã¼
ã³ãã³ã
PERMISSION="" â PermissionSetsã®Arnãå ¥åãã¾ãã aws sso-admin get-inline-policy-for-permission-set \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --permission-set-arn ${PERMISSION}
- å®è¡çµæ
{ "InlinePolicy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}]}" }
ã¤ã³ã©ã¤ã³ããªã·ã¼ã®è¡¨ç¤ºãæ¹è¡ãããã¦ããªããããå°ãåããã¥ããã§ããã ã¨ãããã¨ã§æ¹è¡ããã¦ãå°ãåããããããã¦ã¿ã¾ããã
ã³ãã³ãï¼ã¡ãã£ã¨åãããããï¼
PERMISSION="" â PermissionSetsã®Arnãå ¥åãã¾ãã aws sso-admin get-inline-policy-for-permission-set \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --permission-set-arn ${PERMISSION} \ --output text | sed -e 's/,/,\n/g' -e 's/{/\n{\n/g' -e 's/\[/\n\[/g' -e 's/\}/\n\}/g' -e 's/\]/\n\]/g' | sed '1d'
- å®è¡çµæ
{ "Version":"2012-10-17", "Statement": [ { "Effect":"Allow", "Action":"*", "Resource":"*" } ] }
ã¢ã¯ã»ã¹æ¨©éã»ãããç´ã¥ãã¦ããã¢ã«ã¦ã³ãä¸è¦§
ã³ãã³ã
PERMISSION="" â PermissionSetsã®Arnãå ¥åãã¾ãã aws sso-admin list-accounts-for-provisioned-permission-set \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --permission-set-arn ${PERMISSION}
- å®è¡çµæ
{ "AccountIds": [ "xxxxxxxxxxxx", "xxxxxxxxxxxx", "xxxxxxxxxxxx" ] }
ã¢ã«ã¦ã³ãã«ç´ã¥ãã¢ã¯ã»ã¹æ¨©éã»ãã
ã³ãã³ã
ACCOUNTID="" â ã¢ã«ã¦ã³ãIDãå ¥åãã¾ãã aws sso-admin list-permission-sets-provisioned-to-account \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --account-id ${ACCOUNTID}
- å®è¡çµæ
{ "PermissionSets": [ "arn:aws:sso:::permissionSet/ssoins-7758faff83b26bbb/ps-82a2d3c9ca6398a4" ] }
å ¨ã¢ã«ã¦ã³ãã«ç´ã¥ãã¢ã¯ã»ã¹æ¨©éã»ããã®è¡¨ç¤º1
â»ã¢ã«ã¦ã³ãæ
å ±ã¯ãorganizationsã³ãã³ãã§åå¾ãã¦ãã¾ãã
ãã¢ã«ã¦ã³ãæ°åãã³ãã³ããå®è¡ãããããçµæ§æéããããã¾ãã
ã³ãã³ã
INSTNACE_ARN=$(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text);\ aws organizations list-accounts --query "Accounts[].Id" --output text | tr "\t" "\n" | sort | while read line do echo ${line} > /tmp/awscli.tmp for permission in $(aws sso-admin list-permission-sets-provisioned-to-account --instance-arn ${INSTNACE_ARN} --account-id ${line} --query "PermissionSets" --output text) do if [[ ${permission} == None ]] ; then echo "ã¢ã¯ã»ã¹æ¨©éã»ãããªã" >> /tmp/awscli.tmp else aws sso-admin describe-permission-set \ --instance-arn ${INSTNACE_ARN} \ --permission-set-arn ${permission} \ --query "PermissionSet.[Name]" --output text >> /tmp/awscli.tmp fi done (head -n +1 /tmp/awscli.tmp && tail -n +2 /tmp/awscli.tmp | sort) | tr "\n" " " echo "" done;\ rm /tmp/awscli.tmp
- å®è¡çµæ
xxxxxxxxxxxx AdministratorAccess Billing xxxxxxxxxxxx AdministratorAccess
å ¨ã¢ã«ã¦ã³ãã«ç´ã¥ãã¢ã¯ã»ã¹æ¨©éã»ããã®è¡¨ç¤º2
â»ã¢ã«ã¦ã³ãæ
å ±ã¯ãorganizationsã³ãã³ãã§åå¾ãã¦ãã¾ãã
ãã¢ã«ã¦ã³ãæ°åãã³ãã³ããå®è¡ãããããçµæ§æéããããã¾ãã
ã³ãã³ã
INSTNACE_ARN=$(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text);\ aws organizations list-accounts --query "Accounts[].Id" --output text | tr "\t" "\n" | sort | while read line do for permission in $(aws sso-admin list-permission-sets-provisioned-to-account --instance-arn ${INSTNACE_ARN} --account-id ${line} --query "PermissionSets" --output text) do if [[ ${permission} == None ]] ; then echo "${line} : ã¢ã¯ã»ã¹æ¨©éã»ãããªã" >> /tmp/awscli.tmp else aws sso-admin list-account-assignments \ --instance-arn ${INSTNACE_ARN} \ --permission-set-arn ${permission} \ --account-id ${line} \ --query "AccountAssignments[]" --output text >> /tmp/awscli.tmp fi done done;\ rm /tmp/awscli.tmp
- å®è¡çµæ
xxxxxxxxxxxxxx arn:aws:sso:::permissionSet/ssoins-xxxxxxxxxxxxxxxxxxxx/ps-xxxxxxxxxxxxxxxxxx xxxxxxxxxxxx-xxxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxxxx GROUP xxxxxxxxxxxxxx arn:aws:sso:::permissionSet/ssoins-xxxxxxxxxxxxxxxxxxxx/ps-xxxxxxxxxxxxxxxxxx xxxxxxxxxxxx-xxxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxxxx GROUP xxxxxxxxxxxxxx arn:aws:sso:::permissionSet/ssoins-xxxxxxxxxxxxxxxxxxxx/ps-xxxxxxxxxxxxxxxxxx xxxxxxxxxxxx-xxxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxxxx GROUP xxxxxxxxxxxxxx : ã¢ã¯ã»ã¹æ¨©éã»ãããªã xxxxxxxxxxxxxx : ã¢ã¯ã»ã¹æ¨©éã»ãããªã
å ¨ã¢ã¯ã»ã¹æ¨©éã»ããã®è©³ç´°
ã³ãã³ã
INSTNACE_ARN=$(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text);\ aws sso-admin list-permission-sets --instance-arn ${INSTNACE_ARN} --query "PermissionSets" --output text | tr "\t" "\n" | while read line do echo "## ã¢ã¯ã»ã¹æ¨©éã»ããå" RESULT=$(aws sso-admin describe-permission-set --instance-arn ${INSTNACE_ARN} --permission-set-arn ${line} --query "PermissionSet.[Name,PermissionSetArn]" --output text) echo ${RESULT} echo "### ããã¼ã¸ãããªã·ã¼" aws sso-admin list-managed-policies-in-permission-set \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --permission-set-arn ${line} \ --query "AttachedManagedPolicies[].[Name,Arn]" --output text echo "### ã¤ã³ã©ã¤ã³ããªã·ã¼" FILE_NAME=$(echo ${RESULT} | awk '{print $1}').policy aws sso-admin get-inline-policy-for-permission-set \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --permission-set-arn ${line} --output text > /tmp/awscli.tmp;\ if [[ 1 -lt $(wc -c /tmp/awscli.tmp | awk '{print $1}') ]] ; then cat /tmp/awscli.tmp | sed -e 's/,/,\n/g' -e 's/{/\n{\n/g' -e 's/\[/\n\[/g' -e 's/\}/\n\}/g' -e 's/\]/\n\]/g' | sed '1d' ;\ else echo "ã¤ã³ã©ã¤ã³ããªã·ã¼ã¯å®ç¾©ããã¦ãã¾ããã" ;\ fi;\ done;\ rm /tmp/awscli.tmp
- å®è¡çµæ
## ã¢ã¯ã»ã¹æ¨©éã»ããå AdministratorAccess arn:aws:sso:::permissionSet/ssoins-7758faff83b26bbb/ps-82a2d3c9ca6398a4 ### ããã¼ã¸ãããªã·ã¼ Billing arn:aws:iam::aws:policy/job-function/Billing ### ã¤ã³ã©ã¤ã³ããªã·ã¼ { "Version":"2012-10-17", "Statement": [ { "Effect":"Allow", "Action":"*", "Resource":"*" } ] } ## ã¢ã¯ã»ã¹æ¨©éã»ããå Billing arn:aws:sso:::permissionSet/ssoins-7758faff83b26bbb/ps-82c9d5e2c3d089ec ### ããã¼ã¸ãããªã·ã¼ Billing arn:aws:iam::aws:policy/job-function/Billing ### ã¤ã³ã©ã¤ã³ããªã·ã¼ ã¤ã³ã©ã¤ã³ããªã·ã¼ã¯å®ç¾©ããã¦ãã¾ããã #
ãã¾ã
ã¢ã¯ã»ã¹æ¨©éã»ãããã¨ã®ã¤ã³ã©ã¤ã³ããªã·ã¼ããã¡ã¤ã«ã«åºåããVersion
â»æ¨æºåºåããã¾ãã
INSTNACE_ARN=$(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text);\ aws sso-admin list-permission-sets --instance-arn ${INSTNACE_ARN} --query "PermissionSets" --output text | tr "\t" "\n" | sort | while read line do echo "## ã¢ã¯ã»ã¹æ¨©éã»ããå" RESULT=$(aws sso-admin describe-permission-set --instance-arn ${INSTNACE_ARN} --permission-set-arn ${line} --query "PermissionSet.[Name,PermissionSetArn]" --output text) echo "${RESULT}" echo "### ããã¼ã¸ãããªã·ã¼" aws sso-admin list-managed-policies-in-permission-set \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --permission-set-arn ${line} \ --query "AttachedManagedPolicies[].[Name,Arn]" --output text echo "### ã¤ã³ã©ã¤ã³ããªã·ã¼" FILE_NAME=$(echo ${RESULT} | awk '{print $1}').policy aws sso-admin get-inline-policy-for-permission-set \ --instance-arn $(aws sso-admin list-instances --query "Instances[].InstanceArn" --output text) \ --permission-set-arn ${line} --output text > /tmp/awscli.tmp;\ if [[ 1 -lt $(wc -c /tmp/awscli.tmp | awk '{print $1}') ]] ; then cat /tmp/awscli.tmp | sed -e 's/,/,\n/g' -e 's/{/\n{\n/g' -e 's/\[/\n\[/g' -e 's/\}/\n\}/g' -e 's/\]/\n\]/g' | sed '1d' | tee ${FILE_NAME};\ else echo "ã¤ã³ã©ã¤ã³ããªã·ã¼ã¯å®ç¾©ããã¦ãã¾ããã" | tee ${FILE_NAME};\ fi;\ done;\ rm /tmp/awscli.tmp
- å®è¡çµæ
## ã¢ã¯ã»ã¹æ¨©éã»ããå AdministratorAccess arn:aws:sso:::permissionSet/ssoins-7758faff83b26bbb/ps-82a2d3c9ca6398a4 ### ããã¼ã¸ãããªã·ã¼ AdministratorAccess arn:aws:iam::aws:policy/AdministratorAccess ### ã¤ã³ã©ã¤ã³ããªã·ã¼ { "Version":"2012-10-17", "Statement": [ { "Effect":"Allow", "Action":"*", "Resource":"*" } ] } ## ã¢ã¯ã»ã¹æ¨©éã»ããå Billing arn:aws:sso:::permissionSet/ssoins-7758faff83b26bbb/ps-82c9d5e2c3d089ec ### ããã¼ã¸ãããªã·ã¼ Billing arn:aws:iam::aws:policy/job-function/Billing ### ã¤ã³ã©ã¤ã³ããªã·ã¼ ã¤ã³ã©ã¤ã³ããªã·ã¼ã¯å®ç¾©ããã¦ãã¾ããã
# ls -lrt -rwxrwxrwx 1 kazuya kazuya 96 Oct 27 00:35 AdministratorAccess.policy -rwxrwxrwx 1 kazuya kazuya 61 Oct 27 00:35 Billing.policy # # cat AdministratorAccess.policy { "Version":"2012-10-17", "Statement": [ { "Effect":"Allow", "Action":"*", "Resource":"*" } ] } # # cat Billing.policy ã¤ã³ã©ã¤ã³ããªã·ã¼ã¯å®ç¾©ããã¦ãã¾ããã #
ãããã«
ä»åã¯ãAWS SSOé¢é£ã®æ
å ±ãåå¾ããã³ãã³ãããç´¹ä»ãããã¾ããã
次åã¯ãIAMãããã¯AWS SSOã®ã¢ã¯ã»ã¹æ¨©éã»ããã®ä½æã»åé¤ãªã©ããç´¹ä»ãããã¨æãã¾ãï½