English 中文(简体)
我能否寻找现有的伊玛雅政策,以采取具体行动?
原标题:Can I search existing IAM policies for a specific action?

在“世界妇女论坛”中,无论是通过文字还是网吧,都能够找到哪些现行政策含有某种行动?

例如,我要允许<条码>米罗莱>进入对我所有的EC2事例采取行动。 我知道,我可以以适当的规则制定我自己的政策,但如果存在这样的情况,我想采用现有的亚马孙政策。

最佳回答

这是一个老的职位,但可以帮助某人...... 尽管其他人已经说过的话,你可以这样做。 这只是需要说明。

你可以与世界妇女联盟一道做以下工作。

  1. • 政策分析,储存在<条码>中。

    www.un.org/Depts/DGACM/index_french.htm

  2. 在每个政策中使用版本,并在<代码>policies_ver阵列中储存。

    mapfile -t policies_ver < <(aws iam list-policies --query Policies[*].[DefaultVersionId] --output text)

  3. 每一政策中的休息时间,并在<条码>中储存政策文件。

    for (i=0; i<${#policies_arn[@]}; i++ ); do re${policies_arn[i]} >> policies. txt && aws iam Rec-policy-version -policy-arn${policies_arn[i]} —————————————————— - 产出;

  4. 开放式<代码>policies.txt, 文本编辑,请你采取行动。

注:根据您的CLI配置,您可能或不一定需要<代码>-产出文本参数。 然而,产出必须是案文(而不是JSON),才能工作。

从那以后,你可以很容易地将这段文字变为<条码>。

产出:

arn:aws:iam::123456789012:policy/DenyAllAccess
{
    "PolicyVersion": {
        "CreateDate": "2016-12-06T18:40:51Z",
        "VersionId": "v1",
        "Document": {
            "Statement": [
                {
                    "Action": "*",
                    "Effect": "Deny",
                    "Resource": "*"
                }
            ],
            "Version": "2012-10-17"
        },
        "IsDefaultVersion": true
    }
}

Cheers!

问题回答

To elaborate on my understanding of https://stackoverflow.com/a/43128660/447862 the important thing is to get the JSON from the default version of each policy. Since my machine does not have mapfile I opted to use Python.

import boto3, json, sys

iam = boto3.client( iam )
policy_arn = sys.argv[1]
policy_name = policy_arn.split( / )[-1]

version = iam.get_policy(PolicyArn=policy_arn)[ Policy ][ DefaultVersionId ]
policy_version = iam.get_policy_version(PolicyArn=policy_arn, VersionId=version)
policy_document = policy_version[ PolicyVersion ][ Document ]

with open(f"{policy_name}.json",  w ) as outfile:
  outfile.write(json.dumps(policy_document, indent=2))
  outfile.write( 
 )

现在,作为<条码>ws-iam-policy-dump.py,我现在可以按照我的愿望,将每份政策文件写到自己的档案中,进行搜查。

aws iam list-policies --query  Policies[*].Arn  --output text > policy-arns.txt
for arn in $(cat policy-arns.txt); do
  python aws-iam-policy-dump.py $arn
done

也许可以通过在沙尔做所有事来加快,但这种混合办法对我来说是充分的。

aws iam list-policies --query  Policies[*].[Arn, DefaultVersionId]  | jq -rc  .[] | join(" ")  | xargs -l bash -c  aws iam get-policy-version --policy-arn=$0 --version-id=$1 --query="{"$0": PolicyVersion.Document.Statement[*].[Action, NotAction][][]}"  | jq -c | grep YOUR_POLICY_ACTION_HERE
  1. This basically captures all the Arns and Versions in the single call
  2. Then joins the output into a single space-separated string
  3. This string is then sent to another bash process via xargs where the ARN and VersionId are passed in as separate parameters to get-policy-version
  4. The result of this is combined with the ARN into a single line
  5. Lines are grepped for your pleasure with the search action you re looking for.

我在谈到这一问题时,寻求找到可能包含具体行动的现有政策的途径。 指挥部将根据政策数目在奥(n)时间进行,因为对你们的每一项政策分别发出呼吁。

我无法说明如何获得<代码>.contains()>,在最后的-query中适当开展工作,以便一夫能够过滤而不是灰色。

纯一流的@amacleod反应:

# based on https://stackoverflow.com/questions/38270609/can-i-search-existing-iam-policies-for-a-specific-action
#          https://www.learnaws.org/2021/05/12/aws-iam-boto3-guide/

import boto3, json, sys

iam = boto3.client( iam )


def write_policy(policy_arn):

    # policy_arn = sys.argv[1]
    policy_name = policy_arn.split( / )[-1]

    version = iam.get_policy(PolicyArn=policy_arn)[ Policy ][ DefaultVersionId ]
    policy_version = iam.get_policy_version(PolicyArn=policy_arn, VersionId=version)
    policy_document = policy_version[ PolicyVersion ][ Document ]

    with open(f"{policy_name}.json",  w ) as outfile:
        outfile.write(json.dumps(policy_document, indent=2))
        outfile.write( 
 )

def list_policies():
    paginator = iam.get_paginator( list_policies )
    for response in paginator.paginate(Scope="Local"):
        for policy in response["Policies"]:
            print(f"Policy Name: {policy[ PolicyName ]} ARN: {policy[ Arn ]}")
            write_policy(policy[ Arn ])


if __name__ ==  __main__ :
    list_policies()

由于我多年来一直在探寻并发现这一问题和一套答案,这里有“平原编码”(第<条码>jq 要求)指示我用这个方法编制一份国际水域政策名称及其相关行动的清单:

$ aws iam list-policies --query  Policies[*].[PolicyName, Arn, DefaultVersionId]  --output text |
    while read NAME ARN VER; do
      echo "$NAME $(aws iam get-policy-version --policy-arn=$ARN --version-id=$VER --query  PolicyVersion.Document.Statement[*].Action[]  --output text | tr  	     )"
    done > policies.txt

这样做需要时间,但我可以很快地抓住产出,找到我可以再利用的现有政策。





相关问题
Mount windows shared drive to MWAA in bootscript

In MWAA startup script sudo yum install samba-client cifs-utils -y sudo mount.cifs //dev/test/drop /mnt/dev/test-o username=testuser,password= pwd ,domain=XX Executing above commonds giving error - ...

How to get Amazon Seller Central orders programmatically?

We have been manually been keying Amazon orders into our system and would like to automate it. However, I can t seem to figure out how to go about it. Their documentation is barely there. There is: ...

Using a CDN like Amazon S3 to control access to media

I want to use Amazon S3/CloudFront to store flash files. These files must be private as they will be accessed by members. This will be done by storing each file with a link to Amazon using a mysql ...

unable to connect to database on AWS

actually I have my website build with Joomla hosted on hostmonster but all Joomla website need a database support to run this database is on AWS configuration files need to be updated for that I ...

Using EC2 Load Balancing with Existing Wordpress Blog

I currently have a virtual dedicated server through Media Temple that I use to run several high traffic Wordpress blogs. Both tend to receive sudden StumbleUpon traffic surges that (I m assuming) ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

热门标签