Skip to content

Commit 86e02fa

Browse files
committed
Add EC checks for StepActions
Ref: https://issues.redhat.com/browse/EC-1010 Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
1 parent b2d4ae5 commit 86e02fa

File tree

4 files changed

+75
-12
lines changed

4 files changed

+75
-12
lines changed

.tekton/tasks/ec-checks.yaml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,33 @@ metadata:
1111
spec:
1212
description: >-
1313
This task can be used to run enterprise contract checks
14+
stepTemplate:
15+
securityContext:
16+
# runAsUser is needed because the different images used in this Task run as different users. Ideally,
17+
# we'd let OpenShift do its thing and set a random UID with a common group ID for *all* containers
18+
# in the namespace, but that is currently disabled so it's wild west.
19+
runAsUser: 0
20+
env:
21+
- name: HOME
22+
value: /tekton/home
1423
steps:
1524
- name: gather-tasks
1625
image: quay.io/konflux-ci/appstudio-utils:48c311af02858e2422d6229600e9959e496ddef1@sha256:91ddd999271f65d8ec8487b10f3dd378f81aa894e11b9af4d10639fd52bba7e8
1726
# per https://kubernetes.io/docs/concepts/containers/images/#imagepullpolicy-defaulting
1827
# the cluster will set imagePullPolicy to IfNotPresent
1928
workingDir: $(workspaces.source.path)/source
2029
script: |
30+
#!/bin/bash
31+
set -euo pipefail
32+
2133
source hack/ec-checks.sh
22-
$(build_tasks_dir build_tasks-ec)
23-
$(all_tasks_dir all_tasks-ec)
34+
35+
build_tasks_dir build_tasks-ec
36+
all_tasks_dir all_tasks-ec
37+
stepactions_dir stepactions-ec
2438
- name: validate-all-tasks
2539
workingDir: "$(workspaces.source.path)/source"
26-
image: quay.io/enterprise-contract/ec-cli:snapshot@sha256:ccbf00aee7d4af1f78ba66aa04b0899b7e770dea44f6df0a1aa0a9a12529e9fe
40+
image: quay.io/enterprise-contract/ec-cli:snapshot@sha256:46fae4d356d678383a926de8a68f79177d7e685d5497675acf41c9d3425aaacc
2741
script: |
2842
set -euo pipefail
2943
@@ -37,7 +51,7 @@ spec:
3751
ec validate input --policy "${policy}" --output yaml --strict=true ${args[*]}
3852
- name: validate-build-tasks
3953
workingDir: "$(workspaces.source.path)/source"
40-
image: quay.io/enterprise-contract/ec-cli:snapshot@sha256:ccbf00aee7d4af1f78ba66aa04b0899b7e770dea44f6df0a1aa0a9a12529e9fe
54+
image: quay.io/enterprise-contract/ec-cli:snapshot@sha256:46fae4d356d678383a926de8a68f79177d7e685d5497675acf41c9d3425aaacc
4155
script: |
4256
set -euo pipefail
4357
@@ -49,5 +63,20 @@ spec:
4963
policy='./policies/build-tasks.yaml'
5064
5165
ec validate input --policy "${policy}" --output yaml --strict=true ${args[*]}
66+
- name: validate-step-actions
67+
workingDir: "$(workspaces.source.path)/source"
68+
image: quay.io/enterprise-contract/ec-cli:snapshot@sha256:46fae4d356d678383a926de8a68f79177d7e685d5497675acf41c9d3425aaacc
69+
script: |
70+
#!/bin/bash
71+
set -euo pipefail
72+
73+
# Generate array of file parameters, e.g. --file=foo.yaml --file=bar.yaml
74+
files=( stepactions-ec/*.yaml )
75+
readarray -t args < <(printf -- '--file=%s\n' "${files[@]}")
76+
echo "[DEBUG] Files parameter: ${args[*]}"
77+
78+
policy='./policies/step-actions.yaml'
79+
ec validate input --show-successes --policy "${policy}" --output yaml --strict=true "${args[@]}"
80+
5281
workspaces:
5382
- 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,19 @@ 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+
shopt -s globstar
69+
for f in stepactions/**/*.yaml; do
70+
yq eval -e '.kind == "StepAction"' "${f}" || continue
71+
dest="${f#*/*/}"
72+
dest="${d}/${dest/\//-}"
73+
echo "[DEBUG] Copying ${f} to ${dest}"
74+
cp "${f}" "${dest}"
75+
done
76+
}

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)