【问题标题】:Is there any way to list out all permissions and on which resources an IAM user have access?有没有办法列出所有权限以及 IAM 用户可以访问哪些资源?
【发布时间】:2019-08-19 11:02:47
【问题描述】:

我被要求列出我公司的 aws 帐户中的所有用户访问权限。有什么方法可以列出用户拥有的资源和各自的权限?我觉得通过查看 IAM 策略和基于资源的策略很难获得详细信息。如果用户有跨账户访问,那就很难了。

【问题讨论】:

    标签: amazon-web-services amazon-iam


    【解决方案1】:

    没有一个命令可以列出所有权限。如果你有兴趣使用一些工具,那么你可以试试a tool for quickly evaluating IAM permissions in AWS.

    你也可以试试这个脚本,因为单个命令的列出权限是不可能的,你可以用多个命令的组合来检查。

    #!/bin/bash
    username=ahsan
    
    echo "**********************"
    echo "user info"
    aws iam get-user --user-name $username
    echo "***********************"
    echo ""
    
    # if [ $1=="test" ]; then
    # all_users=$(aws iam list-users --output text | cut -f 6)
    # echo "users in account are $all_users"
    # fi
    
    echo "get user groups"
    echo "***********************************************"
    Groups=$(aws iam list-groups-for-user --user-name ahsan --output text | awk '{print $5}')
    echo "user $username belong to $Groups"
    echo "***********************************************"
    
    echo "listing policies in group"
    for Group in $Groups
    do  
        echo ""
        echo "***********************************************"
        echo "list attached policies with group $Group"
        aws iam list-attached-group-policies --group-name $Group --output table
        echo "***********************************************"
        echo ""
    
    done
    
    echo "list attached policies"
    aws iam list-attached-user-policies --user-name $username --output table
    
    echo "-------- Inline Policies --------"
    for Group in $Groups
    do
        aws iam list-group-policies --group-name $Group --output table
    done
    aws iam list-user-policies --user-name $username --output table
    

    【讨论】:

      【解决方案2】:

      请在关于列出所有用户及其策略、组、附加策略的一个 bash 脚本下方运行。

      aws iam list-users |grep -i username > list_users ; cat list_users |awk '{print $NF}' |tr '\"' ' ' |tr '\,' ' '|while read user; do echo "\n\n--------------Getting information for user $user-----------\n\n" ; aws iam list-user-policies --user-name $user --output yaml; aws iam list-groups-for-user  --user-name $user --output yaml;aws iam  list-attached-user-policies --user-name $user --output yaml ;done ;echo;echo
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-02-06
        • 1970-01-01
        • 2013-12-23
        • 2020-06-01
        • 2017-11-07
        相关资源
        最近更新 更多