Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions server/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustix::io::close;
use rustix::process::{Pid, Signal, ioctl_tiocsctty, kill_process_group, setsid};
use slog::{Logger, debug, error, o, warn};
use tokio::fs::{DirBuilder, OpenOptions};
use tokio::io::AsyncWriteExt as _;
use tokio::process::{Child, Command};
use tokio::spawn;
use tokio::sync::{mpsc, watch};
Expand Down Expand Up @@ -258,6 +259,27 @@ async fn job_spawn(
format!("creating job stderr file `{}`", stderr_path.display())
);

// Record the signed request beside the output it produces, so
// the job directory attests what ran even after gossip forgets.
let job_path = job_dir.join("job.json");
let json = with_io_err!(
serde_json::to_vec_pretty(&*request).map_err(io::Error::other),
format!("encoding job request file `{}`", job_path.display())
);
let mut job_file = with_io_err!(
OpenOptions::new()
.create_new(true)
.write(true)
.mode(file_mode)
.open(&job_path)
.await,
format!("creating job request file `{}`", job_path.display())
);
with_io_err!(
job_file.write_all(&json).await,
format!("writing job request file `{}`", job_path.display())
);

// Set up the job command.
let mut cmd = Command::new("bash");
cmd.kill_on_drop(true);
Expand Down
1 change: 1 addition & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ libc.workspace = true
pwd.workspace = true
rand_core.workspace = true
rumors.workspace = true
serde_json.workspace = true
sha3.workspace = true
sled-hardware-types.workspace = true
slog.workspace = true
Expand Down
38 changes: 36 additions & 2 deletions tests/src/manager_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use pwd::Passwd;
use sled_hardware_types::BaseboardId;
use slog::{Discard, Logger, o};
use tempfile::TempDir;
use tokio::fs::{metadata, write};
use tokio::fs::{metadata, read, write};
use tokio::sync::watch;
use tokio::time::{sleep, timeout};
use tokio_util::sync::CancellationToken;
Expand All @@ -29,7 +29,7 @@ use sush_client::context::Authz;
use sush_common::authn::{Challenge, ChallengeResponse, Credentials, Identity, Nonce, RequestKey};
use sush_common::jobs::{
Access, JobId, JobLimits, JobOutputState, JobOutputStream::*, JobStartRequest, JobStatus,
ProcessError, Session, SessionId,
ProcessError, Session, SessionId, SignedJob,
};
use sush_common::keys::{EphemeralKey, KeyError, KeyId, KeyType, Signer as _, pem_cert_chain};
use sush_common::targets::{Cubbies, Target};
Expand Down Expand Up @@ -2130,3 +2130,37 @@ async fn interactive_target_required() {
Err(JobError::InteractiveTarget)
));
}

/// Each job's directory records the signed request beside its output.
#[named]
#[tokio::test]
async fn job_json() {
let log = test_logger(function_name!());
let (mgr, mut root, dir, _shutdown) = manager_and_test_root(log).await;
let authn = fake_identity(&mut root).await;
let session_id = SessionId::random();
let mut session = Session::new(session_id);
mgr.session_start(&authn, session_id, true).await.unwrap();

let job_id = session.next_job_id();
let job = root.sign_job_request(&job_id, "true", false).await;
mgr.job_start(
&authn,
job.clone().into_signed(),
JobStartParams {
wait: JobWait::Stop,
..Default::default()
},
)
.await
.unwrap();
session.job_started(job.clone().into_signed());

let path = dir
.path()
.join("jobs")
.join(job_id.to_string())
.join("job.json");
let recorded: SignedJob = serde_json::from_slice(&read(&path).await.unwrap()).unwrap();
assert_eq!(recorded, job.into_signed());
}