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

Lock TUF client during target loading operations #1992

Closed
wants to merge 1 commit into from
Closed
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 pkg/cosign/tuf/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var GetRemoteRoot = func() string {
}

type TUF struct {
sync.Mutex
client *client.Client
targets targetImpl
local client.LocalStore
Expand Down Expand Up @@ -345,6 +346,8 @@ func isValidTarget(testTarget []byte, validMeta data.TargetFileMeta) bool {

func (t *TUF) GetTarget(name string) ([]byte, error) {
// Get valid target metadata. Does a local verification.
t.Lock()
defer t.Unlock()
validMeta, err := t.client.Target(name)
if err != nil {
return nil, fmt.Errorf("error verifying local metadata; local cache may be corrupt: %w", err)
Expand All @@ -364,10 +367,13 @@ func (t *TUF) GetTarget(name string) ([]byte, error) {
// Get target files by a custom usage metadata tag. If there are no files found,
// use the fallback target names to fetch the targets by name.
func (t *TUF) GetTargetsByMeta(usage UsageKind, fallbacks []string) ([]TargetFile, error) {
t.Lock()
targets, err := t.client.Targets()
t.Unlock()
if err != nil {
return nil, fmt.Errorf("error getting targets: %w", err)
}

var matchedTargets []TargetFile
for name, targetMeta := range targets {
// Skip any targets that do not include custom metadata.
Expand Down