Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue preventing some SBOMs being fetched from Docker Hub #1119

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ All notable changes to `src-cli` are documented in this file.

## Unreleased

## 5.8.2

### Fixed

- Fixed a compatibility issue that prevented `src sbom fetch` from fetching some SBOMs [#1119](https://github.com/sourcegraph/src-cli/pull/1119)

## 5.8.1

### Fixed
Expand Down
9 changes: 8 additions & 1 deletion cmd/src/sbom_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"bytes"
"encoding/base64"
"encoding/json"
"flag"
Expand Down Expand Up @@ -262,8 +263,14 @@ type attestation struct {
}

func extractSBOM(attestationBytes []byte) (string, error) {
// Ensure we only use the first line - occasionally Cosign includes multiple lines
lines := bytes.Split(attestationBytes, []byte("\n"))
if len(lines) == 0 {
return "", fmt.Errorf("attestation is empty")
}

var a attestation
if err := json.Unmarshal(attestationBytes, &a); err != nil {
if err := json.Unmarshal(lines[0], &a); err != nil {
return "", fmt.Errorf("failed to unmarshal attestation: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/src/sbom_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func getImageDigestDockerHub(image string, tag string) (string, error) {
return "", err
}
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
req.Header.Add("Accept", "Accept: application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json")
req.Header.Add("Accept", "application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json")

// Make the HTTP request
resp, err := http.DefaultClient.Do(req)
Expand Down
Loading