Skip to content

Commit e7a095a

Browse files
committed
fix(server): refuse name-based run IDs on person run, rerun and ad-hoc requests
The server derives version 5 run IDs for group members, retries, sensor and scheduled runs. A person-supplied version 5 ID could collide with one of those, so job run, rerun and ad-hoc requests now refuse it with a 400 that says why. Internal paths keep their derived IDs.
1 parent 16e22dc commit e7a095a

14 files changed

Lines changed: 228 additions & 17 deletions

File tree

‎clients/typescript/src/schema.d.ts‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,10 @@ export interface components {
14501450
/** Format: int64 */
14511451
priority: number;
14521452
reason: string;
1453-
/** Format: uuid */
1453+
/**
1454+
* Format: uuid
1455+
* @description A new random (UUID v4) or time-ordered (UUID v7) ID; name-based (v5) IDs are refused as the server derives those.
1456+
*/
14541457
run_id: string;
14551458
target: string;
14561459
};
@@ -1883,7 +1886,10 @@ export interface components {
18831886
/** Format: int64 */
18841887
priority: number;
18851888
reason: string;
1886-
/** Format: uuid */
1889+
/**
1890+
* Format: uuid
1891+
* @description A new random (UUID v4) or time-ordered (UUID v7) ID; name-based (v5) IDs are refused as the server derives those.
1892+
*/
18871893
run_id: string;
18881894
/** @description Narrow the job with `sqb build` selectors; only nodes already in the job can remain. */
18891895
select?: string[];
@@ -2684,7 +2690,10 @@ export interface components {
26842690
/** Format: int64 */
26852691
priority: number;
26862692
reason: string;
2687-
/** Format: uuid */
2693+
/**
2694+
* Format: uuid
2695+
* @description A new random (UUID v4) or time-ordered (UUID v7) ID; name-based (v5) IDs are refused as the server derives those.
2696+
*/
26882697
run_id: string;
26892698
/** Format: uuid */
26902699
source_run_id: string;
@@ -6040,6 +6049,14 @@ export interface operations {
60406049
"application/json": components["schemas"]["MutationResponse"];
60416050
};
60426051
};
6052+
400: {
6053+
headers: {
6054+
[name: string]: unknown;
6055+
};
6056+
content: {
6057+
"application/json": components["schemas"]["ApiErrorBody"];
6058+
};
6059+
};
60436060
/** @description Session rejected */
60446061
401: {
60456062
headers: {
@@ -6200,6 +6217,14 @@ export interface operations {
62006217
"application/json": components["schemas"]["MutationResponse"];
62016218
};
62026219
};
6220+
400: {
6221+
headers: {
6222+
[name: string]: unknown;
6223+
};
6224+
content: {
6225+
"application/json": components["schemas"]["ApiErrorBody"];
6226+
};
6227+
};
62036228
/** @description Session rejected */
62046229
401: {
62056230
headers: {

‎crates/sqlbuild-orchestration/src/api/_helpers/resources/person_operations.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ pub(crate) async fn statistics(
6767

6868
#[utoipa::path(post, path = "/api/control/runs", operation_id = "requestJobRun",
6969
params(("x-sqb-csrf" = String, Header)), request_body = JobRunRequest,
70-
responses((status = 200, body = MutationResponse), (status = 401, description = "Session rejected"),
70+
responses((status = 200, body = MutationResponse),
71+
(status = 400, body = crate::api::models::ApiErrorBody), (status = 401, description = "Session rejected"),
7172
(status = 403, body = crate::api::models::ApiErrorBody)), security(("session" = []), ("cliSession" = [])))]
7273
pub(crate) async fn request_job(
7374
(State(store), Extension(context)): (State<ControlStore>, Extension<AuditContext>),
@@ -148,7 +149,8 @@ pub(crate) async fn cancel_run(
148149

149150
#[utoipa::path(post, path = "/api/control/runs/rerun", operation_id = "rerunPersonRun",
150151
params(("x-sqb-csrf" = String, Header)), request_body = RerunRequest,
151-
responses((status = 200, body = MutationResponse), (status = 401, description = "Session rejected"),
152+
responses((status = 200, body = MutationResponse),
153+
(status = 400, body = crate::api::models::ApiErrorBody), (status = 401, description = "Session rejected"),
152154
(status = 403, body = crate::api::models::ApiErrorBody)), security(("session" = []), ("cliSession" = [])))]
153155
pub(crate) async fn rerun(
154156
(State(store), Extension(context)): (State<ControlStore>, Extension<AuditContext>),

‎crates/sqlbuild-orchestration/src/runs/_helpers/requests/adhoc.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::runs::_helpers::requests::permissions::{authorize_execution, executio
1414
use crate::runs::_helpers::requests::publication::{
1515
publish_request, record_authored, request_retry,
1616
};
17+
use crate::runs::_helpers::requests::run_id::refuse_derived_run_id;
1718
use crate::runs::constants::ADHOC_AUDIT_TAG;
1819
use crate::runs::models::{
1920
AdhocCheckRequest, AdhocPermission, AdhocRunRequest, CommandPlan, PlannerResource, RunCommand,
@@ -222,6 +223,7 @@ pub(in crate::runs) async fn request_adhoc_run_in(
222223
(context, principal_id): (&AuditContext, Uuid),
223224
(planner, request): (&dyn CommandPlanner, &AdhocRunRequest),
224225
) -> Result<(ControlTransaction, bool), ControlError> {
226+
refuse_derived_run_id(request.run_id)?;
225227
let (transaction, context) = authorize_listing(
226228
transaction,
227229
(context, principal_id),

‎crates/sqlbuild-orchestration/src/runs/_helpers/requests/manual_job.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::runs::_helpers::requests::permissions::authorize_execution;
1212
use crate::runs::_helpers::requests::publication::{
1313
publish_request, record_authored, request_retry,
1414
};
15+
use crate::runs::_helpers::requests::run_id::refuse_derived_run_id;
1516
use crate::runs::constants::MANUAL_JOB_AUDIT_TAG;
1617
use crate::runs::main::frozen_job_request::frozen_job_request;
1718
use crate::runs::models::{JobRunRequest, RunWindow};
@@ -26,6 +27,7 @@ pub(crate) async fn request_job_run_in(
2627
(context, credentials): (&AuditContext, Option<Uuid>),
2728
(planner, request): (Option<&dyn CommandPlanner>, &JobRunRequest),
2829
) -> Result<(ControlTransaction, bool), ControlError> {
30+
refuse_derived_run_id(request.run_id)?;
2931
let mut context = context.clone();
3032
let scope = PermissionScope {
3133
action: Action::JobRun,

‎crates/sqlbuild-orchestration/src/runs/_helpers/requests/manual_rerun.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::runs::_helpers::requests::publication::{
1010
publish_request, record_authored, request_retry,
1111
};
1212
use crate::runs::_helpers::requests::rerun::frozen_rerun;
13+
use crate::runs::_helpers::requests::run_id::refuse_derived_run_id;
1314
use crate::runs::constants::RERUN_AUDIT_TAG;
1415
use crate::runs::models::{RerunRequest, RunRequest};
1516
use crate::store::errors::ControlError;
@@ -22,6 +23,7 @@ pub(crate) async fn request_rerun_in(
2223
(context, credentials): (&AuditContext, Option<Uuid>),
2324
request: &RerunRequest,
2425
) -> Result<(ControlTransaction, bool), ControlError> {
26+
refuse_derived_run_id(request.run_id)?;
2527
let mut context = context.clone();
2628
let mut prepared = None;
2729
if let Some(credentials) = credentials {

‎crates/sqlbuild-orchestration/src/runs/_helpers/requests/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pub(in crate::runs) mod permissions;
77
pub(in crate::runs) mod plan;
88
pub(in crate::runs) mod publication;
99
pub(in crate::runs) mod rerun;
10+
pub(in crate::runs) mod run_id;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! A run ID a person supplies must not be of the kind the server derives for its own runs.
2+
3+
use uuid::Uuid;
4+
5+
use crate::runs::constants::DERIVED_RUN_ID_VERSION;
6+
use crate::store::errors::ControlError;
7+
8+
/// Refuses a name-based run ID, the kind the server derives for group members and retries.
9+
pub(in crate::runs) fn refuse_derived_run_id(run_id: Uuid) -> Result<(), ControlError> {
10+
if run_id.get_version_num() != DERIVED_RUN_ID_VERSION {
11+
return Ok(());
12+
}
13+
Err(ControlError::Invalid(format!(
14+
"run_id {run_id} is a name-based UUID (version 5), which the server reserves for the IDs it \
15+
derives for group members and retries; send a random (version 4) or time-ordered \
16+
(version 7) UUID"
17+
)))
18+
}

‎crates/sqlbuild-orchestration/src/runs/constants.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ pub(crate) const DEFAULT_RUN_LOG_RETENTION_COUNT: u16 = 200;
3838
pub(crate) const RUN_LOG_RETENTION_BATCH: usize = 10;
3939
/// Artifact digests checked for remaining references per statement.
4040
pub(crate) const RUN_LOG_DIGEST_CHUNK: usize = 500;
41+
/// The UUID version of the run IDs the server derives from other IDs, which people may not supply.
42+
pub(crate) const DERIVED_RUN_ID_VERSION: usize = 5;

‎crates/sqlbuild-orchestration/src/runs/models.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ impl RunRequest {
188188
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, utoipa::ToSchema)]
189189
#[serde(deny_unknown_fields)]
190190
pub struct JobRunRequest {
191+
/// A new random (UUID v4) or time-ordered (UUID v7) ID; name-based (v5) IDs are refused as the server derives those.
191192
pub run_id: Uuid,
192193
pub location_id: Uuid,
193194
pub target: String,
@@ -211,6 +212,7 @@ pub struct JobRunRequest {
211212
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, utoipa::ToSchema)]
212213
#[serde(deny_unknown_fields)]
213214
pub struct RerunRequest {
215+
/// A new random (UUID v4) or time-ordered (UUID v7) ID; name-based (v5) IDs are refused as the server derives those.
214216
pub run_id: Uuid,
215217
pub source_run_id: Uuid,
216218
pub from_failure: bool,
@@ -742,6 +744,7 @@ pub struct RunObservation {
742744
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, utoipa::ToSchema)]
743745
#[serde(deny_unknown_fields)]
744746
pub struct AdhocRunRequest {
747+
/// A new random (UUID v4) or time-ordered (UUID v7) ID; name-based (v5) IDs are refused as the server derives those.
745748
pub run_id: Uuid,
746749
pub location_id: Uuid,
747750
pub target: String,

‎crates/sqlbuild-orchestration/tests/api/test_contracts.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ mod test_publish_encoding;
8888
mod test_reads;
8989
#[path = "test_resource_costs.rs"]
9090
mod test_resource_costs;
91+
#[path = "test_run_ids.rs"]
92+
mod test_run_ids;
9193
#[path = "test_server_errors.rs"]
9294
mod test_server_errors;
9395
#[path = "test_statistics_recovery.rs"]

0 commit comments

Comments
 (0)