1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Event delivery abstractions for canary triggers.
//!
//! This module defines the [`Sink`] trait and provides built-in
//! implementations. Sinks receive [`CanaryEvent`] metadata only — never
//! the canary value.
pub use CallbackSink;
pub use FileAuditSink;
pub use TracingSink;
use crateCanaryEvent;
pub use LogSink;
pub use DeduplicatingSink;
pub use RateLimitedSink;
/// A destination for canary event metadata.
///
/// Implementations receive [`CanaryEvent`] metadata only. They never receive
/// the canary value itself.
///
/// # Security
///
/// Implementations should not log, print, or persist the canary value. The
/// event type intentionally does not contain the value, but implementations
/// must also avoid reconstructing or leaking it through side channels.
///
/// # Error handling
///
/// Implementations should handle their own internal errors. A sink must not
/// break the instrumented application. `CanaryToken` additionally isolates
/// sink panics, but sink implementations should prefer graceful degradation
/// over panicking.
///
/// # Example
///
/// ```
/// use std::sync::atomic::{AtomicUsize, Ordering};
/// use std::sync::Arc;
///
/// use canarytrap::{CallbackSink, CanaryKind, CanaryToken, Sink};
///
/// let count = Arc::new(AtomicUsize::new(0));
/// let counter = count.clone();
///
/// let sink = CallbackSink::new(move |_event| {
/// counter.fetch_add(1, Ordering::SeqCst);
/// });
///
/// let token = CanaryToken::new("prod.db.password", CanaryKind::Password, "fake")
/// .with_sink(sink);
///
/// token.reveal();
///
/// assert_eq!(count.load(Ordering::SeqCst), 1);
/// ```