Skip to content

Commit 1d37a50

Browse files
authored
Merge pull request #3118 from arewm/fix/ta-missing-basename
fix: VSA generation issues in verify-conforma-konflux-ta task
2 parents b13a734 + 0057798 commit 1d37a50

6 files changed

Lines changed: 82 additions & 8 deletions

File tree

acceptance/kubernetes/kind/kubernetes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func (k *kindCluster) TaskInfo(ctx context.Context) (*types.TaskInfo, error) {
381381

382382
results := map[string]any{}
383383
for _, r := range tr.Status.Results {
384-
results[r.Name] = r.Value
384+
results[r.Name] = paramValue(r.Value)
385385
}
386386

387387
info := types.TaskInfo{

acceptance/kubernetes/kubernetes.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,30 @@ func taskResultsShouldMatchTheSnapshot(ctx context.Context) error {
395395
return snaps.MatchSnapshot(ctx, "results", string(j), nil)
396396
}
397397

398+
func taskResultShouldEqual(ctx context.Context, resultName, expectedValue string) error {
399+
c := testenv.FetchState[ClusterState](ctx)
400+
401+
if err := mustBeUp(ctx, *c); err != nil {
402+
return err
403+
}
404+
405+
info, err := c.cluster.TaskInfo(ctx)
406+
if err != nil {
407+
return err
408+
}
409+
410+
actual, ok := info.Results[resultName]
411+
if !ok {
412+
return fmt.Errorf("result %q not found in task results", resultName)
413+
}
414+
415+
if fmt.Sprintf("%v", actual) != expectedValue {
416+
return fmt.Errorf("result %q: expected %q, got %q", resultName, expectedValue, actual)
417+
}
418+
419+
return nil
420+
}
421+
398422
func taskLogsShouldContain(ctx context.Context, stepName, needle string) error {
399423
c := testenv.FetchState[ClusterState](ctx)
400424

@@ -467,6 +491,7 @@ func AddStepsTo(sc *godog.ScenarioContext) {
467491
sc.Step("^the task logs for step \"([^\"]*)\" should contain `([^`]+)`$", taskLogsShouldContain)
468492
sc.Step(`^the task env var for step "([^"]*)" named "([^"]*)" should be set to "([^"]*)"$`, stepEnvVarShouldBe)
469493
sc.Step(`^the task results should match the snapshot$`, taskResultsShouldMatchTheSnapshot)
494+
sc.Step(`^the task result "([^"]*)" should equal "([^"]*)"$`, taskResultShouldEqual)
470495
sc.Step(`^policy configuration named "([^"]*)" with (\d+) policy sources from "([^"]*)"(?:, patched with)$`, createNamedPolicyWithManySources)
471496
// stop usage of the cluster once a test is done, godog will call this
472497
// function on failure and on the last step, so more than once if the

docs/modules/ROOT/pages/verify-conforma-konflux-ta.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ paths can be provided by using the `:` separator.
9595
*VSA_SIGNING_KEY* (`string`):: Signing key for format=dsse (k8s:// or file:// URL)
9696
*VSA_UPLOAD* (`string`):: VSA upload destination
9797
+
98-
*Default*: `local@/var/workdir/vsa`
98+
*Default*: `local@/var/workdir/conforma/vsa`
9999
*ociStorage* (`string`):: OCI storage URL for trusted artifacts
100100

101101
== Results

features/__snapshots__/ta_task_validate_image.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
[Golden container image with trusted artifacts:results - 1]
135135
{
136136
"TEST_OUTPUT": "{\"timestamp\":\"${TIMESTAMP}\",\"namespace\":\"\",\"successes\":5,\"failures\":0,\"warnings\":0,\"result\":\"SUCCESS\"}\n",
137-
"VSA_GENERATED": "false\n"
137+
"VSA_GENERATED": "false"
138138
}
139139
---
140140

features/ta_task_validate_image.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,31 @@ Feature: Verify Conforma Trusted Artifact Tekton Task
5050
And the task results should match the snapshot
5151
And the task logs for step "show-config" should match the snapshot
5252

53+
Scenario: VSA generation with predicate format
54+
Given a working namespace
55+
Given a snapshot artifact with content:
56+
```
57+
{
58+
"components": [
59+
{
60+
"containerImage": "quay.io/hacbs-contract-demo/golden-container@sha256:e76a4ae9dd8a52a0d191fd34ca133af5b4f2609536d32200a4a40a09fdc93a0d"
61+
}
62+
]
63+
}
64+
```
65+
When version 0.1 of the task named "verify-conforma-konflux-ta" is run with parameters:
66+
| SNAPSHOT_FILENAME | snapshotartifact |
67+
| SOURCE_DATA_ARTIFACT | oci:${REGISTRY}/acceptance/snapshotartifact@${BUILD_SNAPSHOT_DIGEST} |
68+
| POLICY_CONFIGURATION | {"publicKey":"-----BEGIN PUBLIC KEY-----\\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAERhr8Zj4dZW67zucg8fDr11M4lmRp\\nzN6SIcIjkvH39siYg1DkCoa2h2xMUZ10ecbM3/ECqvBV55YwQ2rcIEa7XQ==\\n-----END PUBLIC KEY-----","sources":[{"policy":["git::github.com/conforma/policy//policy/release?ref=d34eab36b23d43748e451004177ca144296bf323","git::github.com/conforma/policy//policy/lib?ref=d34eab36b23d43748e451004177ca144296bf323"],"config":{"include":["slsa_provenance_available"]}}]} |
69+
| STRICT | true |
70+
| IGNORE_REKOR | true |
71+
| ENABLE_VSA | true |
72+
| ATTESTATION_FORMAT | predicate |
73+
| TRUSTED_ARTIFACTS_DEBUG | "true" |
74+
| ORAS_OPTIONS | --plain-http |
75+
Then the task should succeed
76+
And the task result "VSA_GENERATED" should equal "true"
77+
5378
Scenario: Policy configuration passed as JSON string
5479
Given a working namespace
5580
Given a snapshot artifact with content:

tasks/verify-conforma-konflux-ta/0.1/verify-conforma-konflux-ta.yaml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ spec:
203203
- name: VSA_UPLOAD
204204
type: string
205205
description: VSA upload destination
206-
default: "local@/var/workdir/vsa"
206+
default: "local@/var/workdir/conforma/vsa"
207207

208208
- name: ociStorage
209209
type: string
@@ -322,22 +322,44 @@ spec:
322322
if [[ "$(params.ENABLE_VSA)" == "true" ]]; then
323323
EC_ARGS+=(--vsa --attestation-format=$(params.ATTESTATION_FORMAT))
324324
325+
# Extract local path from VSA_UPLOAD for output directory
326+
# VSA_UPLOAD format is "local@/path/to/dir"
327+
VSA_LOCAL_PATH=$(echo "$(params.VSA_UPLOAD)" | grep -oE '^local@[^ ]+' | sed 's/^local@//' | head -n1 || true)
328+
325329
if [[ "$(params.ATTESTATION_FORMAT)" == "dsse" ]]; then
326330
if [[ -z "$(params.VSA_SIGNING_KEY)" ]]; then
327331
echo "ERROR: VSA_SIGNING_KEY required for format=dsse" >&2
328332
exit 1
329333
fi
330334
EC_ARGS+=(--vsa-signing-key "$(params.VSA_SIGNING_KEY)")
335+
EC_ARGS+=(--vsa-upload "$(params.VSA_UPLOAD)")
331336
fi
332337
333-
EC_ARGS+=(--vsa-upload "$(params.VSA_UPLOAD)")
334-
echo "true" > $(results.VSA_GENERATED.path)
338+
# ec requires --attestation-output-dir to be under /tmp or cwd.
339+
# Write there first, then copy to the workdir so
340+
# create-trusted-artifact includes them in the archive.
341+
VSA_TMP_DIR="/tmp/vsa-output"
342+
mkdir -p "$VSA_TMP_DIR"
343+
EC_ARGS+=(--attestation-output-dir "$VSA_TMP_DIR")
344+
345+
echo -n "true" > $(results.VSA_GENERATED.path)
335346
else
336-
echo "false" > $(results.VSA_GENERATED.path)
347+
echo -n "false" > $(results.VSA_GENERATED.path)
337348
fi
338349
339350
# Execute EC with constructed arguments
340351
ec "${EC_ARGS[@]}"
352+
353+
# Copy VSA output from /tmp to workdir for trusted artifact archival
354+
if [[ "$(params.ENABLE_VSA)" == "true" ]]; then
355+
VSA_LOCAL_PATH=$(echo "$(params.VSA_UPLOAD)" | grep -oE '^local@[^ ]+' | sed 's/^local@//' | head -n1 || true)
356+
if [[ -n "$VSA_LOCAL_PATH" && -d "/tmp/vsa-output" ]]; then
357+
mkdir -p "$VSA_LOCAL_PATH"
358+
cp -r /tmp/vsa-output/* "$VSA_LOCAL_PATH"/ 2>/dev/null || true
359+
# Include raw JSON report for downstream SLSA VSA generation
360+
cp "$(params.HOMEDIR)/report-json.json" "$VSA_LOCAL_PATH"/ 2>/dev/null || true
361+
fi
362+
fi
341363
env:
342364
# POLICY_CONFIGURATION is passed via environment variable to safely handle JSON strings
343365
# This avoids shell quoting issues when Tekton substitutes parameter values directly in scripts
@@ -449,7 +471,9 @@ spec:
449471
- name: ociStorage
450472
value: $(params.ociStorage)
451473
- name: workDir
452-
value: /var/workdir
474+
value: $(params.TRUSTED_ARTIFACTS_EXTRACT_DIR)
475+
- name: sourceDataArtifact
476+
value: $(results.sourceDataArtifact.path)
453477

454478
volumes:
455479
- name: trusted-ca

0 commit comments

Comments
 (0)