Skip to main content

SecretsState

Struct SecretsState 

Source
pub struct SecretsState {
    pub nodes: HashMap<String, NodeIdentity>,
    pub wrapped_dek: Option<WrappedDek>,
    pub secrets: HashMap<String, ReplicatedSecret>,
    pub revoked_tokens: HashMap<String, DateTime<Utc>>,
    pub trusted_bundles: HashMap<String, TrustBundle>,
    pub jwt_algorithm: JwtAlgorithm,
    pub join_secret_wiped_at: Option<DateTime<Utc>>,
}
Expand description

Snapshot of the cluster secrets state on this node.

Followers and the leader hold identical content. Snapshots (de)serialize through serde for openraft.

Fields§

§nodes: HashMap<String, NodeIdentity>

Every node ever registered, keyed by node_id. Soft-revocation is recorded inline (NodeIdentity::revoked_at); the entry is kept so historical wraps in old WrappedDek generations can still be referenced for audit.

§wrapped_dek: Option<WrappedDek>

Current cluster DEK envelope (per-node sealed-box wraps + generation). None until the first RegisterNode + RotateDek pair lands.

§secrets: HashMap<String, ReplicatedSecret>

Replicated secrets, keyed by their storage_key ("{scope}:{name}").

§revoked_tokens: HashMap<String, DateTime<Utc>>

Revoked join tokens, keyed by token_hash (lowercase hex SHA-256 of the full token b64 envelope). Auto-pruned during apply: any RevokeToken op also sweeps entries whose expires_at < now().

§trusted_bundles: HashMap<String, TrustBundle>

Trusted foreign-cluster trust bundles, keyed by cluster_domain. Imported via SecretsRaftOp::ImportTrustBundle and consulted by crate::cluster_signer::ClusterCa::verify_ca_cert when a v=2 signed token carries a ca_chain whose cluster_domain is not the local cluster’s.

#[serde(default)] so snapshots written before this field existed restore with an empty map.

§jwt_algorithm: JwtAlgorithm

Cluster-wide JWT algorithm policy. Drives which join-token formats cluster_join accepts. Default Both for safety — the daemon’s bootstrap may override based on whether {data_dir}/join_secret is already present on first start.

#[serde(default)] so pre-Wave-11 snapshots restore cleanly.

§join_secret_wiped_at: Option<DateTime<Utc>>

Timestamp when WipeJoinSecret last applied (None = never).

Two daemon mechanisms consult this field:

  • The apply-time wrapper in zlayer_scheduler::raft::ClusterState fires NodeSideEffects::fire_wipe_join_secret, which the daemon’s watcher task drains to delete {data_dir}/join_secret.
  • The boot-time reconcile in zlayer serve checks this field on startup; if Some(_) and the file still exists locally (e.g. the node restored from a snapshot where the wipe already happened), the file is removed before the HS256 HMAC loader runs.

Both paths are idempotent.

#[serde(default)] for pre-Wave-11 snapshots.

Implementations§

Source§

impl SecretsState

Source

pub fn apply(&mut self, op: SecretsRaftOp) -> Result<(), SecretsError>

Apply a Raft op to local state.

Deterministic — every replica that sees the same op sequence must end up with the same SecretsState. Returns an error only on genuinely impossible inputs (e.g. DeleteSecret for an unknown key); the leader’s orchestration is expected to ensure the inputs are well-formed before proposing.

§Errors
  • SecretsError::Provider if the op references state that doesn’t exist (revoke unknown node, delete unknown secret).
Source

pub fn snapshot(&self) -> Result<Vec<u8>, SecretsError>

Serialize the state for an openraft snapshot. Uses JSON for now; the consensus wire-up task may swap this for a more compact codec once it audits whatever the scheduler SM uses.

§Errors
Source

pub fn restore(bytes: &[u8]) -> Result<Self, SecretsError>

Restore from a snapshot blob produced by Self::snapshot.

§Errors
Source

pub fn node_can_decrypt(&self, node_id: &str) -> bool

Convenience: is this node currently in the active recipient set for the current DEK generation?

Source

pub fn token_revoked(&self, token_hash: &str) -> bool

Returns true if the given token hash is currently revoked.

Auto-pruning happens at apply time; callers can rely on the in-memory map being a tight view of un-expired revocations.

Source

pub fn trust_bundle_for(&self, cluster_domain: &str) -> Option<&TrustBundle>

Look up a trusted foreign cluster’s bundle by domain.

Source

pub fn jwt_algorithm(&self) -> JwtAlgorithm

Return the current JWT algorithm policy.

Source

pub fn join_secret_wiped(&self) -> bool

true if WipeJoinSecret has been applied at least once.

Trait Implementations§

Source§

impl Clone for SecretsState

Source§

fn clone(&self) -> SecretsState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SecretsState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SecretsState

Source§

fn default() -> SecretsState

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SecretsState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SecretsState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromBase64 for T
where T: for<'de> Deserialize<'de>,

Source§

fn from_base64<Input>(raw: &Input) -> Result<T, Error>
where Input: AsRef<[u8]> + ?Sized,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<C> SignWithKey<String> for C
where C: ToBase64,

Source§

impl<T> ToBase64 for T
where T: Serialize,

Source§

fn to_base64(&self) -> Result<Cow<'_, str>, Error>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more