AshVault.RotationPolicy behaviour (AshVault v0.2.0)

Copy Markdown View Source

Describes when a scope's key should be rotated, and the behaviour that supplies it.

A policy is a plain struct:

  • :strategy — :manual (rotate only when asked), :age (rotate once the current key is older than :max_age), or :provider (the key provider decides, e.g. a KMS with its own rotation schedule)
  • :max_age — an Elixir.Duration, only meaningful for :age
  • :rotate_on_write? — whether a write should opportunistically trigger rotation

Rotation triggered by a write is always best-effort: a failing rotation must never fail the write.

Summary

Callbacks

Return the rotation policy in force for a scope and operation.

Functions

Whether the given key is due for rotation under this policy.

Types

strategy()

@type strategy() :: :manual | :age | :provider

t()

@type t() :: %AshVault.RotationPolicy{
  max_age: Duration.t() | nil,
  rotate_on_write?: boolean(),
  strategy: strategy()
}

Callbacks

policy(scope, t)

@callback policy(scope :: term(), AshVault.Context.t()) :: t()

Return the rotation policy in force for a scope and operation.

Functions

due?(policy, key_info, now \\ DateTime.utc_now())

Whether the given key is due for rotation under this policy.

:manual and :provider are never due — rotation is driven from outside. :age is due once key_info.created_at is older than now minus :max_age.

Examples

policy = %AshVault.RotationPolicy{strategy: :manual}
AshVault.RotationPolicy.due?(policy, key_info)
#=> false