Skip to content

Agent Mesh

identity: keep the authorizer error when no trusted key verifies a credential

HosniBelfeki54ec3d3e5d02
diff --git a/internal/identity/biscuit.go b/internal/identity/biscuit.go
index c0d47a9c..0921776a 100644
--- a/internal/identity/biscuit.go
+++ b/internal/identity/biscuit.go
@@ -607,7 +607,10 @@ func verifyBiscuit(biscuitData []byte, expectedPeer peer.ID, trustedPublicKeys [
}
if authorizer == nil {
- return nil, nil, time.Time{}, fmt.Errorf("no valid key found for verification: %v", lastErr)
+ if lastErr == nil {
+ lastErr = errors.New("no trusted keys")
+ }
+ return nil, nil, time.Time{}, fmt.Errorf("no valid key found for verification: %w", lastErr)
}
if err := RequireAuthorityBinding(b, expectedPeer); err != nil {
diff --git a/internal/identity/biscuit_test.go b/internal/identity/biscuit_test.go
index f8267c88..f4e7d4b3 100644
--- a/internal/identity/biscuit_test.go
+++ b/internal/identity/biscuit_test.go
@@ -655,6 +655,13 @@ func TestVerifyBiscuitRole_TimeoutIsHonored(t *testing.T) {
if !errors.Is(err, datalog.ErrWorldRunLimitTimeout) {
t.Errorf("expected datalog timeout error, got %v", err)
}
+
+ // Verification keeps the reason too, so a caller can tell a world that
+ // ran out of time from a credential no trusted key signed.
+ _, _, err = VerifyBiscuitAndGetKey(biscuitData, dummyPeer, []ed25519.PublicKey{pub}, time.Nanosecond)
+ if !errors.Is(err, datalog.ErrWorldRunLimitTimeout) {
+ t.Errorf("VerifyBiscuitAndGetKey with a 1ns timeout = %v, want an error wrapping %v", err, datalog.ErrWorldRunLimitTimeout)
+ }
}
// TestRequireRole covers the role gate every router-only path shares. The