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
16 changes: 16 additions & 0 deletions architecture/security-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ After any successful policy write, pending chunks already covered by the new
live effective policy are rejected as redundant. This keeps the review inbox
aligned with what the sandbox currently enforces.

Endpoint and binary advisor markers are provenance, not authorization or
connection metadata. Provider- or user-authored declarations carry explicit
provenance; `policy.local` declarations carry advisor provenance. A difference
in endpoint provenance alone is compatible during effective-policy ambiguity
validation. When identical endpoint or binary identities merge, an explicit
declaration dominates an advisor declaration. Proposal coverage likewise
ignores provenance so an approved overlay converges when an existing explicit
declaration already supplies the same identity.

This compatibility does not weaken SSRF classification. Exact-host trust
requires one matching rule to contain both an exact explicit endpoint and an
explicit binary identity. An advisor-only endpoint or binary cannot assemble
that trust from unrelated rules. A provider rule may independently establish
trust for its own explicit endpoint and binary pair, but an advisor overlay
does not broaden that pair to a different binary.

### Security-notes gate

Separately from the prover, each chunk carries advisory `security_notes`.
Expand Down
116 changes: 111 additions & 5 deletions crates/openshell-cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7117,6 +7117,10 @@ pub async fn sandbox_logs(
}

fn print_log_line(log: &openshell_core::proto::SandboxLogLine) {
println!("{}", format_log_line(log));
}

fn format_log_line(log: &openshell_core::proto::SandboxLogLine) -> String {
let source = if log.source.is_empty() {
"gateway"
} else {
Expand All @@ -7125,10 +7129,10 @@ fn print_log_line(log: &openshell_core::proto::SandboxLogLine) {
let secs = log.timestamp_ms / 1000;
let millis = log.timestamp_ms % 1000;
if log.fields.is_empty() {
println!(
format!(
"[{secs}.{millis:03}] [{source:<7}] [{:<5}] [{}] {}",
log.level, log.target, log.message
);
)
} else {
let mut fields_str = String::new();
let mut entries: Vec<_> = log.fields.iter().collect();
Expand All @@ -7141,10 +7145,10 @@ fn print_log_line(log: &openshell_core::proto::SandboxLogLine) {
fields_str.push('=');
fields_str.push_str(v);
}
println!(
format!(
"[{secs}.{millis:03}] [{source:<7}] [{:<5}] [{}] {} {}",
log.level, log.target, log.message, fields_str
);
)
}
}

Expand Down Expand Up @@ -7509,7 +7513,7 @@ fn format_endpoint(endpoint: &openshell_core::proto::NetworkEndpoint) -> String
mod tests {
use super::{
PolicyGetView, ProvisioningStep, build_sandbox_resource_limits,
dockerfile_sources_supported_for_gateway, format_endpoint,
dockerfile_sources_supported_for_gateway, format_endpoint, format_log_line,
format_provider_attachment_table, git_sync_files, has_main_process_result,
inferred_provider_type, parse_cli_setting_value, parse_credential_expiry_cli_value,
parse_credential_expiry_pairs, parse_credential_pairs, parse_driver_config_json,
Expand Down Expand Up @@ -8974,4 +8978,106 @@ mod tests {
assert!(json["revision"].is_null());
assert!(json["policy"].is_null());
}

fn log_line(
level: &str,
target: &str,
message: &str,
source: &str,
fields: &[(&str, &str)],
) -> openshell_core::proto::SandboxLogLine {
openshell_core::proto::SandboxLogLine {
sandbox_id: "sb-1".to_string(),
timestamp_ms: 1_234_567,
level: level.to_string(),
target: target.to_string(),
message: message.to_string(),
source: source.to_string(),
fields: fields
.iter()
.map(|(k, v)| ((*k).to_string(), (*v).to_string()))
.collect(),
}
}

#[test]
fn format_log_line_without_fields() {
let log = log_line("INFO", "openshell_server", "hello world", "sandbox", &[]);
assert_eq!(
format_log_line(&log),
"[1234.567] [sandbox] [INFO ] [openshell_server] hello world"
);
}

#[test]
fn format_log_line_empty_source_defaults_to_gateway() {
let log = log_line("WARN", "t", "msg", "", &[]);
assert_eq!(
format_log_line(&log),
"[1234.567] [gateway] [WARN ] [t] msg"
);
}

#[test]
fn format_log_line_pads_source_and_level() {
let log = log_line("OCSF", "ocsf", "NET:OPEN", "gateway", &[]);
assert_eq!(
format_log_line(&log),
"[1234.567] [gateway] [OCSF ] [ocsf] NET:OPEN"
);

let short_source = log_line("ERROR", "t", "m", "vm", &[]);
assert_eq!(
format_log_line(&short_source),
"[1234.567] [vm ] [ERROR] [t] m"
);
}

#[test]
fn format_log_line_sorts_fields_alphabetically() {
let log = log_line(
"INFO",
"ocsf",
"CONNECT",
"sandbox",
&[("dst_port", "443"), ("action", "allow"), ("dst_host", "x")],
);
assert_eq!(
format_log_line(&log),
"[1234.567] [sandbox] [INFO ] [ocsf] CONNECT action=allow dst_host=x dst_port=443"
);
}

#[test]
fn format_log_line_keeps_empty_field_values() {
let log = log_line("INFO", "t", "m", "sandbox", &[("a", ""), ("b", "1")]);
assert_eq!(
format_log_line(&log),
"[1234.567] [sandbox] [INFO ] [t] m a= b=1"
);
}

#[test]
fn format_log_line_renders_empty_target_as_empty_brackets() {
let log = log_line("INFO", "", "m", "sandbox", &[]);
assert_eq!(format_log_line(&log), "[1234.567] [sandbox] [INFO ] [] m");
}

#[test]
fn format_log_line_zero_pads_millis() {
let mut log = log_line("INFO", "t", "m", "sandbox", &[]);
log.timestamp_ms = 1_000_007;
assert_eq!(format_log_line(&log), "[1000.007] [sandbox] [INFO ] [t] m");

log.timestamp_ms = 0;
assert_eq!(format_log_line(&log), "[0.000] [sandbox] [INFO ] [t] m");
}

#[test]
fn format_log_line_preserves_message_verbatim() {
// OCSF shorthand must pass through unchanged.
let message = "NET:OPEN [MED] DENIED /usr/bin/curl(4711) -> api.example.com:443";
let log = log_line("OCSF", "ocsf", message, "sandbox", &[]);
assert!(format_log_line(&log).ends_with(message));
}
}
6 changes: 3 additions & 3 deletions crates/openshell-driver-kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ its pod. The driver sets `spec.operatingMode: Suspended` for `v1beta1` or
`spec.replicas: 0` for `v1alpha1`. Start sets `Running` or one replica for the
same resource, so the replacement pod mounts the existing claim. Delete is the
only lifecycle operation that removes the Sandbox resource and its owned
storage. The driver confirms the stop from the published `Suspended`
condition when available. Legacy `v1alpha1` controllers omit a zero replica
count from status, so the driver confirms that their backing pod is gone.
storage. The driver confirms the stop from both the published `Suspended`
condition and deletion of the backing pod. Legacy `v1alpha1` controllers omit
a usable stopped condition, so pod deletion alone confirms their stop.

The workspace PVC size defaults to `workspace_default_storage_size`. Set
`workspace_storage_class` to pin the PVC to a specific `StorageClass`; an empty
Expand Down
70 changes: 60 additions & 10 deletions crates/openshell-driver-kubernetes/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1623,8 +1623,7 @@ impl KubernetesComputeDriver {
let (agent_sandbox_api, kube_name, pod_name, namespace, stop_timeout) = self
.patch_sandbox_operating_state(sandbox_id, false)
.await?;
let legacy_pod_api = (agent_sandbox_api.resource.version == SANDBOX_VERSION_V1ALPHA1)
.then(|| Api::<Pod>::namespaced(self.client.clone(), &namespace));
let pod_api = Api::<Pod>::namespaced(self.client.clone(), &namespace);

let deadline = tokio::time::Instant::now() + stop_timeout;
let mut poll_interval = STOP_INITIAL_POLL_INTERVAL;
Expand All @@ -1649,17 +1648,18 @@ impl KubernetesComputeDriver {
))
})?
.map_err(KubernetesDriverError::from_kube)?;
if kubernetes_sandbox_has_stopped_condition(&object) {
return Ok(());
}
if let Some(error) = kubernetes_sandbox_stop_failure(&object) {
return Err(KubernetesDriverError::Message(error));
}
if let Some(pod_api) = legacy_pod_api.as_ref()
&& kubernetes_sandbox_pod_is_gone(pod_api, &pod_name, deadline)
.await
.map_err(KubernetesDriverError::Message)?
{
let pod_is_gone = kubernetes_sandbox_pod_is_gone(&pod_api, &pod_name, deadline)
.await
.map_err(KubernetesDriverError::Message)?;
let stop_is_complete = kubernetes_sandbox_stop_is_complete(
&agent_sandbox_api.resource.version,
&object,
pod_is_gone,
);
if stop_is_complete {
return Ok(());
}
let now = tokio::time::Instant::now();
Expand Down Expand Up @@ -4560,6 +4560,19 @@ fn kubernetes_sandbox_has_stopped_condition(obj: &DynamicObject) -> bool {
})
}

fn kubernetes_sandbox_stop_is_complete(
api_version: &str,
obj: &DynamicObject,
pod_is_gone: bool,
) -> bool {
if api_version == SANDBOX_VERSION_V1ALPHA1 {
// v1alpha1 omits a usable stopped condition.
pod_is_gone
} else {
kubernetes_sandbox_has_stopped_condition(obj) && pod_is_gone
}
}

fn kubernetes_sandbox_stop_failure(obj: &DynamicObject) -> Option<String> {
obj.data
.get("status")?
Expand Down Expand Up @@ -5392,6 +5405,43 @@ mod tests {
assert!(kubernetes_sandbox_has_stopped_condition(&sandbox));
}

#[test]
fn beta_stop_requires_suspended_condition_and_deleted_pod() {
let resource = ApiResource::from_gvk(&GroupVersionKind::gvk(
SANDBOX_GROUP,
SANDBOX_VERSION_V1BETA1,
SANDBOX_KIND,
));
let mut sandbox = DynamicObject::new("sandbox", &resource);

assert!(!kubernetes_sandbox_stop_is_complete(
SANDBOX_VERSION_V1BETA1,
&sandbox,
true,
));

sandbox.data = serde_json::json!({
"status": {
"conditions": [{"type": "Suspended", "status": "True"}]
}
});
assert!(!kubernetes_sandbox_stop_is_complete(
SANDBOX_VERSION_V1BETA1,
&sandbox,
false,
));
assert!(kubernetes_sandbox_stop_is_complete(
SANDBOX_VERSION_V1BETA1,
&sandbox,
true,
));
assert!(kubernetes_sandbox_stop_is_complete(
SANDBOX_VERSION_V1ALPHA1,
&DynamicObject::new("sandbox", &resource),
true,
));
}

#[test]
fn stop_failure_only_rejects_terminal_suspension_condition() {
let resource = ApiResource::from_gvk(&GroupVersionKind::gvk(
Expand Down
Loading
Loading