-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does Cfn_nag traverse Global section of SAM tempaltes? #141
Comments
If the tags are placed in Global section the rules fails as expected. Can we make rules check global section? |
Honestly, I'm not sure. the SAM support was added recently without me taking a careful look. Will try to look tonight or tomorrow and see where things are at. |
Thank you for your reply. I am aware SAM support is new so i'm running my tests against cloudformation created from SAM template by aws cloudformation package command. I am not running tests against SAM template directly. In converted export-template.yml cloudformation file Global section appears like this.
|
Ok, so if you are developing your own rule, and operating against the template you just posted (with a Globals key), you can write a rule that runs against the "raw" model of the cfn template. Globals isn't "processed" by the cfn-model objects..... but you can access the Hash from the direct parse of the yaml inside your rule and make a decision on your own about what to do. There's nothing wrong with directly accessing the Hash, but where cfn-model provides "support" - there is typically a better abstraction that simplifies the rule and allows it to ignore missing properties and issues with multiplicity. An example of accessing the "raw" model is here:
|
Consult the code here: the serverless transform object in cfn-model is consulting Globals for a few properties - the code, runtime, handler, etc. to finish this issue, we can generalize to cover all the Globals |
… parsing and adding validation test.
Hi,
Sorry to bother you.
I created a rule to make Tags mandatory for Lambda Functions however my rule doesn't check Global section of SAM template. Does Cfn_nag support this kind of check?
###LambdaFunctionTaggingMandatoryRule###
require 'cfn-nag/violation'
require 'cfn-nag/custom_rules/base'
class LambdaFunctionTaggingMandatoryRule < BaseRule
def rule_text
'Lambda Function is missing tags, please add tags to Lambda Function'
end
def rule_type
Violation::FAILING_VIOLATION
end
def rule_id
'F8000'
end
def audit_impl(cfn_model)
violating_lambdas = cfn_model.resources_by_type('AWS::Lambda::Function').select do |lambda_function|
lambda_function.tags.nil?
end
end
end
The text was updated successfully, but these errors were encountered: