Repository navigation
fix(E3051): skip Automation schema for AppConfig SSM document types - #4844
Conversation
When a resource's Condition provably always evaluates to true, there is no scenario in which the resource does not exist, so E3005 no longer reports that the DependsOn target will not exist when the condition is False. Adds Conditions.is_always_true (SAT-backed, cached) and consults it in Template.is_resource_available before scenario analysis. A genuinely conditional target still reports the False scenario. Fixes aws-cloudformation#4820 Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
AWS::SSM::Document resources with DocumentType ApplicationConfiguration or ApplicationConfigurationSchema hold configuration data or a JSON Schema. Neither content format carries an SSM schemaVersion key, so validating Content against the Automation document schema only produces false positives. E3051 now skips the Automation schema when DocumentType is one of the AppConfig types. A missing or intrinsic DocumentType keeps the current validation (fail closed). Fixes aws-cloudformation#4834 Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
|
Hi team, on this fix(E3051) PR: the [CI] Test PR workflow run on the current head is still parked waiting for a first-time-contributor approval (action_required). Could a maintainer approve the run so CI can proceed? Thanks. |
|
Hi @kddejong, friendly follow up: the CI runs on this PR are still parked at the first-time-contributor approval gate (action_required), so the checks cannot start until a maintainer approves the run. Could you approve it when you have a moment? Thanks! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4844 +/- ##
==========================================
- Coverage 94.68% 94.66% -0.03%
==========================================
Files 439 439
Lines 16016 16025 +9
Branches 3111 3114 +3
==========================================
+ Hits 15165 15170 +5
- Misses 468 470 +2
- Partials 383 385 +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:
|
|
The substance here is right, and I confirmed it against the service rather than the docs: an
Rather than add tests for shapes that mostly cannot occur, the helper can go away entirely. The rule is keyworded at def __init__(self):
super().__init__(
- ["Resources/AWS::SSM::Document/Properties/Content"],
+ ["Resources/AWS::SSM::Document/Properties"],- if self._is_appconfig_document(validator):
+ if not validator.is_type(instance, "object"):
+ return
+ if instance.get("DocumentType") in self._APPCONFIG_DOCUMENT_TYPES:
return
+ if "Content" not in instance:
+ return
+ instance = instance.get("Content")and the whole yield ValidationError(
f"Document is not valid ({errs[0].message!r})",
validator="type",
rule=self,
+ path=["Content"],
) if not err.validator.startswith("fn_") and err.validator not in ["cfnLint"]:
err.rule = self
+ err.path.appendleft("Content")
yield errI built this and compared it against your branch. Output is identical, error locations included: Also identical on a string What this buys: no The cost is that the existing unit tests pass Two test gaps worth closing while you are in there, neither of which mutation testing can see because there is no assertion either way:
Unrelated to this PR but adjacent, and worth knowing before the string path is tested: E3051 cannot validate a string |
…limb Keyword the rule at Resources/AWS::SSM::Document/Properties so DocumentType and Content are both keys of the instance. This deletes the _is_appconfig_document helper and its template climb, path arithmetic, and isinstance guards, and restores the Content path segment on both error paths so findings still point at Content. Update the unit tests to pass Properties objects instead of Content values, and add coverage for string Content on AppConfig types and for a Command document without schemaVersion. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
|
Thanks for the detailed review and for verifying the exemption against the service, that confirms the narrow scope is the right call. Applied the refactor as suggested:
Verification: Noted on the string- |
#4844 moved E3051's keyword from Resources/AWS::SSM::Document/Properties/Content up to Resources/AWS::SSM::Document/Properties so validate() could read the sibling DocumentType off the instance. Properties sits in front of cfn-lint's intrinsic-function machinery, so the rule began receiving a raw dict for Content instead of a resolved value and reported 'schemaVersion' is a required property on every document whose Content comes from Ref, Fn::GetAtt or Fn::Sub. Put the keyword back at Content and read DocumentType through Template.get_cfn_path, the same way E1041 reads a sibling VpcId. The logical ID comes from validator.context.path.path[1], as in E3035, E3036, E3055 and W2530. get_cfn_path yields each Fn::If branch with its condition bound, so a conditional DocumentType is now handled too; #4844 and its predecessor both validated it as an unresolved dict. The AppConfig exemption from #4844 is unchanged: ApplicationConfiguration and ApplicationConfigurationSchema still skip the Automation schema, an absent or unresolvable DocumentType still validates, and a Command document without a schemaVersion still errors. Errors are no longer prefixed with Content: at this keyword the path already ends in Content, so appending it produced a doubled Resources/<id>/Properties/Content/Content in json and sarif output.
What
E3051 validates the
ContentofAWS::SSM::Documentagainst the Automation document schema, which requires aschemaVersionkey. Resources withDocumentTypeApplicationConfigurationorApplicationConfigurationSchemahold AppConfig configuration data or a JSON Schema (draft-04); neither format carries an SSMschemaVersionkey, so every such document was a false positive. E3051 now skips the Automation-document schema when the resource'sDocumentTypeis one of the two AppConfig types. A missingDocumentTypeor one given as an intrinsic keeps the current validation (fail closed).Why
Resolves the report in #4834. The schema in
src/cfnlint/data/schemas/other/ssm/document.jsonis the Automation document schema (its title says so), and applying it to AppConfig document types is meaningless.How
src/cfnlint/rules/resources/ssm/Document.py: new_is_appconfig_documenthelper reads the containing resource'sDocumentTypefrom the validator's context path and template;validatereturns early for the two AppConfig types. Only a plain-stringDocumentTypeis conclusive.Testing
Automationdocument withoutschemaVersion, anAutomationdocument with an out-of-enumschemaVersion(9.9), and a document whoseDocumentTypeis an intrinsic (!Ref).test/unit/rules/resources/ssm/test_document.py::test_validate_document_type_scoping: both AppConfig types produce 0 errors;Automationand intrinsic-typed documents still produce 1 error each.test_document.py12 passed (8 existing plus 4 new).ruff checkandruff formatclean on all touched files.Fixes #4834