Skip to main content

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.Context
required
Context for cancellation and timeouts
string
required
Key to delete
error
Returns ErrNotFound if key doesn’t exist, or other error on failure
Example
See lib/store/interface.go:33

Get

Retrieves a value from the store.
context.Context
required
Context for cancellation and timeouts
string
required
Key to retrieve
[]byte
Raw byte value stored at the key
error
Returns ErrNotFound if key doesn’t exist or has expired
Example
See lib/store/interface.go:36

Set

Stores a value with automatic expiration.
context.Context
required
Context for cancellation and timeouts
string
required
Key to store value under
[]byte
required
Raw byte data to store
time.Duration
required
Time until the value expires and is automatically deleted
error
Error if storage operation fails
Example
See lib/store/interface.go:39

IsPersistent

Indicates whether the storage backend persists data across restarts.
bool
  • true: Data survives process restarts (bbolt, valkey, s3)
  • false: Data is volatile and lost on restart (memory)
Usage: Anubis uses this to warn administrators when using volatile storage in production.
See lib/store/interface.go:44

Generic Wrapper

JSON

Type-safe wrapper for JSON serialization/deserialization.
Interface
Base storage backend
string
Optional key prefix for namespacing (e.g., “challenge:”, “dronebl:“)

Get

Retrieves and unmarshals a typed value.
context.Context
required
Context
string
required
Key to retrieve (prefix automatically added)
T
Unmarshaled value of type T
error
Returns ErrNotFound, ErrCantDecode, or underlying error
See lib/store/interface.go:62-78

Set

Marshals and stores a typed value.
context.Context
required
Context
string
required
Key to store under (prefix automatically added)
T
required
Value to marshal and store
time.Duration
required
Expiration duration
error
Returns ErrCantEncode or underlying error
See lib/store/interface.go:80-95

Delete

Deletes a key from the store.
context.Context
required
Context
string
required
Key to delete (prefix automatically added)
error
Error if deletion fails
See lib/store/interface.go:54-60
Example Usage

Registry

Factory

Interface for storage backend factories.

Build

Constructs a storage backend from configuration.
context.Context
required
Context for initialization
json.RawMessage
required
Backend-specific configuration (from policy YAML)
Interface
Initialized storage backend
error
Configuration or initialization error
See lib/store/registry.go:16

Valid

Validates configuration without building the backend.
json.RawMessage
required
Configuration to validate
error
Validation error if configuration is invalid
See lib/store/registry.go:17

Register

Registers a storage backend factory.
string
required
Unique backend name (e.g., “memory”, “bbolt”, “valkey”)
Factory
required
Factory implementation
Example
See lib/store/registry.go:20-24

Get

Retrieves a registered storage factory.
string
required
Backend name
Factory
The storage factory
bool
True if backend is registered
Example
See lib/store/registry.go:27-32

Methods

Returns all registered backend names.
[]string
Sorted list of registered backend names
Example
See 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
Configuration:
Implementation: 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
Storage format:
  • Each key gets its own bucket
  • Buckets contain: data (value) and expiry (RFC3339Nano timestamp)
Configuration:
Implementation: 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
Configuration:
Implementation: 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
Configuration:
Implementation: lib/store/s3api/s3api.go

Errors

error
Key does not exist or has expired
error
Failed to unmarshal stored value
error
Failed to marshal value for storage
error
Backend configuration is invalid
See lib/store/interface.go:11-26

Implementing a Custom Backend