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
2 changes: 2 additions & 0 deletions changelog.d/391.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Kubernetes `pods.delete` without `gracePeriodSeconds` now uses the pod's own grace period,
as `kubectl delete pod` does, instead of force-deleting; pass `0` to force (#391).
7 changes: 7 additions & 0 deletions changelog.d/391.security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Kubernetes connector: object names and namespaces must be Kubernetes names, so `.`, `..`
and empty values can no longer turn `pods.get` into an unredacted list or `pods.delete`
into a collection delete. `pods.delete` returns `{deleted, namespace, name}` instead of
the deleted Pod with its environment values, and pod and deployment results are redacted
whatever their shape. The connection test no longer echoes a non-Kubernetes response
body, and `defaultNamespace` and `namespaces` are validated when a connection is saved
(#391).
4 changes: 2 additions & 2 deletions crates/orbit-api/src/connectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub fn builtin_manifests() -> Vec<ConnectorManifest> {
slug: "kubernetes".into(),
name: "Kubernetes".into(),
version: "0.2.0".into(),
description: "Read-only Kubernetes inspection: namespaces, pods, logs, deployments and events.".into(),
description: "Kubernetes inspection (namespaces, pods, logs, deployments, events) and controlled recovery (restart a deployment, delete a pod).".into(),
auth: vec![AuthMethod::ApiToken],
webhooks: false,
capabilities: vec![
Expand All @@ -202,7 +202,7 @@ pub fn builtin_manifests() -> Vec<ConnectorManifest> {
capability(
"pods.delete",
"Delete pod",
"Deletes one pod; its Deployment/ReplicaSet recreates it. Use for a stuck pod.",
"Deletes one pod in an allowed namespace; its Deployment/ReplicaSet recreates it.",
CapabilityEffect::ExternalSideEffect,
),
capability("events.list", "List events", "Lists namespace events.", CapabilityEffect::Read),
Expand Down
16 changes: 10 additions & 6 deletions crates/orbit-api/src/handlers/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,11 @@ fn sanitize_provider_config(config: &mut serde_json::Value) {
const CONNECTION_URL_FIELDS: [&str; 4] = ["baseUrl", "cloneBaseUrl", "url", "apiServer"];

/// Validate URL-typed connection config fields against the outbound policy
/// (`ORBIT_OUTBOUND_ALLOW_PRIVATE` / `ORBIT_OUTBOUND_ALLOWED_HOSTS`); errors are 422s on
/// the offending field name. A kubeconfig credential's own `server` is checked when the
/// Kubernetes client connects.
pub(crate) async fn validate_connection_urls(config: &serde_json::Value) -> Result<(), ApiError> {
/// (`ORBIT_OUTBOUND_ALLOW_PRIVATE` / `ORBIT_OUTBOUND_ALLOWED_HOSTS`) and the Kubernetes
/// namespace fields (`defaultNamespace`, `namespaces`), which are spliced into request
/// paths (#391); errors are 422s on the offending field name. A kubeconfig credential's
/// own `server` is checked when the Kubernetes client connects.
pub(crate) async fn validate_connection_config(config: &serde_json::Value) -> Result<(), ApiError> {
let policy = orbit_security::OutboundPolicy::from_env();
let mut issues = Vec::new();
for field in CONNECTION_URL_FIELDS {
Expand All @@ -550,6 +551,9 @@ pub(crate) async fn validate_connection_urls(config: &serde_json::Value) -> Resu
issues.push(orbit_domain::ValidationIssue::new(field, error.to_string()));
}
}
for (field, message) in orbit_kubernetes::config_issues(config) {
issues.push(orbit_domain::ValidationIssue::new(field, message));
}
if issues.is_empty() {
Ok(())
} else {
Expand Down Expand Up @@ -605,7 +609,7 @@ pub async fn create_connection(
.get_connector_by_slug(auth.org_id, &body.connector_slug)
.await?
.ok_or_else(|| ApiError::not_found(format!("connector '{}'", body.connector_slug)))?;
validate_connection_urls(&body.config).await?;
validate_connection_config(&body.config).await?;

let secret_ref = if let Some(credential) = &body.credential {
if credential.trim().is_empty() {
Expand Down Expand Up @@ -693,7 +697,7 @@ pub async fn update_connection(
&existing.visibility,
)?;
if let Some(config) = &body.config {
validate_connection_urls(config).await?;
validate_connection_config(config).await?;
// A stored credential must never follow an edited endpoint (#321), the same rule
// providers follow: changing a URL field requires the credential for it.
if existing.credential_ref.is_some() && body.credential.is_none() {
Expand Down
3 changes: 2 additions & 1 deletion crates/orbit-api/src/handlers/import_portable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ async fn translate(
if config.is_null() {
config = json!({});
}
if let Err(error) = crate::handlers::catalog::validate_connection_urls(&config).await {
if let Err(error) = crate::handlers::catalog::validate_connection_config(&config).await
{
for issue in &error.details {
found.issue(issue.path.clone(), issue.message.clone());
}
Expand Down
29 changes: 29 additions & 0 deletions crates/orbit-api/tests/api_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9141,6 +9141,35 @@ async fn kubernetes_api_server_is_guarded_and_testing_needs_write() {
.as_array()
.is_some_and(|details| details.iter().any(|detail| detail["path"] == "apiServer")));

// #391: namespaces are spliced into request paths, so a path-like value is refused.
let (status, body) = send(
&app.router,
post(
"/api/v1/connections",
json!({
"connectorSlug": "kubernetes",
"name": "Dot namespace",
"config": {
"authMode": "service_account",
"apiServer": "https://93.184.216.34",
"defaultNamespace": "a/../b",
"namespaces": ["payments", ".."]
},
"credential": "dummy-token"
}),
),
)
.await;
assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY, "{body}");
let paths: Vec<&str> = body["error"]["details"]
.as_array()
.unwrap()
.iter()
.filter_map(|detail| detail["path"].as_str())
.collect();
assert!(paths.contains(&"defaultNamespace"), "{body}");
assert!(paths.contains(&"namespaces"), "{body}");

// A loopback API server stored before this check is refused when the test connects,
// and the response does not echo what the address returned.
let kubernetes = app
Expand Down
Loading