Skip to content

Commit

Permalink
sast-coverity-check: use kustomize to build the task
Browse files Browse the repository at this point in the history
... from the build-container task.  The `hack/generate-sast-tasks.sh`
script can be used to rebuild `sast-coverity-check.yaml`.

Related: #1653
  • Loading branch information
kdudka committed Jan 28, 2025
1 parent 5ca7732 commit c47c70d
Show file tree
Hide file tree
Showing 9 changed files with 1,270 additions and 273 deletions.
4 changes: 2 additions & 2 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
# renovate groupName=integration
/task/coverity-availability-check @konflux-ci/integration-service-maintainers @kdudka
/task/coverity-availability-check-oci-ta @konflux-ci/integration-service-maintainers @kdudka
/task/sast-coverity-check @konflux-ci/integration-service-maintainers @kdudka
/task/sast-coverity-check-oci-ta @konflux-ci/integration-service-maintainers @kdudka
/task/sast-coverity-check @konflux-ci/integration-service-maintainers @konflux-ci/build-maintainers @kdudka
/task/sast-coverity-check-oci-ta @konflux-ci/integration-service-maintainers @konflux-ci/build-maintainers @kdudka
/task/sast-shell-check @konflux-ci/integration-service-maintainers @kdudka
/task/sast-shell-check-oci-ta @konflux-ci/integration-service-maintainers @kdudka
/task/sast-snyk-check @konflux-ci/integration-service-maintainers @kdudka
Expand Down
19 changes: 19 additions & 0 deletions hack/generate-sast-tasks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
set -o posix

shopt -s globstar nullglob

HACK_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
ROOT_DIR="$(git rev-parse --show-toplevel)"
TASK_DIR="$(realpath "${ROOT_DIR}/task")"

# sast-coverity-check of version 0.2 and newer uses kustomize to build the task
# definition from the buildah task and a locally maintained patch.yaml
for dir in "${TASK_DIR}/sast-coverity-check"/0.[2-9]; do (
cd "$dir" && kustomize build > sast-coverity-check.yaml
) done
53 changes: 38 additions & 15 deletions pipelines/docker-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ This pipeline is pushed as a Tekton bundle to [quay.io](https://quay.io/reposito
## Parameters
|name|description|default value|used in (taskname:taskrefversion:taskparam)|
|---|---|---|---|
|build-args| Array of --build-arg values ("arg=value" strings) for buildah| []| build-container:0.3:BUILD_ARGS|
|build-args-file| Path to a file with build arguments for buildah, see https://www.mankier.com/1/buildah-build#--build-arg-file| | build-container:0.3:BUILD_ARGS_FILE|
|build-args| Array of --build-arg values ("arg=value" strings) for buildah| []| build-container:0.3:BUILD_ARGS ; sast-coverity-check:0.2:BUILD_ARGS|
|build-args-file| Path to a file with build arguments for buildah, see https://www.mankier.com/1/buildah-build#--build-arg-file| | build-container:0.3:BUILD_ARGS_FILE ; sast-coverity-check:0.2:BUILD_ARGS_FILE|
|build-image-index| Add built image into an OCI image index| false| build-image-index:0.1:ALWAYS_BUILD_INDEX|
|build-source-image| Build a source image.| false| |
|dockerfile| Path to the Dockerfile inside the context specified by parameter path-context| Dockerfile| build-container:0.3:DOCKERFILE ; push-dockerfile:0.1:DOCKERFILE|
|dockerfile| Path to the Dockerfile inside the context specified by parameter path-context| Dockerfile| build-container:0.3:DOCKERFILE ; sast-coverity-check:0.2:DOCKERFILE ; push-dockerfile:0.1:DOCKERFILE|
|git-url| Source Repository URL| None| clone-repository:0.1:url|
|hermetic| Execute the build with network isolation| false| build-container:0.3:HERMETIC|
|image-expires-after| Image tag expiration time, time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively.| | build-container:0.3:IMAGE_EXPIRES_AFTER ; build-image-index:0.1:IMAGE_EXPIRES_AFTER|
|output-image| Fully Qualified Output Image| None| show-summary:0.2:image-url ; init:0.2:image-url ; build-container:0.3:IMAGE ; build-image-index:0.1:IMAGE ; build-source-image:0.1:BINARY_IMAGE|
|path-context| Path to the source code of an application's component from where to build image.| .| build-container:0.3:CONTEXT ; push-dockerfile:0.1:CONTEXT|
|prefetch-input| Build dependencies to be prefetched by Cachi2| | prefetch-dependencies:0.1:input ; build-container:0.3:PREFETCH_INPUT|
|hermetic| Execute the build with network isolation| false| build-container:0.3:HERMETIC ; sast-coverity-check:0.2:HERMETIC|
|image-expires-after| Image tag expiration time, time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively.| | build-container:0.3:IMAGE_EXPIRES_AFTER ; build-image-index:0.1:IMAGE_EXPIRES_AFTER ; sast-coverity-check:0.2:IMAGE_EXPIRES_AFTER|
|output-image| Fully Qualified Output Image| None| show-summary:0.2:image-url ; init:0.2:image-url ; build-container:0.3:IMAGE ; build-image-index:0.1:IMAGE ; build-source-image:0.1:BINARY_IMAGE ; sast-coverity-check:0.2:IMAGE|
|path-context| Path to the source code of an application's component from where to build image.| .| build-container:0.3:CONTEXT ; sast-coverity-check:0.2:CONTEXT ; push-dockerfile:0.1:CONTEXT|
|prefetch-input| Build dependencies to be prefetched by Cachi2| | prefetch-dependencies:0.1:input ; build-container:0.3:PREFETCH_INPUT ; sast-coverity-check:0.2:PREFETCH_INPUT|
|rebuild| Force rebuild image| false| init:0.2:rebuild|
|revision| Revision of the Source Repository| | clone-repository:0.1:revision|
|skip-checks| Skip checks against built image| false| init:0.2:skip-checks|
Expand Down Expand Up @@ -167,17 +167,40 @@ This pipeline is pushed as a Tekton bundle to [quay.io](https://quay.io/reposito
### sast-coverity-check:0.2 task parameters
|name|description|default value|already set by|
|---|---|---|---|
|AUTH_TOKEN_COVERITY_IMAGE| Name of secret which contains the authentication token for pulling the Coverity image.| auth-token-coverity-image| |
|ACTIVATION_KEY| Name of secret which contains subscription activation key| activation-key| |
|ADDITIONAL_SECRET| Name of a secret which will be made available to the build with 'buildah build --secret' at /run/secrets/$ADDITIONAL_SECRET| does-not-exist| |
|ADD_CAPABILITIES| Comma separated list of extra capabilities to add when running 'buildah build'| | |
|BUILD_ARGS| Array of --build-arg values ("arg=value" strings)| []| '['$(params.build-args[*])']'|
|BUILD_ARGS_FILE| Path to a file with build arguments, see https://www.mankier.com/1/buildah-build#--build-arg-file| | '$(params.build-args-file)'|
|COMMIT_SHA| The image is built from this commit.| | '$(tasks.clone-repository.results.commit)'|
|CONTEXT| Path to the directory to use as context.| .| '$(params.path-context)'|
|COV_ANALYZE_ARGS| Arguments to be appended to the cov-analyze command| --enable HARDCODED_CREDENTIALS --security --concurrency --spotbugs-max-mem=4096| |
|COV_CAPTURE_ARGS| Arguments to be appended to the coverity capture command| | |
|COV_LICENSE| Name of secret which contains the Coverity license| cov-license| |
|DOCKERFILE| Path to the Dockerfile to build.| ./Dockerfile| '$(params.dockerfile)'|
|ENTITLEMENT_SECRET| Name of secret which contains the entitlement certificates| etc-pki-entitlement| |
|HERMETIC| Determines if build will be executed without network access.| false| '$(params.hermetic)'|
|IMAGE| Reference of the image buildah will produce.| None| '$(params.output-image)'|
|IMAGE_EXPIRES_AFTER| Delete image tag after specified time. Empty means to keep the image tag. Time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively.| | '$(params.image-expires-after)'|
|IMP_FINDINGS_ONLY| Report only important findings. Default is true. To report all findings, specify "false"| true| |
|KFP_GIT_URL| URL from repository to download known false positives files| | |
|PROJECT_NAME| Name of the scanned project, used to find path exclusions. By default, the Konflux component name will be used.| | |
|RECORD_EXCLUDED| Write excluded records in file. Useful for auditing (defaults to false).| false| |
|LABELS| Additional key=value labels that should be applied to the image| []| |
|PREFETCH_INPUT| In case it is not empty, the prefetched content should be made available to the build.| | '$(params.prefetch-input)'|
|PRIVILEGED_NESTED| Whether to enable privileged mode| false| |
|PROJECT_NAME| | | |
|RECORD_EXCLUDED| | false| |
|SBOM_TYPE| Select the SBOM format to generate. Valid values: spdx, cyclonedx. Note: the SBOM from the prefetch task - if there is one - must be in the same format.| cyclonedx| |
|SKIP_SBOM_GENERATION| Skip SBOM-related operations. This will likely cause EC policies to fail if enabled| false| |
|SKIP_UNUSED_STAGES| Whether to skip stages in Containerfile that seem unused by subsequent stages| true| |
|SQUASH| Squash all new and previous layers added as a part of this build, as per --squash| false| |
|STORAGE_DRIVER| Storage driver to configure for buildah| vfs| |
|TARGET_STAGE| Target stage in Dockerfile to build. If not specified, the Dockerfile is processed entirely to (and including) its last stage.| | |
|TLSVERIFY| Verify the TLS on the registry endpoint (for push/pull to a non-TLS registry)| true| |
|YUM_REPOS_D_FETCHED| Path in source workspace where dynamically-fetched repos are present| fetched.repos.d| |
|YUM_REPOS_D_SRC| Path in the git repository in which yum repository files are stored| repos.d| |
|YUM_REPOS_D_TARGET| Target path on the container in which yum repository files should be made available| /etc/yum.repos.d| |
|caTrustConfigMapKey| The name of the key in the ConfigMap that contains the CA bundle data.| ca-bundle.crt| |
|caTrustConfigMapName| The name of the ConfigMap to read CA bundle data from.| trusted-ca| |
|image-url| Image URL.| None| '$(tasks.build-image-index.results.IMAGE_URL)'|
|image-url| | None| '$(tasks.build-image-index.results.IMAGE_URL)'|
### sast-shell-check:0.1 task parameters
|name|description|default value|already set by|
|---|---|---|---|
Expand Down Expand Up @@ -287,7 +310,7 @@ This pipeline is pushed as a Tekton bundle to [quay.io](https://quay.io/reposito
|---|---|---|
|CHAINS-GIT_COMMIT| The precise commit SHA that was fetched by this Task. This result uses Chains type hinting to include in the provenance.| |
|CHAINS-GIT_URL| The precise URL that was fetched by this Task. This result uses Chains type hinting to include in the provenance.| |
|commit| The precise commit SHA that was fetched by this Task.| build-container:0.3:COMMIT_SHA ; build-image-index:0.1:COMMIT_SHA|
|commit| The precise commit SHA that was fetched by this Task.| build-container:0.3:COMMIT_SHA ; build-image-index:0.1:COMMIT_SHA ; sast-coverity-check:0.2:COMMIT_SHA|
|commit-timestamp| The commit timestamp of the checkout| |
|short-commit| The commit SHA that was fetched by this Task limited to params.shortCommitLength number of characters| |
|url| The precise URL that was fetched by this Task.| show-summary:0.2:git-url|
Expand Down Expand Up @@ -359,7 +382,7 @@ This pipeline is pushed as a Tekton bundle to [quay.io](https://quay.io/reposito
### sast-coverity-check:0.2 task workspaces
|name|description|optional|workspace from pipeline
|---|---|---|---|
|source| | False| workspace|
|source| Workspace containing the source code to build.| False| workspace|
### sast-shell-check:0.1 task workspaces
|name|description|optional|workspace from pipeline
|---|---|---|---|
Expand Down
48 changes: 48 additions & 0 deletions pipelines/docker-build/patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,51 @@
- $(params.build-args[*])
- name: BUILD_ARGS_FILE
value: "$(params.build-args-file)"

# FIXME: duplicate the "add" operations for sast-coverity-check, which is based on build-container
- op: add
path: /spec/tasks/11/params/-
value:
name: IMAGE
value: $(params.output-image)
- op: add
path: /spec/tasks/11/params/-
value:
name: DOCKERFILE
value: $(params.dockerfile)
- op: add
path: /spec/tasks/11/params/-
value:
name: CONTEXT
value: $(params.path-context)
- op: add
path: /spec/tasks/11/params/-
value:
name: HERMETIC
value: "$(params.hermetic)"
- op: add
path: /spec/tasks/11/params/-
value:
name: PREFETCH_INPUT
value: "$(params.prefetch-input)"
- op: add
path: /spec/tasks/11/params/-
value:
name: IMAGE_EXPIRES_AFTER
value: "$(params.image-expires-after)"
- op: add
path: /spec/tasks/11/params/-
value:
name: COMMIT_SHA
value: "$(tasks.clone-repository.results.commit)"
- op: add
path: /spec/tasks/11/params/-
value:
name: BUILD_ARGS
value:
- $(params.build-args[*])
- op: add
path: /spec/tasks/11/params/-
value:
name: BUILD_ARGS_FILE
value: "$(params.build-args-file)"
24 changes: 23 additions & 1 deletion task/sast-coverity-check/0.2/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

- The unused `IMAGE_DIGEST` parameter has been removed.

- The `sast-coverity-check` task now supports buildful SAST scanning, too.

## Action from users

- The workspace for this task in the build pipeline should be renamed to `source`.
- All parameters that are set for the `build-container` task now need to be set for `sast-coverity-check`, too.
- The `IMAGE_DIGEST` parameter definition can optionally be removed for this task in the build pipeline.

### Example
```diff
--- a/.tekton/konflux-test-operator-pipelines-pull-request.yaml
+++ b/.tekton/konflux-test-operator-pipelines-pull-request.yaml
@@ -417,40 +417,38 @@ spec:
@@ -417,40 +417,57 @@ spec:
when:
- input: $(params.skip-checks)
operator: in
Expand All @@ -26,6 +29,25 @@
- value: $(tasks.build-image-index.results.IMAGE_DIGEST)
- name: image-url
value: $(tasks.build-image-index.results.IMAGE_URL)
+ - name: IMAGE
+ value: $(params.output-image)
+ - name: DOCKERFILE
+ value: $(params.dockerfile)
+ - name: CONTEXT
+ value: $(params.path-context)
+ - name: HERMETIC
+ value: $(params.hermetic)
+ - name: PREFETCH_INPUT
+ value: $(params.prefetch-input)
+ - name: IMAGE_EXPIRES_AFTER
+ value: $(params.image-expires-after)
+ - name: COMMIT_SHA
+ value: $(tasks.clone-repository.results.commit)
+ - name: BUILD_ARGS
+ value:
+ - $(params.build-args[*])
+ - name: BUILD_ARGS_FILE
+ value: $(params.build-args-file)
runAfter:
- coverity-availability-check
taskRef:
Expand Down
6 changes: 2 additions & 4 deletions task/sast-coverity-check/0.2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

## Description:

The sast-coverity-check task uses Coverity tool to perform Static Application Security Testing (SAST). In this task, we use the buildless mode, where Coverity has the ability to capture source code without the need of building the product.
The sast-coverity-check task uses Coverity tool to perform Static Application Security Testing (SAST).

The documentation for this mode can be found here: https://sig-product-docs.synopsys.com/bundle/coverity-docs/page/commands/topics/coverity_capture.html

The characteristics of these tasks are:

- Perform buildless scanning with Coverity
- The whole source code is scanned (by scanning `$(workspaces.source.path)` )
- Perform buildful scanning with Coverity
- Only important findings are reported by default. A parameter ( `IMP_FINDINGS_ONLY`) is provided to override this configuration.
- The csdiff/v1 SARIF fingerprints are provided for all findings
- A parameter ( `KFP_GIT_URL`) is provided to remove false positives providing a known false positives repository. By default, no repository is provided.
Expand All @@ -20,7 +19,6 @@ The characteristics of these tasks are:

| name | description | default value | required |
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------|---------------------------|----------|
| COV_CAPTURE_ARGS | Append arguments to the Coverity Capture CLI command | "" | no |
| COV_ANALYZE_ARGS | Append arguments to the cov-analyze CLI command | "" | no |
| COV_LICENSE | Name of secret which contains the Coverity license | cov-license | no |
| AUTH_TOKEN_COVERITY_IMAGE | Name of secret which contains the authentication token for pulling the Coverity image | auth-token-coverity-image | no |
Expand Down
10 changes: 10 additions & 0 deletions task/sast-coverity-check/0.2/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../../buildah/0.3

patches:
- path: patch.yaml
target:
kind: Task
Loading

0 comments on commit c47c70d

Please sign in to comment.