Kiểm tra và giải thích AWS IAM policy API
Lint và giải thích AWS IAM policy: mở rộng wildcard thành action thật, kiểm tra ARN và condition key, cảnh báo quyền admin, PassRole, leo thang đặc quyền.
Gửi identity-based policy, resource-based policy (S3 bucket, KMS, SQS…), trust policy của role hoặc SCP (tự nhận diện, hoặc đặt type). Danh mục khoảng 460 dịch vụ và 22.500 action kèm mức truy cập, loại tài nguyên (định dạng ARN) và condition key lấy từ AWS Service Authorization Reference, cập nhật hằng tuần. Không gửi gì tới AWS và không cần thông tin đăng nhập.
Lint (action=lint, cũng nằm trong chế độ mặc định analyze): cú pháp (Version, Effect, Action / NotAction, Resource / NotResource, Principal theo loại policy, Sid), dịch vụ và action không tồn tại kèm gợi ý "did you mean", wildcard không khớp action nào, cú pháp ARN, action có loại tài nguyên không khớp Resource nào (lỗi kinh điển: s3:GetObject trên arn:aws:s3:::bucket thiếu /*), action chỉ chạy với Resource "*", toán tử điều kiện, condition key sai hoặc không được hỗ trợ, kiểu giá trị, ForAllValues với Allow, quyền admin *, wildcard cả dịch vụ, Allow + NotAction / NotResource, iam:PassRole trên "*", 27 con đường leo thang đặc quyền đã biết, principal công khai và trust federated không có điều kiện, giới hạn kích thước.
Explain (action=explain) liệt kê từng statement với các action đã mở rộng và mức truy cập (List / Read / Write / Permissions management / Tagging), tài nguyên, principal và điều kiện, kèm tổng hợp theo dịch vụ. action=minimize viết lại các statement Allow thành danh sách action cụ thể, lọc theo access_levels (ví dụ list,read) và / hoặc actions_used (từ CloudTrail hoặc IAM Access Analyzer).
Markdown · OpenAPI · Postman · llms.txt
Tham số
| Tên | Vị trí | Kiểu | Bắt buộc | Mặc định | |
|---|---|---|---|---|---|
policy | body | object | có | JSON của policy (object hoặc chuỗi; tối đa 200 KB). | |
action | body|query | string | không | analyze | analyze (lint + explain), lint, explain hoặc minimize (tên khác mode). |
type | body|query | string | không | identity, resource, trust hoặc scp (mặc định: tự nhận diện). | |
max_actions | body|query | number | không | 200 | Số action mở rộng liệt kê mỗi statement. |
access_levels | body|query | string | không | minimize: chỉ giữ các mức này, ví dụ list,read. | |
actions_used | body | array | không | minimize: các action thực sự dùng (ví dụ từ CloudTrail). |
Ví dụ
curl -X POST "https://apibox.io.vn/v1/iam-policy" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"action":"lint","policy":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:GetObject","s3:ListBucket"],"Resource":"arn:aws:s3:::my-bucket"},{"Effect":"Allow","Action":"iam:PassRole","Resource":"*"}]}}'const res = await fetch('https://apibox.io.vn/v1/iam-policy', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"action": "lint",
"policy": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::my-bucket"
},
{
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "*"
}
]
}
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/iam-policy",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"action": "lint", "policy": {"Version": "2012-10-17", "Statement": [{"Effect": "Allow", "Action": ["s3:GetObject", "s3:ListBucket"], "Resource": "arn:aws:s3:::my-bucket"}, {"Effect": "Allow", "Action": "iam:PassRole", "Resource": "*"}]}},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/iam-policy');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"action":"lint","policy":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:GetObject","s3:ListBucket"],"Resource":"arn:aws:s3:::my-bucket"},{"Effect":"Allow","Action":"iam:PassRole","Resource":"*"}]}}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Kết quả trả về
{
"valid": true,
"errors": 0,
"warnings": 2,
"info": 0,
"summary": {
"type": "identity",
"statements": 2,
"allow_all": false,
"allowed_actions": 3,
"services": {
"iam": {
"Write": 1
},
"s3": {
"List": 1,
"Read": 1
}
}
},
"findings": [
{
"rule": "resource-mismatch",
"severity": "warning",
"message": "No Resource of this statement matches the resource types of s3:GetObject (object actions need arn:aws:s3:::bucket/*, bucket actions arn:aws:s3:::bucket): this action is never granted",
"statement": 0
},
{
"rule": "passrole-wildcard",
"severity": "warning",
"message": "iam:PassRole on Resource \"*\": the principal can hand any role (incl. admin roles) to a service; restrict Resource to specific role ARNs and add an iam:PassedToService condition",
"statement": 1
}
],
"source": {
"name": "AWS Service Authorization Reference (servicereference.us-east-1.amazonaws.com)",
"licence": "CC BY-SA 4.0 (AWS documentation)",
"url": "https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html"
},
"data_built": "2026-11-16"
}
Ứng dụng
- Review IAM policy trong pull request Terraform / CloudFormation
- Xem s3:Get* hay ec2:Describe* thực sự cấp những quyền gì trước khi duyệt
- Biến policy dùng wildcard thành policy chỉ đọc theo quyền tối thiểu
- Rà soát tài khoản khách hàng tìm trust policy công khai và đường leo thang quyền
Hỏi đáp
Có gọi tới AWS không?
Không. Phân tích offline theo Service Authorization Reference đã công bố; chỉ cần gửi JSON của policy.
Danh sách action có mới không?
Được dựng lại hằng tuần từ dữ liệu máy đọc của AWS; trường data_built trong kết quả cho biết ngày.
Kết quả quyền hiệu lực có chính xác tuyệt đối không?
Chỉ là ước lượng: chỉ trừ các statement Deny không điều kiện trên "*", và không biết permission boundary / SCP của tài khoản.
API liên quan
Tạo mã hash
Tính MD5, SHA-1, SHA-256, SHA-384, SHA-512 và CRC32 của chuỗi hoặc file trong một lần gọi, xuất hex hoặc base64, hỗ trợ ký HMAC.
B64Mã hoá / Giải mã
Mã hoá hoặc giải mã chuỗi sang Base64, Base64URL, hex, URL encode, HTML entity, Unicode escape, ROT13 hay nhị phân chỉ với một lần gọi API.
***Tạo mật khẩu
Tạo mật khẩu ngẫu nhiên an toàn bằng CSPRNG (4–256 ký tự, tối đa 100 cái mỗi lần) hoặc kiểm tra độ mạnh, entropy và thời gian bẻ khoá của mật khẩu.