OneLinersCommand workbench
AI
Back to skills
SKILL.md

Cloud IAM policy reviewer

An evidence-first workflow to identify unintended permissions and privilege-escalation paths in cloud access policy.

Revision
2
Verified
2026-10-20
Save or explore
Save to collectionCreate a collection in the sidebar first.

Compatibility and paths

Codexskills/iam-policy-review/SKILL.md
Claude Code.claude/skills/iam-policy-review/SKILL.md
VS Code.github/skills/iam-policy-review/SKILL.md

Trust and provenance

Curated record reviewed 2026-10-20. Results still depend on the supplied context and target environment.

Generated assetReady to copy or download
---
name: iam-policy-review
description: Reviews a named principal's required actions, resource scope and surrounding policy inventory. Use before a cloud permission change; distinguish an identity-policy match from an effective provider decision and reject missing policy context.
license: CC-BY-4.0
compatibility: Complete closed S3 teaching exercise uses Node.js 22.13+ only, no cloud account or credentials. It is not an AWS simulator. Real policy inspection/testing requires separately authorized read/test permissions.
metadata:
  author: oneliners
  version: "2.0.0"
---

# Cloud IAM policy reviewer

## Inventory authority before reading a single Allow
Record provider/account, exact user/role/session principal, identity attachments, resource/trust policies, boundaries, session and organization guardrails, service-specific controls and request context. Mark missing inventory explicitly. Pair required allowed operations with prohibited cases and the relevant resource/condition keys. An identity policy copied from a ticket is not a complete effective-permissions report.

## Complete bounded S3 example
The example uses a fictional IAM user in one account and explicitly assumes no other policies/controls in its closed teaching case. These assumptions are not facts about an AWS account. The user reads already known red/ keys, never lists a bucket and cannot read red/restricted/. All policy JSON, requests and context are included below.

Save as iam-review.mjs and run node iam-review.mjs with Node.js 22.13+. It reads no credentials or files, contacts no service and changes no permissions. It is a deliberately small comparison exercise: unsupported IAM syntax or incomplete context returns UNKNOWN instead of a misleading permit/deny.

```js
import assert from "node:assert/strict";
const closedIamContext = {
  "sameAccount": true,
  "principalType": "iam-user",
  "identityPoliciesComplete": true,
  "resourcePolicies": "none",
  "boundary": "none",
  "sessionPolicy": "none",
  "organizationPolicies": "none",
  "otherServiceControls": "none"
};
const iamPolicyBefore = {
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadTooWide",
      "Effect": "Allow",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-reports/*"
    },
    {
      "Sid": "ListOnWrongResource",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::amzn-s3-demo-reports/*"
    },
    {
      "Sid": "ProtectedStillDenied",
      "Effect": "Deny",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-reports/red/restricted/*"
    }
  ]
};
const iamPolicyAfter = {
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "KnownKeysOnly",
      "Effect": "Allow",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-reports/red/*"
    },
    {
      "Sid": "ProtectedStillDenied",
      "Effect": "Deny",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-reports/red/restricted/*"
    }
  ]
};
function evaluateClosedIam(policy, request, context) {
  const unknown = (reason) => ({ decision: "UNKNOWN", reason });
  for (const [key, value] of Object.entries(closedIamContext)) if (context?.[key] !== value) return unknown("Incomplete or unsupported policy/principal context: " + key);
  if (!policy || policy.Version !== "2012-10-17" || !Array.isArray(policy.Statement) || Object.keys(policy).some((key) => !["Version", "Statement", "Id"].includes(key))) return unknown("Unsupported policy document");
  const supportedAction = (action) => typeof action === "string" && ["s3:getobject", "s3:listbucket"].includes(action.toLowerCase());
  const array = (value) => Array.isArray(value) ? value : [value];
  const resourcePattern = (value) => typeof value === "string" && (value === "*" || (/^arn:aws:s3:::[^?${}]+$/.test(value) && !value.slice(0, -1).includes("*")));
  if (!supportedAction(request?.action) || typeof request?.resource !== "string" || !/^arn:aws:s3:::[^*?${}]+$/.test(request.resource)) return unknown("Unsupported request");
  const objectResource = request.resource.slice("arn:aws:s3:::".length).includes("/");
  if ((request.action.toLowerCase() === "s3:getobject") !== objectResource) return unknown("Unsupported action/resource type pair");
  for (const statement of policy.Statement) {
    if (!statement || Object.keys(statement).some((key) => !["Sid", "Effect", "Action", "Resource"].includes(key)) || !["Allow", "Deny"].includes(statement.Effect) || !array(statement.Action).length || !array(statement.Action).every(supportedAction) || !array(statement.Resource).length || !array(statement.Resource).every(resourcePattern)) return unknown("Unsupported statement; do not ignore conditions, principals or other IAM syntax");
  }
  const matchResource = (pattern, resource) => pattern === "*" || (pattern.endsWith("*") ? resource.startsWith(pattern.slice(0, -1)) : pattern === resource);
  const matches = policy.Statement.filter((statement) => array(statement.Action).some((action) => action.toLowerCase() === request.action.toLowerCase()) && array(statement.Resource).some((pattern) => matchResource(pattern, request.resource)));
  if (matches.some((statement) => statement.Effect === "Deny")) return { decision: "EXPLICIT_DENY", statements: matches.filter((statement) => statement.Effect === "Deny").map((statement) => statement.Sid) };
  if (matches.some((statement) => statement.Effect === "Allow")) return { decision: "IDENTITY_ALLOW_IN_CLOSED_FIXTURE", statements: matches.filter((statement) => statement.Effect === "Allow").map((statement) => statement.Sid) };
  return { decision: "IMPLICIT_DENY_IN_CLOSED_FIXTURE", statements: [] };
}
function runIamLab() {
  const requests = [
    ["known red key", { action: "s3:GetObject", resource: "arn:aws:s3:::amzn-s3-demo-reports/red/report.json" }],
    ["other prefix", { action: "s3:GetObject", resource: "arn:aws:s3:::amzn-s3-demo-reports/blue/report.json" }],
    ["protected key", { action: "s3:GetObject", resource: "arn:aws:s3:::amzn-s3-demo-reports/red/restricted/private.json" }],
    ["bucket listing", { action: "s3:ListBucket", resource: "arn:aws:s3:::amzn-s3-demo-reports" }],
  ];
  const rows = requests.map(([name, request]) => ({ name, before: evaluateClosedIam(iamPolicyBefore, request, closedIamContext).decision, after: evaluateClosedIam(iamPolicyAfter, request, closedIamContext).decision }));
  assert.deepEqual(rows.map((row) => row.before), ["IDENTITY_ALLOW_IN_CLOSED_FIXTURE", "IDENTITY_ALLOW_IN_CLOSED_FIXTURE", "EXPLICIT_DENY", "IMPLICIT_DENY_IN_CLOSED_FIXTURE"]);
  assert.deepEqual(rows.map((row) => row.after), ["IDENTITY_ALLOW_IN_CLOSED_FIXTURE", "IMPLICIT_DENY_IN_CLOSED_FIXTURE", "EXPLICIT_DENY", "IMPLICIT_DENY_IN_CLOSED_FIXTURE"]);
  assert.equal(evaluateClosedIam(iamPolicyBefore, requests[0][1], { ...closedIamContext, resourcePolicies: "not inventoried" }).decision, "UNKNOWN");
  const conditionPolicy = structuredClone(iamPolicyBefore); conditionPolicy.Statement[0].Condition = { StringEquals: { "aws:PrincipalTag/team": "red" } };
  assert.equal(evaluateClosedIam(conditionPolicy, requests[0][1], closedIamContext).decision, "UNKNOWN");
  return { rows, missingResourcePolicyInventory: "UNKNOWN", unsupportedCondition: "UNKNOWN", scope: "Literal/suffix-prefix comparisons in a declared closed teaching case, not AWS IAM simulation or live access." };
}
console.log(JSON.stringify(runIamLab(), null, 2));
```

## Worked scope review and preserved negative case
Declared requirement: this fictional IAM user reads known object keys below red/, excluding red/restricted/. It does not need listing, writes or other prefixes. The initial ReadTooWide statement also matches blue/report.json, so it exceeds that identity-policy requirement. ProtectedStillDenied still explicitly denies the restricted key despite a matching allow. ListOnWrongResource uses object ARNs, while the bucket-list request names the bucket ARN; it does not grant that request in this closed case.

The candidate restricts the known-key read to red/*, retains the explicit restricted-key deny and removes unnecessary listing rather than adding a broad bucket grant. The four rows now show: intended read still identity-allowed; blue prefix implicitly denied; restricted key explicitly denied; listing still implicitly denied. These outcomes are calculated from the included documents and explicit fictional context, not observed AWS decisions.

The program refuses to call a request allowed when resource-policy inventory is missing, and refuses to approximate a Condition it does not implement: both return UNKNOWN. It intentionally supports only the two exact S3 actions, literal ARNs/a final resource wildcard and allow/deny statements. It is not an IAM language implementation. Identity/resource policy combinations, principal types, boundaries, session/organization policies, conditions, KMS and service controls need the actual provider evaluation rules. A resource policy grant to a user or session can change how an implicit deny applies; never generalize this fixture's identity-only intersection to all AWS principals.

Real handoff: exact account/principal/session and attachment inventory; required action/resource/context matrix; named overgrant and retained positive case; service-specific resource/condition review; bounded authorized policy simulation and owned live positive/negative verification where appropriate; residual limitations and rollback owner. No AWS CLI, credentials, network request, policy attachment or permission modification occurred. Passing a simulator alone is not proof an application is correctly authorized or that every live service condition was represented.

## Verify provider behavior separately
Use [AWS policy evaluation documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic_policy-eval-denyallow.html), the [S3 policy resource/action model](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-policy-language-overview.html) and [IAM simulator limitations](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html) for the actual principal/service. Do not add a wildcard Allow just because a test is denied. Inspect dependent permissions, resource policy/trust, exact condition values and evaluation scope before recommending a minimal change. Restricting this one identity document does not repair a different overbroad resource grant.

## Acceptance and stop conditions
Return principal/policy versions, required and prohibited request matrix, confirmed statement/resource mismatch, candidate diff, actual provider test evidence, residual risk and owner. Preserve needed access while verifying removed authority. Missing attachments/context, unsupported conditions or an unreviewed escalation chain must stay UNKNOWN. Review does not authorize attaching policies, assuming new roles, creating credentials or testing another tenant/account. This exercise is not OneLiners infrastructure and establishes no production vulnerability or cloud access.

Real example

Input

Review the complete closed S3 IAM example in SKILL.md: known red/ keys only, restricted/ denied, no listing requirement. Compare all four request rows, retain the intended read, and show why missing policy inventory or an unsupported Condition must stay UNKNOWN. Do not contact AWS or change permissions.

Expected result

Declared requirement: this fictional IAM user reads known object keys below red/, excluding red/restricted/. It does not need listing, writes or other prefixes. The initial ReadTooWide statement also matches blue/report.json, so it exceeds that identity-policy requirement. ProtectedStillDenied still explicitly denies the restricted key despite a matching allow. ListOnWrongResource uses object ARNs, while the bucket-list request names the bucket ARN; it does not grant that request in this closed case.

The candidate restricts the known-key read to red/*, retains the explicit restricted-key deny and removes unnecessary listing rather than adding a broad bucket grant. The four rows now show: intended read still identity-allowed; blue prefix implicitly denied; restricted key explicitly denied; listing still implicitly denied. These outcomes are calculated from the included documents and explicit fictional context, not observed AWS decisions.

The program refuses to call a request allowed when resource-policy inventory is missing, and refuses to approximate a Condition it does not implement: both return UNKNOWN. It intentionally supports only the two exact S3 actions, literal ARNs/a final resource wildcard and allow/deny statements. It is not an IAM language implementation. Identity/resource policy combinations, principal types, boundaries, session/organization policies, conditions, KMS and service controls need the actual provider evaluation rules. A resource policy grant to a user or session can change how an implicit deny applies; never generalize this fixture's identity-only intersection to all AWS principals.

Real handoff: exact account/principal/session and attachment inventory; required action/resource/context matrix; named overgrant and retained positive case; service-specific resource/condition review; bounded authorized policy simulation and owned live positive/negative verification where appropriate; residual limitations and rollback owner. No AWS CLI, credentials, network request, policy attachment or permission modification occurred. Passing a simulator alone is not proof an application is correctly authorized or that every live service condition was represented.

Source evidence

Agent Skills specificationofficialAWS IAM best practicesofficialAWS IAM policy evaluation — principal-specific allow/deny rulesofficialAmazon S3 policy resources and actionsofficialAWS IAM policy simulator scope and limitationsofficial