-
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,90 @@ | ||
| #!/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 | ||
| # Kubernetes resource names: DNS label, max 63 chars | ||
| # ECP references are "name" or "namespace/name" | ||
| VALID_ECP_REF='^[a-z0-9]([-a-z0-9]*[a-z0-9])?(/[a-z0-9]([-a-z0-9]*[a-z0-9])?)?$' | ||
| if [[ "${POLICY_CONFIGURATION}" =~ $VALID_ECP_REF ]]; then | ||
| 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 | ||
| else | ||
| echo "Unsupported POLICY_CONFIGURATION format: ${POLICY_CONFIGURATION}" | ||
| echo "Policy bundle digest pinning is not supported for this format, skipping." | ||
| exit 0 | ||
| fi | ||
|
simonbaird marked this conversation as resolved.
|
||
| fi | ||
|
|
||
| ORIGINAL="oci::quay.io/conforma/release-policy:konflux" | ||
|
simonbaird marked this conversation as resolved.
|
||
| 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,59 @@ | ||
| #!/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"}" | ||
|
|
||
| # The two task definitions are the important placess where the digest | ||
| # should update, but it also appears in some tests, and in the docs. | ||
| # Update all those files as well so the change is ready to merge. | ||
| 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.