security

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package security provides the SecretRotator, a port of Etherpad's src/node/security/SecretRotator.ts. It maintains an array of secrets across one or more Etherpad instances sharing the same database, periodically rotating in a new secret and removing the oldest secret.

The secrets are generated using a key derivation function (HKDF) with input keying material coming from a long-lived secret stored in the database (generated if missing). The first secret in the array is the one that should be used to generate new MACs/signatures; every secret in the array should be accepted when validating an existing MAC/signature.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SecretRotator

type SecretRotator struct {
	// contains filtered or unexported fields
}

SecretRotator maintains a rotating array of secrets persisted in the database.

func NewSecretRotator

func NewSecretRotator(store SecretStore, prefix string, interval, lifetime time.Duration, legacyStaticSecret *string, logger *zap.SugaredLogger) *SecretRotator

NewSecretRotator creates a rotator. interval is how often a new secret is rotated in; lifetime is how long after the end of an interval a secret stays usable. legacyStaticSecret, if non-nil, covers the period before the first rotated secret to ease migration from a previously static secret.

func (*SecretRotator) OnRotate

func (r *SecretRotator) OnRotate(fn func())

OnRotate registers a callback invoked after every successful update (initial and each rotation). Must be set before Start.

func (*SecretRotator) Secrets

func (r *SecretRotator) Secrets() [][]byte

Secrets returns a snapshot of the active secrets. The first entry is the one to use for generating new MACs/signatures; all entries are valid for verification.

func (*SecretRotator) Start

func (r *SecretRotator) Start() error

Start performs the first update synchronously (so Secrets is populated before use) and schedules subsequent rotations.

func (*SecretRotator) Stop

func (r *SecretRotator) Stop()

Stop cancels the scheduled rotation.

type SecretStore

type SecretStore interface {
	SaveSecretParams(id string, prefix string, payload string) error
	ListSecretParams(prefix string) (map[string]string, error)
	DeleteSecretParams(id string) error
}

SecretStore is the persistence contract backing the rotator. *db.DataStore satisfies it through the dedicated secret_rotation table.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL