-
Notifications
You must be signed in to change notification settings - Fork 53
Pin the policy bundle by modifying the ECP in tekton tasks #3268
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
Draft
simonbaird
wants to merge
3
commits into
conforma:main
Choose a base branch
from
simonbaird:policy-with-bundle-pin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright The Conforma Contributors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # This script resolves a policy configuration and replaces the release | ||
| # policy OCI tag reference with a digest-pinned reference. It requires | ||
| # the following environment variables: | ||
| # | ||
| # - POLICY_CONFIGURATION: Policy reference (k8s name, inline JSON, or file path). | ||
| # - POLICY_BUNDLE_DIGEST: OCI digest to pin to (e.g. "sha256:abc123..." or "abc123..."). | ||
| # If empty, the script is a no-op. | ||
| # - HOME: Home directory (defaults to /tekton/home in Tekton tasks). | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| if [[ -z "${POLICY_BUNDLE_DIGEST}" ]]; then | ||
| echo "POLICY_BUNDLE_DIGEST is empty, skipping policy bundle digest override." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Normalize digest: prepend sha256: if not present | ||
| if [[ "${POLICY_BUNDLE_DIGEST}" != sha256:* ]]; then | ||
| POLICY_BUNDLE_DIGEST="sha256:${POLICY_BUNDLE_DIGEST}" | ||
| fi | ||
|
|
||
| echo "Applying policy bundle digest override: ${POLICY_BUNDLE_DIGEST}" | ||
|
|
||
| WORKING_POLICY="$(mktemp /tmp/policy.XXXXXX)" | ||
|
|
||
| if [[ "${POLICY_CONFIGURATION}" == "{"* ]]; then | ||
| # Inline JSON | ||
| printf "%s" "${POLICY_CONFIGURATION}" > "$WORKING_POLICY" | ||
|
|
||
| elif [[ -f "${POLICY_CONFIGURATION}" ]]; then | ||
| # File path | ||
| cp "${POLICY_CONFIGURATION}" "$WORKING_POLICY" | ||
|
|
||
| else | ||
| # Treat as k8s EnterpriseContractPolicy reference (namespace/name or name) | ||
| if [[ "${POLICY_CONFIGURATION}" == *"/"* ]]; then | ||
| NAMESPACE="${POLICY_CONFIGURATION%%/*}" | ||
| NAME="${POLICY_CONFIGURATION##*/}" | ||
| kubectl get enterprisecontractpolicy/"${NAME}" -n "${NAMESPACE}" -o json \ | ||
| | jq '.spec' > "$WORKING_POLICY" || \ | ||
| { echo "Failed to get EnterpriseContractPolicy: ${POLICY_CONFIGURATION}"; exit 1; } | ||
| else | ||
| kubectl get enterprisecontractpolicy/"${POLICY_CONFIGURATION}" -o json \ | ||
| | jq '.spec' > "$WORKING_POLICY" || \ | ||
| { echo "Failed to get EnterpriseContractPolicy: ${POLICY_CONFIGURATION}"; exit 1; } | ||
| fi | ||
| fi | ||
|
|
||
| ORIGINAL="oci::quay.io/conforma/release-policy:konflux" | ||
| REPLACEMENT="oci::quay.io/conforma/release-policy@${POLICY_BUNDLE_DIGEST}" | ||
|
|
||
| if ! grep -q "${ORIGINAL}" "$WORKING_POLICY"; then | ||
| echo "'${ORIGINAL}' not found in policy configuration, nothing to do." | ||
| exit 0 | ||
| fi | ||
|
|
||
| sed -i "s|${ORIGINAL}|${REPLACEMENT}|g" "$WORKING_POLICY" | ||
| echo "Replaced: ${ORIGINAL}" | ||
| echo " with: ${REPLACEMENT}" | ||
|
|
||
| POLICY_PATH="${HOME}/policy-with-pinned-bundle.yaml" | ||
| cp "$WORKING_POLICY" "${POLICY_PATH}" | ||
| echo "Modified policy written to: ${POLICY_PATH}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright The Conforma Contributors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Update the POLICY_BUNDLE_DIGEST default value in tekton task definitions. | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| IMAGE="${IMAGE:-"quay.io/conforma/release-policy:konflux"}" | ||
|
|
||
| FILES=( | ||
| tasks/verify-conforma-konflux-ta/0.1/verify-conforma-konflux-ta.yaml | ||
| tasks/verify-enterprise-contract/0.1/verify-enterprise-contract.yaml | ||
| docs/modules/ROOT/pages/verify-conforma-konflux-ta.adoc | ||
| docs/modules/ROOT/pages/verify-enterprise-contract.adoc | ||
| features/__snapshots__/task_validate_image.snap | ||
| features/task_validate_image.feature | ||
| ) | ||
|
|
||
| MANIFEST=$(skopeo inspect --raw "docker://${IMAGE}") | ||
| HASH=$(echo -n "${MANIFEST}" | sha256sum | awk '{print $1}') | ||
| NEW_DIGEST="sha256:${HASH}" | ||
|
|
||
| OLD_DIGEST=$(sed -n '/- name: POLICY_BUNDLE_DIGEST$/,/- name: /{s/.*default: "\(sha256:[a-f0-9]*\)".*/\1/p;}' "${FILES[0]}") | ||
|
|
||
| echo "Old digest: ${OLD_DIGEST}" | ||
| echo "New digest: ${NEW_DIGEST}" | ||
|
|
||
| if [[ "${OLD_DIGEST}" == "${NEW_DIGEST}" ]]; then | ||
| echo "Already up to date." | ||
| exit 0 | ||
| fi | ||
|
|
||
| for f in "${FILES[@]}"; do | ||
| if [[ ! -f "${f}" ]]; then | ||
| echo "Warning: ${f} not found, skipping" >&2 | ||
| continue | ||
| fi | ||
| sed -i "s|${OLD_DIGEST}|${NEW_DIGEST}|g" "${f}" | ||
| echo "Updated ${f}" | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,6 +157,21 @@ spec: | |
| description: Merge additional Rego variables into the policy data. Use syntax "key=value,key2=value2..." | ||
| default: "" | ||
|
|
||
| - name: POLICY_BUNDLE_DIGEST | ||
| type: string | ||
| description: >- | ||
| Optional OCI digest to pin the release policy bundle. When provided, | ||
| the policy configuration is resolved and the reference | ||
| oci::quay.io/conforma/release-policy:konflux is replaced with | ||
| oci::quay.io/conforma/release-policy@<digest>. Accepts a full digest | ||
| (sha256:abc123...) or just the hex hash (abc123...). | ||
| # For Konflux stability we want to try pinning the policy bundle rather | ||
| # than use the floating oci::quay.io/conforma/release-policy:konflux tag. | ||
| # Instead of needing to bump this in hundreds of separate ECPs, we'll do | ||
| # it here instead. If you don't want this behavior then provide an empty | ||
| # string value for this param. | ||
| default: "sha256:1b296a925b4021f4b4959ea289596925a8735540e554f3ba7754a651731a216f" | ||
|
Member
Author
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. If konflux-ci/build-definitions#3490 is merged, then we have the possibility of a slightly nicer way to set this at build time, instead of hard coding it. But I don't think that's a blocker, since the end result is the same. |
||
|
|
||
| - name: WORKERS | ||
| type: string | ||
| description: > | ||
|
|
@@ -326,6 +341,15 @@ spec: | |
| onError: continue # progress even if the step fails so we can see the debug logs | ||
| command: [reduce-snapshot.sh] | ||
|
|
||
| - name: pin-policy-bundle | ||
| env: | ||
| - name: POLICY_CONFIGURATION | ||
| value: $(params.POLICY_CONFIGURATION) | ||
| - name: POLICY_BUNDLE_DIGEST | ||
| value: $(params.POLICY_BUNDLE_DIGEST) | ||
| image: quay.io/conforma/cli:latest | ||
| command: [pin-konflux-policy-bundle.sh] | ||
|
|
||
| - name: validate | ||
| image: quay.io/conforma/cli:latest | ||
| onError: continue # progress even if the step fails so we can see the debug logs | ||
|
|
@@ -337,6 +361,11 @@ spec: | |
| export SSL_CERT_FILE="/mnt/trusted-ca/ca-bundle.crt" | ||
| fi | ||
|
|
||
| # Use policy override file if pin-policy-bundle produced one | ||
| if [[ -f "${HOMEDIR}/policy-with-pinned-bundle.yaml" ]]; then | ||
| POLICY_CONFIGURATION="${HOMEDIR}/policy-with-pinned-bundle.yaml" | ||
| fi | ||
|
|
||
| cmd_args=( | ||
| validate | ||
| image | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does matching the tag provide any value? Also, we're still pushing to
quay.io/enterprise-contract/ec-release-policy. Should that be added as well?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 wanted to match the tag since I think we should support people for whatever reason that deliberately want to use something other than the konflux tag. E.g. if you explicitly use :latest then let's respect that.
I don't think there's any good reason for anyone to still be using quay.io/enterprise-contract, so I'd rather not carry forward support for old deprecated repos.