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: repetitive and incorrect log lines on witness verify #317 #485

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
39 changes: 28 additions & 11 deletions cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,31 @@ func runVerify(ctx context.Context, vo options.VerifyOptions, verifiers ...crypt
collectionSource source.Sourcer
archivistaClient *archivista.Client
)
memSource := source.NewMemorySource()

collectionSource = memSource
var memSource *source.MemorySource
if len(vo.AttestationFilePaths) > 0 {
memSource = source.NewMemorySource()
for _, path := range vo.AttestationFilePaths {
if err := memSource.LoadFile(path); err != nil {
return fmt.Errorf("failed to load attestation file: %w", err)
}
}
}

var archivistaSource *source.ArchivistaSource
if vo.ArchivistaOptions.Enable {
archivistaClient = archivista.New(vo.ArchivistaOptions.Url)
collectionSource = source.NewMultiSource(collectionSource, source.NewArchvistSource(archivistaClient))
archivistaSource = source.NewArchvistSource(archivistaClient)
}

if memSource != nil && archivistaSource != nil {
collectionSource = source.NewMultiSource(memSource, archivistaSource)
} else if memSource != nil {
collectionSource = memSource
} else if archivistaSource != nil {
collectionSource = archivistaSource
} else {
return fmt.Errorf("either `--enable-archivista` or `--attestation-file-paths` flags must be used")
}

if vo.KeyPath == "" && len(vo.PolicyCARootPaths) == 0 && len(verifiers) == 0 {
Expand Down Expand Up @@ -179,12 +198,6 @@ func runVerify(ctx context.Context, vo options.VerifyOptions, verifiers ...crypt
return errors.New("at least one subject is required, provide an artifact file or subject")
}

for _, path := range vo.AttestationFilePaths {
if err := memSource.LoadFile(path); err != nil {
return fmt.Errorf("failed to load attestation file: %w", err)
}
}

verifiedEvidence, err := witness.Verify(
ctx,
policyEnvelope,
Expand All @@ -209,11 +222,15 @@ func runVerify(ctx context.Context, vo options.VerifyOptions, verifiers ...crypt
}
for _, p := range result.Rejected {
if p.Collection.Collection.Name != "" {
log.Errorf("collection rejected: %s, Reason: %s ", p.Collection.Collection.Name, p.Reason)
log.Errorf("collection rejected: %s, reference: %s, reason: %s ", p.Collection.Collection.Name, p.Collection.Reference, p.Reason)
} else {
log.Errorf("verification failure: Reason: %s", p.Reason)
log.Errorf("verification failure: reason: %s", p.Reason)
}
}
if len(result.Passed) == 0 && len(result.Rejected) == 0 {
log.Errorf("verification failure: no collections found")
continue
}
}
}
return fmt.Errorf("failed to verify policy: %w", err)
Expand Down
Loading