Complete backport of all features from apollo_nxt-trcaa repository: - Three-tier shell execution safety system (Tier 1: auto, Tier 2: approve, Tier 3: deny) - Ollama function calling with tool use support - AI provider tool calling auto-detection - kubectl binary bundling and management - kubeconfig upload and context management - Shell approval modal with real-time UI - MCP protocol HTTP transport with custom headers - Enhanced security audit logging - Comprehensive test coverage (275+ tests) - Updated CI/CD workflows for Gitea Actions - Complete documentation (ADRs, wiki, release notes) Sanitization applied to all files: - Removed all MSI, Motorola, VNXT, Vesta references - Replaced internal infrastructure references with TFTSR equivalents - Updated all URLs and API endpoints - Sanitized commit history references in documentation Technical changes: - New modules: shell/classifier, shell/executor, shell/kubectl, shell/kubeconfig - Enhanced AI providers: ollama.rs, openai.rs with function calling - New Tauri commands: shell execution, kubeconfig management, tool calling detection - Database migrations: shell_execution_audit table - Frontend: ShellApprovalModal, ShellExecution, KubeconfigManager pages - CI/CD: kubectl bundling, multi-platform builds, Gitea Actions integration Version: 1.0.8 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
22 KiB
Shell Execution
Status: ✅ Production-ready agentic shell execution with three-tier safety classification (v1.0.0)
Overview
The Shell Execution feature enables AI-powered autonomous execution of diagnostic commands with intelligent safety controls. The AI can directly execute kubectl, Proxmox tools, and general shell commands to gather troubleshooting data without manual intervention.
Key Features:
- Three-tier command safety classification (auto/approve/deny)
- Real-time approval modal for mutating operations
- kubectl integration with bundled binary (v1.30.0)
- Multi-cluster support via multiple kubeconfig files
- AES-256-GCM encrypted kubeconfig storage
- Complete audit trail for all executions
- Pipe/chain command analysis with tier escalation
- Command timeout protection (30s)
- Approval timeout protection (60s)
Three-Tier Safety Architecture
Commands are automatically classified into three safety tiers based on their potential impact:
Tier 1: Auto-Execute (Read-Only)
Behavior: Execute immediately without user approval
kubectl commands:
kubectl get [resource]- List resourceskubectl describe [resource]- Show detailed resource informationkubectl logs [pod]- View pod logs
General commands:
cat [file]- Display file contentsgrep [pattern]- Search text patternsls- List directory contentspwd- Print working directorywhoami- Display current userdate- Show system date/timeuptime- Show system uptimedf -h- Show disk usagefree -m- Show memory usageps aux- List processes
Proxmox commands:
pvecm status- Show cluster statuspvesh get /cluster/status- Get cluster status via API
Tier 2: Require Approval (Mutating)
Behavior: Pause execution and display approval modal to user
kubectl commands:
kubectl apply -f [file]- Apply configurationkubectl delete [resource]- Delete resourceskubectl scale [deployment]- Scale deploymentskubectl exec -it [pod]- Execute command in containerkubectl port-forward- Forward portskubectl patch- Update resource fieldskubectl create- Create resourceskubectl edit- Edit resources
System commands:
ssh- Remote shell accessscp- Secure copychmod- Change file permissionschown- Change file ownershipsystemctl restart [service]- Restart servicessystemctl stop [service]- Stop servicessystemctl start [service]- Start servicesdocker restart [container]- Restart Docker containersdocker stop [container]- Stop Docker containersreboot(with confirmation) - System reboot
Proxmox commands:
qm start [vmid]- Start virtual machineqm stop [vmid]- Stop virtual machineqm restart [vmid]- Restart virtual machine
Tier 3: Always Deny (Destructive)
Behavior: Immediate denial with clear reasoning
Destructive operations:
rm -rf- Recursive force deletemkfs- Format filesystemdd- Low-level disk operationsfdisk- Partition manipulationparted- Partition editingshutdown- System shutdowninit 0- System halthalt- System haltpoweroff- System power offwipefs- Wipe filesystem signatures
Why Tier 3 is Denied: These commands can cause irreversible data loss, system downtime, or infrastructure damage. They should only be executed manually by authorized personnel with explicit intent.
Pipe and Chain Analysis
The classifier analyzes complex command structures and escalates to the highest tier found:
Piped Commands
# Tier 1: Both commands are read-only
kubectl get pods | grep nginx
# Tier 2: Second command is mutating (escalates entire chain)
kubectl get pods | kubectl delete -f -
# Tier 3: Contains destructive operation (entire chain denied)
cat /tmp/list.txt | xargs rm -rf
Logical Operators
# Tier 2: Uses && to chain mutating operations
kubectl apply -f deployment.yaml && kubectl rollout status deployment/nginx
# Tier 2: Uses || for fallback (escalates to highest tier)
ssh server1 || ssh server2
# Tier 3: Contains destructive command (entire chain denied)
cd /tmp && rm -rf *
Command Substitution
Commands using $() or backticks are flagged with a risk factor and analyzed recursively:
# Tier 2: Inner command is read-only, but ssh requires approval
ssh server "$(cat /tmp/script.sh)"
# Tier 3: Inner command is destructive (entire operation denied)
rm -rf $(find / -name "*.tmp")
Approval Workflow
When a Tier 2 command is detected:
- Execution Paused: Command execution stops before running
- Modal Displayed: Real-time modal appears in the UI showing:
- Full command text
- Safety tier badge
- Classification reasoning
- Risk factors (if any)
- Safety controls in place
- User Decision: Three options available:
- Deny: Reject the command permanently
- Allow Once: Execute this specific command only
- Allow for Session: Execute this and future similar commands in the current session
- Timeout: If no response within 60 seconds, automatically deny
Approval Modal Screenshot
┌─────────────────────────────────────────────────────────┐
│ 🛡️ Command Approval Required │
├─────────────────────────────────────────────────────────┤
│ This command requires your approval before execution │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ $ kubectl delete pod nginx-5d5f4c7d9-abcde │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Safety Tier: [Tier 2] │
│ │
│ ⚠️ Why approval is needed: │
│ Mutating operation: kubectl delete │
│ │
│ Safety Controls: │
│ • Command execution is logged and auditable │
│ • 30-second timeout protection │
│ • PII detection before execution │
│ • Output is captured for review │
│ │
│ [Deny] [Allow Once] [Allow for Session] │
└─────────────────────────────────────────────────────────┘
kubectl Integration
Bundled Binary
kubectl v1.30.0 is bundled with the application for all platforms:
- Linux: amd64, arm64
- macOS: Intel (x86_64), Apple Silicon (aarch64)
- Windows: amd64
The binary is automatically selected based on the runtime platform.
Kubeconfig Management
Upload Process:
- Navigate to Settings → Kubeconfig
- Click Upload Kubeconfig
- Select your kubeconfig file (.yaml or .yml)
- Provide a friendly name (e.g., "production-cluster")
- File is parsed and validated
- Content is encrypted using AES-256-GCM
- Stored in
kubeconfig_filestable
Multiple Clusters:
- Upload multiple kubeconfig files for different clusters
- Only one can be active at a time
- Activate a config by clicking Activate button
- Active config is used for all kubectl commands
- Cluster URL and context displayed for each config
Auto-Detection:
Kubeconfig auto-detection from ~/.kube/config is implemented but not enabled at startup due to AppHandle state access limitations. Users must manually upload kubeconfig files via the UI.
Environment Isolation
When kubectl commands execute:
KUBECONFIGenvironment variable set to active config path- Sensitive environment variables cleared (AWS credentials, etc.)
- Working directory isolated if specified
- 30-second timeout per command
Command Execution Flow
Full Execution Pipeline
- AI Tool Call: AI invokes
execute_shell_commandtool with command text - PII Detection: Command text scanned for sensitive data (passwords, tokens, API keys)
- Audit Log (Pre-Execution): Command logged with hash chain before execution
- Classification: CommandClassifier analyzes command structure and assigns tier
- Tier Decision:
- Tier 1: Proceed directly to execution
- Tier 2: Emit
shell:approval-neededevent, wait for user response - Tier 3: Return error immediately with reasoning
- Execution (if approved):
- For kubectl: Use
execute_kubectl()with active kubeconfig - For general: Use
tokio::process::Commandwith 30s timeout
- For kubectl: Use
- Result Capture: Capture exit code, stdout, stderr, execution time
- Database Record: Store execution in
command_executionstable - Audit Log (Post-Execution): Log result with exit code
- Return to AI: Format output as text for AI analysis
Error Handling
- Timeout: 30s command timeout, returns timeout error
- Approval Timeout: 60s approval timeout, command denied
- Execution Failure: Exit code != 0, stderr captured and returned
- Classification Error: Unparseable command, denied with reasoning
- PII Detected: Warning logged but execution continues (non-blocking)
Audit Trail
All command executions are recorded in the command_executions table:
Fields:
id: Unique UUIDcommand: Full command texttier: Safety tier (1, 2, or 3)approval_status: "auto", "approved", or "denied"kubeconfig_id: Reference to active kubeconfig (if kubectl)exit_code: Command exit codestdout: Command outputstderr: Error outputexecution_time_ms: Execution durationexecuted_at: Timestamp
Audit Logging:
All executions are also written to the audit log (audit_events table) with:
- Event type:
shell_command_execution - Entity type:
shell_command - Entity ID: Command text
- Details JSON:
{"command": "...", "exit_code": 0} - Hash chain linkage for tamper detection
Viewing History: Navigate to Settings → Shell Execution to view recent command executions:
- Last 10 commands displayed
- Tier badge and approval status
- Exit code (green for 0, red for non-zero)
- Execution time
- Timestamp
- Collapsible stdout output
Security Controls
Encryption
- Kubeconfig Files: AES-256-GCM encryption at rest
- Encryption Key: Derived from
TRCAA_ENCRYPTION_KEY(or legacyTRCAA_ENCRYPTION_KEY) environment variable - Nonce: Random 12-byte nonce per encryption operation
- Authentication Tag: 16-byte tag for integrity verification
PII Detection
Before execution, commands are scanned for:
- Passwords (e.g.,
--password=secret) - API keys (patterns like
AKIAIOSFODNN7EXAMPLE) - Tokens (e.g.,
token=abc123) - SSH keys (private key patterns)
If PII is detected:
- Warning logged with span count
- Execution continues (non-blocking)
- Consider sanitizing command history in future enhancement
Command Injection Prevention
- No shell interpretation of user-provided arguments
- Arguments passed directly to
tokio::process::Command - kubectl arguments parsed from command string, not shell-interpreted
Timeout Protection
- Command Timeout: 30 seconds per command
- Approval Timeout: 60 seconds for user response
- Prevents indefinite hangs or runaway processes
Hash-Chained Audit Log
All executions recorded in audit log with:
- Previous event hash
- Current event data hash
- Timestamp
- Tamper detection via hash verification
Settings
Shell Execution Settings
Location: Settings → Shell Execution
Features:
- kubectl installation status and version display
- Link to Kubeconfig Manager
- Three-tier safety architecture visualization
- Recent command execution history (last 10)
Kubeconfig Manager
Location: Settings → Kubeconfig
Features:
- Upload kubeconfig files (.yaml, .yml)
- List all uploaded configs with context and cluster URL
- Activate/deactivate configs
- Delete configs with confirmation
- Preview uploaded file content (first 500 chars)
API Reference
Backend Commands
upload_kubeconfig
Upload and encrypt a kubeconfig file.
Parameters:
name: String- Friendly name for the configcontent: String- Full kubeconfig YAML content
Returns: Result<String, String> - Config ID on success
list_kubeconfigs
List all uploaded kubeconfig files.
Returns: Result<Vec<KubeconfigInfo>, String>
KubeconfigInfo:
pub struct KubeconfigInfo {
pub id: String,
pub name: String,
pub context: String,
pub cluster_url: Option<String>,
pub is_active: bool,
}
activate_kubeconfig
Set a kubeconfig as active.
Parameters:
id: String- Config ID to activate
Returns: Result<(), String>
delete_kubeconfig
Delete a kubeconfig file.
Parameters:
id: String- Config ID to delete
Returns: Result<(), String>
respond_to_shell_approval
Respond to a shell command approval request.
Parameters:
approval_id: String- Unique approval request IDdecision: String- "deny", "allow_once", or "allow_session"
Returns: Result<(), String>
list_command_executions
List recent command executions.
Parameters:
issue_id: Option<String>- Filter by issue ID (optional)
Returns: Result<Vec<CommandExecution>, String>
CommandExecution:
pub struct CommandExecution {
pub id: String,
pub command: String,
pub tier: i32,
pub approval_status: String,
pub exit_code: Option<i32>,
pub stdout: Option<String>,
pub stderr: Option<String>,
pub execution_time_ms: Option<i64>,
pub executed_at: String,
}
check_kubectl_installed
Check if kubectl is installed and get version info.
Returns: Result<KubectlStatus, String>
KubectlStatus:
pub struct KubectlStatus {
pub installed: bool,
pub path: Option<String>,
pub version: Option<String>,
}
AI Tool: execute_shell_command
Description: Execute shell commands with automatic safety classification.
Parameters:
command: String(required) - Shell command to executeworking_directory: String(optional) - Working directory for executionkubeconfig_id: String(optional) - Kubeconfig file ID for kubectl commands
Returns: String with formatted output:
Exit Code: 0
Stdout:
NAME READY STATUS RESTARTS AGE
nginx-5d5f4c7d9-abcde 1/1 Running 0 5m
Stderr:
Usage in AI Context:
{
"name": "execute_shell_command",
"arguments": {
"command": "kubectl get pods -n production",
"kubeconfig_id": "uuid-of-active-config"
}
}
Database Schema
shell_commands (Migration 024)
Pre-defined command templates with tier classification.
CREATE TABLE IF NOT EXISTS shell_commands (
id TEXT PRIMARY KEY,
command_template TEXT NOT NULL,
tier INTEGER NOT NULL CHECK(tier IN (1, 2, 3)),
description TEXT,
category TEXT NOT NULL, -- 'kubectl', 'proxmox', 'general'
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
kubeconfig_files (Migration 025)
Encrypted kubeconfig storage.
CREATE TABLE IF NOT EXISTS kubeconfig_files (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
encrypted_content TEXT NOT NULL,
context TEXT NOT NULL,
cluster_url TEXT,
is_active INTEGER NOT NULL DEFAULT 0,
uploaded_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX idx_kubeconfig_active ON kubeconfig_files(is_active);
command_executions (Migration 026)
Full audit trail of all command executions.
CREATE TABLE IF NOT EXISTS command_executions (
id TEXT PRIMARY KEY,
issue_id TEXT,
command TEXT NOT NULL,
tier INTEGER NOT NULL,
approval_status TEXT NOT NULL, -- 'auto', 'approved', 'denied'
kubeconfig_id TEXT,
exit_code INTEGER,
stdout TEXT,
stderr TEXT,
execution_time_ms INTEGER,
executed_at TEXT NOT NULL DEFAULT (datetime('now')),
FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE CASCADE,
FOREIGN KEY (kubeconfig_id) REFERENCES kubeconfig_files(id) ON DELETE SET NULL
);
CREATE INDEX idx_command_executions_issue ON command_executions(issue_id);
CREATE INDEX idx_command_executions_executed ON command_executions(executed_at);
approval_decisions (Migration 027)
Session-based approval preferences.
CREATE TABLE IF NOT EXISTS approval_decisions (
id TEXT PRIMARY KEY,
command_pattern TEXT NOT NULL,
decision TEXT NOT NULL CHECK(decision IN ('allow_once', 'allow_session', 'deny')),
session_id TEXT,
decided_at TEXT NOT NULL DEFAULT (datetime('now')),
expires_at TEXT
);
CREATE INDEX idx_approval_decisions_session ON approval_decisions(session_id);
Testing
Backend Tests
Location: src-tauri/src/shell/
Classifier Tests (classifier.rs):
test_tier1_kubectl_get- Auto-execute kubectl gettest_tier2_kubectl_delete- Require approval for kubectl deletetest_tier3_rm_rf- Deny rm -rftest_pipe_tier_escalation- Piped command tier analysis- 19 total tests covering all tier classifications
kubectl Tests (kubectl.rs):
test_locate_kubectl_finds_binary- Binary location logictest_kubectl_version_check- Verify binary workstest_execute_kubectl_with_timeout- Timeout implementation- 3 total tests
Executor Tests (executor.rs):
- Currently ignored (require full app setup)
- Placeholder tests for approval flow
Coverage:
- Classifier: 100% (critical safety component)
- kubectl: 90%
- Executor: Needs integration test environment
Frontend Tests
Location: src/components/__tests__/, src/pages/__tests__/
Component Tests:
- ShellApprovalModal: Event listener, modal rendering, button actions
- All existing tests passing (103 total)
Integration Testing
Manual Test Cases:
-
Tier 1 Auto-Execution
- AI request: "Show me all pods in the default namespace"
- Expected: Command executes immediately without modal
- Verify:
command_executionshasapproval_status='auto'
-
Tier 2 Approval Flow
- AI request: "Scale the nginx deployment to 5 replicas"
- Expected: Approval modal appears
- Test: Deny → execution blocked
- Test: Allow Once → execution proceeds
- Test: Allow for Session → execution proceeds
-
Tier 3 Denial
- AI request: "Delete all files in /tmp"
- Expected: No modal, immediate error with reasoning
- Verify: Command not executed
-
Piped Command Analysis
- Command:
kubectl get pods | grep nginx→ Tier 1 (auto-execute) - Command:
kubectl get pods | kubectl delete -f -→ Tier 2 (approval) - Command:
cat /tmp/list.txt | xargs rm -rf→ Tier 3 (deny)
- Command:
-
Timeout Protection
- Command:
sleep 60→ Times out after 30s - Approval: Wait 61s → Approval times out, command denied
- Command:
-
Audit Trail
- Query:
SELECT * FROM command_executions ORDER BY executed_at DESC - Verify: All commands logged with correct tier, status, exit code
- Query:
Troubleshooting
kubectl not found
Problem: "kubectl is not installed" message in Shell Execution settings
Solutions:
- Check if kubectl is bundled: Binary should be at
Resources/kubectl(macOS) or similar platform path - Verify PATH: Ensure system PATH includes kubectl location
- Reinstall: Download latest application bundle with kubectl included
Kubeconfig upload fails
Problem: "Failed to parse kubeconfig" error
Solutions:
- Validate YAML: Ensure kubeconfig is valid YAML format
- Check contexts: Kubeconfig must have at least one context defined
- Cluster URL: Ensure cluster URL is accessible
- File format: Only .yaml or .yml files accepted
Commands not executing
Problem: Commands hang or don't execute
Solutions:
- Check timeout: Commands timeout after 30 seconds
- Approval timeout: User must respond within 60 seconds for Tier 2
- Active kubeconfig: Ensure a kubeconfig is activated for kubectl commands
- Review logs: Check audit log for denial reason
Approval modal not appearing
Problem: Tier 2 command doesn't show approval modal
Solutions:
- Check browser: Ensure JavaScript is enabled
- Event listener: Modal listens for
shell:approval-neededevent - Tauri events: Verify Tauri event system is working
- Console errors: Check browser console for errors
Future Enhancements
Planned Features:
- Session-based approval preferences (approve all kubectl get for 1 hour)
- Command templating (save frequently used commands)
- Execution rollback (undo kubectl apply operations)
- Tier overrides (admin can override tier classification)
- Command history search and filtering
- Export execution history as CSV/JSON
- Integration with issue timeline (show commands executed during incident)
- Proxmox advanced commands (cluster management, backups)
- Multi-kubeconfig context switching within single file
- Auto-detection of ~/.kube/config on startup (pending AppHandle fix)
Stretch Goals:
- Parallel command execution (run multiple commands concurrently)
- Command scheduling (execute command at specific time)
- Command chaining with dependencies (run X, then Y if X succeeds)
- Command output parsing (extract structured data from stdout)
- Integration with monitoring systems (auto-execute commands on alerts)
Related Documentation
- Architecture - Overall application architecture
- Security-Model - Security architecture and threat model
- Database - Database schema and migrations
- IPC-Commands - Frontend-backend communication
- AI-Providers - AI integration and tool use
Version History
- v1.0.0 (2026-06-02): Initial release with three-tier safety classification, kubectl bundling, and multi-cluster support