Git Product home page Git Product logo

Comments (2)

joshfried-aws avatar joshfried-aws commented on August 17, 2024

Hey @Aaron-Garrett I think i was able to come up with a rule to help you with this specific use case. I think one issue with the logic in your original rule was to do with the way if intrinsic functions is mapped to their json equivalent..

In this case your first if function maps to this in json format

{
    "Fn::If": [
        "CreateDevRole",
        {
            "Fn::Sub": "arn:aws:iam::${AWS::AccountId}:policy/aws-allowed-policies"
        },
        {
            "Ref": "AWS::NoValue"
        }
    ]
}

It's important to note here when evaluating this mapped if function that youre comparing a value (in this case a list where some elements are strings, some elements are maps/structs) to an array of regex. This will always pass in this case due to the contents of the list.

Heres the rule, i have added some comments to help clear things up

let aws_iam_entities_no_managed_policy = Resources.*[
  Type in [ /AWS::IAM::User/,
            /AWS::IAM::Role/,
            /AWS::IAM::Group/ ]
  Metadata.guard.SuppressedRules not exists or
  Metadata.guard.SuppressedRules.* != "IAM_ONLY_ALLOW_ManagedPolicies"
]

let INVALID_VALUES = [/(?i)\/AWS/, /(?i)\/VMImportExportRoleForAWSConnector/]

rule IAM_ONLY_ALLOW_ManagedPolicies when %aws_iam_entities_no_managed_policy !empty {
  let managed_policy_arns = %aws_iam_entities_no_managed_policy.Properties.ManagedPolicyArns

  when %managed_policy_arns !empty {
    check(%managed_policy_arns)
  }
}


rule check(curr) {
    # if is string, we can do direct comparison to the list of strings/regex
    when %curr is_string {
        %curr NOT IN %INVALID_VALUES
    }


    # if is_list or is_struct iterate and check each individual value
    when %curr is_list OR %curr is_struct{
        %curr.* {
            check(this)
        }
    }
}

I hope this was helpful to you, please let me know if you have anymore questions.

from cloudformation-guard.

joshfried-aws avatar joshfried-aws commented on August 17, 2024

Hey @Aaron-Garrett just checking in to see if the information I provided was enough to help you resolve your issue here.

Please let us know if you need anymore help on this issue

from cloudformation-guard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.