Skip to content

Commit cdec316

Browse files
committed
Add EC checks for StepActions
Ref: https://issues.redhat.com/browse/EC-1010 Signed-off-by: Luiz Carvalho <[email protected]>
1 parent 93bae89 commit cdec316

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

.tekton/tasks/ec-checks.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ spec:
1818
# the cluster will set imagePullPolicy to IfNotPresent
1919
workingDir: $(workspaces.source.path)/source
2020
script: |
21+
#!/bin/bash
22+
set -euo pipefail
23+
2124
source hack/ec-checks.sh
22-
$(build_tasks_dir build_tasks-ec)
23-
$(all_tasks_dir all_tasks-ec)
25+
26+
build_tasks_dir build_tasks-ec
27+
all_tasks_dir all_tasks-ec
28+
stepactions_dir stepactions-ec
2429
- name: validate-all-tasks
2530
workingDir: "$(workspaces.source.path)/source"
2631
image: quay.io/enterprise-contract/ec-cli:snapshot@sha256:46fae4d356d678383a926de8a68f79177d7e685d5497675acf41c9d3425aaacc
@@ -49,5 +54,19 @@ spec:
4954
policy='./policies/build-tasks.yaml'
5055
5156
ec validate input --policy "${policy}" --output yaml --strict=true ${args[*]}
57+
- name: validate-step-actions
58+
workingDir: "$(workspaces.source.path)/source"
59+
image: quay.io/enterprise-contract/ec-cli:snapshot@sha256:46fae4d356d678383a926de8a68f79177d7e685d5497675acf41c9d3425aaacc
60+
script: |
61+
#!/bin/bash
62+
set -euo pipefail
63+
64+
# Generate array of file parameters, e.g. --file=foo.yaml --file=bar.yaml
65+
readarray -d '' args < <(find stepactions -name '*.yaml' -printf '--file=%p\0')
66+
echo "[DEBUG] Files parameter: ${args[*]}"
67+
68+
policy='./policies/step-actions.yaml'
69+
ec validate input --show-successes --policy "${policy}" --output yaml --strict=true "${args[@]}"
70+
5271
workspaces:
5372
- name: source

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ Specify the Quay repository using the `QUAY_NAMESPACE` environment variable in t
135135
### Compliance
136136
137137
Task definitions must comply with the [Enterprise Contract](https://enterprisecontract.dev/) policies.
138-
Currently, there are two policy configurations.
139-
- The [all-tasks](./policies/all-tasks.yaml) policy
140-
configuration applies to all Task definitions
141-
- The [build-tasks](./policies/build-tasks.yaml)
142-
policy configuration applies only to build Task definitions.
143-
144-
A build Task, i.e., one that produces a
145-
container image, must abide by both policy configurations.
138+
Currently, there are three policy configurations.
139+
140+
- The [all-tasks](./policies/all-tasks.yaml) policy configuration applies to all Task definitions.
141+
- The [build-tasks](./policies/build-tasks.yaml) policy configuration applies only to build Task
142+
definitions.
143+
- The [step-actions](./policies/step-actions.yaml) policy configuration applies to all StepAction
144+
definitions.
145+
146+
A build Task, e.g. one that produces a container image, must abide by both `all-tasks` and
147+
`build-tasks` policy configurations.

hack/ec-checks.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,20 @@ function all_tasks_dir {
5858
copy_all_task_versions "${task/*\//}" $tasks_dir
5959
done
6060
}
61+
62+
function stepactions_dir {
63+
if [[ ! -d $1 ]]; then
64+
mkdir $1
65+
fi
66+
local d=$1
67+
68+
while IFS= read -r -d '' f; do
69+
found="$(yq eval '.kind == "StepAction"' "${f}")"
70+
[[ ${found} != "true" ]] && continue
71+
# Include version in the filename:
72+
# stepactions/spam/0.1/spam.yaml -> 0.1-spam.yaml
73+
dest="${d}/$(printf "${f}" | cut -d/ -f3- | sed 's_/_-_g')"
74+
echo "[DEBUG] Copying ${f} to ${dest}"
75+
cp "${f}" "${dest}"
76+
done < <(find stepactions -name '*.yaml' -print0)
77+
}

policies/step-actions.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
# These policies are meant to be applied to all of the Tasks in this repo.
3+
sources:
4+
- policy:
5+
- github.com/enterprise-contract/ec-policies//policy/lib
6+
- github.com/enterprise-contract/ec-policies//policy/stepaction
7+
data:
8+
- oci::quay.io/konflux-ci/tekton-catalog/data-acceptable-bundles:latest
9+
- github.com/release-engineering/rhtap-ec-policy//data
10+
config:
11+
include:
12+
- stepaction.image
13+
- stepaction.kind
14+
# Support legacy matchers for now
15+
- image
16+
- kind

0 commit comments

Comments
 (0)