Integrate host escalation with production sessions
This commit is contained in:
parent
254bb37764
commit
696dae610a
1 changed files with 1175 additions and 96 deletions
|
|
@ -988,7 +988,14 @@ impl NonInteractiveSessionExecutor for RunscNonInteractiveExecutor {
|
|||
for argument in &self.global_arguments {
|
||||
target = target.argument(argument.clone());
|
||||
}
|
||||
target = target.argument("exec").argument(self.container.clone());
|
||||
target = target
|
||||
.argument("exec")
|
||||
.argument("-env")
|
||||
.argument(format!(
|
||||
"LAZARET_SESSION_ID={}",
|
||||
hex_lower(request.session_id.as_bytes())
|
||||
))
|
||||
.argument(self.container.clone());
|
||||
for argument in &request.argv {
|
||||
target = target.argument(OsString::from_vec(argument.clone()));
|
||||
}
|
||||
|
|
@ -1530,9 +1537,23 @@ impl PublishedControlFace {
|
|||
where
|
||||
Admit: FnMut(ControlSessionAdmission) -> Result<(), ControlError>,
|
||||
Disconnect: FnMut(SessionId) -> Result<(), ControlError>,
|
||||
{
|
||||
self.serve_next_coordinated_with_registration(admit, |_, _| Ok(()), disconnect)
|
||||
}
|
||||
|
||||
pub(crate) fn serve_next_coordinated_with_registration<Admit, Registered, Disconnect>(
|
||||
&self,
|
||||
admit: Admit,
|
||||
registered: Registered,
|
||||
disconnect: Disconnect,
|
||||
) -> Result<(), ControlError>
|
||||
where
|
||||
Admit: FnMut(ControlSessionAdmission) -> Result<(), ControlError>,
|
||||
Registered: FnMut(SessionBinding, SessionRegistrationResponse) -> Result<(), ControlError>,
|
||||
Disconnect: FnMut(SessionId) -> Result<(), ControlError>,
|
||||
{
|
||||
let connection = self.accept_connection()?;
|
||||
self.serve_connection_coordinated(connection, admit, disconnect)
|
||||
self.serve_connection_coordinated(connection, admit, registered, disconnect)
|
||||
}
|
||||
|
||||
pub(crate) fn accept_connection(&self) -> Result<AcceptedControlConnection, ControlError> {
|
||||
|
|
@ -1540,14 +1561,16 @@ impl PublishedControlFace {
|
|||
Ok(AcceptedControlConnection { socket })
|
||||
}
|
||||
|
||||
pub(crate) fn serve_connection_coordinated<Admit, Disconnect>(
|
||||
pub(crate) fn serve_connection_coordinated<Admit, Registered, Disconnect>(
|
||||
&self,
|
||||
connection: AcceptedControlConnection,
|
||||
mut admit: Admit,
|
||||
mut registered: Registered,
|
||||
mut disconnect: Disconnect,
|
||||
) -> Result<(), ControlError>
|
||||
where
|
||||
Admit: FnMut(ControlSessionAdmission) -> Result<(), ControlError>,
|
||||
Registered: FnMut(SessionBinding, SessionRegistrationResponse) -> Result<(), ControlError>,
|
||||
Disconnect: FnMut(SessionId) -> Result<(), ControlError>,
|
||||
{
|
||||
let socket = connection.socket;
|
||||
|
|
@ -1571,9 +1594,13 @@ impl PublishedControlFace {
|
|||
let mut stream = rustls::StreamOwned::new(connection, socket);
|
||||
match peer_certificate {
|
||||
None => self.serve_enrollment(&mut stream),
|
||||
Some(certificates) => {
|
||||
self.serve_registration(&mut stream, &certificates, &mut admit, &mut disconnect)
|
||||
}
|
||||
Some(certificates) => self.serve_registration(
|
||||
&mut stream,
|
||||
&certificates,
|
||||
&mut admit,
|
||||
&mut registered,
|
||||
&mut disconnect,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1596,15 +1623,17 @@ impl PublishedControlFace {
|
|||
)
|
||||
}
|
||||
|
||||
fn serve_registration<Admit, Disconnect>(
|
||||
fn serve_registration<Admit, Registered, Disconnect>(
|
||||
&self,
|
||||
stream: &mut rustls::StreamOwned<ServerConnection, std::os::unix::net::UnixStream>,
|
||||
certificates: &[Vec<u8>],
|
||||
admit: &mut Admit,
|
||||
registered: &mut Registered,
|
||||
disconnect: &mut Disconnect,
|
||||
) -> Result<(), ControlError>
|
||||
where
|
||||
Admit: FnMut(ControlSessionAdmission) -> Result<(), ControlError>,
|
||||
Registered: FnMut(SessionBinding, SessionRegistrationResponse) -> Result<(), ControlError>,
|
||||
Disconnect: FnMut(SessionId) -> Result<(), ControlError>,
|
||||
{
|
||||
let [leaf] = certificates else {
|
||||
|
|
@ -1622,18 +1651,18 @@ impl PublishedControlFace {
|
|||
&self.anchor.coordinator_protocol_key,
|
||||
)?;
|
||||
let session_id = request.session_binding.session_id;
|
||||
let binding = request.session_binding.clone();
|
||||
admit(ControlSessionAdmission {
|
||||
request,
|
||||
credential,
|
||||
})?;
|
||||
let result = (|| {
|
||||
write_frame(
|
||||
stream,
|
||||
&ControlResponse::Registered(SessionRegistrationResponse {
|
||||
protocol_version: ProtocolVersion::V1,
|
||||
session_capability: capability,
|
||||
}),
|
||||
)?;
|
||||
let registration = SessionRegistrationResponse {
|
||||
protocol_version: ProtocolVersion::V1,
|
||||
session_capability: capability,
|
||||
};
|
||||
registered(binding, registration.clone())?;
|
||||
write_frame(stream, &ControlResponse::Registered(registration))?;
|
||||
let request: ControlRequest = match read_frame(stream, MAX_CONTROL_BYTES) {
|
||||
Ok(request) => request,
|
||||
Err(ControlError::Io(error))
|
||||
|
|
@ -2156,10 +2185,18 @@ mod tests {
|
|||
runner.observed.lock().unwrap().as_ref().unwrap(),
|
||||
&(
|
||||
OsString::from("runsc"),
|
||||
["--root=/runtime", "exec", "container-id", "printf", "hello"]
|
||||
.into_iter()
|
||||
.map(OsString::from)
|
||||
.collect()
|
||||
vec![
|
||||
OsString::from("--root=/runtime"),
|
||||
OsString::from("exec"),
|
||||
OsString::from("-env"),
|
||||
OsString::from(format!(
|
||||
"LAZARET_SESSION_ID={}",
|
||||
hex_lower(session_id.as_bytes())
|
||||
)),
|
||||
OsString::from("container-id"),
|
||||
OsString::from("printf"),
|
||||
OsString::from("hello"),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue