Skip to content

Commit c2f98e8

Browse files
authored
Add guard rule to enforce tag property is not create only (#76)
* Add guard rule to enforce tag property is not create only * Fixed issue in tag018 condition
1 parent 51cb5fa commit c2f98e8

File tree

4 files changed

+121
-2
lines changed

4 files changed

+121
-2
lines changed

src/rpdk/guard_rail/rule_library/tags/schema-linter-core-tagging-rules.guard

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ rule ensure_property_tags_exists_v2 when tagging exists {
144144
}
145145
>>
146146
}
147+
when createOnlyProperties exists {
148+
tagging.tagProperty !IN createOnlyProperties
149+
<<
150+
{
151+
"result": "WARNING",
152+
"check_id": "TAG017",
153+
"message": "`tagProperty` MUST NOT be a part of `createOnlyProperties`"
154+
}
155+
>>
156+
when tagging.tagProperty IN createOnlyProperties {
157+
tagging.tagUpdatable == false
158+
<<
159+
{
160+
"result": "WARNING",
161+
"check_id": "TAG018",
162+
"message": "`tagProperty` MUST NOT be a part of `createOnlyProperties` when `tagUpdatable` is true"
163+
}
164+
>>
165+
}
166+
}
147167
}
148168
tagging.permissions exists
149169
<<
@@ -161,7 +181,7 @@ rule ensure_property_tags_exists_v2 when tagging exists {
161181
{
162182
"result": "NON_COMPLIANT",
163183
"check_id": "TAG016",
164-
"message": "`tagging.taggable` MUST be true when Taging Property is defined in the schema"
184+
"message": "`tagging.taggable` MUST be true when Tagging Property is defined in the schema"
165185
}
166186
>>
167187
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"properties": {
3+
"Tags": {},
4+
"Arn": {}
5+
},
6+
"createOnlyProperties": [
7+
"/properties/Tags"
8+
],
9+
"tagging": {
10+
"taggable": true,
11+
"tagOnCreate": true,
12+
"tagUpdatable": true,
13+
"cloudFormationSystemTags": false,
14+
"tagProperty": "/properties/Tags"
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"properties": {
3+
"Tags": {},
4+
"Arn": {}
5+
},
6+
"createOnlyProperties": [
7+
"/properties/Tags"
8+
],
9+
"tagging": {
10+
"taggable": true,
11+
"tagOnCreate": true,
12+
"tagUpdatable": false,
13+
"cloudFormationSystemTags": false,
14+
"tagProperty": "/properties/Tags"
15+
}
16+
}

tests/integ/runner/test_integ_runner.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,73 @@
285285
},
286286
{},
287287
),
288+
(
289+
collect_schemas(
290+
schemas=[
291+
"file:/"
292+
+ str(
293+
Path(os.path.dirname(os.path.realpath(__file__))).joinpath(
294+
"../data/schema-tag-property-createonly-updatable.json"
295+
)
296+
)
297+
]
298+
),
299+
[],
300+
{
301+
"ensure_property_tags_exists_v2": {
302+
GuardRuleResult(
303+
check_id="TAG012",
304+
message="Resource MUST provide `permissions` if `tagging.taggable` is true",
305+
path="",
306+
),
307+
},
308+
},
309+
{
310+
"ensure_property_tags_exists_v2": {
311+
GuardRuleResult(
312+
check_id="TAG017",
313+
message="`tagProperty` MUST NOT be a part of `createOnlyProperties`",
314+
path="/tagging/tagProperty",
315+
),
316+
GuardRuleResult(
317+
check_id="TAG018",
318+
message="`tagProperty` MUST NOT be a part of `createOnlyProperties` when `tagUpdatable` is true",
319+
path="/tagging/tagUpdatable",
320+
),
321+
},
322+
},
323+
),
324+
(
325+
collect_schemas(
326+
schemas=[
327+
"file:/"
328+
+ str(
329+
Path(os.path.dirname(os.path.realpath(__file__))).joinpath(
330+
"../data/schema-tag-property-createonly.json"
331+
)
332+
)
333+
]
334+
),
335+
[],
336+
{
337+
"ensure_property_tags_exists_v2": {
338+
GuardRuleResult(
339+
check_id="TAG012",
340+
message="Resource MUST provide `permissions` if `tagging.taggable` is true",
341+
path="",
342+
),
343+
},
344+
},
345+
{
346+
"ensure_property_tags_exists_v2": {
347+
GuardRuleResult(
348+
check_id="TAG017",
349+
message="`tagProperty` MUST NOT be a part of `createOnlyProperties`",
350+
path="/tagging/tagProperty",
351+
),
352+
},
353+
},
354+
),
288355
(
289356
collect_schemas(
290357
schemas=[
@@ -499,7 +566,7 @@ def test_exec_compliance_stateless_tagging_permission_specified(
499566
"ensure_property_tags_exists_v2": {
500567
GuardRuleResult(
501568
check_id="TAG016",
502-
message="`tagging.taggable` MUST be true when Taging Property is defined in the schema",
569+
message="`tagging.taggable` MUST be true when Tagging Property is defined in the schema",
503570
path="/properties/StageDescription/Tags",
504571
),
505572
}

0 commit comments

Comments
 (0)