扩展 IAM 动作
由Unix哲学所建,这是一个小工具,能很好地做一件事:用通配符来解释IAM动作.
用于:
- 在您的政策中不允许使用通配符时, 扩展通配符 .
- 获得一份详尽清单,列出列入一项政策的行动,以便迅速寻找有意义的行动.
- 调查你的政策中 哪些行为有趣或可疑.
扩展演示 在YouTube上的发言。 。 。 .
发表于 npm 软件包 在无害环境管理和共同jS中加上作为 国 际。 。 。 .
所有信息来源于 @cloud-copilot/iam-data (英语) 每日更新.
只有有效值
iam-expand 如果任何无效的值以无效格式或不存在的服务/行动等形式传递,那么它们将被排除在输出之外。 有可以推翻这种行为的选项.
在浏览器中使用
http://iam.cloudcopilot.io/tools/iam-expansed (中文(简体) )
国 际
有一个CLI! 这个 示例文件夹 有实例显示如何利用CLI在您的IAM政策中找到有趣的行动.
全球CLI安装
你可以在全球安装 这在默认的 AWS CloudShell 中也是有效的!
npm install -g @cloud-copilot/iam-expand
根据您的配置, 可能需要在全球安装 sudo .
安装 CLI 在一个项目中
您也可以在工程中安装 CLI 并使用 npx。 。 。 .
npm install @cloud-copilot/iam-expand
# Run with npx inside your project
npx @cloud-copilot/iam-expand
扩展动作
最简单的用法是在您想要扩展的动作中通过.
iam-expand s3:Get*Tagging
# Outputs all Get*Tagging actions
s3:GetBucketTagging
s3:GetJobTagging
s3:GetObjectTagging
s3:GetObjectVersionTagging
s3:GetStorageLensConfigurationTaggin
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
倒转动作
使用此选项查找所有未在一组模式中的动作
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
...
帮助
在没有选项的情况下运行命令以显示用途 :
iam-expand
选项
--expand-asterisk
默认情况下,一个 * 将不扩大。 如果你想扩展一个单曲 * 您可以设置此旗帜.
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*(分离器太多)
它将被默默地忽略 并被忽略在输出。 如果您想要在通过无效格式时出错, 您可以设置此旗帜 .
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数据中不存在的某个服务被传递,则会默默地被忽略并被忽略出输出. 如果您想要在服务通过时丢出一个不存在的错误, 您可以设置此旗帜 .
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。 。 。 .
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的无结构内容.
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 动作或模式.
cat policy.json | iam-expand --invert-not-actions
见 从 Stdin 读取 详情
--show-data-version
显示用于扩展动作和退出的数据的版本.
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读取时( 见 下级) CLI将等10秒后第一个字节被读取后再计时出局. 这为大多数行动提供了足够的时间。 如果您想要等待更长的时间, 您可以设置此旗帜为您想要等待的毫秒 .
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
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:Get*Tagging",
"Resource": "*"
},
{
"Effect": "Deny",
"NotAction": ["s3:Get*Tagging", "s3:Put*Tagging"],
"Resource": "*"
}
]
}
cat policy.json | iam-expand > expanded-policy.json
将此文件输入 expanded-policy.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。 。 。 .
cat policy.json | iam-expand --invert-not-actions > inverted-policy.json
将此文件输入 inverted-policy.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": "*"
}
]
}
您也可以使用它来从命令输出中扩展动作.
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动作,然后扩展. 抛出任何东西,它会找到一切它能做的动作,并扩展它们.
您可以回声内容 :
echo "s3:Get*Tagging" | iam-expand
你可以抽出Json文件的一部分 把它吸进去:
cat policy.json | jq '.Statement[].Action' | iam-expand
或一些地平线:
cat main.tf | iam-expand
或有出云法门:
cat template.yaml | iam-expand
甚至是一些 HTML:
curl "https://docs.aws.amazon.com/aws-managed-policy/latest/reference/ReadOnlyAccess.html" | iam-expand
或任何命令的输出.
因为有可能找到一个异教徒 * 在输入中; 如果 stdin 的值不是有效的 json 文档, stdin 选项将找不到或扩展一个 * 即便 --expand-asterisk 通过.
如果有改进的机会,请给它任何你能想到的东西,并打开一个问题.
类型/节点JS 使用量
添加到项目中
npm install @cloud-copilot/iam-expand
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。 。 。 .
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。 。 。 .
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。 。 。 .
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。 。 。 .
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。 。 。 .