Repository navigation
Conversation
d84b19c to
07d524b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4655 +/- ##
==========================================
+ Coverage 94.67% 94.78% +0.10%
==========================================
Files 435 439 +4
Lines 15584 15805 +221
Branches 3021 3055 +34
==========================================
+ Hits 14754 14980 +226
+ Misses 453 450 -3
+ Partials 377 375 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bf651b1 to
0494029
Compare
|
Always great to see AWS IaC devs contribute to cfn-lint! Would this be information that can contribute to an LLM context? This RFC aws/aws-cdk-rfcs#981 seems to be more of a CDK change. |
Agreed @r-heimann . I think we're leaning towards defaulting to disabling this for YAML completely, or disabling when we see any YAML comments. Do you see any issue with leaving it enabled for JSON?
Yes that's the intent. We'll update the PR description soon with more context (pun intended). |
I never really used the JSON version of CloudFormation, but i think it doesn't support something like JSONC so it may be a good idea to include it.
Got it, thank you |
|
On severity + default enablement The bigger risk here is the blast radius at Warning + on-by-default. Severity letter alone isn't quite the lever people expect: dropping to Suggestion: ship this family as experimental +
Both gates are silent by default, so no pipeline breaks. Teams adopting Context opt in explicitly. Graduation path: drop |
0494029 to
4f9a56a
Compare
b1e1441 to
90d2700
Compare
Thank you for the feedback. Updated this PR so that the missing context rule is informational instead of warning. We will keep the other two rules as warnings, since it flags invalid syntax and will only flag if the context is already present in the template. Also, added the rules only in the experimental section for now. What would the graduation path and "stabilization" look like? These metadata contexts are already released to the public |
| @@ -1,4 +1,31 @@ | |||
| [ | |||
| { | |||
There was a problem hiding this comment.
These test fixtures use the experimental mode and need to account for the new rules
2d684cb to
32acbfb
Compare
|
Follow-up on the CDK skip: Rather than carry two definitions that can drift, should we push the Separate, non-blocking thought: since the Context rules validate per-resource, is there appetite for a per-resource |
d7f6175 to
d0182f2
Compare
For the per-resource note, we decided that for now we'll go with the all-or-nothing approach until at least the rule is out of experimental. There isn't much appetite for mixed template validation at the moment |
Summary
Three new experimental rules that check for structured design context (
Metadata["com.aws.cloudformation.Context"]) on CloudFormation templates and resources. All three are off by default; their severities differ by intent (see Severity):whyrationale (and no reduced-confidencetrustblock)Severity
The severity split follows what triggers each rule:
continuewhen no block is present). The author opted in, and the block is then incomplete (W4011, nowhy) or invalid against the schema (W4012). A supplied-but-broken block is a real defect in something the author chose to write, so it warrants a warning rather than an info note.E. Per project convention, errors are reserved for problems that fail a CloudFormation deployment. Context metadata is documentation and never blocks a deploy.Numbering is intentionally left as
I4010/W4011/W4012(the rule number and severity prefix are independent in cfn-lint). If maintainers prefer a contiguous prefix, these can be renumbered.Off by default
All three rules are
experimental=True, so a defaultcfn-lintrun emits nothing and exits 0 — the experimental gate blocks them regardless of severity.Enablement then differs by severity:
--include-experimentaland--include-checks I.--include-experimental— warnings are already in cfn-lint's default check set, so no--include-checksis needed once experimental rules are included.Verified end-to-end:
--include-experimentalalone: W4011/W4012 fire on a supplied-but-invalid Context block; I4010 stays silent--include-experimental --include-checks I: all three activeSchema
The
context.jsonschema matches the published CloudFormation Metadata Context schema:why,must,mutable,mutability,trust,deps(additionalProperties: false)arch,must,ref,owner(additionalProperties: false)src(required),conf(required),cite,noteResource selection
I4010 uses a significance gate -- not every resource is required to carry context:
LogRetention,framework-onEvent/isComplete/onTimeout), and theAwsCustomResourceprovider singleton. CDK's own context aspect (aws/aws-cdk#38381) deliberately skips these resources, so they arrive in the synthesized template without context by design. The pattern set approximates by naming convention a distinction CDK draws structurally viadefaultChild. It is not exhaustive --BucketDeploymenthandlers and others are not matched.lambdaPurposeis the axis to extend along. Users can extend per-run viaadditional_incidental_patterns.AWS::Logs::LogGroup,AWS::Logs::LogStream,AWS::IAM::Policy,AWS::S3::BucketPolicy,AWS::SNS::TopicPolicy,AWS::SQS::QueuePolicy,AWS::Lambda::Permission. Resource policies and permission grants are exempt because the policy body is the rationale and the template already contains it.AWS::IAM::RoleandAWS::IAM::ManagedPolicyare deliberately kept -- both have real hand-authored forms wherewhyadds value. Users can extend viaadditional_low_value_types.*::MODULE) are excluded: the resources they expand to live in the registered module body, so architectural significance cannot be determined from the Type.CDK templates
CDK-synthesized templates are out of scope: all three rules return no findings when a CDK marker is present (
AWS::CDK::Metadata, theCDKMetadatalogical ID, or any resource carryingaws:cdk:path). The author wrote L2/L3 constructs, not raw CloudFormation, so raw-resource context expectations do not apply.Aggregate design
I4010 emits at most two findings per template:
Per-resource suppression via
Metadata.cfn-lint.config.ignore_checks: [I4010]removes individual resources from the aggregate rather than suppressing the entire finding. (W4011/W4012 are per-resource / per-field, matching cfn-lint's per-location convention.)Remediation guidance
When
whyis unknown, I4010 and W4011 guide users to record reduced confidence rather than guessing:This uses the schema's
trust.notefield ("Reason for reduced confidence, typically when conf=low") as the honest-unknown path.Upstream status
This convention is being adopted alongside:
Both the CDK feature and its RFC are still open; the Context convention is not yet finalized. This is the primary reason these rules ship experimental and off by default. The wire format was verified against #38381's integration snapshot:
why,must,mutable,mutability,trust(src/conf),arch,ref(at/has/scope),owner, and all four mutability tokens agree.Configuration
additional_incidental_patternsis available on all three rules;additional_low_value_typesis I4010-only (W4011/W4012 validate supplied context everywhere, so low-value types are not exempt from validation).Testing
test/unit/rules/metadata/, split one-file-per-rule (test_context_missing.py,test_context_missing_why.py,test_context_schema.py,test_context_targeting.py,test_context_enablement.py) -- 76 passing._BaseContext.py(CDK/incidental detection, resource iteration, shared config).