Consume from Go¶
Goal: check an Aval result from your own Go program with pkg/evidence, and
tell a miss from a security event.
flowchart LR
fetch([envelope bytes,<br>fetched by digest]) --> check[Check]
check -- nil bytes --> miss([ErrNotFound:<br>run the test]):::muted
check -- ErrVerification --> alert([alert,<br>do not reuse]):::err
check -- ok --> p([predicate]):::ok
The example¶
Check from
examples/evidence-consumer,
a module that imports only pkg/evidence:
// Check returns the verified predicate of a DSSE envelope fetched by digest.
// nil envBytes means the lookup found nothing: evidence.ErrNotFound, a miss.
// Every other failure wraps evidence.ErrVerification, a security event. The
// caller runs the test unless Check returns a passed predicate.
func Check(ctx context.Context, envBytes []byte, opts evidence.VerifyOptions) (*evidence.Predicate, error) {
if envBytes == nil {
return nil, evidence.ErrNotFound
}
var env evidence.Envelope
if err := json.Unmarshal(envBytes, &env); err != nil {
return nil, &evidence.VerificationError{Reason: "decoding envelope: " + err.Error()}
}
v, err := evidence.Verify(ctx, &env, opts)
if err != nil {
return nil, err
}
return v.Predicate, nil
}
Check returns |
Do |
|---|---|
a predicate with Result == evidence.ResultPassed |
reuse it |
evidence.ErrNotFound |
a miss: run the test |
evidence.ErrVerification |
alert, run the test, do not reuse |
a predicate with another Result |
a trusted failure: the test failed |
What you bring¶
- Envelope bytes, fetched by digest with any registry client (layout).
- A
SignatureVerifier.pkg/evidencechecks the policy, not the cryptography. The example brings ed25519; a Sigstore one is planned for milestone 5. - Identities from your own policy, never from the predicate.
Reading aval verify -o json instead? Use evidence.Report, as the
example's Reuse does.
Read next¶
- Consume evidence: every symbol of
pkg/evidence - Outcomes