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
51 changes: 51 additions & 0 deletions pkgs/fleet/crates/fleet-queue/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,19 @@ pub(crate) fn validate_delay_seconds(value: i64) -> Result<i64, String> {
validate_duration("delay-seconds", value, DELAY_SECONDS_MAX)
}

/// Validate a `--not-before` flag value (#6426): the same rule the
/// packet validator and the broker apply — a non-empty RFC 3339
/// timestamp no more than 366 days in the future. Until now the raw
/// string went into the park/revive body unchecked, so garbage
/// failed only as a downstream DB cast error. A valid value is
/// returned unchanged, so the broker body for valid timestamps is
/// byte-for-byte what it was before; an invalid one is a usage
/// error naming `--not-before` (the caller dies with exit 2).
pub(crate) fn validate_not_before_flag(raw: &str) -> Result<String, String> {
crate::validate::validate_not_before(&json!(raw), "--not-before")?;
Ok(raw.to_string())
}

fn env_or_default(value: Option<&str>, default: &str) -> String {
value
.map(str::trim)
Expand Down Expand Up @@ -1939,6 +1952,10 @@ fn cmd_park(rest: &[String]) -> i32 {
"progress": progress_arg(&args).unwrap_or(json!({})),
});
if let Some(nb) = args.get("not-before") {
let nb = match validate_not_before_flag(&nb) {
Ok(v) => v,
Err(e) => die(2, &e),
};
body["not_before"] = json!(nb);
} else if let Some(d) = args.get_i64("delay-seconds") {
let d = match validate_delay_seconds(d) {
Expand Down Expand Up @@ -2152,6 +2169,10 @@ fn cmd_revive(rest: &[String]) -> i32 {
"reason": args.get("reason").unwrap_or_default(),
});
if let Some(nb) = args.get("not-before") {
let nb = match validate_not_before_flag(&nb) {
Ok(v) => v,
Err(e) => die(2, &e),
};
body["not_before"] = json!(nb);
}
let resp = unwrap_ok(call("/revive", &body));
Expand Down Expand Up @@ -3398,6 +3419,36 @@ mod tests {
);
}

#[test]
fn not_before_flag_is_validated() {
// #6426: park/revive --not-before went into the broker body
// as a raw string — garbage failed only as a downstream DB
// cast error, and a far-future value parked a task out of
// reach for years. It is now a usage error naming the flag
// (cmd_park/cmd_revive die with exit 2 on Err).
for bad in [
"banana",
"",
" ",
"2026-02-31T00:00:00Z",
"9999-01-01T00:00:00Z",
] {
let err = validate_not_before_flag(bad)
.err()
.expect("invalid --not-before must be rejected");
assert!(err.contains("--not-before"), "error names the flag: {err}");
}
// Valid timestamps pass through unchanged — the broker body
// for a valid value is byte-for-byte what it was before.
for ok in [
"2020-01-01T00:00:00Z",
"2026-11-06T00:00:00Z",
"2026-11-06T05:30:00+05:30",
] {
assert_eq!(validate_not_before_flag(ok), Ok(ok.to_string()));
}
}

#[test]
fn well_formed_invocation_is_unchanged() {
// Control (#5939 acceptance): list --queue alpha records
Expand Down
56 changes: 51 additions & 5 deletions pkgs/fleet/crates/fleet-queue/src/queue_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,23 @@ fn validate_durations(path: &str, req: &Value) -> Result<(), String> {
}
}

/// The not_before gate (#6426): /park and /revive carry a raw
/// not_before that dispatch forwards to the RPC (or the turso
/// backend) — validate it BEFORE either, with the same rule the
/// packet validator applies on /enqueue (validate_packet runs
/// inside both /enqueue handlers ahead of their RPC call). An
/// absent or null not_before is untouched; a present one must be a
/// non-empty RFC 3339 timestamp no more than 366 days out.
fn validate_request_not_before(path: &str, req: &Value) -> Result<(), String> {
if !matches!(path, "/park" | "/revive") {
return Ok(());
}
match req.get("not_before").filter(|v| !v.is_null()) {
Some(nb) => crate::validate::validate_not_before(nb, "not_before"),
None => Ok(()),
}
}

fn ok(fields: Value) -> Value {
let mut m = json!({"ok": true});
if let (Some(dst), Some(src)) = (m.as_object_mut(), fields.as_object()) {
Expand Down Expand Up @@ -664,7 +681,6 @@ fn verb_with_execution(st: &State, fn_name: &str, args: Value, req: &Value) -> V
}
}


/// The GitHub token the dep rechecker authenticates with,
/// resolved by name through the secrets broker like every other
/// broker credential (#8276).
Expand Down Expand Up @@ -770,10 +786,7 @@ impl crate::turso_queue::DepProbe for GhDepProbe {
use crate::turso_queue::DepObs;
match self.get_json(&format!("/repos/{repo}/pulls/{number}")) {
Ok(v) => {
let merged = v
.get("merged")
.and_then(|m| m.as_bool())
.unwrap_or(false);
let merged = v.get("merged").and_then(|m| m.as_bool()).unwrap_or(false);
let state = v.get("state").and_then(|s| s.as_str()).unwrap_or("");
if merged {
DepObs::Cleared("pr merged".to_string())
Expand Down Expand Up @@ -811,6 +824,9 @@ fn dispatch(st: &State, path: &str, req: &Value) -> Value {
if let Err(e) = validate_durations(path, req) {
return fail(2, e);
}
if let Err(e) = validate_request_not_before(path, req) {
return fail(2, e);
}
if let Some(t) = &st.turso {
if path != "/validate" && path != "/healthz" {
return crate::turso_queue::dispatch(t, path, req);
Expand Down Expand Up @@ -1428,6 +1444,36 @@ pub fn run() -> i32 {
mod tests {
use super::*;

#[test]
fn park_and_revive_not_before_are_gated_before_the_rpc() {
// #6426: /park and /revive forwarded a raw not_before to the
// RPC unchecked. The dispatch gate rejects garbage and
// far-future values; absent/null and valid values pass, and
// other verbs are untouched by the gate.
for path in ["/park", "/revive"] {
for bad in [
json!("banana"),
json!(""),
json!(42),
json!("9999-01-01T00:00:00Z"),
] {
let req = json!({"not_before": bad});
let err = validate_request_not_before(path, &req)
.err()
.expect("invalid not_before must be rejected");
assert!(err.contains("not_before"), "error names the field: {err}");
}
assert!(validate_request_not_before(path, &json!({})).is_ok());
assert!(validate_request_not_before(path, &json!({"not_before": Value::Null})).is_ok());
assert!(
validate_request_not_before(path, &json!({"not_before": "2020-01-01T00:00:00Z"}))
.is_ok()
);
}
// A verb without a not_before surface is not gated.
assert!(validate_request_not_before("/claim", &json!({"not_before": "banana"})).is_ok());
}

#[test]
fn pre_body_refusal_decides_from_headers_alone() {
// #6515 oracle (thread 4492609604): the gate's answer
Expand Down
Loading
Loading