Skip to content

Commit

Permalink
Add EC checks for StepActions
Browse files Browse the repository at this point in the history
  • Loading branch information
lcarva committed Nov 27, 2024
1 parent 68fe43e commit ad93d5e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
31 changes: 29 additions & 2 deletions .tekton/tasks/ec-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,28 @@ metadata:
spec:
description: >-
This task can be used to run enterprise contract checks
stepTemplate:
env:
- name: HOME
value: /tekton/home
steps:
- name: gather-tasks
image: quay.io/konflux-ci/appstudio-utils:48c311af02858e2422d6229600e9959e496ddef1@sha256:91ddd999271f65d8ec8487b10f3dd378f81aa894e11b9af4d10639fd52bba7e8
# per https://kubernetes.io/docs/concepts/containers/images/#imagepullpolicy-defaulting
# the cluster will set imagePullPolicy to IfNotPresent
workingDir: $(workspaces.source.path)/source
script: |
#!/bin/bash
set -euo pipefail
source hack/ec-checks.sh
$(build_tasks_dir build_tasks-ec)
$(all_tasks_dir all_tasks-ec)
# chmod is needed because the different images used in this Task run as different users. Ideally,
# we'd let OpenShift do its thing and set a random UID with a common group ID for *all* containers
# in the namespace, but that is currently disabled so it's wild west.
build_tasks_dir build_tasks-ec && chmod -R o+r build_tasks-ec
all_tasks_dir all_tasks-ec && chmod -R o+r all_tasks-ec
stepactions_dir stepactions-ec && chmod -R o+r stepactions-ec
- name: validate-all-tasks
workingDir: "$(workspaces.source.path)/source"
image: quay.io/enterprise-contract/ec-cli:snapshot@sha256:ccbf00aee7d4af1f78ba66aa04b0899b7e770dea44f6df0a1aa0a9a12529e9fe
Expand Down Expand Up @@ -49,5 +61,20 @@ spec:
policy='./policies/build-tasks.yaml'
ec validate input --policy "${policy}" --output yaml --strict=true ${args[*]}
- name: validate-step-actions
workingDir: "$(workspaces.source.path)/source"
image: quay.io/enterprise-contract/ec-cli:snapshot@sha256:46fae4d356d678383a926de8a68f79177d7e685d5497675acf41c9d3425aaacc
script: |
#!/bin/bash
set -euo pipefail
# Generate array of file parameters, e.g. --file=foo.yaml --file=bar.yaml
files=( stepactions-ec/*.yaml )
readarray -t args < <(printf -- '--file=%s\n' "${files[@]}")
echo "[DEBUG] Files parameter: ${args[*]}"
policy='./policies/step-actions.yaml'
ec validate input --show-successes --policy "${policy}" --output yaml --strict=true "${args[@]}"
workspaces:
- name: source
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ Specify the Quay repository using the `QUAY_NAMESPACE` environment variable in t
### Compliance
Task definitions must comply with the [Enterprise Contract](https://enterprisecontract.dev/) policies.
Currently, there are two policy configurations.
- The [all-tasks](./policies/all-tasks.yaml) policy
configuration applies to all Task definitions
- The [build-tasks](./policies/build-tasks.yaml)
policy configuration applies only to build Task definitions.
A build Task, i.e., one that produces a
container image, must abide by both policy configurations.
Currently, there are three policy configurations.
- The [all-tasks](./policies/all-tasks.yaml) policy configuration applies to all Task definitions.
- The [build-tasks](./policies/build-tasks.yaml) policy configuration applies only to build Task
definitions.
- The [step-actions](./policies/step-actions.yaml) policy configuration applies to all StepAction
definitions.
A build Task, e.g. one that produces a container image, must abide by both `all-tasks` and
`build-tasks` policy configurations.
17 changes: 17 additions & 0 deletions hack/ec-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,20 @@ function all_tasks_dir {
copy_all_task_versions "${task/*\//}" $tasks_dir
done
}

function stepactions_dir {
if [[ ! -d $1 ]]; then
mkdir $1
fi
local d=$1

while IFS= read -r -d '' f; do
found="$(yq eval '.kind == "StepAction"' "${f}")"
[[ ${found} != "true" ]] && continue
# Include version in the filename:
# stepactions/spam/0.1/spam.yaml -> 0.1-spam.yaml
dest="${d}/$(printf "${f}" | cut -d/ -f3- | sed 's_/_-_g')"
echo "[DEBUG] Copying ${f} to ${dest}"
cp "${f}" "${dest}"
done < <(find stepactions -name '*.yaml' -print0)
}
16 changes: 16 additions & 0 deletions policies/step-actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
# These policies are meant to be applied to all of the Tasks in this repo.
sources:
- policy:
- github.com/enterprise-contract/ec-policies//policy/lib
- github.com/enterprise-contract/ec-policies//policy/stepaction
data:
- oci::quay.io/konflux-ci/tekton-catalog/data-acceptable-bundles:latest
- github.com/release-engineering/rhtap-ec-policy//data
config:
include:
- stepaction.image
- stepaction.kind
# Support legacy matchers for now
- image
- kind

0 comments on commit ad93d5e

Please sign in to comment.