Skip to content

Release v1.1.0: Production Guardrails & Performance Protection

Latest

Choose a tag to compare

@halovina halovina released this 06 Dec 08:16
· 1 commit to main since this release

🛡️ KacaSQL v1.1.0 — Production Guardrails & Performance Protection

Safe enough to point directly at production read-replicas without risking resource exhaustion or accidental data leaks.

v1.1.0 upgrades KacaSQL from strict read-only query enforcement into a production-ready database MCP server with multi-layer guardrails across both PostgreSQL and MySQL.


✨ What's New

1. Execution Resource Caps & Streaming Payload Truncation

  • Millisecond Timeouts (timeout_ms): Enforced directly at the database session level (SET LOCAL statement_timeout on PostgreSQL, SET SESSION max_execution_time on MySQL).
  • Hard Payload Byte Cap (max_payload_bytes, default 51200 / 50 KB): Prevents LLM context-window blowups on wide result sets via streaming row assembly.
  • Structured _meta Truncation Hints: Whenever results are capped by max_rows or max_payload_bytes, KacaSQL appends actionable _meta hints so AI agents know whether to narrow columns, tighten WHERE filters, or lower LIMIT.

2. Granular Access Control (allowed_schemas & blocked_tables)

  • 2-Layer Enforcement: Applied consistently across all discovery/inspection tools (list_schemas, list_tables, search_schema, describe_table, get_table_relationships, get_table_sample), db://{connection_id}/overview, and sqlglot AST table/schema checks.
  • Supports exact table names, schema-qualified names (private.billing_tokens), and glob patterns (audit_*, private.*) while safely ignoring local CTE aliases.

3. Full PII Protection (Column-Name + Value-Level Regex)

  • Column-Name Masking: Global masked_columns merged with per-connection custom_pii_columns.
  • Value-Level PII Redaction: Built-in ReDoS-safe presets (credit_card, jwt, id_nik, id_npwp, email) plus user-defined custom_pii_value_patterns (validated fail-fast at config load) to redact sensitive values leaked inside free-text or JSONB columns.

4. EXPLAIN-First Full Table Scan Blocker (block_full_table_scan)

  • Environment-Aware Safe Default: Automatically enabled (true) when environment: prod and false for local/dev/staging (always explicitly overridable).
  • PostgreSQL: Detects Seq Scan and Parallel Seq Scan (accounting for Workers Planned) above scan_row_threshold (default 100,000), with a limit-aware exception so simple peeks like SELECT * FROM orders LIMIT 5 (without filters/sorts) are not falsely blocked.
  • MySQL: Detects ALL and index full scans exceeding scan_row_threshold.
  • Returns a compact offending_scans summary + rewrite hint so the AI can self-correct using indexed columns.

5. Privacy-First Local JSONL Audit Trail

  • Opt-in persistent JSONL log via defaults.audit_log_path or KACASQL_AUDIT_LOG (e.g., ~/.kacasql/audit.jsonl).
  • Default SQL Literal Redaction (audit_redact_sql_literals: true): Replaces string & numeric literals with placeholders via sqlglot AST (preventing audit logs from becoming a shadow PII store) and records sql_hash (SHA-256).
  • Enforces 0600 file permissions on POSIX, size-capped rotation (audit_max_bytes, default 10 MB), and fail-safe writes.

6. Declarative guardrails: YAML Block & CLI --version

  • Clean guardrails: configuration block (100% backward-compatible with v1.0 flat fields; strictly dsn_env-only).
  • Added kacasql --version CLI flag.

📦 Quick Upgrade (uvx)

Update your MCP client config (~/.gemini/config/mcp_config.json or Claude Desktop) to @v1.1.0:

{
  "mcpServers": {
    "kacasql": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/halovina/kacasql.git@v1.1.0",
        "kacasql"
      ],
      "env": {
        "KACASQL_CONFIG": "/path/to/connections.yaml",
        "KACASQL_AUDIT_LOG": "~/.kacasql/audit.jsonl",
        "PROD_REPLICA_PG_DSN": "postgresql://readonly_user:password@prod-replica:5432/app"
      }
    }
  }
}

✅ Verification

  • 112 tests passed (103 unit tests + 9 live Docker PostgreSQL 16 & MySQL 8.4 integration & multi-scenario stress tests).
  • Verified under 80 concurrent mixed adversarial/valid/timeout/payload-cap calls and 100-query burst pool saturation (223.5 QPS, 0 pool errors, 0 credential/PII leaks).

Full Changelog: v1.0.1...v1.1.0