Skip to content

Commit fdc7c87

Browse files
a-waiJenySadadia
authored andcommitted
kernelci: api: helper: fix rules enforcement for missing params
By default, if a rule refers to a param that can be found neither in the to-be-created node nor in any of its ancestors we assume the rule is verified (as in, we don't block creating the node). This behaviour felt safe enough until we encountered a rare corner case: `coverage-report` nodes were created with a `kunit-x86_64` parent, although such nodes should only be created on jobs run for a kernel built with the `coverage` fragment. This could happen because `kunit-x86_64` is created from a `checkout` node, not a `kbuild` one, and therefore neither this job nor its parent contain a `fragments` attribute. The above showed we needed to be a bit stricter when checking rules. To this end, the following behaviour is enforced for missing attributes: - if the rule only contains a deny-list, the rule is verified and the node can be created (a non-existing attribute cannot have a forbidden value, precisely because it doesn't have a value) - if an allow-list is present, then the attribute's value MUST be part of this list; as a consequence, we now require the attribute to exist, and deny the node creation if it doesn't Fixes kernelci/kernelci-pipeline#1290 Signed-off-by: Arnaud Ferraris <[email protected]>
1 parent f16f2fd commit fdc7c87

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

kernelci/api/helper.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,25 @@ def _is_allowed(self, rules, key, node):
162162
# Find the node (or ancestor node) attribute corresponding to the
163163
# rule we're applying
164164
base = self._find_container(key, node)
165-
if not base:
166-
return True
167165

168166
deny = [f.lstrip('!') for f in rules[key] if f.startswith('!')]
169167
allow = [f for f in rules[key] if not f.startswith('!')]
170168

169+
# If the parameter (key) associated to a given rule cannot be found
170+
# in the current hierarchy, there are two cases:
171+
# * the rule only excludes certain values (no allowed value, only
172+
# denied ones): as the parameter doesn't exist, it can't use a
173+
# denied value, so we can proceed with creating the node
174+
# * the rule does have an allow-list: here we can assume that the
175+
# parameter is REQUIRED to have one of the allowed values, and
176+
# therefore MUST exist; if it doesn't, then we shouldn't create
177+
# the node on the basis that its rules aren; t fulfilled
178+
if not base:
179+
if len(allow) > 0:
180+
print(f"rules[{key}]: attribute '{key}' not found in node hierarchy")
181+
return False
182+
return True
183+
171184
# Rules are appied depending on how the data is initially stored:
172185
# * if it's a list (e.g. config fragments), then it must contain
173186
# at least one element from the allow-list; additionally, none

0 commit comments

Comments
 (0)