Skip to content

Commit 961e996

Browse files
committed
bug: debug dcgm 3 not creating attestations
1 parent ed79e99 commit 961e996

File tree

4 files changed

+323
-111
lines changed

4 files changed

+323
-111
lines changed

.github/actions/sbom-and-attest/action.yml

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,97 @@ runs:
9191
9292
SBOM_FILE="${{ steps.find-sbom.outputs.sbom_file }}"
9393
IMAGE_REF="${{ inputs.image_name }}@${{ inputs.image_digest }}"
94+
MAX_RETRIES=3
95+
RETRY_DELAY=5
96+
97+
# Function to attest with retry logic
98+
attest_with_retry() {
99+
local target_ref="$1"
100+
local platform_info="${2:-unknown}"
101+
local attempt=1
102+
103+
while [ $attempt -le $MAX_RETRIES ]; do
104+
echo "Attesting ${target_ref} (${platform_info}) - attempt ${attempt}/${MAX_RETRIES}"
105+
106+
if cosign attest \
107+
--yes \
108+
--predicate "$SBOM_FILE" \
109+
--type cyclonedx \
110+
"$target_ref" 2>&1 | tee /tmp/cosign_output.log; then
111+
112+
# Verify attestation was created by checking for success indicators
113+
if grep -q "tlog entry created\|Attestation written\|successfully" /tmp/cosign_output.log || \
114+
[ ${PIPESTATUS[0]} -eq 0 ]; then
115+
echo "✓ Attestation successful for ${target_ref}"
116+
117+
# Additional verification: check if attestation exists in registry
118+
sleep 2 # Brief delay for registry propagation
119+
if cosign verify-attestation \
120+
--type cyclonedx \
121+
--certificate-identity-regexp=".*" \
122+
--certificate-oidc-issuer-regexp=".*" \
123+
"$target_ref" &>/dev/null; then
124+
echo "✓ Attestation verified in registry for ${target_ref}"
125+
return 0
126+
else
127+
echo "⚠ Attestation created but not yet visible in registry, continuing anyway"
128+
return 0
129+
fi
130+
fi
131+
fi
132+
133+
# If we get here, attestation failed
134+
echo "✗ Attestation attempt ${attempt} failed for ${target_ref}"
135+
cat /tmp/cosign_output.log || true
136+
137+
if [ $attempt -lt $MAX_RETRIES ]; then
138+
echo "Retrying in ${RETRY_DELAY} seconds..."
139+
sleep $RETRY_DELAY
140+
attempt=$((attempt + 1))
141+
else
142+
echo "::error::Failed to attest ${target_ref} after ${MAX_RETRIES} attempts"
143+
return 1
144+
fi
145+
done
146+
}
94147
95148
# Check if this is a multi-platform image (OCI index)
96149
MANIFEST_TYPE=$(crane manifest "$IMAGE_REF" | jq -r '.mediaType // "unknown"')
97150
98151
if [[ "$MANIFEST_TYPE" == "application/vnd.oci.image.index.v1+json" ]] || \
99152
[[ "$MANIFEST_TYPE" == "application/vnd.docker.distribution.manifest.list.v2+json" ]]; then
100153
# Multi-platform: attest each platform digest separately
101-
PLATFORM_DIGESTS=$(crane manifest "$IMAGE_REF" | \
102-
jq -r '.manifests[] | select((.annotations."vnd.docker.reference.type" // "") != "attestation-manifest") | .digest')
154+
echo "Detected multi-platform image, will attest each platform separately"
103155
104-
while IFS= read -r DIGEST; do
105-
echo "Attesting ${{ inputs.image_name }}@${DIGEST}"
106-
cosign attest \
107-
--yes \
108-
--predicate "$SBOM_FILE" \
109-
--type cyclonedx \
110-
"${{ inputs.image_name }}@${DIGEST}"
111-
done <<< "$PLATFORM_DIGESTS"
156+
# Get platform digests with architecture info
157+
PLATFORM_INFO=$(crane manifest "$IMAGE_REF" | \
158+
jq -r '.manifests[] | select((.annotations."vnd.docker.reference.type" // "") != "attestation-manifest") | "\(.digest) \(.platform.architecture)/\(.platform.os)"')
159+
160+
FAILED_PLATFORMS=()
161+
while IFS= read -r line; do
162+
DIGEST=$(echo "$line" | awk '{print $1}')
163+
PLATFORM=$(echo "$line" | awk '{print $2}')
164+
165+
if ! attest_with_retry "${{ inputs.image_name }}@${DIGEST}" "$PLATFORM"; then
166+
FAILED_PLATFORMS+=("$PLATFORM ($DIGEST)")
167+
fi
168+
done <<< "$PLATFORM_INFO"
169+
170+
# Check if any platforms failed
171+
if [ ${#FAILED_PLATFORMS[@]} -gt 0 ]; then
172+
echo "::error::Failed to attest the following platforms:"
173+
printf '::error:: - %s\n' "${FAILED_PLATFORMS[@]}"
174+
exit 1
175+
fi
176+
177+
echo "✓ All platform attestations completed successfully"
112178
else
113179
# Single-platform: attest directly
114-
echo "Attesting $IMAGE_REF"
115-
cosign attest \
116-
--yes \
117-
--predicate "$SBOM_FILE" \
118-
--type cyclonedx \
119-
"$IMAGE_REF"
180+
echo "Detected single-platform image"
181+
attest_with_retry "$IMAGE_REF" "single-platform"
120182
fi
183+
184+
echo "✓ SBOM attestation process completed"
121185
122186
- name: Attest build provenance
123187
uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0

distros/kubernetes/nvsentinel/policies/must-have-sbom.yaml

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
# - Third-party images (databases, sidecars, etc.) are NOT affected
88
#
99
# This policy uses Sigstore Policy Controller to verify that NVSentinel images
10-
# have BOTH:
11-
# 1. Valid SLSA Build Provenance attestations
12-
# 2. Valid SBOM (CycloneDX) attestations
13-
# Both signed by the official GitHub Actions workflow using keyless signing.
10+
# have valid SBOM (CycloneDX) attestations signed by the official GitHub Actions
11+
# workflow using keyless signing.
12+
#
13+
# Note: SLSA Build Provenance verification is handled separately by
14+
# must-have-slsa.yaml policy.
1415
#
1516
# Multi-platform support:
1617
# - Images are built for linux/amd64 and linux/arm64
@@ -26,19 +27,19 @@
2627
apiVersion: policy.sigstore.dev/v1beta1
2728
kind: ClusterImagePolicy
2829
metadata:
29-
name: verify-nvsentinel-image-attestation
30+
name: verify-nvsentinel-sbom
3031
annotations:
3132
description: >-
32-
Verifies that NVSentinel container images have valid SLSA Build
33-
Provenance and SBOM attestations signed by the official GitHub Actions
34-
workflow. Ensures images were built from the official NVIDIA/NVSentinel
35-
repository with proper attestations before allowing them to run in the cluster.
36-
Only applies to ghcr.io/nvidia/nvsentinel/** images.
33+
Verifies that NVSentinel container images have valid SBOM attestations
34+
signed by the official GitHub Actions workflow. Ensures images have proper
35+
Software Bill of Materials documentation before allowing them to run in the
36+
cluster. Only applies to ghcr.io/nvidia/nvsentinel/** images.
3737
category: Supply Chain Security
3838
severity: high
3939
spec:
4040
# WARN MODE: Currently in warn mode due to bundle format v0.3 incompatibility
4141
# Policy Controller 0.10.5 cannot read Sigstore bundle format v0.3
42+
# Both SLSA and SBOM attestations have the same issue
4243
# Will be changed to enforce mode when Policy Controller adds v0.3 support
4344
mode: warn
4445

@@ -62,39 +63,9 @@ spec:
6263
# Use public Sigstore Rekor instance for transparency log
6364
ctlog:
6465
url: https://rekor.sigstore.dev
65-
# Validate attestations - both SLSA provenance and SBOM
66+
# Validate SBOM attestation only
6667
attestations:
67-
# 1. SLSA Build Provenance - verifies the build process
68-
- name: slsa-provenance
69-
predicateType: https://slsa.dev/provenance/v1
70-
policy:
71-
type: cue
72-
data: |
73-
// Validate the builder is the official GitHub Actions workflow
74-
predicateType: "https://slsa.dev/provenance/v1"
75-
predicate: buildDefinition: {
76-
buildType: "https://slsa-framework.github.io/github-actions-buildtypes/workflow/v1"
77-
externalParameters: {
78-
workflow: {
79-
ref: =~"^refs/(heads|tags)/"
80-
repository: "https://github.com/NVIDIA/NVSentinel"
81-
}
82-
}
83-
internalParameters: {
84-
github: {
85-
event_name: "push" | "workflow_dispatch" | "release"
86-
}
87-
}
88-
}
89-
90-
// Validate the source repository
91-
predicate: runDetails: {
92-
builder: {
93-
id: =~"^https://github.com/NVIDIA/NVSentinel/"
94-
}
95-
}
96-
97-
# 2. SBOM (Software Bill of Materials) - verifies components are documented
68+
# SBOM (Software Bill of Materials) - verifies components are documented
9869
- name: sbom-cyclonedx
9970
# Cosign uses this predicate type for CycloneDX SBOMs
10071
predicateType: https://cyclonedx.org/bom

distros/kubernetes/nvsentinel/policies/must-have-slsa.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
apiVersion: policy.sigstore.dev/v1beta1
1919
kind: ClusterImagePolicy
2020
metadata:
21-
name: verify-nvsentinel-image-attestation
21+
name: verify-nvsentinel-slsa
2222
annotations:
2323
description: >-
2424
Verifies that NVSentinel container images have valid SLSA Build

0 commit comments

Comments
 (0)