Fix the wildcard audit for generated IAM policies

Review the AI's codeEasy10 minAmazon style

Your task

You asked an AI to let a Lambda read one config file from S3. It wrote an IAM statement that allows the action s3:* on the resource *: every S3 action on every bucket in the account. A security review flagged it. Your team now audits each generated IAM statement for wildcards before it merges.

An assistant wrote audit_policy_statements(actions, resources). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • actions: the action of each statement, such as s3:GetObject, as a string.
  • resources: the resource of the statement at the same index, such as arn:aws:s3:::my-bucket/config.json, as a string.
  • Return a list of strings, one verdict per statement, in statement order.

Rules the tests check:

  • The number of statements is the length of the shorter list. Extra entries in the longer list are ignored.
  • An action is a wildcard when it contains * anywhere. A resource is a wildcard when it contains * anywhere. An empty string is not a wildcard.
  • The verdict is:
    • "both_wildcard" when the action and the resource are both wildcards.
    • "action_wildcard" when only the action is a wildcard.
    • "resource_wildcard" when only the resource is a wildcard.
    • "ok" when neither is.

Examples

audit_policy_statements(actions: list[str], resources: list[str]) -> list[str]
Example 1
Inputaudit_policy_statements(["s3:*"], ["*"])
Output["both_wildcard"]
Example 2
Inputaudit_policy_statements(["s3:GetObject"], ["arn:aws:s3:::my-bucket/config.json"])
Output["ok"]