13
13
description : |-
14
14
Buildah task builds source code into a container image and pushes the image into container registry using buildah tool.
15
15
In addition it generates a SBOM file, injects the SBOM file into final container image and pushes the SBOM file as separate image using cosign tool.
16
- When [Java dependency rebuild](https://redhat-appstudio.github.io/docs.stonesoup.io/Documentation/main/cli/proc_enabled_java_dependencies.html) is enabled it triggers rebuilds of Java artifacts.
17
16
When prefetch-dependencies task was activated it is using its artifacts to run build in hermetic environment.
18
17
params :
19
18
- name : ACTIVATION_KEY
82
81
be made available to the build.
83
82
type : string
84
83
default : " "
84
+ - name : PRIVILEGED_NESTED
85
+ description : Whether to enable privileged mode
86
+ type : string
87
+ default : " false"
88
+ - name : SKIP_SBOM_GENERATION
89
+ description : Skip SBOM-related operations. This will likely cause EC
90
+ policies to fail if enabled
91
+ type : string
92
+ default : " false"
85
93
- name : SKIP_UNUSED_STAGES
86
94
description : Whether to skip stages in Containerfile that seem unused
87
95
by subsequent stages
@@ -206,16 +214,10 @@ spec:
206
214
description : Image reference of the built image
207
215
- name : IMAGE_URL
208
216
description : Image repository and tag where the built image was pushed
209
- - name : JAVA_COMMUNITY_DEPENDENCIES
210
- description : The Java dependencies that came from community sources
211
- such as Maven central.
212
217
- name : SBOM_BLOB_URL
213
218
description : Reference of SBOM blob digest to enable digest-based verification
214
219
from provenance
215
220
type : string
216
- - name : SBOM_JAVA_COMPONENTS_COUNT
217
- description : The counting of Java components by publisher in JSON format
218
- type : string
219
221
volumes :
220
222
- name : activation-key
221
223
secret :
@@ -254,6 +256,13 @@ spec:
254
256
- name : workdir
255
257
emptyDir : {}
256
258
stepTemplate :
259
+ computeResources :
260
+ limits :
261
+ cpu : " 4"
262
+ memory : 4Gi
263
+ requests :
264
+ cpu : " 1"
265
+ memory : 1Gi
257
266
env :
258
267
- name : ACTIVATION_KEY
259
268
value : $(params.ACTIVATION_KEY)
@@ -275,6 +284,10 @@ spec:
275
284
value : $(params.IMAGE)
276
285
- name : IMAGE_EXPIRES_AFTER
277
286
value : $(params.IMAGE_EXPIRES_AFTER)
287
+ - name : PRIVILEGED_NESTED
288
+ value : $(params.PRIVILEGED_NESTED)
289
+ - name : SKIP_SBOM_GENERATION
290
+ value : $(params.SKIP_SBOM_GENERATION)
278
291
- name : SKIP_UNUSED_STAGES
279
292
value : $(params.SKIP_UNUSED_STAGES)
280
293
- name : SOURCE_CODE_DIR
@@ -326,7 +339,7 @@ spec:
326
339
name : workdir
327
340
steps :
328
341
- name : use-trusted-artifact
329
- image : quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:52f1391e6f1c472fd10bb838f64fae2ed3320c636f536014978a5ddbdfc6b3af
342
+ image : quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:ff35e09ff5c89e54538b50abae241a765b2b7868f05d62c4835bebf0978f3659
330
343
args :
331
344
- use
332
345
- $(params.SOURCE_ARTIFACT)=/var/workdir/source
@@ -371,8 +384,7 @@ spec:
371
384
elif [ -e "$SOURCE_CODE_DIR/$DOCKERFILE" ]; then
372
385
dockerfile_path="$(pwd)/$SOURCE_CODE_DIR/$DOCKERFILE"
373
386
elif [ -e "$DOCKERFILE" ]; then
374
- # Custom Dockerfile location is mainly used for instrumented builds for SAST scanning and analyzing.
375
- # Instrumented builds use this step as their base and also need to provide modified Dockerfile.
387
+ # Instrumented builds (SAST) use this custom dockerffile step as their base
376
388
dockerfile_path="$DOCKERFILE"
377
389
elif echo "$DOCKERFILE" | grep -q "^https\?://"; then
378
390
echo "Fetch Dockerfile from $DOCKERFILE"
@@ -395,11 +407,6 @@ spec:
395
407
dockerfile_copy=$(mktemp --tmpdir "$(basename "$dockerfile_path").XXXXXX")
396
408
cp "$dockerfile_path" "$dockerfile_copy"
397
409
398
- if [ -n "${JVM_BUILD_WORKSPACE_ARTIFACT_CACHE_PORT_80_TCP_ADDR-}" ] && grep -q '^\s*RUN \(./\)\?mvn' "$dockerfile_copy"; then
399
- sed -i -e "s|^\s*RUN \(\(./\)\?mvn\)\(.*\)|RUN echo \"<settings><mirrors><mirror><id>mirror.default</id><url>http://$JVM_BUILD_WORKSPACE_ARTIFACT_CACHE_PORT_80_TCP_ADDR/v1/cache/default/0/</url><mirrorOf>*</mirrorOf></mirror></mirrors></settings>\" > /tmp/settings.yaml; \1 -s /tmp/settings.yaml \3|g" "$dockerfile_copy"
400
- touch /var/lib/containers/java
401
- fi
402
-
403
410
# Fixing group permission on /var/lib/containers
404
411
chown root:root /var/lib/containers
405
412
@@ -428,7 +435,7 @@ spec:
428
435
shift
429
436
# Note: this may result in multiple --build-arg=KEY=value flags with the same KEY being
430
437
# passed to buildah. In that case, the *last* occurrence takes precedence. This is why
431
- # we append BUILD_ARGS after the content of the BUILD_ARGS_FILE - they take precedence.
438
+ # we append BUILD_ARGS after the content of the BUILD_ARGS_FILE
432
439
while [[ $# -gt 0 && $1 != --* ]]; do
433
440
build_args+=("$1")
434
441
shift
@@ -477,6 +484,12 @@ spec:
477
484
478
485
BUILDAH_ARGS+=("${BUILD_ARG_FLAGS[@]}")
479
486
487
+ if [ "${PRIVILEGED_NESTED}" == "true" ]; then
488
+ BUILDAH_ARGS+=("--security-opt=label=disable")
489
+ BUILDAH_ARGS+=("--cap-add=all")
490
+ BUILDAH_ARGS+=("--device=/dev/fuse")
491
+ fi
492
+
480
493
if [ -n "${ADD_CAPABILITIES}" ]; then
481
494
BUILDAH_ARGS+=("--cap-add=${ADD_CAPABILITIES}")
482
495
fi
@@ -538,15 +551,15 @@ spec:
538
551
ACTIVATION_KEY_PATH="/activation-key"
539
552
ENTITLEMENT_PATH="/entitlement"
540
553
554
+ # 0. if hermetic=true, skip all subscription related stuff
541
555
# 1. do not enable activation key and entitlement at same time. If both vars are provided, prefer activation key.
542
556
# 2. Activation-keys will be used when the key 'org' exists in the activation key secret.
543
557
# 3. try to pre-register and mount files to the correct location so that users do no need to modify Dockerfiles.
544
558
# 3. If the Dockerfile contains the string "subcription-manager register", add the activation-keys volume
545
- # to buildah but don't pre-register for backwards compatibility. In this case mount an empty directory on
546
- # shared emptydir volume to "/etc/pki/entitlement" to prevent certificates from being included in the produced
547
- # container.
559
+ # to buildah but don't pre-register for backwards compatibility. Mount an empty directory on
560
+ # shared emptydir volume to "/etc/pki/entitlement" to prevent certificates from being included
548
561
549
- if [ -e /activation-key/org ]; then
562
+ if [ "${HERMETIC}" != "true" ] && [ -e /activation-key/org ]; then
550
563
cp -r --preserve=mode "$ACTIVATION_KEY_PATH" /tmp/activation-key
551
564
mkdir -p /shared/rhsm/etc/pki/entitlement
552
565
mkdir -p /shared/rhsm/etc/pki/consumer
@@ -570,17 +583,15 @@ spec:
570
583
VOLUME_MOUNTS+=(--volume /etc/rhsm/ca/redhat-uep.pem:/etc/rhsm/ca/redhat-uep.pem:Z)
571
584
fi
572
585
573
- # was: if [ -d "$ACTIVATION_KEY_PATH" ]; then
574
- elif find /entitlement -name "*.pem" >>null; then
586
+ elif [ "${HERMETIC}" != "true" ] && find /entitlement -name "*.pem" >>null; then
575
587
cp -r --preserve=mode "$ENTITLEMENT_PATH" /tmp/entitlement
576
588
VOLUME_MOUNTS+=(--volume /tmp/entitlement:/etc/pki/entitlement)
577
589
echo "Adding the entitlement to the build"
578
590
fi
579
591
580
592
if [ -n "${ADDITIONAL_VOLUME_MOUNTS-}" ]; then
581
593
# ADDITIONAL_VOLUME_MOUNTS allows to specify more volumes for the build.
582
- # This is primarily used in instrumented builds for SAST scanning and analyzing.
583
- # Instrumented builds use this step as their base and add some other tools.
594
+ # Instrumented builds (SAST) use this step as their base and add some other tools.
584
595
while read -r volume_mount; do
585
596
VOLUME_MOUNTS+=("--volume=$volume_mount")
586
597
done <<<"$ADDITIONAL_VOLUME_MOUNTS"
@@ -665,23 +676,26 @@ spec:
665
676
fi
666
677
667
678
container=$(buildah from --pull-never "$IMAGE")
668
- buildah mount $container | tee /shared/container_path
669
- # delete symlinks - they may point outside the container rootfs, messing with SBOM scanners
670
- find $(cat /shared/container_path) -xtype l -delete
671
- echo $container >/shared/container_name
672
679
673
680
# Save the SBOM produced by Cachi2 so it can be merged into the final SBOM later
674
681
if [ -f "/tmp/cachi2/output/bom.json" ]; then
682
+ echo "Making copy of sbom-cachi2.json"
675
683
cp /tmp/cachi2/output/bom.json ./sbom-cachi2.json
676
684
fi
677
685
686
+ buildah mount $container | tee /shared/container_path
687
+ # delete symlinks - they may point outside the container rootfs, messing with SBOM scanners
688
+ find $(cat /shared/container_path) -xtype l -delete
689
+ echo $container >/shared/container_name
690
+
678
691
touch /shared/base_images_digests
692
+ echo "Recording base image digests used"
679
693
for image in $BASE_IMAGES; do
680
694
base_image_digest=$(buildah images --format '{{ .Name }}:{{ .Tag }}@{{ .Digest }}' --filter reference="$image")
681
695
# In some cases, there might be BASE_IMAGES, but not any associated digest. This happens
682
696
# if buildah did not use that particular image during build because it was skipped
683
697
if [ -n "$base_image_digest" ]; then
684
- echo "$image $base_image_digest" >> /shared/base_images_digests
698
+ echo "$image $base_image_digest" | tee -a /shared/base_images_digests
685
699
fi
686
700
done
687
701
computeResources :
@@ -695,6 +709,20 @@ spec:
695
709
capabilities :
696
710
add :
697
711
- SETFCAP
712
+ - name : icm
713
+ image : quay.io/konflux-ci/icm-injection-scripts:latest@sha256:462980e94ba689b5f56c3d5dfb3358cd8c685300daf65a71532f11898935e7f1
714
+ workingDir : /var/workdir
715
+ volumeMounts :
716
+ - mountPath : /var/lib/containers
717
+ name : varlibcontainers
718
+ script : |
719
+ #!/bin/bash
720
+ set -euo pipefail
721
+ /scripts/inject-icm.sh "$IMAGE"
722
+ securityContext :
723
+ capabilities :
724
+ add :
725
+ - SETFCAP
698
726
- name : push
699
727
image : quay.io/konflux-ci/buildah-task:latest@sha256:b2d6c32d1e05e91920cd4475b2761d58bb7ee11ad5dff3ecb59831c7572b4d0c
700
728
workingDir : /var/workdir
@@ -765,44 +793,22 @@ spec:
765
793
- mountPath : /shared
766
794
name : shared
767
795
script : |
796
+ if [ "${SKIP_SBOM_GENERATION}" = "true" ]; then
797
+ echo "Skipping SBOM generation"
798
+ exit 0
799
+ fi
768
800
echo "Running syft on the source directory"
769
801
syft dir:"/var/workdir/$SOURCE_CODE_DIR/$CONTEXT" --output cyclonedx-json="/var/workdir/sbom-source.json"
770
802
echo "Running syft on the image filesystem"
771
803
syft dir:"$(cat /shared/container_path)" --output cyclonedx-json="/var/workdir/sbom-image.json"
772
- computeResources :
773
- limits :
774
- cpu : " 2"
775
- memory : 4Gi
776
- requests :
777
- cpu : 500m
778
- memory : 1Gi
779
- - name : analyse-dependencies-java-sbom
780
- image : quay.io/redhat-appstudio/hacbs-jvm-build-request-processor:127ee0c223a2b56a9bd20a6f2eaeed3bd6015f77
781
- volumeMounts :
782
- - mountPath : /var/lib/containers
783
- name : varlibcontainers
784
- - mountPath : /shared
785
- name : shared
786
- script : |
787
- if [ -f /var/lib/containers/java ]; then
788
- /opt/jboss/container/java/run/run-java.sh analyse-dependencies path $(cat /shared/container_path) -s /var/workdir/sbom-image.json --task-run-name $(context.taskRun.name) --publishers $(results.SBOM_JAVA_COMPONENTS_COUNT.path)
789
- sed -i 's/^/ /' $(results.SBOM_JAVA_COMPONENTS_COUNT.path) # Workaround for SRVKP-2875
790
- else
791
- touch $(results.JAVA_COMMUNITY_DEPENDENCIES.path)
792
- fi
793
- computeResources :
794
- limits :
795
- cpu : 200m
796
- memory : 512Mi
797
- requests :
798
- cpu : 100m
799
- memory : 256Mi
800
- securityContext :
801
- runAsUser : 0
802
804
- name : prepare-sboms
803
- image : quay.io/redhat-appstudio/sbom-utility-scripts-image@sha256:e1347023ef1e83d52813c26384f551e3a03e482539d17a647955603e7ea6b579
805
+ image : quay.io/redhat-appstudio/sbom-utility-scripts-image@sha256:9f1fd11d9c3c517ecc112d192ad361d16ecf6ce00b83b109c93cf3d1c644a357
804
806
workingDir : /var/workdir
805
807
script : |
808
+ if [ "${SKIP_SBOM_GENERATION}" = "true" ]; then
809
+ echo "Skipping SBOM generation"
810
+ exit 0
811
+ fi
806
812
echo "Merging contents of sbom-source.json and sbom-image.json into sbom-cyclonedx.json"
807
813
python3 /scripts/merge_syft_sboms.py
808
814
@@ -847,6 +853,10 @@ spec:
847
853
readOnly : true
848
854
script : |
849
855
#!/bin/bash
856
+ if [ "${SKIP_SBOM_GENERATION}" = "true" ]; then
857
+ echo "Skipping SBOM generation"
858
+ exit 0
859
+ fi
850
860
851
861
ca_bundle=/mnt/trusted-ca/ca-bundle.crt
852
862
if [ -f "$ca_bundle" ]; then
@@ -891,4 +901,4 @@ spec:
891
901
export QUARKUS_OIDC_CLIENT_CLIENT_ID="$(params.INDY_PROXY_CLIENT_ID)"
892
902
export QUARKUS_OIDC_CLIENT_CREDENTIALS_SECRET="$(params.INDY_PROXY_CLIENT_CREDENTIAL)"
893
903
/deployment/start-service.sh
894
- fi
904
+ fi
0 commit comments