@@ -45,9 +45,14 @@ helm_chart_name := $(notdir $(helm_chart_image_name))
4545helm_chart_image_registry := $(dir $(helm_chart_image_name ) )
4646helm_chart_image_tag := $(helm_chart_version )
4747helm_chart_sources := $(shell find $(helm_chart_source_dir ) -maxdepth 1 -type f) $(shell find $(helm_chart_source_dir ) /templates -type f)
48- helm_chart_archive := $(bin_dir ) /scratch/image/$(helm_chart_name ) -$(helm_chart_version ) .tgz
48+ helm_chart_archive := $(bin_dir ) /scratch/helm/$(helm_chart_name ) -$(helm_chart_version ) .tgz
49+ helm_digest_path := $(bin_dir ) /scratch/helm/$(helm_chart_name ) -$(helm_chart_version ) .digests
50+ helm_digest = $(shell head -1 $(helm_digest_path ) 2> /dev/null)
4951
50- $(helm_chart_archive ) : $(helm_chart_sources ) | $(NEEDS_HELM ) $(NEEDS_YQ ) $(bin_dir ) /scratch/image
52+ $(bin_dir ) /scratch/helm :
53+ @mkdir -p $@
54+
55+ $(helm_chart_archive ) : $(helm_chart_sources ) | $(NEEDS_HELM ) $(NEEDS_YQ ) $(bin_dir ) /scratch/helm
5156 $(eval helm_chart_source_dir_versioned := $@ .tmp)
5257 rm -rf $(helm_chart_source_dir_versioned )
5358 mkdir -p $(dir $(helm_chart_source_dir_versioned ) )
@@ -59,7 +64,7 @@ $(helm_chart_archive): $(helm_chart_sources) | $(NEEDS_HELM) $(NEEDS_YQ) $(bin_d
5964 echo "Chart name does not match the name in the helm_chart_name variable"; \
6065 exit 1; \
6166 fi
62-
67+
6368 $(YQ) '.annotations."artifacthub.io/prerelease" = "$(IS_PRERELEASE)"' \
6469 --inplace $(helm_chart_source_dir_versioned)/Chart.yaml
6570
@@ -74,8 +79,13 @@ $(helm_chart_archive): $(helm_chart_sources) | $(NEEDS_HELM) $(NEEDS_YQ) $(bin_d
7479# # Will also create a non-v-prefixed tag for the OCI image.
7580# # @category [shared] Publish
7681helm-chart-oci-push : $(helm_chart_archive ) | $(NEEDS_HELM ) $(NEEDS_CRANE )
77- $(HELM ) push " $( helm_chart_archive) " " oci://$( helm_chart_image_registry) "
78- $(CRANE ) copy " $( helm_chart_image_name) :$( helm_chart_image_tag) " " $( helm_chart_image_name) :$( helm_chart_image_tag:v%=%) "
82+ $(HELM ) push " $( helm_chart_archive) " " oci://$( helm_chart_image_registry) " 2>&1 \
83+ | tee >( grep -o " sha256:.\+" | tee $( helm_digest_path) )
84+
85+ @# $(helm_chart_image_tag:v%=%) removes the v prefix from the value stored in helm_chart_image_tag.
86+ @# See https://www.gnu.org/software/make/manual/html_node/Substitution-Refs.html for the manual on the syntax.
87+ helm_digest=$$(cat $(helm_digest_path)) && \
88+ $(CRANE) copy "$(helm_chart_image_name)@$$helm_digest" "$(helm_chart_image_name):$(helm_chart_image_tag:v%=%)"
7989
8090.PHONY : helm-chart
8191# # Create a helm chart
@@ -109,12 +119,34 @@ verify-helm-values: | $(NEEDS_HELM-TOOL) $(NEEDS_GOJQ)
109119
110120shared_verify_targets += verify-helm-values
111121
122+ $(bin_dir ) /scratch/kyverno :
123+ @mkdir -p $@
124+
125+ $(bin_dir ) /scratch/kyverno/pod-security-policy.yaml : | $(NEEDS_KUSTOMIZE ) $(bin_dir ) /scratch/kyverno
126+ @$(KUSTOMIZE ) build https://github.com/kyverno/policies/pod-security/enforce > $@
127+
128+ # Extra arguments for kyverno apply.
129+ kyverno_apply_extra_args :=
130+ # Allows known policy violations to be skipped by supplying Kyverno policy
131+ # exceptions.
132+ ifneq ("$(wildcard make/verify-pod-security-standards-exceptions.yaml) ","")
133+ kyverno_apply_extra_args += --exceptions make/verify-pod-security-standards-exceptions.yaml
134+ endif
135+
112136.PHONY : verify-pod-security-standards
113137# # Verify that the Helm chart complies with the pod security standards.
138+ # #
139+ # # You can add Kyverno policy exceptions to
140+ # # `make/verify-pod-security-standards-exceptions.yaml`, to skip some of the pod
141+ # # security policy rules.
142+ # #
114143# # @category [shared] Generate/ Verify
115- verify-pod-security-standards : $(helm_chart_archive ) | $(NEEDS_KYVERNO ) $(NEEDS_KUSTOMIZE ) $(NEEDS_HELM )
116- $(KYVERNO ) apply <( $( KUSTOMIZE) build https://github.com/kyverno/policies/pod-security/enforce) \
117- --resource <( $( HELM) template $( helm_chart_archive) ) 2> /dev/null
144+ verify-pod-security-standards : $(helm_chart_archive ) $(bin_dir ) /scratch/kyverno/pod-security-policy.yaml | $(NEEDS_KYVERNO ) $(NEEDS_HELM )
145+ @$(HELM ) template $(helm_chart_archive ) $(INSTALL_OPTIONS ) \
146+ | $(KYVERNO ) apply $(bin_dir ) /scratch/kyverno/pod-security-policy.yaml \
147+ $(kyverno_apply_extra_args ) \
148+ --resource - \
149+ --table
118150
119151shared_verify_targets_dirty += verify-pod-security-standards
120152
0 commit comments