# @cloud-copilot/iam-expand 中文文档

规范地址：https://npmcn.com/package/%40cloud-copilot/iam-expand/

版本：0\.11\.82
npm 元数据更新时间：2026-08-29T12:13:28.691Z
中文译文更新时间：2026-11-10T02:20:37.931Z
软件包许可：AGPL-3\.0-or-later

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40cloud-copilot/iam-expand
原文对照：https://npmcn.com/package/%40cloud-copilot/iam-expand/?lang=original
项目主页：https://github.com/cloud-copilot/iam-expand#readme
源码仓库：https://github.com/cloud-copilot/iam-expand

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：156 kB，77 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：@cloud-copilot/iam-data \>=0\.12\.0 \<1\.0\.0
- 首次发布：2024-08-31T19:10:03.739Z
- 最新版本发布：2026-08-29T12:13:28.375Z
- 近 30 天下载量：4534（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：108（近 12 个月 42 个）

## 中文简介

以通配符扩展 AWS IAM 动作

## 安装

```sh
npm install @cloud-copilot/iam-expand
```

也可以使用：`pnpm add @cloud-copilot/iam-expand`、`yarn add @cloud-copilot/iam-expand`、`bun add @cloud-copilot/iam-expand`

## README

# 扩展 IAM 动作

[![NPM Version](https://img.shields.io/npm/v/@cloud-copilot/iam-expand.svg?logo=nodedotjs)](https://www.npmjs.com/package/@cloud-copilot/iam-expand) [![License: AGPL v3](https://img.shields.io/github/license/cloud-copilot/iam-expand)](https://npmcn.com/package/%40cloud-copilot/iam-expand/LICENSE.txt) [![GuardDog](https://github.com/cloud-copilot/iam-expand/actions/workflows/guarddog.yml/badge.svg)](https://github.com/cloud-copilot/iam-expand/actions/workflows/guarddog.yml) [![Known Vulnerabilities](https://snyk.io/test/github/cloud-copilot/iam-expand/badge.svg?targetFile=package.json&style=flat-square)](https://snyk.io/test/github/cloud-copilot/iam-expand?targetFile=package.json)

由Unix哲学所建,这是一个小工具,能很好地做一件事:用通配符来解释IAM动作.

用于:

1.  在您的政策中不允许使用通配符时, 扩展通配符 .
2.  获得一份详尽清单,列出列入一项政策的行动,以便迅速寻找有意义的行动.
3.  调查你的政策中 哪些行为有趣或可疑.

![Demo](https://npmcn.com/package/%40cloud-copilot/iam-expand/assets/demo.svg)

扩展演示 [在YouTube上的发言](https://www.youtube.com/watch?v=357-uGru7300)。 。 。 .

发表于 [npm 软件包](https://npmcn.com/package/%40cloud-copilot/iam-expand/#readme-typescriptnodejs-usage) 在无害环境管理和共同jS中加上作为 [国 际](https://npmcn.com/package/%40cloud-copilot/iam-expand/#readme-cli)。 。 。 .

所有信息来源于 [@cloud-copilot/iam-data (英语)](https://github.com/cloud-copilot/iam-data) 每日更新.

## 只有有效值

`iam-expand` 如果任何无效的值以无效格式或不存在的服务/行动等形式传递,那么它们将被排除在输出之外。 有可以推翻这种行为的选项.

## 在浏览器中使用

[http://iam.cloudcopilot.io/tools/iam-expansed (中文(简体) )](http://iam.cloudcopilot.io/tools/iam-expand)

## 国 际

有一个CLI! 这个 [示例文件夹](https://npmcn.com/package/%40cloud-copilot/iam-expand/examples/README.md) 有实例显示如何利用CLI在您的IAM政策中找到有趣的行动.

### 全球CLI安装

你可以在全球安装 这在默认的 AWS CloudShell 中也是有效的!

```bash
npm install -g @cloud-copilot/iam-expand
```

_根据您的配置, 可能需要在全球安装 sudo ._

### 安装 CLI 在一个项目中

您也可以在工程中安装 CLI 并使用 `npx`。 。 。 .

```bash
npm install @cloud-copilot/iam-expand
# Run with npx inside your project
npx @cloud-copilot/iam-expand
```

### 扩展动作

最简单的用法是在您想要扩展的动作中通过.

```bash
iam-expand s3:Get*Tagging
# Outputs all Get*Tagging actions
s3:GetBucketTagging
s3:GetJobTagging
s3:GetObjectTagging
s3:GetObjectVersionTagging
s3:GetStorageLensConfigurationTaggin
```

```bash
iam-expand s3:Get*Tagging s3:Put*Tagging
# Outputs the combination of Get*Tagging and Put*Tagging actions deduplicated and sorted
s3:GetBucketTagging
s3:GetJobTagging
s3:GetObjectTagging
s3:GetObjectVersionTagging
s3:GetStorageLensConfigurationTagging
s3:PutBucketTagging
s3:PutJobTagging
s3:PutObjectTagging
s3:PutObjectVersionTagging
s3:PutStorageLensConfigurationTaggin
```

### 倒转动作

使用此选项查找所有未在一组模式中的动作

```bash
iam-expand --invert s3:Get*Tagging s3:Put*Tagging
#Outputs all actions that are not Get*Tagging or Put*Tagging
a2c:GetContainerizationJobDetails
a2c:GetDeploymentJobDetails
a2c:StartContainerizationJob
a2c:StartDeploymentJob
a4b:ApproveSkill
a4b:AssociateContactWithAddressBook
...
```

### 帮助

在没有选项的情况下运行命令以显示用途 :

```bash
iam-expand
```

### 选项

#### `--expand-asterisk`

默认情况下,一个 `*` 将不扩大。 如果你想扩展一个单曲 `*` 您可以设置此旗帜.

```bash
iam-expand "*"
# Returns the asterisk
*

iam-expand --expand-asterisk "*"
# Returns very many strings, very very fast. 📚 🚀
```

#### `--error-on-invalid-format`

默认情况下,如果一个无效格式被传递,例如:

-   `s3Get*Tagging` (缺少分隔符)或
-   `s3:Get:Tagging*` (分离器太多)

它将被默默地忽略 并被忽略在输出。 如果您想要在通过无效格式时出错, 您可以设置此旗帜 .

```bash
iam-expand "s3Get*Tagging"
# Returns nothing

iam-expand --error-on-invalid-format "s3Get*Tagging"
# Throws an error and returns a non zero exit code
# Invalid action format: s3Get*Tagging
```

#### `--error-on-invalid-service`

默认情况下,如果在IAM数据中不存在的某个服务被传递,则会默默地被忽略并被忽略出输出. 如果您想要在服务通过时丢出一个不存在的错误, 您可以设置此旗帜 .

```bash
iam-expand "r2:Get*Tagging"
# Returns nothing

iam-expand --error-on-invalid-service "r2:Get*Tagging"
# Throws an error and returns a non zero exit code
# Service not found: r2
```

#### `--invalid-action-behavior`

默认情况下,如果在IAM数据中不存在的动作被传递,则会默默地被忽略并被忽略出输出. 推翻这种行为有两个选项: `error` 财务报告和审定财务报表 `include`。 。 。 .

```bash
iam-expand "ec2:DestroyAvailabilityZone"
# Returns nothing

iam-expand --invalid-action-behavior remove "ec2:DestroyAvailabilityZone"
# Returns nothing

iam-expand --invalid-action-behavior error "ec2:DestroyAvailabilityZone"
# Throws an error and returns a non zero exit code
# Invalid action: ec2:DestroyAvailabilityZone

iam-expand --invalid-action-behavior include "ec2:DestroyAvailabilityZone"
# Returns the invalid action
ec2:DestroyAvailabilityZone
```

#### `--invert`

使用它来查找所有没有在一组图案中的动作. 仅用于作为参数传递的动作,或来自stdin的无结构内容.

```bash
iam-expand --invert s3:Get*Tagging s3:Put*Tagging
#Outputs all actions that are not Get*Tagging or Put*Tagging
a2c:GetContainerizationJobDetails
a2c:GetDeploymentJobDetails
a2c:StartContainerizationJob
a2c:StartDeploymentJob
a4b:ApproveSkill
a4b:AssociateContactWithAddressBook
...
```

#### `--invert-not-actions`

_这只操作于 JSON 输入_它会连续搜索 JSON 文件以获取任何 `NotAction` 那是个字符串或一系列字符串。 这个 `NotAction` 将替换为 `Action` 键为反向 `NotAction` 动作或模式.

```bash
cat policy.json | iam-expand --invert-not-actions
```

见 [从 Stdin 读取](https://npmcn.com/package/%40cloud-copilot/iam-expand/#readme-read-from-stdin) 详情

#### `--show-data-version`

显示用于扩展动作和退出的数据的版本.

```bash
iam-expand --show-data-version
@cloud-copilot/iam-data version: 0.3.202409051
Data last updated: Thu Sep 05 2024 04:46:39 GMT+0000 (Coordinated Universal Time)
Update with either:
  npm update @cloud-copilot/iam-data
  npm update -g @cloud-copilot/iam-data
```

#### `--read-wait-ms`

从stdin读取时( 见 [下级](https://npmcn.com/package/%40cloud-copilot/iam-expand/#readme-read-from-stdin)) CLI将等10秒后第一个字节被读取后再计时出局. 这为大多数行动提供了足够的时间。 如果您想要等待更长的时间, 您可以设置此旗帜为您想要等待的毫秒 .

```bash
cat policy.json | iam-expand
# Will wait up to 10 seconds for input to start, which is plenty of time for a local file.

curl "https://government-secrets.s3.amazonaws.com/secret-policy.json" | iam-expand --read-wait-ms 20000
# Will wait up to 20 seconds to receive first byte from curl before timing out. Adjust as needed
```

### 从 stdin 读取

如果不通过任何行动作为论据,CLI将从stdin读取.

#### 扩展 JSON 输入

如果输入是有效的json文档,则CLI将找到每个实例 `Action` 财务报告和审定财务报表 `NotAction` 这是字符串或数组字符串,然后扩展它们。 这有助于在政策文件或一套文件中找到所有行动.

鉴于 `policy.json`

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:Get*Tagging",
      "Resource": "*"
    },
    {
      "Effect": "Deny",
      "NotAction": ["s3:Get*Tagging", "s3:Put*Tagging"],
      "Resource": "*"
    }
  ]
}
```

```bash
cat policy.json | iam-expand > expanded-policy.json
```

将此文件输入 `expanded-policy.json`

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      // Was "s3:Get*Tagging"
      "Action": [
        "s3:GetBucketTagging",
        "s3:GetJobTagging",
        "s3:GetObjectTagging",
        "s3:GetObjectVersionTagging",
        "s3:GetStorageLensConfigurationTagging"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Deny",
      // Was ["s3:Get*Tagging", "s3:Put*Tagging"]
      "NotAction": [
        "s3:GetBucketTagging",
        "s3:GetJobTagging",
        "s3:GetObjectTagging",
        "s3:GetObjectVersionTagging",
        "s3:GetStorageLensConfigurationTagging",
        "s3:PutBucketTagging",
        "s3:PutJobTagging",
        "s3:PutObjectTagging",
        "s3:PutObjectVersionTagging",
        "s3:PutStorageLensConfigurationTagging"
      ],
      "Resource": "*"
    }
  ]
}
```

也可以反转 `NotAction` 使用 `--invert-not-actions`这将取代 `NotAction` 元素,带有 `Action` 元素是该表格所列行动的反向 `NotAction`。 。 。 .

```bash
cat policy.json | iam-expand --invert-not-actions > inverted-policy.json
```

将此文件输入 `inverted-policy.json`

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      // Was "s3:Get*Tagging"
      "Action": [
        "s3:GetBucketTagging",
        "s3:GetJobTagging",
        "s3:GetObjectTagging",
        "s3:GetObjectVersionTagging",
        "s3:GetStorageLensConfigurationTagging"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Deny",
      // Was NotAction: ["s3:Get*Tagging", "s3:Put*Tagging"]
      // Now is Action: everything but the Get*Tagging and Put*Tagging actions
      "Action": [
        "a2c:GetContainerizationJobDetails",
        "a2c:GetDeploymentJobDetails",
        "a2c:StartContainerizationJob",
        ...
        "xray:UntagResource",
        "xray:UpdateGroup",
        "xray:UpdateSamplingRule",
      ],
      "Resource": "*"
    }
  ]
 }
```

您也可以使用它来从命令输出中扩展动作.

```bash
aws iam get-account-authorization-details --output json | iam-expand --read-wait-ms 20000 > expanded-authorization-details.json
# Now you can search the output for actions you are interested in
grep -n "kms:DisableKey" expanded-authorization-details.json
```

#### 扩展任意输入

如果stdin的输入不是json,则内容会被搜索到IAM动作,然后扩展. 抛出任何东西,它会找到一切它能做的动作,并扩展它们.

您可以回声内容 :

```bash
echo "s3:Get*Tagging" | iam-expand
```

你可以抽出Json文件的一部分 把它吸进去:

```bash
cat policy.json | jq '.Statement[].Action' | iam-expand
```

或一些地平线:

```bash
cat main.tf | iam-expand
```

或有出云法门:

```bash
cat template.yaml | iam-expand
```

甚至是一些 HTML:

```bash
curl "https://docs.aws.amazon.com/aws-managed-policy/latest/reference/ReadOnlyAccess.html" | iam-expand
```

或任何命令的输出.

因为有可能找到一个异教徒 `*` 在输入中; 如果 stdin 的值不是有效的 json 文档, stdin 选项将找不到或扩展一个 `*` 即便 `--expand-asterisk` 通过.

如果有改进的机会,请给它任何你能想到的东西,并打开一个问题.

## 类型/节点JS 使用量

## 添加到项目中

```bash
npm install @cloud-copilot/iam-expand
```

```typescript
import { expandIamActions } from '@cloud-copilot/iam-expand'

expandIamActions('s3:Get*Tagging')[
  ('s3:GetBucketTagging',
  's3:GetJobTagging',
  's3:GetObjectTagging',
  's3:GetObjectVersionTagging',
  's3:GetStorageLensConfigurationTagging')
]

expandIamActions(['s3:Get*Tagging', 's3:Put*Tagging'])[
  ('s3:GetBucketTagging',
  's3:GetJobTagging',
  's3:GetObjectTagging',
  's3:GetObjectVersionTagging',
  's3:GetStorageLensConfigurationTagging',
  's3:PutBucketTagging',
  's3:PutJobTagging',
  's3:PutObjectTagging',
  's3:PutObjectVersionTagging',
  's3:PutStorageLensConfigurationTagging')
]
```

## API 参考

## `expandIamActions`

`expandIamActions(actionStringOrStrings: string | string[], overrideOptions?: Partial<ExpandIamActionsOptions>)` 是扩大机构间委员会政策行动的主要职能。 取出字符串或数组并返回输入匹配的字符串.

## 只有有效值

`expandIamActions` 如果任何无效的值以无效格式或不存在的服务/行动等形式传递,那么它们将被排除在输出之外。 有可以推翻这种行为的选项.

任何出逃的unicode字符都会被转换为原始字符,作为过程的一部分. 这么说吧 `s3:\\u0067et*` 将转换为 `s3:Get*` 处理前。 即使是类似的东西 `s3:\\u0067etBucket` 将转换为 `s3:GetBucket` 尽管它没有通配符...

## 选项

`expandIamActions` 具有下列选项的对象的可选第二个参数:

### `expandAsterisk`

默认情况下,一个 `*` 将不扩大。 如果你想扩展一个单曲 `*` 您可以设置此选项为 `true`。 。 。 .

```typescript
import { expandIamActions } from '@cloud-copilot/iam-expand';

//Returns the unexpanded value
expandIamActions('*')
['*']

//Returns the expanded value
expandIamActions('*', { expandAsterisk: true })
[
  //Many many strings. 🫢
]
```

### `errorOnInvalidFormat`

默认情况下,如果一个无效格式被传递,例如:

-   `s3Get*Tagging` (缺少分隔符)或
-   `s3:Get:Tagging*` (分离器太多)

它将被默默地忽略 并被忽略在输出。 如果您想要在通过无效格式时出错, 您可以设置此选项为 `true`。 。 。 .

```typescript
import { expandIamActions } from '@cloud-copilot/iam-expand';

//Ignore invalid format
expandIamActions('s3Get*Tagging')
[]

//Throw an error on invalid format
expandIamActions('s3Get*Tagging', { errorOnInvalidFormat: true })
//Uncaught Error: Invalid action format: s3Get*Tagging
```

### `errorOnInvalidService`

默认情况下,如果在IAM数据中不存在的某个服务被传递,则会默默地被忽略并被忽略出输出. 如果您想要在某项服务在不存在时发生错误, 您可以设置此选项 `true`。 。 。 .

```typescript
import { expandIamActions } from '@cloud-copilot/iam-expand';

//Ignore invalid service
expandIamActions('r2:Get*Tagging')
[]

//Throw an error on invalid service
expandIamActions('r2:Get*Tagging', { errorOnInvalidService: true })
//Uncaught Error: Service not found: r2
```

### `invalidActionBehavior`

默认情况下,如果在IAM数据中不存在的动作被传递,则会默默地被忽略并被忽略出输出. 推翻这种行为有两个选项: `Error` 财务报告和审定财务报表 `Include`。 。 。 .

```typescript
import { expandIamActions, InvalidActionBehavior } from '@cloud-copilot/iam-expand';

//Ignore invalid action by default
expandIamActions('ec2:DestroyAvailabilityZone')
[]

//Ignore invalid action explicitly
expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Remove })
[]

//Throw an error on invalid action
expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Error })
//Uncaught Error: Invalid action: ec2:DestroyAvailabilityZone

//Include invalid action
expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Include })
['ec2:DestroyAvailabilityZone']
```

## `invertIamActions`

`invertIamActions(actionString: string): string` 将采取一个动作字符串并返回所有不匹配的动作。 举个例子 `s3:Get*Tagging` 除符合模式的 s3 动作外, 将返回所有服务的所有动作 `Get*Tagging`。 。 。 .

## 常见问题

### @cloud-copilot/iam-expand 是什么？

以通配符扩展 AWS IAM 动作

### 如何安装 @cloud-copilot/iam-expand？

在项目目录运行 npm install @cloud-copilot/iam-expand，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@cloud-copilot/iam-data（\>=0\.12\.0 \<1\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。它还提供命令行工具 iam-expand，可以用 npx iam-expand 直接运行。

### @cloud-copilot/iam-expand 支持 TypeScript 吗？

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

### @cloud-copilot/iam-expand 支持 ESM 还是 CommonJS？

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

### @cloud-copilot/iam-expand 可以商用吗？

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

### @cloud-copilot/iam-expand 的下载量有多少？

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

### @cloud-copilot/iam-expand 还在维护吗？

最新版本 0\.11\.82 发布于 2026/08/29（2 个月前）；至今共发布 108 个版本，其中过去 12 个月发布了 42 个；首次发布于 2024/09/01。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

