-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(label-tool): Implement some more rules
- Loading branch information
1 parent
018f074
commit 7210e00
Showing
9 changed files
with
224 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
scripts/labels/invariant_check/rules/guideline_implies_profile_security.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- | ||
from typing import List, Set, Tuple | ||
|
||
from ...checker_labels import MultipleLabels | ||
from ... import fixit | ||
from .base import Base | ||
|
||
|
||
class GuidelineImpliesProfileSecurity(Base): | ||
kind = "guideline.implies_profile_security" | ||
description = """ | ||
Ensures that checkers with a "guideline" label corresponding to a published | ||
security guideline (e.g., SEI-CERT) are added to the 'security' profile. | ||
""".replace('\n', ' ') | ||
supports_fixes = True | ||
|
||
# Only the following guidelines will trigger the implication. | ||
interesting_guidelines: Set[str] = {"sei-cert", | ||
} | ||
|
||
@classmethod | ||
def check(cls, labels: MultipleLabels, analyser: str, checker: str) \ | ||
-> Tuple[bool, List[fixit.FixAction]]: | ||
guidelines: Set[str] = set(labels[checker].get("guideline", list())) | ||
if not guidelines & cls.interesting_guidelines: | ||
return True, [] | ||
|
||
profiles: Set[str] = set(labels[checker].get("profile", list())) | ||
missing_profiles = {"security"} - profiles | ||
return not missing_profiles, \ | ||
[fixit.AddLabelAction("profile:%s" % (profile)) | ||
for profile in missing_profiles] |
46 changes: 46 additions & 0 deletions
46
scripts/labels/invariant_check/rules/guideline_requires_rule_number_annotation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- | ||
from typing import List, Set, Tuple | ||
|
||
from ...checker_labels import MultipleLabels | ||
from ...output import log, coloured, emoji | ||
from ... import fixit | ||
from .base import Base | ||
|
||
|
||
class GuidelineRequiresRuleNumberAnnotation(Base): | ||
kind = "guideline.requires_rule_number_annotation" | ||
description = """ | ||
Checks that checkers with a "guideline" label corresponding to a published | ||
security guideline (e.g., SEI-CERT) must be labelled with a | ||
"<guideline-name>:<rule-number>" label as well. | ||
""".replace('\n', ' ') | ||
supports_fixes = False | ||
|
||
# Only the following guidelines will trigger the check. | ||
interesting_guidelines: Set[str] = {"sei-cert", | ||
} | ||
|
||
@classmethod | ||
def check(cls, labels: MultipleLabels, analyser: str, checker: str) \ | ||
-> Tuple[bool, List[fixit.FixAction]]: | ||
guidelines: Set[str] = set(labels[checker].get("guideline", list())) | ||
|
||
failed: List[str] = list() | ||
for guideline in (guidelines & cls.interesting_guidelines): | ||
if not labels[checker].get(guideline, list()): | ||
log("%s%s: %s/%s - \"%s\" without \"%s\"", | ||
emoji(":police_car_light: "), | ||
coloured("RULE VIOLATION", "red"), | ||
analyser, checker, | ||
coloured("guideline:%s" % guideline, "green"), | ||
coloured("%s:<RULE-NUMBER>" % guideline, "red"), | ||
) | ||
failed.append(guideline) | ||
|
||
return not failed, [] |
56 changes: 56 additions & 0 deletions
56
scripts/labels/invariant_check/rules/guideline_rule_number_annotation_requires_guideline.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- | ||
from typing import List, Set, Tuple | ||
|
||
from ...checker_labels import MultipleLabels | ||
from ...output import log, coloured, emoji | ||
from ... import fixit | ||
from .base import Base | ||
|
||
|
||
class GuidelineRuleNumberAnnotationRequiresGuideline(Base): | ||
kind = "guideline.rule_number_annotation_requires_guideline" | ||
description = """ | ||
Ensures that checkers with a "<guideline-name>:<rule-number>" labels for a | ||
published security guideline (e.g., SEI-CERT) must be labelled with a | ||
"guideline:<guideline-name>" label as well. | ||
""".replace('\n', ' ') | ||
supports_fixes = True | ||
|
||
# Only the following guidelines will trigger the check. | ||
interesting_guidelines: Set[str] = {"sei-cert", | ||
} | ||
|
||
@classmethod | ||
def check(cls, labels: MultipleLabels, analyser: str, checker: str) \ | ||
-> Tuple[bool, List[fixit.FixAction]]: | ||
labelled_guidelines: Set[str] = set(labels[checker] | ||
.get("guideline", list())) | ||
missing_guidelines: List[str] = list() | ||
|
||
for guideline in cls.interesting_guidelines: | ||
guideline_rule_annotations = set(labels[checker] | ||
.get(guideline, list())) | ||
if guideline_rule_annotations and \ | ||
guideline not in labelled_guidelines: | ||
missing_guidelines.append(guideline) | ||
log("%s%s: %s/%s - \"%s\" without \"%s\"", | ||
emoji(":police_car_light: "), | ||
coloured("RULE VIOLATION", "red"), | ||
analyser, checker, | ||
"\", \"".join(( | ||
coloured("%s:%s" % (guideline, rule_annotation), | ||
"green") | ||
for rule_annotation in guideline_rule_annotations | ||
)), | ||
coloured("guideline:%s" % (guideline), "red"), | ||
) | ||
|
||
return not missing_guidelines, \ | ||
[fixit.AddLabelAction("guideline:%s" % (guideline)) | ||
for guideline in missing_guidelines] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
scripts/labels/invariant_check/rules/profile_no_alpha_checkers_in_production.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- | ||
from typing import List, Set, Tuple | ||
|
||
from ...checker_labels import MultipleLabels | ||
from ... import fixit | ||
from .base import Base | ||
|
||
|
||
class ProfileNoAlphaCheckersInProduction(Base): | ||
kind = "profile.no_alpha_checkers_in_production_profiles" | ||
description = """ | ||
Ensures that Clang SA checkers in the 'alpha.' (and 'debug.') checker groups | ||
do not belong to a production-grade "profile", e.g., 'default' or 'security'. | ||
""".replace('\n', ' ') | ||
supports_fixes = True | ||
|
||
# FIXME(v6.25?): It is planned that we will create a profile specifically | ||
# for Alpha checkers that are not good enough to be possible to lift from | ||
# Alpha status, but not bad enough to be completely unusable, in order to | ||
# suggest ad-hoc use for interested clients. | ||
# These groups **SHOULD** allow Alpha checkers. | ||
profiles_allowing_alphas: Set[str] = {"<placeholder>", | ||
} | ||
|
||
@classmethod | ||
def supports_analyser(cls, analyser: str) -> bool: | ||
return analyser == "clangsa" | ||
|
||
@classmethod | ||
def check(cls, labels: MultipleLabels, analyser: str, checker: str) \ | ||
-> Tuple[bool, List[fixit.FixAction]]: | ||
if not cls.supports_analyser(analyser) \ | ||
or not checker.startswith(("alpha.", "debug.")): | ||
return True, [] | ||
|
||
profiles: Set[str] = set(labels[checker].get("profile", list())) | ||
unexpected_profiles = profiles - cls.profiles_allowing_alphas | ||
|
||
return not unexpected_profiles, \ | ||
[fixit.RemoveLabelAction("profile:%s" % (profile)) | ||
for profile in unexpected_profiles] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters