rotation

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package rotation defines key rotation records and reasons.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListFilter

type ListFilter struct {
	KeyID    *id.KeyID `json:"key_id,omitempty"`
	TenantID string    `json:"tenant_id,omitempty"`
	Reason   Reason    `json:"reason,omitempty"`
	Limit    int       `json:"limit,omitempty"`
	Offset   int       `json:"offset,omitempty"`
}

ListFilter contains filters for listing rotation records.

type Reason

type Reason string

Reason indicates why a rotation occurred.

const (
	// ReasonScheduled indicates a policy-driven auto-rotation.
	ReasonScheduled Reason = "scheduled"

	// ReasonManual indicates a user-initiated rotation.
	ReasonManual Reason = "manual"

	// ReasonCompromise indicates a rotation due to a security incident.
	ReasonCompromise Reason = "compromise"

	// ReasonPolicy indicates a rotation forced by a policy change.
	ReasonPolicy Reason = "policy"
)

type Record

type Record struct {
	ID         id.RotationID `json:"id" db:"id"`
	KeyID      id.KeyID      `json:"key_id" db:"key_id"`
	TenantID   string        `json:"tenant_id" db:"tenant_id"`
	OldKeyHash string        `json:"-" db:"old_key_hash"`
	NewKeyHash string        `json:"-" db:"new_key_hash"`
	// OldHint and NewHint are the last four characters of each raw key, the
	// same public hint key.Key carries. They are empty on records written
	// before these fields existed.
	OldHint   string        `json:"old_hint" db:"old_hint"`
	NewHint   string        `json:"new_hint" db:"new_hint"`
	Reason    Reason        `json:"reason" db:"reason"`
	GraceTTL  time.Duration `json:"grace_ttl" db:"grace_ttl_ms"`
	GraceEnds time.Time     `json:"grace_ends" db:"grace_ends"`
	RotatedBy string        `json:"rotated_by,omitempty" db:"rotated_by"`
	CreatedAt time.Time     `json:"created_at" db:"created_at"`
}

Record tracks a key rotation event.

type Store

type Store interface {
	Create(ctx context.Context, rec *Record) error
	Get(ctx context.Context, rotID id.RotationID) (*Record, error)
	List(ctx context.Context, filter *ListFilter) ([]*Record, error)
	ListPendingGrace(ctx context.Context, now time.Time) ([]*Record, error)
	LatestForKey(ctx context.Context, keyID id.KeyID) (*Record, error)

	// GetInGraceByOldHash returns the record whose OldKeyHash equals hash and
	// whose GraceEnds is after now. It returns store.ErrRotationNotFound when
	// none matches. If several match, the one with the latest GraceEnds wins.
	GetInGraceByOldHash(ctx context.Context, hash string, now time.Time) (*Record, error)

	// EndGrace sets GraceEnds to at on every record for the key whose
	// GraceEnds is after at, and returns how many records changed.
	EndGrace(ctx context.Context, keyID id.KeyID, at time.Time) (int64, error)

	// EndGraceByID sets one record's GraceEnds to at when it is after at,
	// the way EndGrace does for every record on a key. Other records on the
	// same key keep their windows. A missing record, or one whose window
	// already ended at or before at, changes nothing and returns nil, just
	// as EndGrace counts it as zero.
	EndGraceByID(ctx context.Context, rotID id.RotationID, at time.Time) error
}

Store is the persistence interface for key rotation records.

Jump to

Keyboard shortcuts

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