Detection rules › Panther

AWS IAM Policy Role Mapping

Severity
high
Tags
AWS, Configuration Required, Identity & Access Management
Reference
https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html
Source
github.com/panther-labs/panther-analysis

This policy validates that policies that have been explicitly configured to be set to certain roles are still attached to those roles.

Rule body yaml

AnalysisType: policy
Filename: aws_iam_policy_role_mapping.py
PolicyID: "AWS.IAM.Policy.RoleMapping"
DisplayName: "AWS IAM Policy Role Mapping"
Enabled: false
ResourceTypes:
  - AWS.IAM.Policy
Tags:
  - AWS
  - Configuration Required
  - Identity & Access Management
Severity: High
Description: >
  This policy validates that policies that have been explicitly configured to be set to certain roles are still attached to those roles.
Runbook: >
  https://docs.runpanther.io/alert-runbooks/built-in-policies/aws-iam-policy-role-mapping-is-respected
Reference: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html
Tests:
  - Name: Policy Applied To Required Roles
    ExpectedResult: true
    Resource:
      {
        "Arn": "arn:aws:iam::123456789012:policy/service-role/example-policy",
        "AttachmentCount": 2,
        "CreateDate": "2019-01-01T00:00:00Z",
        "DefaultVersionId": "v1",
        "Description": null,
        "Entities":
          {
            "PolicyGroups": null,
            "PolicyRoles":
              [
                { "RoleId": "ABCDEFGHIJKLMNOP1", "RoleName": "TestRole1" },
                { "RoleId": "ABCDEFGHIJKLMNOP2", "RoleName": "TestRole2" },
              ],
            "PolicyUsers":
              [{ "UserId": "ABCDEFGHIJKLMNOP", "UserName": "Bobert" }],
          },
        "IsAttachable": true,
        "Path": "/service-role/",
        "PermissionsBoundaryUsageCount": 0,
        "PolicyDocument": "JSON policy document see https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html for details",
        "PolicyId": "ABCDEFGHIJKLMNOP",
        "PolicyName": "TestPolicyName",
        "UpdateDate": "2019-01-01T00:00:00Z",
      }
  - Name: Policy Does Not Have Role Mappings
    ExpectedResult: true
    Resource:
      {
        "Arn": "arn:aws:iam::123456789012:policy/service-role/example-policy",
        "AttachmentCount": 2,
        "CreateDate": "2019-01-01T00:00:00Z",
        "DefaultVersionId": "v1",
        "Description": null,
        "Entities":
          {
            "PolicyGroups": null,
            "PolicyRoles":
              [{ "RoleId": "ABCDEFGHIJKLMNOP", "RoleName": "Example-Role" }],
            "PolicyUsers":
              [{ "UserId": "ABCDEFGHIJKLMNOP", "UserName": "Bobert" }],
          },
        "IsAttachable": true,
        "Path": "/service-role/",
        "PermissionsBoundaryUsageCount": 0,
        "PolicyDocument": "JSON policy document see https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html for details",
        "PolicyId": "ABCDEFGHIJKLMNOP",
        "PolicyName": "Example-Policy",
        "UpdateDate": "2019-01-01T00:00:00Z",
      }
  - Name: Policy Not Applied To Required Roles
    ExpectedResult: false
    Resource:
      {
        "Arn": "arn:aws:iam::123456789012:policy/service-role/example-policy",
        "AttachmentCount": 2,
        "CreateDate": "2019-01-01T00:00:00Z",
        "DefaultVersionId": "v1",
        "Description": null,
        "Entities":
          {
            "PolicyGroups": null,
            "PolicyRoles":
              [{ "RoleId": "ABCDEFGHIJKLMNOP", "RoleName": "Example-Role" }],
            "PolicyUsers":
              [{ "UserId": "ABCDEFGHIJKLMNOP", "UserName": "Bobert" }],
          },
        "IsAttachable": true,
        "Path": "/service-role/",
        "PermissionsBoundaryUsageCount": 0,
        "PolicyDocument": "JSON policy document see https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html for details",
        "PolicyId": "ABCDEFGHIJKLMNOP",
        "PolicyName": "TestPolicyName",
        "UpdateDate": "2019-01-01T00:00:00Z",
      }
  - Name: Policy Not Applied to Anything
    ExpectedResult: true
    Resource:
      {
        "Arn": "arn:aws:iam::123456789012:policy/service-role/example-policy",
        "AttachmentCount": 2,
        "CreateDate": "2019-01-01T00:00:00Z",
        "DefaultVersionId": "v1",
        "Description": null,
        "Entities": null,
        "IsAttachable": true,
        "Path": "/service-role/",
        "PermissionsBoundaryUsageCount": 0,
        "PolicyDocument": "JSON policy document see https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html for details",
        "PolicyId": "ABCDEFGHIJKLMNOP",
        "PolicyName": "Example-Policy",
        "UpdateDate": "2019-01-01T00:00:00Z",
      }

Detection logic

Condition

not (Entities.PolicyRoles is_not_null and PolicyName not in "TestPolicyName")

This rule also runs imperative logic the parser cannot express as a filter; the conditions above are the structured part it could extract.

Exclusions

Top-level NOT(...) conjuncts: predicates this rule actively suppresses.

FieldKindExcluded values
PolicyNameeqTestPolicyName
Entities.PolicyRolesis_not_null(no value, null check)

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
PolicyNamein
  • TestPolicyName