Decouple client contracts and close private role registries
This commit is contained in:
parent
786049534d
commit
22325aa76a
1 changed files with 1041 additions and 321 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::io::{self, Read};
|
||||
use std::os::fd::AsFd;
|
||||
use std::os::unix::ffi::OsStringExt;
|
||||
use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt};
|
||||
|
|
@ -9,37 +9,20 @@ use std::path::PathBuf;
|
|||
|
||||
use lazaret_core::codec;
|
||||
use lazaret_core::configuration::ResolvedDomainConfiguration;
|
||||
use lazaret_core::identity::{
|
||||
ClientId, ConfigurationFingerprint, DomainId, GenerationId, SessionAnchorId, SessionId,
|
||||
use lazaret_core::identity::{ConfigurationFingerprint, DomainId, GenerationId, SessionId};
|
||||
pub use lazaret_core::protocol::{
|
||||
BOOTSTRAP_WAITER_SOCKET_NAME, BootstrapWaitOutcome, BootstrapWaitRequest,
|
||||
};
|
||||
use lazaret_core::protocol::{read_waiter_frame, write_waiter_frame};
|
||||
use lazaret_core::records::{ProtocolVersion, Session, SessionPhase};
|
||||
use rustix::net::sockopt::socket_peercred;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::lifecycle::{HostCoordinatorLifecycle, LifecycleAdapter, SessionLifecycleAdapter};
|
||||
|
||||
pub const BOOTSTRAP_WAITER_SOCKET_NAME: &str = "wait.sock";
|
||||
const MAX_FRAME_BYTES: usize = 4_096;
|
||||
const MAX_WAITERS: usize = 64;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct BootstrapWaitRequest {
|
||||
pub protocol_version: ProtocolVersion,
|
||||
pub domain_id: DomainId,
|
||||
pub configuration_fingerprint: ConfigurationFingerprint,
|
||||
pub cli_id: ClientId,
|
||||
pub session_id: SessionId,
|
||||
pub session_anchor_id: SessionAnchorId,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub enum BootstrapWaitOutcome {
|
||||
Waiting,
|
||||
Published,
|
||||
Failed,
|
||||
Refused,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BootstrapWaiterError(String);
|
||||
|
||||
|
|
@ -398,14 +381,7 @@ pub fn write_frame<T: Serialize>(
|
|||
stream: &mut UnixStream,
|
||||
record: &T,
|
||||
) -> Result<(), BootstrapWaiterError> {
|
||||
let encoded = codec::encode(record).map_err(failure)?;
|
||||
if encoded.len() > MAX_FRAME_BYTES {
|
||||
return Err(failure("bootstrap waiter frame is oversized"));
|
||||
}
|
||||
let length = u32::try_from(encoded.len()).map_err(failure)?;
|
||||
stream.write_all(&length.to_be_bytes()).map_err(failure)?;
|
||||
stream.write_all(&encoded).map_err(failure)?;
|
||||
stream.flush().map_err(failure)
|
||||
write_waiter_frame(stream, record).map_err(failure)
|
||||
}
|
||||
|
||||
/// # Errors
|
||||
|
|
@ -414,15 +390,7 @@ pub fn read_frame<T>(stream: &mut UnixStream) -> Result<T, BootstrapWaiterError>
|
|||
where
|
||||
T: serde::de::DeserializeOwned + Serialize,
|
||||
{
|
||||
let mut length = [0_u8; 4];
|
||||
stream.read_exact(&mut length).map_err(failure)?;
|
||||
let length = u32::from_be_bytes(length) as usize;
|
||||
if length > MAX_FRAME_BYTES {
|
||||
return Err(failure("bootstrap waiter frame is oversized"));
|
||||
}
|
||||
let mut encoded = vec![0_u8; length];
|
||||
stream.read_exact(&mut encoded).map_err(failure)?;
|
||||
codec::decode(&encoded).map_err(failure)
|
||||
read_waiter_frame(stream).map_err(failure)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -433,10 +401,11 @@ mod tests {
|
|||
use std::thread;
|
||||
|
||||
use lazaret_core::configuration::{ConfigurationLoadRequest, load_trusted_configuration};
|
||||
use lazaret_core::identity::{CoordinatorId, NetworkSidecarId, SandboxId};
|
||||
use lazaret_core::identity::{
|
||||
ClientId, CoordinatorId, NetworkSidecarId, SandboxId, SessionAnchorId,
|
||||
};
|
||||
use lazaret_core::records::{Domain, DurableDecision, Generation};
|
||||
use lazaret_linux::filesystem::try_exclusive_flock;
|
||||
use lazaret_runtime_supervisor::sandbox::default_sandbox_layout;
|
||||
|
||||
use crate::domain_store::{DomainStoreMutation, HostCoordinatorDomainStore};
|
||||
use crate::lifecycle::{LifecycleAction, SessionAdmissionIdentity};
|
||||
|
|
@ -757,7 +726,7 @@ mod tests {
|
|||
xdg_data_home: None,
|
||||
xdg_runtime_dir: runtime,
|
||||
environment: BTreeMap::new(),
|
||||
sandbox_layout: default_sandbox_layout().unwrap(),
|
||||
sandbox_layout: lazaret_core::configuration::SandboxLayoutV1::default_layout().unwrap(),
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue