使用 IAM 访问分析器示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 IAM 访问分析器示例 Amazon CLI

以下代码示例向您展示了如何使用 Amazon Command Line Interface 与 IAM Access Analyzer 配合使用来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 apply-archive-rule

Amazon CLI

将存档规则应用于符合存档规则标准的现有查找结果

以下apply-archive-rule示例将存档规则应用于符合存档规则条件的现有查找结果。

aws accessanalyzer apply-archive-rule \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/UnusedAccess-ConsoleAnalyzer-organization \ --rule-name MyArchiveRule

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IAM 用户指南中的存档规则

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ApplyArchiveRule中的。

以下代码示例演示如何使用 cancel-policy-generation

Amazon CLI

取消所请求的策略生成

以下cancel-policy-generation示例取消了请求的策略生成任务 ID。

aws accessanalyzer cancel-policy-generation \ --job-id 923a56b0-ebb8-4e80-8a3c-a11ccfbcd6f2

此命令不生成任何输出。

有关更多信息,请参阅 IAM 用户指南中的 I Amazon AM 访问分析器策略生成

以下代码示例演示如何使用 check-access-not-granted

Amazon CLI

检查策略是否不允许指定访问权限

以下check-access-not-granted示例检查策略是否不允许指定访问。

aws accessanalyzer check-access-not-granted \ --policy-document file://myfile.json \ --access actions="s3:DeleteBucket","s3:GetBucketLocation" \ --policy-type IDENTITY_POLICY

myfile.json 的内容:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::DOC-EXAMPLE-BUCKET", "arn:aws:s3:::DOC-EXAMPLE-BUCKET/*" ] } ] }

输出:

{ "result": "PASS", "message": "The policy document does not grant access to perform the listed actions." }

有关更多信息,请参阅 IAM 用户指南中的使用 IAM Access Analyzer API 预览访问权限。Amazon

以下代码示例演示如何使用 check-no-new-access

Amazon CLI

检查与现有策略相比,更新后的策略是否允许新的访问权限

以下check-no-new-access示例检查与现有策略相比,更新后的策略是否允许新的访问权限。

aws accessanalyzer check-no-new-access \ --existing-policy-document file://existing-policy.json \ --new-policy-document file://new-policy.json \ --policy-type IDENTITY_POLICY

existing-policy.json 的内容:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::DOC-EXAMPLE-BUCKET", "arn:aws:s3:::DOC-EXAMPLE-BUCKET/*" ] } ] }

new-policy.json 的内容:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:GetObjectAcl", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::DOC-EXAMPLE-BUCKET", "arn:aws:s3:::DOC-EXAMPLE-BUCKET/*" ] } ] }

输出:

{ "result": "FAIL", "message": "The modified permissions grant new access compared to your existing policy.", "reasons": [ { "description": "New access in the statement with index: 0.", "statementIndex": 0 } ] }

有关更多信息,请参阅 IAM 用户指南中的使用 IAM Access Analyzer API 预览访问权限。Amazon

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CheckNoNewAccess中的。

以下代码示例演示如何使用 create-access-preview

Amazon CLI

创建访问预览,允许您在部署资源权限之前预览资源的 IAM Access Analyzer 调查结果

以下create-access-preview示例创建了一个访问预览,允许您在 Amazon 账户中部署资源权限之前预览资源的 IAM Access Analyzer 结果。

aws accessanalyzer create-access-preview \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account \ --configurations file://myfile.json

myfile.json 的内容:

{ "arn:aws:s3:::DOC-EXAMPLE-BUCKET": { "s3Bucket": { "bucketPolicy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"arn:aws:iam::111122223333:root\"]},\"Action\":[\"s3:PutObject\",\"s3:PutObjectAcl\"],\"Resource\":\"arn:aws:s3:::DOC-EXAMPLE-BUCKET/*\"}]}", "bucketPublicAccessBlock": { "ignorePublicAcls": true, "restrictPublicBuckets": true }, "bucketAclGrants": [ { "grantee": { "id": "79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be" }, "permission": "READ" } ] } } }

输出:

{ "id": "3c65eb13-6ef9-4629-8919-a32043619e6b" }

有关更多信息,请参阅 IAM 用户指南中的使用 IAM Access Analyzer API 预览访问权限。Amazon

以下代码示例演示如何使用 create-analyzer

Amazon CLI

创建分析器

以下create-analyzer示例在您的 Amazon 账户中创建了一个分析器。

aws accessanalyzer create-analyzer \ --analyzer-name example \ --type ACCOUNT

输出:

{ "arn": "arn:aws:access-analyzer:us-east-2:111122223333:analyzer/example" }

有关更多信息,请参阅 Amazon IAM 用户指南中的 I dent Amazon ity and Access Management Access Analyzer 发现的入门

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateAnalyzer中的。

以下代码示例演示如何使用 create-archive-rule

Amazon CLI

为指定的分析器创建存档规则

以下create-archive-rule示例为您 Amazon 账户中的指定分析器创建存档规则。

aws accessanalyzer create-archive-rule \ --analyzer-name UnusedAccess-ConsoleAnalyzer-organization \ --rule-name MyRule \ --filter '{"resource": {"contains": ["Cognito"]}, "resourceType": {"eq": ["AWS::IAM::Role"]}}'

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IAM 用户指南中的存档规则

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateArchiveRule中的。

以下代码示例演示如何使用 delete-analyzer

Amazon CLI

删除指定的分析器

以下delete-analyzer示例删除了您 Amazon 账户中的指定分析器。

aws accessanalyzer delete-analyzer \ --analyzer-name example

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IAM 用户指南中的存档规则

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteAnalyzer中的。

以下代码示例演示如何使用 delete-archive-rule

Amazon CLI

删除指定的存档规则

以下delete-archive-rule示例删除了您 Amazon 账户中指定的存档规则。

aws accessanalyzer delete-archive-rule \ --analyzer-name UnusedAccess-ConsoleAnalyzer-organization \ --rule-name MyRule

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IAM 用户指南中的存档规则

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteArchiveRule中的。

以下代码示例演示如何使用 get-access-preview

Amazon CLI

检索有关指定分析器的访问预览的信息

以下get-access-preview示例检索有关您 Amazon 账户中指定分析器的访问预览的信息。

aws accessanalyzer get-access-preview \ --access-preview-id 3c65eb13-6ef9-4629-8919-a32043619e6b \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account

输出:

{ "accessPreview": { "id": "3c65eb13-6ef9-4629-8919-a32043619e6b", "analyzerArn": "arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account", "configurations": { "arn:aws:s3:::DOC-EXAMPLE-BUCKET": { "s3Bucket": { "bucketPolicy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"arn:aws:iam::111122223333:root\"]},\"Action\":[\"s3:PutObject\",\"s3:PutObjectAcl\"],\"Resource\":\"arn:aws:s3:::DOC-EXAMPLE-BUCKET/*\"}]}", "bucketAclGrants": [ { "permission": "READ", "grantee": { "id": "79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be" } } ], "bucketPublicAccessBlock": { "ignorePublicAcls": true, "restrictPublicBuckets": true } } } }, "createdAt": "2024-02-17T00:18:44+00:00", "status": "COMPLETED" } }

有关更多信息,请参阅 IAM 用户指南中的使用 IAM Access Analyzer API 预览访问权限。Amazon

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetAccessPreview中的。

以下代码示例演示如何使用 get-analyzed-resource

Amazon CLI

检索有关已分析资源的信息

以下get-analyzed-resource示例检索有关在您的 Amazon 账户中分析过的资源的信息。

aws accessanalyzer get-analyzed-resource \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account \ --resource-arn arn:aws:s3:::DOC-EXAMPLE-BUCKET

输出:

{ "resource": { "analyzedAt": "2024-02-15T18:01:53.002000+00:00", "isPublic": false, "resourceArn": "arn:aws:s3:::DOC-EXAMPLE-BUCKET", "resourceOwnerAccount": "111122223333", "resourceType": "AWS::S3::Bucket" } }

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

以下代码示例演示如何使用 get-analyzer

Amazon CLI

检索有关指定分析器的信息

以下get-analyzer示例检索有关您 Amazon 账户中指定分析器的信息。

aws accessanalyzer get-analyzer \ --analyzer-name ConsoleAnalyzer-account

输出:

{ "analyzer": { "arn": "arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account", "createdAt": "2019-12-03T07:28:17+00:00", "lastResourceAnalyzed": "arn:aws:sns:us-west-2:111122223333:config-topic", "lastResourceAnalyzedAt": "2024-02-15T18:01:53.003000+00:00", "name": "ConsoleAnalyzer-account", "status": "ACTIVE", "tags": { "auto-delete": "no" }, "type": "ACCOUNT" } }

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetAnalyzer中的。

以下代码示例演示如何使用 get-archive-rule

Amazon CLI

检索有关存档规则的信息

以下get-archive-rule示例检索有关您 Amazon 账户中存档规则的信息。

aws accessanalyzer get-archive-rule \ --analyzer-name UnusedAccess-ConsoleAnalyzer-organization \ --rule-name MyArchiveRule

输出:

{ "archiveRule": { "createdAt": "2024-02-15T00:49:27+00:00", "filter": { "resource": { "contains": [ "Cognito" ] }, "resourceType": { "eq": [ "AWS::IAM::Role" ] } }, "ruleName": "MyArchiveRule", "updatedAt": "2024-02-15T00:49:27+00:00" } }

有关更多信息,请参阅 Amazon IAM 用户指南中的存档规则

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetArchiveRule中的。

以下代码示例演示如何使用 get-finding-v2

Amazon CLI

检索有关指定结果的信息

以下get-finding-v2示例检索有关您 Amazon 账户中指定结果的信息。

aws accessanalyzer get-finding-v2 \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-organization \ --id 0910eedb-381e-4e95-adda-0d25c19e6e90

输出:

{ "findingDetails": [ { "externalAccessDetails": { "action": [ "sts:AssumeRoleWithWebIdentity" ], "condition": { "cognito-identity.amazonaws.com:aud": "us-west-2:EXAMPLE0-0000-0000-0000-000000000000" }, "isPublic": false, "principal": { "Federated": "cognito-identity.amazonaws.com" } } } ], "resource": "arn:aws:iam::111122223333:role/Cognito_testpoolAuth_Role", "status": "ACTIVE", "error": null, "createdAt": "2021-02-26T21:17:50.905000+00:00", "resourceType": "AWS::IAM::Role", "findingType": "ExternalAccess", "resourceOwnerAccount": "111122223333", "analyzedAt": "2024-02-16T18:17:47.888000+00:00", "id": "0910eedb-381e-4e95-adda-0d25c19e6e90", "updatedAt": "2021-02-26T21:17:50.905000+00:00" }

有关更多信息,请参阅 Amazon IAM 用户指南中的查看调查结果

  • 有关 API 的详细信息,请参阅《Amazon CLI 命令参考》中的 GetFindingV2

以下代码示例演示如何使用 get-finding

Amazon CLI

检索有关指定结果的信息

以下get-finding示例检索有关您 Amazon 账户中指定结果的信息。

aws accessanalyzer get-finding \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-organization \ --id 0910eedb-381e-4e95-adda-0d25c19e6e90

输出:

{ "finding": { "id": "0910eedb-381e-4e95-adda-0d25c19e6e90", "principal": { "Federated": "cognito-identity.amazonaws.com" }, "action": [ "sts:AssumeRoleWithWebIdentity" ], "resource": "arn:aws:iam::111122223333:role/Cognito_testpoolAuth_Role", "isPublic": false, "resourceType": "AWS::IAM::Role", "condition": { "cognito-identity.amazonaws.com:aud": "us-west-2:EXAMPLE0-0000-0000-0000-000000000000" }, "createdAt": "2021-02-26T21:17:50.905000+00:00", "analyzedAt": "2024-02-16T18:17:47.888000+00:00", "updatedAt": "2021-02-26T21:17:50.905000+00:00", "status": "ACTIVE", "resourceOwnerAccount": "111122223333" } }

有关更多信息,请参阅 Amazon IAM 用户指南中的查看调查结果

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetFinding中的。

以下代码示例演示如何使用 get-generated-policy

Amazon CLI

检索使用 `StartPolicyGeneration` API 生成的策略

以下get-generated-policy示例检索使用您 Amazon 账户中的 StartPolicyGeneration API 生成的政策。

aws accessanalyzer get-generated-policy \ --job-id c557dc4a-0338-4489-95dd-739014860ff9

输出:

{ "generatedPolicyResult": { "generatedPolicies": [ { "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"SupportedServiceSid0\",\"Effect\":\"Allow\",\"Action\":[\"access-analyzer:GetAnalyzer\",\"access-analyzer:ListAnalyzers\",\"access-analyzer:ListArchiveRules\",\"access-analyzer:ListFindings\",\"cloudtrail:DescribeTrails\",\"cloudtrail:GetEventDataStore\",\"cloudtrail:GetEventSelectors\",\"cloudtrail:GetInsightSelectors\",\"cloudtrail:GetTrailStatus\",\"cloudtrail:ListChannels\",\"cloudtrail:ListEventDataStores\",\"cloudtrail:ListQueries\",\"cloudtrail:ListTags\",\"cloudtrail:LookupEvents\",\"ec2:DescribeRegions\",\"iam:GetAccountSummary\",\"iam:GetOpenIDConnectProvider\",\"iam:GetRole\",\"iam:ListAccessKeys\",\"iam:ListAccountAliases\",\"iam:ListOpenIDConnectProviders\",\"iam:ListRoles\",\"iam:ListSAMLProviders\",\"kms:ListAliases\",\"s3:GetBucketLocation\",\"s3:ListAllMyBuckets\"],\"Resource\":\"*\"}]}" } ], "properties": { "cloudTrailProperties": { "endTime": "2024-02-14T22:44:40+00:00", "startTime": "2024-02-13T00:30:00+00:00", "trailProperties": [ { "allRegions": true, "cloudTrailArn": "arn:aws:cloudtrail:us-west-2:111122223333:trail/my-trail", "regions": [] } ] }, "isComplete": false, "principalArn": "arn:aws:iam::111122223333:role/Admin" } }, "jobDetails": { "completedOn": "2024-02-14T22:47:01+00:00", "jobId": "c557dc4a-0338-4489-95dd-739014860ff9", "startedOn": "2024-02-14T22:44:41+00:00", "status": "SUCCEEDED" } }

有关更多信息,请参阅 IAM 用户指南中的 I Amazon AM 访问分析器策略生成

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetGeneratedPolicy中的。

以下代码示例演示如何使用 list-access-preview-findings

Amazon CLI

检索由指定访问预览生成的访问预览结果列表

以下list-access-preview-findings示例检索您的 Amazon 账户中指定访问预览生成的访问预览结果列表。

aws accessanalyzer list-access-preview-findings \ --access-preview-id 3c65eb13-6ef9-4629-8919-a32043619e6b \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account

输出:

{ "findings": [ { "id": "e22fc158-1c87-4c32-9464-e7f405ce8d74", "principal": { "AWS": "111122223333" }, "action": [ "s3:PutObject", "s3:PutObjectAcl" ], "condition": {}, "resource": "arn:aws:s3:::DOC-EXAMPLE-BUCKET", "isPublic": false, "resourceType": "AWS::S3::Bucket", "createdAt": "2024-02-17T00:18:46+00:00", "changeType": "NEW", "status": "ACTIVE", "resourceOwnerAccount": "111122223333", "sources": [ { "type": "POLICY" } ] } ] }

有关更多信息,请参阅 IAM 用户指南中的使用 IAM Access Analyzer API 预览访问权限。Amazon

以下代码示例演示如何使用 list-access-previews

Amazon CLI

检索指定分析器的访问预览列表

以下list-access-previews示例检索您 Amazon 账户中指定分析器的访问预览列表。

aws accessanalyzer list-access-previews \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account

输出:

{ "accessPreviews": [ { "id": "3c65eb13-6ef9-4629-8919-a32043619e6b", "analyzerArn": "arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account", "createdAt": "2024-02-17T00:18:44+00:00", "status": "COMPLETED" } ] }

有关更多信息,请参阅 IAM 用户指南中的使用 IAM Access Analyzer API 预览访问权限。Amazon

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListAccessPreviews中的。

以下代码示例演示如何使用 list-analyzed-resources

Amazon CLI

列出可用的小部件

以下list-analyzed-resources示例列出了您 Amazon 账户中可用的微件。

aws accessanalyzer list-analyzed-resources \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account \ --resource-type AWS::IAM::Role

输出:

{ "analyzedResources": [ { "resourceArn": "arn:aws:sns:us-west-2:111122223333:Validation-Email", "resourceOwnerAccount": "111122223333", "resourceType": "AWS::SNS::Topic" }, { "resourceArn": "arn:aws:sns:us-west-2:111122223333:admin-alerts", "resourceOwnerAccount": "111122223333", "resourceType": "AWS::SNS::Topic" }, { "resourceArn": "arn:aws:sns:us-west-2:111122223333:config-topic", "resourceOwnerAccount": "111122223333", "resourceType": "AWS::SNS::Topic" }, { "resourceArn": "arn:aws:sns:us-west-2:111122223333:inspector-topic", "resourceOwnerAccount": "111122223333", "resourceType": "AWS::SNS::Topic" } ] }

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

以下代码示例演示如何使用 list-analyzers

Amazon CLI

检索分析器列表

以下list-analyzers示例检索您 Amazon 账户中的分析器列表。

aws accessanalyzer list-analyzers

输出:

{ "analyzers": [ { "arn": "arn:aws:access-analyzer:us-west-2:111122223333:analyzer/UnusedAccess-ConsoleAnalyzer-organization", "createdAt": "2024-02-15T00:46:40+00:00", "name": "UnusedAccess-ConsoleAnalyzer-organization", "status": "ACTIVE", "tags": { "auto-delete": "no" }, "type": "ORGANIZATION_UNUSED_ACCESS" }, { "arn": "arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-organization", "createdAt": "2020-04-25T07:43:28+00:00", "lastResourceAnalyzed": "arn:aws:s3:::DOC-EXAMPLE-BUCKET", "lastResourceAnalyzedAt": "2024-02-15T21:51:56.517000+00:00", "name": "ConsoleAnalyzer-organization", "status": "ACTIVE", "tags": { "auto-delete": "no" }, "type": "ORGANIZATION" }, { "arn": "arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account", "createdAt": "2019-12-03T07:28:17+00:00", "lastResourceAnalyzed": "arn:aws:sns:us-west-2:111122223333:config-topic", "lastResourceAnalyzedAt": "2024-02-15T18:01:53.003000+00:00", "name": "ConsoleAnalyzer-account", "status": "ACTIVE", "tags": { "auto-delete": "no" }, "type": "ACCOUNT" } ] }

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListAnalyzers中的。

以下代码示例演示如何使用 list-archive-rules

Amazon CLI

检索为指定分析器创建的存档规则列表

以下list-archive-rules示例检索您 Amazon 账户中为指定分析器创建的存档规则列表。

aws accessanalyzer list-archive-rules \ --analyzer-name UnusedAccess-ConsoleAnalyzer-organization

输出:

{ "archiveRules": [ { "createdAt": "2024-02-15T00:49:27+00:00", "filter": { "resource": { "contains": [ "Cognito" ] }, "resourceType": { "eq": [ "AWS::IAM::Role" ] } }, "ruleName": "MyArchiveRule", "updatedAt": "2024-02-15T00:49:27+00:00" }, { "createdAt": "2024-02-15T23:27:45+00:00", "filter": { "findingType": { "eq": [ "UnusedIAMUserAccessKey" ] } }, "ruleName": "ArchiveRule-56125a39-e517-4ff8-afb1-ef06f58db612", "updatedAt": "2024-02-15T23:27:45+00:00" } ] }

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListArchiveRules中的。

以下代码示例演示如何使用 list-findings-v2

Amazon CLI

检索指定分析器生成的结果列表

以下list-findings-v2示例检索您的 Amazon 账户中指定分析器生成的结果列表。此示例筛选结果以仅包含名称包含的 IAM 角色Cognito

aws accessanalyzer list-findings-v2 \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account \ --filter '{"resource": {"contains": ["Cognito"]}, "resourceType": {"eq": ["AWS::IAM::Role"]}}'

输出:

{ "findings": [ { "analyzedAt": "2024-02-16T18:17:47.888000+00:00", "createdAt": "2021-02-26T21:17:24.710000+00:00", "id": "597f3bc2-3adc-4c18-9879-5c4b23485e46", "resource": "arn:aws:iam::111122223333:role/Cognito_testpoolUnauth_Role", "resourceType": "AWS::IAM::Role", "resourceOwnerAccount": "111122223333", "status": "ACTIVE", "updatedAt": "2021-02-26T21:17:24.710000+00:00", "findingType": "ExternalAccess" }, { "analyzedAt": "2024-02-16T18:17:47.888000+00:00", "createdAt": "2021-02-26T21:17:50.905000+00:00", "id": "ce0e221a-85b9-4d52-91ff-d7678075442f", "resource": "arn:aws:iam::111122223333:role/Cognito_testpoolAuth_Role", "resourceType": "AWS::IAM::Role", "resourceOwnerAccount": "111122223333", "status": "ACTIVE", "updatedAt": "2021-02-26T21:17:50.905000+00:00", "findingType": "ExternalAccess" } ] }

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

  • 有关 API 的详细信息,请参阅《Amazon CLI 命令参考》中的 ListFindingsV2

以下代码示例演示如何使用 list-findings

Amazon CLI

检索指定分析器生成的结果列表

以下list-findings示例检索您的 Amazon 账户中指定分析器生成的结果列表。此示例筛选结果以仅包含名称包含的 IAM 角色Cognito

aws accessanalyzer list-findings \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account \ --filter '{"resource": {"contains": ["Cognito"]}, "resourceType": {"eq": ["AWS::IAM::Role"]}}'

输出:

{ "findings": [ { "id": "597f3bc2-3adc-4c18-9879-5c4b23485e46", "principal": { "Federated": "cognito-identity.amazonaws.com" }, "action": [ "sts:AssumeRoleWithWebIdentity" ], "resource": "arn:aws:iam::111122223333:role/Cognito_testpoolUnauth_Role", "isPublic": false, "resourceType": "AWS::IAM::Role", "condition": { "cognito-identity.amazonaws.com:aud": "us-west-2:EXAMPLE0-0000-0000-0000-000000000000" }, "createdAt": "2021-02-26T21:17:24.710000+00:00", "analyzedAt": "2024-02-16T18:17:47.888000+00:00", "updatedAt": "2021-02-26T21:17:24.710000+00:00", "status": "ACTIVE", "resourceOwnerAccount": "111122223333" }, { "id": "ce0e221a-85b9-4d52-91ff-d7678075442f", "principal": { "Federated": "cognito-identity.amazonaws.com" }, "action": [ "sts:AssumeRoleWithWebIdentity" ], "resource": "arn:aws:iam::111122223333:role/Cognito_testpoolAuth_Role", "isPublic": false, "resourceType": "AWS::IAM::Role", "condition": { "cognito-identity.amazonaws.com:aud": "us-west-2:EXAMPLE0-0000-0000-0000-000000000000" }, "createdAt": "2021-02-26T21:17:50.905000+00:00", "analyzedAt": "2024-02-16T18:17:47.888000+00:00", "updatedAt": "2021-02-26T21:17:50.905000+00:00", "status": "ACTIVE", "resourceOwnerAccount": "111122223333" } ] }

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListFindings中的。

以下代码示例演示如何使用 list-policy-generations

Amazon CLI

列出过去七天内申请的所有保单世代

以下list-policy-generations示例列出了过去七天内您 Amazon 账户中请求的所有保单生成。

aws accessanalyzer list-policy-generations

输出:

{ "policyGenerations": [ { "completedOn": "2024-02-14T23:43:38+00:00", "jobId": "923a56b0-ebb8-4e80-8a3c-a11ccfbcd6f2", "principalArn": "arn:aws:iam::111122223333:role/Admin", "startedOn": "2024-02-14T23:43:02+00:00", "status": "CANCELED" }, { "completedOn": "2024-02-14T22:47:01+00:00", "jobId": "c557dc4a-0338-4489-95dd-739014860ff9", "principalArn": "arn:aws:iam::111122223333:role/Admin", "startedOn": "2024-02-14T22:44:41+00:00", "status": "SUCCEEDED" } ] }

有关更多信息,请参阅 IAM 用户指南中的 I Amazon AM 访问分析器策略生成

以下代码示例演示如何使用 list-tags-for-resource

Amazon CLI

检索应用于指定资源的标签列表

以下list-tags-for-resource示例检索应用于您 Amazon 账户中指定资源的标签列表。

aws accessanalyzer list-tags-for-resource \ --resource-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account

输出:

{ "tags": { "Zone-of-trust": "Account", "Name": "ConsoleAnalyzer" } }

有关更多信息,请参阅 IAM 用户指南中的 I Amazon AM 访问分析器策略生成

以下代码示例演示如何使用 start-policy-generation

Amazon CLI

启动策略生成请求

以下start-policy-generation示例在您的 Amazon 账户中启动策略生成请求。

aws accessanalyzer start-policy-generation \ --policy-generation-details '{"principalArn":"arn:aws:iam::111122223333:role/Admin"}' \ --cloud-trail-details file://myfile.json

myfile.json 的内容:

{ "accessRole": "arn:aws:iam::111122223333:role/service-role/AccessAnalyzerMonitorServiceRole", "startTime": "2024-02-13T00:30:00Z", "trails": [ { "allRegions": true, "cloudTrailArn": "arn:aws:cloudtrail:us-west-2:111122223333:trail/my-trail" } ] }

输出:

{ "jobId": "c557dc4a-0338-4489-95dd-739014860ff9" }

有关更多信息,请参阅 IAM 用户指南中的 I Amazon AM 访问分析器策略生成

以下代码示例演示如何使用 start-resource-scan

Amazon CLI

立即开始扫描应用于指定资源的策略

以下start-resource-scan示例立即开始扫描应用于您 Amazon 账户中指定资源的策略。

aws accessanalyzer start-resource-scan \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account \ --resource-arn arn:aws:iam::111122223333:role/Cognito_testpoolAuth_Role

此命令不生成任何输出。

有关更多信息,请参阅 IAM 用户指南中的 I Amazon AM 访问分析器策略生成

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考StartResourceScan中的。

以下代码示例演示如何使用 tag-resource

Amazon CLI

为指定资源添加标签

以下tag-resource示例将标签添加到您 Amazon 账户中的指定资源。

aws accessanalyzer tag-resource \ --resource-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account \ --tags Environment=dev,Purpose=testing

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考TagResource中的。

以下代码示例演示如何使用 untag-resource

Amazon CLI

从指定资源中移除标签

以下untag-resource示例从您 Amazon 账户中的指定资源中移除标签。

aws accessanalyzer untag-resource \ --resource-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/ConsoleAnalyzer-account \ --tag-keys Environment Purpose

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UntagResource中的。

以下代码示例演示如何使用 update-archive-rule

Amazon CLI

更新指定存档规则的条件和值

以下update-archive-rule示例更新了您 Amazon 账户中指定存档规则的条件和值。

aws accessanalyzer update-archive-rule \ --analyzer-name UnusedAccess-ConsoleAnalyzer-organization \ --rule-name MyArchiveRule \ --filter '{"resource": {"contains": ["Cognito"]}, "resourceType": {"eq": ["AWS::IAM::Role"]}}'

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IAM 用户指南中的存档规则

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateArchiveRule中的。

以下代码示例演示如何使用 update-findings

Amazon CLI

更新指定发现的状态

以下update-findings示例更新了您 Amazon 账户中指定发现的状态。

aws accessanalyzer update-findings \ --analyzer-arn arn:aws:access-analyzer:us-west-2:111122223333:analyzer/UnusedAccess-ConsoleAnalyzer-organization \ --ids 4f319ac3-2e0c-4dc4-bf51-7013a086b6ae 780d586a-2cce-4f72-aff6-359d450e7500 \ --status ARCHIVED

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IAM 用户指南中的使用 I Amazon dentity and Access Management 访问分析器

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateFindings中的。

以下代码示例演示如何使用 validate-policy

Amazon CLI

请求验证政策并返回调查结果列表

以下validate-policy示例请求验证策略并返回结果列表。示例中的策略是用于网络联合身份验证的 Amazon Cognito 角色的角色信任策略。信任策略生成的结果与空Sid元素值和不匹配的策略主体有关,这是因为使用的代入角色操作不正确,sts:AssumeRole与 Cognito 一起使用的正确假设角色操作是。sts:AssumeRoleWithWebIdentity

aws accessanalyzer validate-policy \ --policy-document file://myfile.json \ --policy-type RESOURCE_POLICY

myfile.json 的内容:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Federated": "cognito-identity.amazonaws.com" }, "Action": [ "sts:AssumeRole", "sts:TagSession" ], "Condition": { "StringEquals": { "cognito-identity.amazonaws.com:aud": "us-west-2_EXAMPLE" } } } ] }

输出:

{ "findings": [ { "findingDetails": "Add a value to the empty string in the Sid element.", "findingType": "SUGGESTION", "issueCode": "EMPTY_SID_VALUE", "learnMoreLink": "https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-reference-policy-checks.html#access-analyzer-reference-policy-checks-suggestion-empty-sid-value", "locations": [ { "path": [ { "value": "Statement" }, { "index": 0 }, { "value": "Sid" } ], "span": { "end": { "column": 21, "line": 5, "offset": 81 }, "start": { "column": 19, "line": 5, "offset": 79 } } } ] }, { "findingDetails": "The sts:AssumeRole action is invalid with the following principal(s): cognito-identity.amazonaws.com. Use a SAML provider principal with the sts:AssumeRoleWithSAML action or use an OIDC provider principal with the sts:AssumeRoleWithWebIdentity action. Ensure the provider is Federated if you use either of the two options.", "findingType": "ERROR", "issueCode": "MISMATCHED_ACTION_FOR_PRINCIPAL", "learnMoreLink": "https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-reference-policy-checks.html#access-analyzer-reference-policy-checks-error-mismatched-action-for-principal", "locations": [ { "path": [ { "value": "Statement" }, { "index": 0 }, { "value": "Action" }, { "index": 0 } ], "span": { "end": { "column": 32, "line": 11, "offset": 274 }, "start": { "column": 16, "line": 11, "offset": 258 } } }, { "path": [ { "value": "Statement" }, { "index": 0 }, { "value": "Principal" }, { "value": "Federated" } ], "span": { "end": { "column": 61, "line": 8, "offset": 202 }, "start": { "column": 29, "line": 8, "offset": 170 } } } ] }, { "findingDetails": "The following actions: sts:TagSession are not supported by the condition key cognito-identity.amazonaws.com:aud. The condition will not be evaluated for these actions. We recommend that you move these actions to a different statement without this condition key.", "findingType": "ERROR", "issueCode": "UNSUPPORTED_ACTION_FOR_CONDITION_KEY", "learnMoreLink": "https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-reference-policy-checks.html#access-analyzer-reference-policy-checks-error-unsupported-action-for-condition-key", "locations": [ { "path": [ { "value": "Statement" }, { "index": 0 }, { "value": "Action" }, { "index": 1 } ], "span": { "end": { "column": 32, "line": 12, "offset": 308 }, "start": { "column": 16, "line": 12, "offset": 292 } } }, { "path": [ { "value": "Statement" }, { "index": 0 }, { "value": "Condition" }, { "value": "StringEquals" }, { "value": "cognito-identity.amazonaws.com:aud" } ], "span": { "end": { "column": 79, "line": 16, "offset": 464 }, "start": { "column": 58, "line": 16, "offset": 443 } } } ] } ] }

有关更多信息,请参阅 Amazon IAM 用户指南中的策略验证检查

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ValidatePolicy中的。