|
| 1 | +--- |
| 2 | +apiVersion: tekton.dev/v1 |
| 3 | +kind: Task |
| 4 | +metadata: |
| 5 | + labels: |
| 6 | + app.kubernetes.io/version: "0.1" |
| 7 | + annotations: |
| 8 | + tekton.dev/pipelines.minVersion: "0.12.1" |
| 9 | + tekton.dev/tags: "konflux" |
| 10 | + name: fips-operator-bundle-check |
| 11 | +spec: |
| 12 | + description: >- |
| 13 | + Checks operator bundle image builds for FIPS compliance using the check-payload tool. |
| 14 | + params: |
| 15 | + - name: image-digest |
| 16 | + description: Image digest to scan. |
| 17 | + - name: image-url |
| 18 | + description: Image URL. |
| 19 | + results: |
| 20 | + - name: TEST_OUTPUT |
| 21 | + description: Tekton task test output. |
| 22 | + value: $(steps.fips-operator-check-step-action.results.TEST_OUTPUT) |
| 23 | + - name: IMAGES_PROCESSED |
| 24 | + description: Images processed in the task. |
| 25 | + value: $(steps.fips-operator-check-step-action.results.IMAGES_PROCESSED) |
| 26 | + steps: |
| 27 | + - name: get-unique-related-images |
| 28 | + image: quay.io/redhat-appstudio/konflux-test:v1.4.9@sha256:eee855e60b437d9a55a30e63f2eb7f95d9fd6d3b111c32cac8730c9b7a071394 |
| 29 | + computeResources: |
| 30 | + limits: |
| 31 | + memory: 512Mi |
| 32 | + cpu: 200m |
| 33 | + requests: |
| 34 | + memory: 256Mi |
| 35 | + cpu: 100m |
| 36 | + env: |
| 37 | + - name: IMAGE_URL |
| 38 | + value: $(params.image-url) |
| 39 | + - name: IMAGE_DIGEST |
| 40 | + value: $(params.image-digest) |
| 41 | + results: |
| 42 | + - name: unique_related_images |
| 43 | + description: Unique relatedImages from input operator bundle image |
| 44 | + - name: images_processed |
| 45 | + description: Images processed in the task. |
| 46 | + securityContext: |
| 47 | + capabilities: |
| 48 | + add: |
| 49 | + - SETFCAP |
| 50 | + script: | |
| 51 | + #!/usr/bin/env bash |
| 52 | + set -euo pipefail |
| 53 | + # shellcheck source=/dev/null |
| 54 | + . /utils.sh |
| 55 | +
|
| 56 | + imagewithouttag=$(echo -n "${IMAGE_URL}" | sed "s/\(.*\):.*/\1/") |
| 57 | + # strip new-line escape symbol from parameter and save it to variable |
| 58 | + imageanddigest="${imagewithouttag}@${IMAGE_DIGEST}" |
| 59 | +
|
| 60 | + imageanddigest_labels=$(skopeo inspect docker://"${imageanddigest}" --config | jq -r '.config.Labels // {} | to_entries[] | "\(.key)=\(.value)"') |
| 61 | + if ! echo "${imageanddigest_labels}" | grep -q 'operators.operatorframework.io.bundle.mediatype.v1='; then |
| 62 | + echo "The image $imageanddigest is not an operator bundle. Skipping FIPS static check..." |
| 63 | + echo "" | tee "$(step.results.images_processed.path)" | tee "$(step.results.unique_related_images.path)" |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | +
|
| 67 | + # Run the FIPS check only if the bundle is part of the Openshift Subscription or has the fips label set |
| 68 | + imageanddigest_render_out=$(opm render "$imageanddigest") |
| 69 | + subscription_label=$(echo "${imageanddigest_render_out}" | jq -r '.properties[] | select(.value.annotations["operators.openshift.io/valid-subscription"] != null) | (.value.annotations["operators.openshift.io/valid-subscription"] | fromjson)[]') |
| 70 | + fips_label=$(echo "${imageanddigest_labels}" | grep 'features.operators.openshift.io/fips-compliant=' | cut -d= -f2 || true) |
| 71 | +
|
| 72 | + if ! echo "${subscription_label}" | grep -e "OpenShift Kubernetes Engine" -e "OpenShift Container Platform" -e "OpenShift Platform Plus"; then |
| 73 | + echo "OpenShift Kubernetes Engine, OpenShift Platform Plus or OpenShift Container Platform are not present in operators.openshift.io/valid-subscription." |
| 74 | + echo "Subscription labels are : $subscription_label" |
| 75 | + if [ -z "${fips_label}" ] || [ "${fips_label}" != "true" ]; then |
| 76 | + echo "The label features.operators.openshift.io/fips-compliant is also not set to true. Skipping the FIPS static check..." |
| 77 | + echo "" | tee "$(step.results.images_processed.path)" | tee "$(step.results.unique_related_images.path)" |
| 78 | + exit 0 |
| 79 | + else |
| 80 | + echo "The label features.operators.openshift.io/fips-compliant is set to true. Running the FIPS static check..." |
| 81 | + fi |
| 82 | + else |
| 83 | + echo "OpenShift Kubernetes Engine, OpenShift Platform Plus or OpenShift Container Platform are present in operators.openshift.io/valid-subscription. Running the FIPS static check..." |
| 84 | + fi |
| 85 | +
|
| 86 | + unique_related_images=() |
| 87 | + digests_processed=() |
| 88 | + images_processed_template='{"image": {"pullspec": "'"$IMAGE_URL"'", "digests": [%s]}}' |
| 89 | +
|
| 90 | + echo "Inspecting raw image manifest $imageanddigest." |
| 91 | + # Get the arch and image manifests by inspecting the image. This is mainly for identifying image indexes |
| 92 | + image_manifests=$(get_image_manifests -i "${imageanddigest}") |
| 93 | + echo "Image manifests are $image_manifests" |
| 94 | +
|
| 95 | + declare -A seen_related_images |
| 96 | + # Extract relatedImages from the bundle image |
| 97 | + while read -r _ arch_sha; do |
| 98 | + digests_processed+=("\"$arch_sha\"") |
| 99 | + bundle_render_out=$(opm render "$imagewithouttag@$arch_sha") |
| 100 | + manifest_related_images=$(echo "${bundle_render_out}" | jq -r '.relatedImages[]?.image') |
| 101 | + if [ -n "$manifest_related_images" ]; then |
| 102 | + for img in $manifest_related_images; do |
| 103 | + if [ -z "${seen_related_images["$img"]:-}" ]; then |
| 104 | + unique_related_images+=("$img") |
| 105 | + seen_related_images["$img"]=1 |
| 106 | + fi |
| 107 | + done |
| 108 | + fi |
| 109 | + done < <(echo "$image_manifests" | jq -r 'to_entries[] | "\(.key) \(.value)"') |
| 110 | +
|
| 111 | + echo "Unique related images: ${unique_related_images[*]}" |
| 112 | + echo "${unique_related_images[*]}" | tee "$(step.results.unique_related_images.path)" |
| 113 | +
|
| 114 | + # If the image is an Image Index, also add the Image Index digest to the list. |
| 115 | + if [[ "${digests_processed[*]}" != *"$IMAGE_DIGEST"* ]]; then |
| 116 | + digests_processed+=("\"$IMAGE_DIGEST\"") |
| 117 | + fi |
| 118 | + digests_processed_string=$(IFS=,; echo "${digests_processed[*]}") |
| 119 | +
|
| 120 | + echo "${images_processed_template/\[%s]/[$digests_processed_string]}" | tee "$(step.results.images_processed.path)" |
| 121 | +
|
| 122 | + - name: fips-operator-check-step-action |
| 123 | + computeResources: |
| 124 | + limits: |
| 125 | + memory: 512Mi |
| 126 | + cpu: 200m |
| 127 | + requests: |
| 128 | + memory: 256Mi |
| 129 | + cpu: 100m |
| 130 | + ref: |
| 131 | + name: fips-operator-check-step-action |
| 132 | + params: |
| 133 | + - name: unique_related_images |
| 134 | + value: $(steps.get-unique-related-images.results.unique_related_images) |
| 135 | + - name: images_processed |
| 136 | + value: $(steps.get-unique-related-images.results.images_processed) |
0 commit comments