Overview
The store package defines the storage abstraction for Anubis. Storage backends persist challenge data, DNS cache entries, and other temporary state.Interface
Interface
Defines the storage operations that Anubis requires.Delete
Removes a key from the store.Context for cancellation and timeouts
Key to delete
Returns
ErrNotFound if key doesn’t exist, or other error on failurelib/store/interface.go:33
Get
Retrieves a value from the store.Context for cancellation and timeouts
Key to retrieve
Raw byte value stored at the key
Returns
ErrNotFound if key doesn’t exist or has expiredlib/store/interface.go:36
Set
Stores a value with automatic expiration.Context for cancellation and timeouts
Key to store value under
Raw byte data to store
Time until the value expires and is automatically deleted
Error if storage operation fails
lib/store/interface.go:39
IsPersistent
Indicates whether the storage backend persists data across restarts.true: Data survives process restarts (bbolt, valkey, s3)false: Data is volatile and lost on restart (memory)
lib/store/interface.go:44
Generic Wrapper
JSON
Type-safe wrapper for JSON serialization/deserialization.Base storage backend
Optional key prefix for namespacing (e.g., “challenge:”, “dronebl:“)
Get
Retrieves and unmarshals a typed value.Context
Key to retrieve (prefix automatically added)
Unmarshaled value of type T
Returns
ErrNotFound, ErrCantDecode, or underlying errorlib/store/interface.go:62-78
Set
Marshals and stores a typed value.Context
Key to store under (prefix automatically added)
Value to marshal and store
Expiration duration
Returns
ErrCantEncode or underlying errorlib/store/interface.go:80-95
Delete
Deletes a key from the store.Context
Key to delete (prefix automatically added)
Error if deletion fails
lib/store/interface.go:54-60
Example Usage
Registry
Factory
Interface for storage backend factories.Build
Constructs a storage backend from configuration.Context for initialization
Backend-specific configuration (from policy YAML)
Initialized storage backend
Configuration or initialization error
lib/store/registry.go:16
Valid
Validates configuration without building the backend.Configuration to validate
Validation error if configuration is invalid
lib/store/registry.go:17
Register
Registers a storage backend factory.Unique backend name (e.g., “memory”, “bbolt”, “valkey”)
Factory implementation
lib/store/registry.go:20-24
Get
Retrieves a registered storage factory.Backend name
The storage factory
True if backend is registered
lib/store/registry.go:27-32
Methods
Returns all registered backend names.Sorted list of registered backend names
lib/store/registry.go:34-43
Built-in Implementations
memory
In-memory storage using a concurrent decay map. Characteristics:- Non-persistent (
IsPersistent() = false) - Fast: O(1) operations
- Automatic cleanup every 5 minutes
- Not suitable for multi-instance deployments
lib/store/memory/memory.go:25-78
bbolt
Embedded key-value database using bbolt. Characteristics:- Persistent (
IsPersistent() = true) - Single-writer (file locking)
- Automatic cleanup every hour
- Good for single-instance deployments
- Each key gets its own bucket
- Buckets contain:
data(value) andexpiry(RFC3339Nano timestamp)
lib/store/bbolt/bbolt.go:38-171
valkey
Redis/Valkey client for distributed storage. Characteristics:- Persistent (
IsPersistent() = true) - Multi-instance safe
- Native TTL support (no cleanup needed)
- Recommended for production
lib/store/valkey/valkey.go:11-48
s3api
S3-compatible object storage backend. Characteristics:- Persistent (
IsPersistent() = true) - Multi-instance safe
- Higher latency than Redis
- Good for low-traffic deployments
lib/store/s3api/s3api.go
Errors
Key does not exist or has expired
Failed to unmarshal stored value
Failed to marshal value for storage
Backend configuration is invalid
lib/store/interface.go:11-26
Implementing a Custom Backend
Related Types
- Anubis Server - Store configuration
- Challenge - Challenge persistence
- Policy - Policy data storage