feat: E2E #2 (Stash) gap remediation + S6 hardening
Closes the gaps and the one security finding from the second end-to-end
CLI test (E2E_STASH_REPORT.md), plus the H1 boot-regression found while
re-reviewing those fixes.
Security
- S6: reserved-path validation (`check_reserved`) now case-folds before
comparing, so `/API/v2/x`, `/HEALTHZ`, `/Admin/x` are rejected like
their lowercase forms. Request-time matching stays case-sensitive.
- S10: "public route != public data" callout in sdk-shape.md (script_gate
skips authz when the principal is anonymous).
Observability / features
- G1: trigger executions now write `execution_logs`. Migration 0043 adds
a `source` column (CHECK mirrors ExecutionSource/OutboxSourceKind,
DEFAULT 'http' backfills history); a shared `build_execution_log` helper
in executor-core; dispatcher logging for outbox triggers + queue
consumers (skips sync-HTTP rows the orchestrator already logs). `pic
logs` gains a source column + `--source` filter.
- G5: dev-only in-memory email capture under PICLOUD_DEV_MODE with no SMTP
(email::send succeeds locally), readable at GET /api/v1/admin/dev/emails
(Owner/Admin only; route mounted only in capture mode).
- G6: generalized the Rhai in-place-mutation footgun note (trim/replace/
make_upper/make_lower/crop/truncate/pad return ()).
- G2/G3/G4 (CLI): `pic members`, `pic files`, `pic queues`, read-only
`pic kv` (+ new kv_api.rs); `pic deploy --timeout/--memory/--kind/
--sandbox`; first-class `pic triggers create-{docs,files,pubsub,queue,
email}` wrappers. All new client path segments percent-encoded via seg().
H1 regression fix (found in re-review)
- The S6 change also runs in `compile_routes`, which compiles every stored
route at boot and on each route CRUD. A single stored route the new
validation rejects (creatable while the S6 gap existed) made the whole
compile Err and aborted startup. `compile_routes` is now lenient: it
skips an un-compilable row with a warning instead of bricking boot
(route creation still validates separately). Migration 0044 sweeps
pre-existing reserved-path routes on upgrade (WHERE mirrors
check_reserved exactly). Added regression tests for both.
Verified: cargo fmt, clippy --all-targets --all-features -D warnings, the
schema_snapshot test, and the new S6/lenient-compile unit tests all pass;
boot-resilience and G1/G5 confirmed live.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,8 @@ use std::collections::BTreeMap;
|
||||
use async_trait::async_trait;
|
||||
use picloud_orchestrator_core::{ResolverError, ScriptResolver};
|
||||
use picloud_shared::{
|
||||
AdminUserId, AppId, ExecutionLog, ExecutionStatus, RequestId, Script, ScriptId, ScriptKind,
|
||||
ScriptSandbox,
|
||||
AdminUserId, AppId, ExecutionLog, ExecutionSource, ExecutionStatus, RequestId, Script,
|
||||
ScriptId, ScriptKind, ScriptSandbox,
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
|
||||
@@ -584,6 +584,7 @@ pub trait ExecutionLogRepository: Send + Sync {
|
||||
script_id: ScriptId,
|
||||
limit: i64,
|
||||
cursor: Option<ExecutionLogCursor>,
|
||||
source: Option<ExecutionSource>,
|
||||
) -> Result<Vec<ExecutionLog>, ScriptRepositoryError>;
|
||||
}
|
||||
|
||||
@@ -605,23 +606,30 @@ impl ExecutionLogRepository for PostgresExecutionLogRepository {
|
||||
script_id: ScriptId,
|
||||
limit: i64,
|
||||
cursor: Option<ExecutionLogCursor>,
|
||||
source: Option<ExecutionSource>,
|
||||
) -> Result<Vec<ExecutionLog>, ScriptRepositoryError> {
|
||||
// The optional `source` filter is folded into one bind via
|
||||
// `$N::text IS NULL OR source = $N` so we don't fan out into four
|
||||
// query strings. `None` → the predicate is always true (no filter).
|
||||
let source = source.map(ExecutionSource::as_str);
|
||||
let rows = match cursor {
|
||||
Some(c) => {
|
||||
sqlx::query_as::<_, ExecutionLogRow>(
|
||||
"SELECT id, app_id, script_id, request_id, \
|
||||
request_path, request_headers, request_body, \
|
||||
response_code, response_body, \
|
||||
logs, duration_ms, status, created_at \
|
||||
logs, duration_ms, status, source, created_at \
|
||||
FROM execution_logs \
|
||||
WHERE script_id = $1 \
|
||||
AND (created_at, id) < ($2, $3) \
|
||||
AND ($4::text IS NULL OR source = $4) \
|
||||
ORDER BY created_at DESC, id DESC \
|
||||
LIMIT $4",
|
||||
LIMIT $5",
|
||||
)
|
||||
.bind(script_id.into_inner())
|
||||
.bind(c.created_at)
|
||||
.bind(c.id)
|
||||
.bind(source)
|
||||
.bind(limit)
|
||||
.fetch_all(&self.pool)
|
||||
.await?
|
||||
@@ -631,13 +639,15 @@ impl ExecutionLogRepository for PostgresExecutionLogRepository {
|
||||
"SELECT id, app_id, script_id, request_id, \
|
||||
request_path, request_headers, request_body, \
|
||||
response_code, response_body, \
|
||||
logs, duration_ms, status, created_at \
|
||||
logs, duration_ms, status, source, created_at \
|
||||
FROM execution_logs \
|
||||
WHERE script_id = $1 \
|
||||
AND ($2::text IS NULL OR source = $2) \
|
||||
ORDER BY created_at DESC, id DESC \
|
||||
LIMIT $2",
|
||||
LIMIT $3",
|
||||
)
|
||||
.bind(script_id.into_inner())
|
||||
.bind(source)
|
||||
.bind(limit)
|
||||
.fetch_all(&self.pool)
|
||||
.await?
|
||||
@@ -662,6 +672,7 @@ struct ExecutionLogRow {
|
||||
logs: serde_json::Value,
|
||||
duration_ms: i32,
|
||||
status: String,
|
||||
source: String,
|
||||
created_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
@@ -675,6 +686,9 @@ impl From<ExecutionLogRow> for ExecutionLog {
|
||||
"budget_exceeded" => ExecutionStatus::BudgetExceeded,
|
||||
_ => ExecutionStatus::Error,
|
||||
};
|
||||
// Unknown values can't occur (CHECK constraint) but default to
|
||||
// Http rather than panicking on a forward-compat surprise.
|
||||
let source = ExecutionSource::from_wire(&r.source).unwrap_or_default();
|
||||
Self {
|
||||
id: r.id,
|
||||
app_id: r.app_id.into(),
|
||||
@@ -688,6 +702,7 @@ impl From<ExecutionLogRow> for ExecutionLog {
|
||||
script_logs: r.logs,
|
||||
duration_ms: u64::try_from(r.duration_ms).unwrap_or(0),
|
||||
status,
|
||||
source,
|
||||
created_at: r.created_at,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user