Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Design: block-list lookups that can say "the lookup failed" (#8750)

## Intent

`BlockList::is_blocked` (crates/id-core/src/block_list.rs) returned only
`bool`. Both store implementations erased lookup failures to `false` —
`EventStore` with `unwrap_or(false)`, `SharedEventStore` with a second
erasure for poisoned locks — and every enforcement consumer
(`AbuseEvaluator`, `PullGate`, the blob gate) treated that `false` as a
successful "not blocked". A corrupt block row, a transient storage
failure, or a poisoned lock therefore silently allowed connections and
pulls, indistinguishable from an ordinary unblocked result, with no
operator diagnostic anywhere.

The ask from #8750: failure observability and an explicit per-surface
indeterminate-result policy. Not a unilateral change to fail-closed —
the documented fail-open default is an availability choice and stays.

## Approach

- **One distinguishing outcome type at the trait boundary.**
`BlockLookup` = `Blocked` | `Unblocked` | `Indeterminate(BlockLookupFailure)`,
added to the `BlockList` trait as `lookup()` with `peer_lookup` /
`topic_tag_lookup` / `ip_lookup` helpers mirroring the bool helpers.
The default `lookup()` derives from `is_blocked`, so implementations
that cannot report failures keep compiling and keep their semantics;
only the two real stores override it.
- **Failure as categories, never storage details.**
`BlockLookupFailure` = `Corrupt` | `Storage` | `Unavailable`. The
category is all that crosses the seam: a remote peer must never learn
store internals (file layout, lock state, error text) from an
enforcement decision. The full store error goes to the operator log
only, via `tracing::warn!` at the implementation that saw it.
- **The bool seam cannot diverge.** Each store's `is_blocked` is now
`lookup(...) == Blocked`, one code path for both answers. The bool
keeps its documented meaning: indeterminate fails open.
- **Store mapping.** `EventStore`: `StoreError::Corrupt` -> `Corrupt`,
any other store error -> `Storage`. `SharedEventStore`: the same for
errors from the backend, and a poisoned lock (or any other
trait-layer failure to run the read) -> `Unavailable`.
- **Operator surfaces.** `LocalEvents::lookup_block` exposes the
distinguishing answer next to `is_blocked`, and `PullGate` gains
`peer_lookup` / `topic_tag_lookup` returning `Option<BlockLookup>`
(`None` = no list attached, as before).

## Decisions and rationale

- **Fail-open at every enforcement seam, stated explicitly.** The
connection seam (`AbuseEvaluator::open_connection_inner`), the pull
gate (`PullGate::admits`), blob serving (`decide_with_blocks`), and
the log-sync topic check each match on the lookup: `Blocked`
refuses; `Indeterminate` logs a `tracing::warn!` diagnostic naming
the failure category and proceeds; `Unblocked` proceeds. Rationale:
a block store that cannot answer must not become a silent,
fleet-wide connection/pull refusal (availability), but the failure
must stop posing as a clean "not blocked" (observability). A future
seam that needs fail-closed can choose it on the same type without
another API change.
- **No change to definite-answer semantics.** Active, absent, and
expired lookups behave exactly as before; the pre-existing block
tests pass unmodified, which is the regression oracle.
- **Diagnostics at two layers.** The store implementations log the
failure with the underlying error; each enforcement seam logs its
own policy application. Either layer alone would leave a gap (a
failure with no decision context, or a decision with no cause).

## Tests (the oracle)

A failed lookup must be distinguishable from an ordinary unblocked
result, per surface:

- id-events: a raw undecodable block row written into the store yields
`Indeterminate(Corrupt)`; a healthy row yields `Blocked`; an absent
one `Unblocked`; the bool seam still reads `false` for the corrupt
row.
- id-store: `SharedEventStore` distinguishes `Blocked` / `Unblocked`,
and a poisoned lock yields `Indeterminate(Unavailable)`.
- id-core abuse: an always-indeterminate list fails open at the
connection seam; definite blocks still refuse.
- id-events pull policy: the gate surfaces `Some(Indeterminate(..))`,
the bool seam reads false, and `admits` follows the stated policy.

---

## 2026-11-11T19-15-00Z Update: record formalized during the implementing PR

The design above was settled in the #8750 issue body and the queue
task packet before implementation (the packet's acceptance criteria
are the test oracle listed here). This file formalizes that record in
the repository's prescribed location; it was added to PR #8761 after
the Codex review (finding on block_list.rs) pointed out the missing
dated record. No design content changed in response — only its
location.
76 changes: 65 additions & 11 deletions pkgs/id/crates/id-core/src/abuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use std::collections::{HashMap, HashSet};
use std::net::IpAddr;
use std::sync::Arc;

use crate::block_list::BlockList;
use crate::block_list::{BlockList, BlockLookup};

/// A remote endpoint identity: the 32 bytes of its verifying key,
/// the same bytes the event store uses as an author key.
Expand Down Expand Up @@ -1138,16 +1138,37 @@ impl AbuseEvaluator {
direct_ip: Option<IpAddr>,
now_ms: u64,
) -> Result<ConnectionId, Refusal> {
if self
.blocks
.as_ref()
.is_some_and(|blocks| blocks.peer_blocked(&endpoint))
{
return Err(Refusal::blocked_by_operator());
}
if let (Some(blocks), Some(ip)) = (&self.blocks, direct_ip) {
if blocks.ip_blocked(&ip) {
return Err(Refusal::blocked_by_operator());
if let Some(blocks) = &self.blocks {
// Explicit indeterminate-result policy (#8750): this seam
// fails open — a block store that cannot answer must not
// become a silent connection refusal — and the failure is
// logged for the operator instead of being treated as a
// clean "not blocked". Only a definite block refuses.
match blocks.peer_lookup(&endpoint) {
BlockLookup::Blocked => {
return Err(Refusal::blocked_by_operator());
}
BlockLookup::Indeterminate(failure) => {
tracing::warn!(
"block-list peer lookup for a new connection failed ({}); failing open",
failure.as_str()
);
}
BlockLookup::Unblocked => {}
}
if let Some(ip) = direct_ip {
match blocks.ip_lookup(&ip) {
BlockLookup::Blocked => {
return Err(Refusal::blocked_by_operator());
}
BlockLookup::Indeterminate(failure) => {
tracing::warn!(
"block-list IP lookup for a new connection failed ({}); failing open",
failure.as_str()
);
}
BlockLookup::Unblocked => {}
}
}
}
let cap = self.policy.max_connections_per_peer;
Expand Down Expand Up @@ -1479,6 +1500,39 @@ mod tests {
.expect("an unblocked endpoint still connects");
}

/// A block list whose lookup never answers (#8750): every check is
/// indeterminate, as a failed store read is at the real seams.
#[derive(Debug)]
struct FailingBlocks;

impl crate::block_list::BlockList for FailingBlocks {
fn is_blocked(&self, _kind: crate::block_list::BlockKind, _value: &[u8]) -> bool {
false
}

fn lookup(
&self,
_kind: crate::block_list::BlockKind,
_value: &[u8],
) -> crate::block_list::BlockLookup {
crate::block_list::BlockLookup::Indeterminate(
crate::block_list::BlockLookupFailure::Unavailable,
)
}
}

#[test]
fn an_indeterminate_block_lookup_fails_open_at_the_connection_seam() {
// #8750 policy, stated at the seam: an indeterminate block
// lookup fails open (and is logged) — the connection is
// admitted, not silently refused, and the failure stays
// visible through `lookup` instead of posing as "not blocked".
let mut eval = evaluator().with_block_list(Arc::new(FailingBlocks));
eval.open_connection(endpoint(7), 0)
.expect("an indeterminate block lookup must fail open");
assert_eq!(eval.active_connection_count(&endpoint(7)), 1);
}

#[test]
fn a_blocked_direct_ip_is_refused_a_new_connection() {
// #2245 listener seam: with a block list attached, a connection
Expand Down
96 changes: 96 additions & 0 deletions pkgs/id/crates/id-core/src/block_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,60 @@ impl BlockKind {
}
}

/// The outcome of one block-list lookup (#8750): a definite answer, or
/// the explicit admission that the lookup itself failed.
///
/// The bool seam ([`BlockList::is_blocked`]) erases a failed lookup (a
/// corrupt block row, a storage error, a poisoned lock) to `false`, so
/// enforcement could not tell it from an ordinary unblocked result and
/// no diagnostic existed anywhere. A seam that needs the distinction
/// asks for a `BlockLookup` and chooses its indeterminate-result policy
/// explicitly; the store implementations report their real failures
/// here instead of erasing them.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlockLookup {
/// An active block names this value.
Blocked,
/// The lookup succeeded and no active block names this value.
Unblocked,
/// The lookup itself failed, so no answer exists. The failure is a
/// category, never a storage detail: nothing about the store's
/// internals may leak to a remote peer through this value.
Indeterminate(BlockLookupFailure),
}

impl BlockLookup {
/// The bool verdict: only a definite block blocks. An indeterminate
/// lookup fails open, exactly as the bool seam always has.
#[must_use]
pub fn is_blocked(&self) -> bool {
matches!(self, BlockLookup::Blocked)
}
}

/// Why a block-list lookup could not answer (#8750), in operator terms.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlockLookupFailure {
/// A stored block row does not decode.
Corrupt,
/// The storage layer failed to answer the read.
Storage,
/// The lookup could not run at all (a poisoned lock, a closed store).
Unavailable,
}

impl BlockLookupFailure {
/// The failure's operator-facing label, for logs and diagnostics.
#[must_use]
pub fn as_str(&self) -> &'static str {
match self {
BlockLookupFailure::Corrupt => "corrupt block row",
BlockLookupFailure::Storage => "block storage read failed",
BlockLookupFailure::Unavailable => "block list unavailable",
}
}
}

/// The operator block list as the enforcement seams consult it (#2245).
///
/// A seam holds an `Arc<dyn BlockList>` and asks it about a peer, a topic
Expand All @@ -61,8 +115,46 @@ impl BlockKind {
pub trait BlockList: std::fmt::Debug + Send + Sync + 'static {
/// Whether (`kind`, `value`) is blocked now. An expired block is not
/// enforced, so this is false for one, however long it stays listed.
///
/// The bool seam fails open by design — the documented default
/// availability behaviour: a lookup that cannot answer (see
/// [`BlockList::lookup`]) is `false` here, so serving never depends
/// on the block store answering. A caller that must tell a failed
/// lookup from an unblocked answer uses `lookup` and states its
/// indeterminate-result policy explicitly (#8750).
fn is_blocked(&self, kind: BlockKind, value: &[u8]) -> bool;

/// The distinguishing form of [`BlockList::is_blocked`]: the same
/// question, with a failed lookup preserved as
/// [`BlockLookup::Indeterminate`] instead of erased to `false`.
///
/// The default derives from `is_blocked`, so an implementation
/// that cannot report failures answers only the definite outcomes;
/// the store implementations override it with their real errors,
/// and log the failure for the operator when it happens.
fn lookup(&self, kind: BlockKind, value: &[u8]) -> BlockLookup {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required design record for the block-lookup API

This introduces a public BlockList::lookup interface and explicit indeterminate-result policies across enforcement seams, but lacks the required dated design record. A repository-wide search of the target commit's documentation for 8750, BlockLookup, block-lookup terms, and fail-open policies found no record covering this change. pkgs/id/AGENTS.md explicitly requires documenting interface changes before implementation; add the prescribed document covering the intent, approach, and policy rationale rather than leaving that record only in Rust comments and the commit message.

AGENTS.md reference: pkgs/id/AGENTS.md:L159-L168

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 93ff717..HEAD: added the prescribed dated design record at pkgs/id/docs/2026-11-11T19-15-00Z_design_block_lookup/2026-11-11T19-15-00Z_design_block_lookup.md (through the docs symlink: doc/2026-11-11T19-15-00Z_design_block_lookup/), covering the intent, the BlockLookup approach, the failure-category/no-storage-leak decision, and the per-surface fail-open policy rationale. The design itself was settled in the #8750 issue and task packet before implementation; the record formalizes it in the protocol location and says so in its closing update section.

if self.is_blocked(kind, value) {
BlockLookup::Blocked
} else {
BlockLookup::Unblocked
}
}

/// The [`BlockLookup`] form of [`BlockList::peer_blocked`].
fn peer_lookup(&self, peer: &[u8; 32]) -> BlockLookup {
self.lookup(BlockKind::PeerKey, peer)
}

/// The [`BlockLookup`] form of [`BlockList::topic_tag_blocked`].
fn topic_tag_lookup(&self, tag: &[u8]) -> BlockLookup {
self.lookup(BlockKind::TopicTag, tag)
}

/// The [`BlockLookup`] form of [`BlockList::ip_blocked`].
fn ip_lookup(&self, ip: &std::net::IpAddr) -> BlockLookup {
self.lookup(BlockKind::Ip, ip.to_string().as_bytes())
}

/// Whether the endpoint with this 32-byte key is blocked.
fn peer_blocked(&self, peer: &[u8; 32]) -> bool {
self.is_blocked(BlockKind::PeerKey, peer)
Expand All @@ -87,4 +179,8 @@ impl<T: BlockList + ?Sized> BlockList for std::sync::Arc<T> {
fn is_blocked(&self, kind: BlockKind, value: &[u8]) -> bool {
(**self).is_blocked(kind, value)
}

fn lookup(&self, kind: BlockKind, value: &[u8]) -> BlockLookup {
(**self).lookup(kind, value)
}
}
Loading
Loading