@actsecurity/iam-lens

中文文档
0.1.193发布于 2026/11/05AGPL-3.0-or-laterTypeScriptESM + CJS构建来源已验证近 30 天下载 3798

Visibility in IAM in and across AWS accounts

原始使用文档
文档目录11 节
  1. Table of Contents
  2. Quick Start
  3. What is iam-lens?
  4. Why use it?
  5. Getting Started
  6. Commands
  7. simulate - Simulate a request
  8. who-can - Find who can perform an action on a resource
  9. principal-can - Get a consolidated policy of all permission…
  10. Contributing & Support
  11. Acknowledgements

iam-lens

NPM Version License: AGPL v3 GuardDog Known Vulnerabilities

Get visibility into the IAM permissions in your AWS organizations and accounts. Use your actual AWS IAM policies (downloaded via iam-collect) and evaluate the effective permissions.

Table of Contents

  1. Quick Start
  2. What is iam-lens?
  3. Why use it?
  4. Getting Started
  5. Commands
  6. Contributing & Support
  7. Acknowledgements

Quick Start

# Install
npm install -g @actsecurity/iam-collect @actsecurity/iam-lens

# Download all IAM policies in your account using default credentials, run download once per account
iam-collect init
iam-collect download

# Simulate a request
iam-lens simulate --principal arn:aws:iam::123456789012:role/ExampleRole --resource arn:aws:s3:::example-bucket/secret-file.txt --action s3:GetObject

# Find out who can do something
iam-lens who-can --resource arn:aws:s3:::example-bucket --actions s3:ListBucket

# Find out who can do all actions on a resource
iam-lens who-can --resource arn:aws:s3:::example-bucket

What is iam-lens?

iam-lens lets you simulate and audit real IAM requests against your collected IAM data from your AWS accounts (collected via iam-collect) and understand the effective permissions that apply to a principal or resource.

Why use it?

  • Understand the permissions that are actually in place.
  • Verify allowed and denied outcomes after all policies are deployed.
  • Discover every principal that can access a given resource.
  • Audit complex policy combinations across all your AWS accounts and orgs.
  • Debug complex conditions locally without deployment or network calls.

Getting Started

  1. Download Your Policies with iam-collect to get all policies from your AWS accounts. iam-collect is highly configurable and can be customized to collect the policies you need. It only downloads information to your file system or an S3 bucket, so you're in full control of your data.
npm install -g @actsecurity/iam-collect
iam-collect init
iam-collect download

To see the effect of SCPs and RCPs, you should download data from your management account; or an account with permission to download organization information. Download data for member accounts you want to analyze. iam-lens will analyze cross-account and cross-organization requests if the data is available.

You can download information for as many accounts, organizations, and regions as you like. The more data you have, the more accurate your answers will be.

  1. Install iam-lens
npm install -g @actsecurity/iam-lens
  1. Execute Commands with iam-lens to simulate requests, discover permissions, and audit your IAM policies.

Simulate a request:

iam-lens simulate \
  --principal arn:aws:iam::123456789012:role/ExampleRole \
  --resource arn:aws:s3:::example-bucket/secret-file.txt \
  --action s3:GetObject

or

Discover who can perform an action on a resource:

iam-lens who-can \
  --resource arn:aws:iam::111111111111:role/ImportantRole \
  --actions sts:AssumeRole iam:PassRole

Commands

simulate - Simulate a request

Evaluates whether a principal can perform a specified action on a resource (or account for wildcard only actions). Returns a decision: Allowed, ImplicitlyDenied, or ExplicitlyDenied. All condition keys are supported and many context keys are set automatically.

Full simulate documentation

# Simple simulate: can this role list objects in the bucket?
iam-lens simulate \
  --principal arn:aws:iam::111111111111:role/MyRole \
  --resource arn:aws:s3:::my-bucket \
  --action s3:ListBucket

# Simulate a wildcard action (ListAllMyBuckets) – normal simulation uses the principal's account
iam-lens simulate \
  --principal arn:aws:iam::222222222222:user/Alice \
  --action s3:ListAllMyBuckets

# Include custom context keys
iam-lens simulate \
  --principal arn:aws:iam::333333333333:role/DevRole \
  --resource arn:aws:sqs:us-east-1:333333333333:my-queue \
  --action sqs:SendMessage \
  --context aws:SourceVpc vpc-1234567890abcdef0 \
  --verbose

# Assert the result must be “Allowed”; exit code will be nonzero if not
iam-lens simulate \
  --principal arn:aws:iam::444444444444:role/ReadOnly \
  --resource arn:aws:dynamodb:us-east-1:444444444444:table/Books \
  --action dynamodb:Query \
  --expect Allowed

# Simulate unsigned access to a concrete resource ARN
iam-lens simulate \
  --anonymous \
  --resource arn:aws:s3:::public-bucket/report.txt \
  --action s3:GetObject

# Simulate an administrator principal outside the dataset, without SCPs
iam-lens simulate \
  --external-principal \
  --principal arn:aws:iam::999999999999:role/ExternalRole \
  --resource arn:aws:s3:::example-bucket/report.txt \
  --action s3:GetObject

# Simulate access to a resource outside the dataset
iam-lens simulate \
  --external-resource \
  --principal arn:aws:iam::444444444444:role/ReadOnly \
  --resource arn:aws:s3:::external-bucket/report.txt \
  --resource-account 999999999999 \
  --action s3:GetObject

The variants make their assumptions explicit:

  • Anonymous requests have no identity policy, session policy, permission boundary, or SCP. A resource ARN is required (wildcard resource patterns are supported), but the resource does not need to be collected; specify --resource-account when its account cannot be inferred. Principal-derived context keys cannot be supplied. Available resource policies, RCPs, VPC endpoint policies, and collected S3 controls still apply.
  • External principal requests model a principal from an uncollected account with a synthetic allow-all identity policy and no permission boundary or SCP. Session policies and collected resource-side controls still apply, so cross-account access still requires an applicable resource-side grant. In Discovery mode, unknown principal attributes such as principal tags are returned as conditions.
  • External resource requests require a concrete resource ARN and keep the collected principal's identity policies, permission boundary, session policy, SCPs, and VPC endpoint policies. They apply no RCPs and use a supplied or synthetic resource/trust policy. S3 ABAC and Block Public Access default to disabled for the uncollected resource; ABAC can be enabled with --s3-abac-override enabled.

Anonymous, external-principal, and external-resource simulations do not support wildcard-only actions. See the full documentation for policy overrides and other details.

Full simulate documentation

who-can - Find who can perform an action on a resource

iam-lens who-can [options]

Lists all principals in your IAM data who are allowed to perform one or more specified actions on a resource (or account for wildcard only actions). If applicable it will check the resource policy to find cross-account permissions and AWS service principals. Potentially public resource policies are also simulated for unsigned access, returned as "principal": "anonymous", including wildcard resource patterns.

Full who-can documentation

Examples:

# Who can get this object?
iam-lens who-can \
  --resource arn:aws:s3:::my-bucket/secret-file.txt \
  --actions s3:GetObject

# Who can list all IAM roles in this account? (wildcard action – no resource)
iam-lens who-can \
  --resource-account 555555555555 \
  --actions iam:ListRoles

# Check multiple actions at once
iam-lens who-can \
  --resource arn:aws:dynamodb:us-east-1:555555555555:table/Books \
  --actions dynamodb:Query dynamodb:UpdateItem

# Check a wildcard resource prefix and inspect allowed patterns
iam-lens who-can \
  --resource arn:aws:s3:::my-bucket/reports/* \
  --actions s3:GetObject

# Check all actions for a bucket
iam-lens who-can \
  --resource arn:aws:s3:::my-bucket

Full who-can documentation

principal-can - Get a consolidated policy of all permissions for a principal

iam-lens principal-can --principal <arn> [--shrink-action-lists]

Creates a consolidated policy document showing all permissions that a principal can perform based on their identity policies, permission boundaries, SCPs, RCPs, and resource policies. The output is a synthesized IAM policy representing the effective permissions after all policy evaluations.

Full principal-can documentation

Examples:

# Get all permissions for a user or role
iam-lens principal-can \
  --principal arn:aws:iam::123456789012:user/Alice

# Get permissions for a role with shrunk action lists
iam-lens principal-can \
  --principal arn:aws:iam::123456789012:role/MyRole \
  --shrink-action-lists

Full principal-can documentation

Contributing & Support

The best way to support is to open an issue and let us know of any bugs, feature requests, or questions you have. We're always looking for ways to improve the project and make it more useful for everyone.

Acknowledgements

Special thanks to Ziyad Almbasher for testing, validating, providing feedback, and for not letting up when the author thinks "this is fine".

版本与发布记录

@actsecurity/iam-lens 共发布 37 个版本,首次发布于 2026/09/01;过去 12 个月发布了 37 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.193latest2026/11/051 天前
0.1.1922026/11/051 天前
0.1.1912026/11/042 天前
0.1.1902026/11/042 天前
0.1.1882026/11/033 天前
0.1.1872026/11/033 天前

关于 @actsecurity/iam-lens 的常见问题

@actsecurity/iam-lens 是什么?

Visibility in IAM in and across AWS accounts

如何安装 @actsecurity/iam-lens?

在项目目录运行 npm install @actsecurity/iam-lens,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 iam-lens,可以用 npx iam-lens 直接运行。

@actsecurity/iam-lens 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@actsecurity/iam-lens 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@actsecurity/iam-lens 可以商用吗?

@actsecurity/iam-lens 使用 AGPL-3.0-or-later 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@actsecurity/iam-lens 的下载量有多少?

根据 npm 官方下载统计,@actsecurity/iam-lens 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,798 次,日均约 127 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@actsecurity/iam-lens 还在维护吗?

最新版本 0.1.193 发布于 2026/11/05(1 天前);至今共发布 37 个版本,其中过去 12 个月发布了 37 个;首次发布于 2026/09/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。