|
| 1 | +# Referrers |
| 2 | + |
| 3 | +# Prepare OCI 1.1 compliant registry |
| 4 | +REGISTRY=127.0.0.1:5000 |
| 5 | +docker container run --detach --name registry --publish "${REGISTRY}:5000" ghcr.io/oras-project/registry:v1.0.0-rc.4 |
| 6 | +regctl registry set "${REGISTRY}" --tls disabled |
| 7 | + |
| 8 | +# Prepare test image |
| 9 | +REPOSITORY=ubuntu |
| 10 | +TAG=22.04 |
| 11 | +IMAGE="${REGISTRY}/${REPOSITORY}:${TAG}" |
| 12 | +docker pull "${REPOSITORY}:${TAG}" |
| 13 | +docker tag "${REPOSITORY}:${TAG}" "${IMAGE}" |
| 14 | +docker push "${IMAGE}" |
| 15 | + |
| 16 | +# Create and link SBOM |
| 17 | +trivy image "${IMAGE}" --format cyclonedx --output cyclonedx.json |
| 18 | +cat cyclonedx.json \ |
| 19 | +| regctl artifact put --subject "${IMAGE}" \ |
| 20 | + --artifact-type application/vnd.cyclonedx+json \ |
| 21 | + --file-media-type application/vnd.cyclonedx+json \ |
| 22 | + --annotation "created-by=trivy" \ |
| 23 | + --annotation "org.opencontainers.artifact.created=$(date -Iseconds)" \ |
| 24 | + --annotation "org.opencontainers.artifact.description=CycloneDX JSON SBOM" |
| 25 | +trivy referrer list "${IMAGE}" |
| 26 | + |
| 27 | +# Create and link SARIF report |
| 28 | +trivy image "${IMAGE}" --format sarif \ |
| 29 | +| regctl artifact put --subject "${IMAGE}" \ |
| 30 | + --artifact-type application/json \ |
| 31 | + --file-media-type application/json \ |
| 32 | + --annotation "created-by=trivy" \ |
| 33 | + --annotation "org.opencontainers.artifact.created=$(date -Iseconds)" \ |
| 34 | + --annotation "org.opencontainers.artifact.description=SARIF JSON" |
| 35 | +trivy referrer list "${IMAGE}" |
| 36 | + |
| 37 | +# Sign container image |
| 38 | +COSIGN_EXPERIMENTAL=1 cosign sign -y --registry-referrers-mode oci-1-1 "${IMAGE}" |
| 39 | + |
| 40 | +# Sign SBOM |
| 41 | +SOURCE_CYCLONEDX="$( |
| 42 | + regctl artifact tree --filter-artifact-type application/vnd.cyclonedx+json "${IMAGE}" --format "{{json .}}" \ |
| 43 | + | jq -r '.referrer | .[0].reference.Digest' |
| 44 | +)" |
| 45 | +COSIGN_EXPERIMENTAL=1 cosign sign -y -- |
| 46 | +registry-referrers-mode oci-1-1 "${IMAGE}@${SOURCE_CYCLONEDX}" |
| 47 | +oras discover "${IMAGE}" --plain-http --output tree |
| 48 | + |
| 49 | +# Sign SARIF |
| 50 | +SOURCE_SARIF="$( |
| 51 | + regctl artifact tree --filter-artifact-type application/sarif+json "${IMAGE}" --format "{{json .}}" \ |
| 52 | + | jq -r '.referrer | .[0].reference.Digest' |
| 53 | +)" |
| 54 | +COSIGN_EXPERIMENTAL=1 cosign sign -y --registry-referrers-mode oci-1-1 "${IMAGE}@${SOURCE_SARIF}" |
0 commit comments