This task hardened the provider layer in three areas:
- added explicit provider trust levels
- added provider readiness states
- added request context minimization and prompt sanitization
- added structured provider response validation
- added trust-aware suppression of executable command suggestions
- preserved the normal plan -> risk review -> approval path for all provider output
- added provider configuration validation before provider use
- added endpoint URL validation
- added missing / placeholder credential detection
- added clearer failure classification for configuration, authentication, network, model, and response failures
- surfaced readiness, trust, and validation state through provider status and health output
- added env-var-first secret resolution
- added optional keyring-backed secret resolution
- added plaintext secret storage detection for config storage
- added redaction for provider-related errors and audit/session logging payloads
- documented that
.envis convenience-oriented and not secure secret storage
Main files changed:
src/komu_cli/models/providers.pysrc/komu_cli/models/config.pysrc/komu_cli/providers/base.pysrc/komu_cli/providers/http_client.pysrc/komu_cli/providers/adapters/ollama.pysrc/komu_cli/providers/adapters/openai_compatible.pysrc/komu_cli/providers/adapters/openai.pysrc/komu_cli/providers/adapters/claude.pysrc/komu_cli/providers/adapters/gemini.pysrc/komu_cli/services/provider_service.pysrc/komu_cli/services/provider_security_service.pysrc/komu_cli/services/config_service.pysrc/komu_cli/logging/audit.pysrc/komu_cli/security/redaction.pysrc/komu_cli/security/secrets.py
New abstractions introduced:
- provider trust model
- provider readiness model
- provider validation result / issue models
- provider security service for request/response hardening
- secret resolution abstraction with optional keyring support
- shared redaction helpers
Integration direction:
- adapters now validate config and expose trust/readiness state
- provider service now sanitizes requests and validates responses
- config service now reports plaintext secret-storage risks
- logging now redacts payloads before writing audit/session records
- CLI provider views now expose trust, readiness, and validation information
The provider layer now uses:
trustedrestricteduntrusted
Default posture:
- official hosted providers are generally
trusted - local/self-hosted providers such as Ollama default to
restricted - remote custom OpenAI-compatible endpoints default to
untrusted
Provider requests now go through a sanitization pass:
- secret-like prompt fragments are redacted
- sensitive context keys are removed
- context size is bounded
- context value length is bounded
- safety notes are attached to the provider request
This prevents accidental leakage of raw secrets, full config state, or unrelated heavy context by default.
Provider responses are now validated before the rest of the system uses them:
- provider key must match the adapter
- summary must be non-empty
- plan steps must be present and bounded
- warning count is bounded
- command suggestion count is bounded
- command stages are restricted to known values
- invalid or malformed command suggestions are rejected
Provider output still cannot bypass:
- plan construction
- plan review
- risk classification
- approval requirements
- execution visibility
Additional enforcement:
- untrusted providers have executable command suggestions suppressed by default
- restricted providers can lose executable suggestions for sensitive tasks
Validation now covers:
- missing API key detection
- placeholder API key detection
- missing model detection
- placeholder model detection
- missing endpoint detection
- invalid endpoint URL detection
- optional secret backend availability warnings
Readiness now distinguishes:
- ready
- restricted
- needs-configuration
- unavailable
Failure classes now distinguish:
- configuration
- authentication
- network
- model
- response
Where this is surfaced:
komu providers listkomu providers currentkomu providers healthkomu providers check <provider>komu config show
Secrets are now resolved in this order:
- direct environment variable
- optional keyring backend when enabled
- missing if neither path resolves a value
KOMU now scans stored config payloads for secret-like keys such as:
api_keytokensecretpasswordcredential
If plaintext secret-like fields are found in config storage, KOMU reports that as a warning.
Optional support was added through a lightweight abstraction:
- enable with
KOMU_SECRET_BACKEND=keyring - service name defaults to
komu-cli - can be changed with
KOMU_KEYRING_SERVICE
This support is optional and does not require a hard dependency in the base package.
Redaction now applies to:
- provider-related error paths
- HTTP error text returned by provider transport
- audit log payloads
- session log payloads
- prompt/context sanitization before provider invocation
New or expanded tests:
-
tests/test_provider_security_service.py- request context minimization
- prompt redaction
- trust-aware command suppression
- malformed provider output rejection
-
tests/test_provider_adapters.py- missing credential validation
- invalid endpoint validation
- placeholder secret rejection
- remote custom endpoint trust posture
- failure-kind classification on health errors
-
tests/test_provider_service.py- sanitized provider request flow
- untrusted provider downgrade behavior
- malformed provider response fallback behavior
-
tests/test_planning_service_provider_security.py- provider-generated commands still flow through risk and approval review
-
tests/test_secret_handling.py- secret redaction
- env-var-first secret resolution
- keyring backend warning path
-
tests/test_config_service.py- plaintext secret storage warning detection
Validation run after implementation:
python -m unittest discover -s tests -p "test_*.py"passed with 57 testspython -m compileall srcpassed
What remains untested:
- real live provider integrations against public remote APIs
- real live keyring backend behavior on each OS
- every possible custom OpenAI-compatible endpoint variant
Important tradeoffs made to preserve stability:
- provider sandboxing is policy-aware application-layer hardening, not OS container isolation
- keyring support is optional and intentionally lightweight
- remote custom endpoints are treated conservatively by default rather than optimistically
- provider trust does not replace the plan/risk/approval model; it narrows provider influence
Deferred or partial areas:
- no full OS-specific secret manager integration matrix yet
- no multi-tenant secret policy model yet
- no dynamic benchmark-based provider trust scoring
- no cryptographic storage of secrets in KOMU-managed files
Immediate next hardening tasks:
- add live integration validation against at least one real hosted provider and one real local provider
- add more explicit CLI messaging for configuration vs trust vs reachability failures
- expand secret redaction tests around audit/session history reads
- add provider trust state to explanation/history views where useful
If KOMU moves toward broader public use next:
- add deeper keyring/backend guidance per operating system
- add stricter provider policy packs for enterprise or regulated environments
- add export-safe audit/report generation with stronger redaction guarantees
- add a richer operator-facing security status view that summarizes provider trust, readiness, and secret-storage risks in one place