-
Notifications
You must be signed in to change notification settings - Fork 14
Add evidence-checker extension #634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| {{- $podName := "test-evidence" }} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed out-of-bands, please rename this consistently to |
||
|
|
||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: {{ $podName }} | ||
| namespace: {{ .Values.target_namespace | default .Release.Namespace }} | ||
| {{- if default dict (.Values.deployment).annotations }} | ||
| annotations: | ||
| {{- range $annotation, $value := .Values.deployment.annotations }} | ||
| {{ $annotation }}: {{ $value }} | ||
| {{- end }} | ||
| {{- end }} | ||
| spec: | ||
| replicas: 0 # will be scaled automatically by backlog-controller | ||
| selector: | ||
| matchLabels: | ||
| app: {{ $podName }} | ||
| delivery-gear.gardener.cloud/service: testEvidence | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: {{ $podName }} | ||
| delivery-gear.gardener.cloud/service: testEvidence | ||
| spec: | ||
| topologySpreadConstraints: | ||
| - maxSkew: 1 | ||
| topologyKey: kubernetes.io/hostname | ||
| whenUnsatisfiable: ScheduleAnyway | ||
| labelSelector: | ||
| matchLabels: | ||
| app: {{ $podName }} | ||
| terminationGracePeriodSeconds: 300 # 5 min | ||
| containers: | ||
| - name: {{ $podName }} | ||
| image: {{ include "image" .Values.image }} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure whether this is on purpose for the first iteration, but the Helm chart image mapping configuration is still missing in the |
||
| imagePullPolicy: IfNotPresent | ||
| command: | ||
| - python3 | ||
| - -m | ||
| - test_evidence_extension | ||
| securityContext: | ||
| allowPrivilegeEscalation: false | ||
| env: | ||
| - name: SECRET_FACTORY_PATH | ||
| value: /secrets | ||
| - name: EXTENSIONS_CFG_PATH | ||
| value: /extensions_cfg/extensions_cfg | ||
| - name: FINDINGS_CFG_PATH | ||
| value: /findings_cfg/findings_cfg | ||
| - name: OCM_REPO_MAPPINGS_PATH | ||
| value: /ocm_repo_mappings/ocm_repo_mappings | ||
| - name: K8S_TARGET_NAMESPACE | ||
| value: {{ .Values.target_namespace | default .Release.Namespace }} | ||
| volumeMounts: | ||
| - name: github | ||
| mountPath: /secrets/github | ||
| - name: github-app | ||
| mountPath: /secrets/github-app | ||
| - name: kubernetes | ||
| mountPath: /secrets/kubernetes | ||
| - name: oci-registry | ||
| mountPath: /secrets/oci-registry | ||
| - name: extensions-cfg | ||
| mountPath: /extensions_cfg | ||
| - name: findings-cfg | ||
| mountPath: /findings_cfg | ||
| - name: ocm-repo-mappings | ||
| mountPath: /ocm_repo_mappings | ||
| readOnly: true | ||
| lifecycle: | ||
| preStop: # hook ensures that just created pods have at least enough time alive to add a termination signal handler | ||
| exec: | ||
| command: | ||
| - sleep | ||
| - "60" | ||
| resources: | ||
| requests: | ||
| memory: 100Mi | ||
| cpu: 250m | ||
| limits: | ||
| memory: 300Mi | ||
| cpu: 500m | ||
| volumes: | ||
| - name: github | ||
| secret: | ||
| secretName: secret-factory-github | ||
| optional: true | ||
| - name: github-app | ||
| secret: | ||
| secretName: secret-factory-github-app | ||
| optional: true | ||
| - name: kubernetes | ||
| secret: | ||
| secretName: secret-factory-kubernetes | ||
| optional: true # might use incluster config | ||
| - name: oci-registry | ||
| secret: | ||
| secretName: secret-factory-oci-registry | ||
| optional: true # oci authentication is optional | ||
| - name: extensions-cfg | ||
| configMap: | ||
| name: extensions-cfg | ||
| - name: findings-cfg | ||
| configMap: | ||
| name: findings-cfg | ||
| - name: ocm-repo-mappings | ||
| configMap: | ||
| name: ocm-repo-mappings | ||
| --- | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: allow-egress-from-test-evidence | ||
| namespace: {{ .Values.target_namespace | default .Release.Namespace }} | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| app: {{ $podName }} | ||
| policyTypes: | ||
| - Egress | ||
| egress: | ||
| - {} # Allows all egress traffic to any destination and port | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some comments to this image:
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| Evidence Checker Extension | ||
| ========================== | ||
|
|
||
| Purpose | ||
| ------- | ||
|
|
||
| Tests are a crucial part of software development, making sure the software's functionality stays intact despite the introduction of new features and enhancements. To prove the software's stability it is therefore often required to document and store test results of unit tests. | ||
|
|
||
| Therefore, the aim of the evidence checker extension is to create a finding for an artefact/resource in case no test evidences from unit tests have been found for this artefact. | ||
|
|
||
| Labels used for the extension | ||
| ----------------------------- | ||
|
|
||
| The extension uses three labels in your component descriptor as described below. | ||
|
|
||
| 1. Purpose Label | ||
| ~~~~~~~~~~~~~~~~ | ||
|
|
||
| The purpose label defines the purpose of the artefact respectively what the artefact is used for. The value of the purpose label could be such as 'lint', 'sast' or 'test'. E.g., if the value is 'test' we know that this artefact is in fact a test evidence. | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| - name: gardener.cloud/purposes | ||
| signing: false | ||
| value: | ||
| - test | ||
|
|
||
| 2. Test Policy Label | ||
| ~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| The test policy label defines whether an artefact requires unit tests - and therefore test evidences - or not. E.g., a helmchart does not require unit tests, while an OCI-image would require unit tests. | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| - name: gardener.cloud/test-policy | ||
| value: false / true | ||
|
|
||
| 3. Test Scope Label | ||
| ~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| The test scope label is set in the component descriptor of a test artefact (aka an artefact whose purpose label has the value 'test) and it defines for which other artefacts it represents the test evidence. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing closing quote in 'test) |
||
|
|
||
| If you do not specify any value in this label it is automatically assumed that the test artefact is valid for all artefacts within a component. | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| - name: gardener.cloud/test-scope | ||
| value: | ||
| - artefact-1 | ||
| - artefact-2 | ||
|
|
||
| Functionality | ||
| ------------- | ||
|
|
||
| 1. The extension scans each artefact of a component and first validates whether the currently scanned artefact is a test evidence itself or not. This is achieved with the use of the gardener.cloud/purposes label. An artefact is considered a test evidence provided the label's value is 'test'. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. label value instead of label's value, no? 🤔 |
||
|
|
||
| 2. Provided the gardener.cloud/purposes label's has NOT been given the value 'test' the extension further checks, whether the artefact requires a test or not. This is achieved with the gardener.cloud/test-policy label which is either 'true' or 'false. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing closing quote in 'false |
||
|
|
||
| 3. In case an artefact has been identified as a test artefact (as described in step 1) the extension further checks, for which artefacts within the component the test-evidence is valid for. This can be defined with the help of the gardener.cloud/test-scope label. | ||
|
|
||
| 4. In case one of the artefacts identified in step 2 is not covered by the test artefacts(aka evidences) a finding will be created and test-evidences will have to be provided retrospectively. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing space before parentheses in artefacts(aka evidences) |
||
|
|
||
| .. image:: evidence-checker.jpg | ||
| :alt: Evidence Checker Flow | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ class Services(enum.StrEnum): | |
| PPMS = 'ppms' | ||
| RESPONSIBLES = 'responsibles' | ||
| SAST = 'sast' | ||
| TEST_EVIDENCE = 'testEvidence' | ||
| ODG_OPERATOR = 'odg-operator' | ||
| SBOM_GENERATOR = 'sbomGenerator' | ||
|
|
||
|
|
@@ -984,6 +985,24 @@ def is_supported( | |
| return True | ||
|
|
||
|
|
||
| @dataclasses.dataclass(kw_only=True) | ||
| class TestEvidenceConfig(BacklogItemMixins): | ||
| service: Services = Services.TEST_EVIDENCE | ||
| delivery_service_url: str | ||
| external_artefacts_require_tests: bool | ||
| interval: int = 60 * 60 * 24 # | ||
|
Comment on lines
+990
to
+993
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 24h |
||
| on_unsupported: WarningVerbosities = WarningVerbosities.WARNING | ||
|
|
||
| def is_supported( | ||
| self, | ||
| artefact_kind: odg.model.ArtefactKind, | ||
| ) -> bool: | ||
| if artefact_kind is not odg.model.ArtefactKind.RESOURCE: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is_supported() can be simplified to a single return statement
|
||
| return False | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| @dataclasses.dataclass(kw_only=True) | ||
| class OsId(BacklogItemMixins): | ||
| ''' | ||
|
|
@@ -1119,6 +1138,7 @@ class ExtensionsConfiguration: | |
| responsibles: ResponsiblesConfig | None | ||
| sast: SASTConfig | None | ||
| sbom_generator: SBOMGeneratorConfig | None | ||
| test_evidence: TestEvidenceConfig | None | ||
| backlog_controller: BacklogControllerConfig = dataclasses.field(default_factory=BacklogControllerConfig) # noqa: E501 | ||
|
|
||
| @staticmethod | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,25 @@ | |
| malware_names: | ||
| - .* | ||
|
|
||
| - type: finding/test-evidence | ||
| issues: | ||
| enable_assignees: False | ||
| categorisations: | ||
| - id: NONE | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it is difficult to change the |
||
| display_name: No Tests required | ||
| value: 0 | ||
| allowed_processing_time: ~ | ||
| rescoring: manual | ||
|
|
||
| - id: BLOCKER | ||
| display_name: No Test Evidence | ||
| value: 16 | ||
| allowed_processing_time: 0 | ||
| rescoring: manual | ||
| selector: | ||
| status: | ||
| - .* | ||
|
|
||
| - type: finding/sast | ||
| issues: | ||
| enable_issues: False | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not use the
intervalof theosidextension here :^)