diff --git a/apps/opsproof/README.md b/apps/opsproof/README.md index f957a8b..5a6e3b9 100644 --- a/apps/opsproof/README.md +++ b/apps/opsproof/README.md @@ -62,8 +62,14 @@ Unhealthy Kubernetes applications link to Doctor target with `--json`, assigns stable evidence IDs to the returned rows, and presents bounded command-output excerpts, observed state, missing evidence, and root-cause hypotheses. Route input is restricted to Kubernetes application -names and cannot become arbitrary Jeannie arguments. The page deliberately has -no mitigation control. +names and cannot become arbitrary Jeannie arguments. + +For warning or failing evidence, the same page now builds a proposal-only view +model tied to the Doctor execution and evidence IDs. It shows the exact +focused Jeannie/Holmes action, preconditions, risk, deterministic validation, +and the absence of a target-specific rollback. A proposal stays blocked and +cannot be approved or executed until later slices add identity, authorization, +current-evidence validation, and a validated rollback. ## Security boundary @@ -89,7 +95,8 @@ Each slice should be a small, independently testable commit: 3. read-only homelab overview backed by Jeannie status; 4. incident evidence page backed by Doctor output (implemented for Kubernetes applications); -5. remediation proposal with risk and rollback details; +5. remediation proposal with risk and rollback details (implemented as a + blocked, non-executable proposal); 6. Dex login and operator authorization; 7. approval-gated execution and live progress; 8. post-change validation and incident report; diff --git a/apps/opsproof/overlay/resources/js/pages/Incident.tsx b/apps/opsproof/overlay/resources/js/pages/Incident.tsx index e3a887c..c1eafb3 100644 --- a/apps/opsproof/overlay/resources/js/pages/Incident.tsx +++ b/apps/opsproof/overlay/resources/js/pages/Incident.tsx @@ -16,6 +16,19 @@ interface Incident { evidence: Evidence[]; missingEvidence: string[]; nextCommand: string; + proposal: { + id: string; + status: string; + summary: string; + action: string; + riskLevel: string; + evidenceIds: string[]; + preconditions: string[]; + riskNotes: string[]; + rollback: string; + validation: string[]; + readyForApproval: boolean; + }; collectedAt: string; } @@ -139,8 +152,78 @@ export default function IncidentPage({ laravelVersion, view }: Props) { {incident.nextCommand} - diff --git a/apps/opsproof/overlay/services/jeannie.go b/apps/opsproof/overlay/services/jeannie.go index 66fbd81..c2a2b8a 100644 --- a/apps/opsproof/overlay/services/jeannie.go +++ b/apps/opsproof/overlay/services/jeannie.go @@ -49,14 +49,29 @@ type IncidentEvidence struct { } type IncidentSnapshot struct { - Scope string `json:"scope"` - Target string `json:"target"` - Title string `json:"title"` - ExecutionID string `json:"executionId"` - Evidence []IncidentEvidence `json:"evidence"` - MissingEvidence []string `json:"missingEvidence"` - NextCommand string `json:"nextCommand"` - CollectedAt string `json:"collectedAt"` + Scope string `json:"scope"` + Target string `json:"target"` + Title string `json:"title"` + ExecutionID string `json:"executionId"` + Evidence []IncidentEvidence `json:"evidence"` + MissingEvidence []string `json:"missingEvidence"` + NextCommand string `json:"nextCommand"` + Proposal RemediationProposal `json:"proposal"` + CollectedAt string `json:"collectedAt"` +} + +type RemediationProposal struct { + ID string `json:"id"` + Status string `json:"status"` + Summary string `json:"summary"` + Action string `json:"action"` + RiskLevel string `json:"riskLevel"` + EvidenceIDs []string `json:"evidenceIds"` + Preconditions []string `json:"preconditions"` + RiskNotes []string `json:"riskNotes"` + Rollback string `json:"rollback"` + Validation []string `json:"validation"` + ReadyForApproval bool `json:"readyForApproval"` } type JeannieClient struct { @@ -119,10 +134,51 @@ func (client *JeannieClient) Doctor(ctx context.Context, scope string, target st snapshot.Target = target snapshot.ExecutionID = completed.ID snapshot.NextCommand = "./jeannie doctor cluster " + target + " --details" + snapshot.Proposal = buildRemediationProposal(snapshot) snapshot.CollectedAt = time.Now().UTC().Format(time.RFC3339) return snapshot, nil } +func buildRemediationProposal(incident IncidentSnapshot) RemediationProposal { + proposal := RemediationProposal{ + ID: "proposal-" + incident.ExecutionID, + Status: "not-needed", + Summary: "No warning or failing evidence supports a remediation proposal.", + RiskLevel: "none", + EvidenceIDs: []string{}, + Preconditions: []string{}, + RiskNotes: []string{}, + Rollback: "No change is proposed, so no rollback is required.", + Validation: []string{incident.NextCommand, "./jeannie status cluster"}, + } + for _, evidence := range incident.Evidence { + if evidence.Status == "warn" || evidence.Status == "fail" { + proposal.EvidenceIDs = append(proposal.EvidenceIDs, evidence.ID) + } + } + if len(proposal.EvidenceIDs) == 0 { + return proposal + } + + proposal.Status = "blocked" + proposal.Summary = "Ask the focused Jeannie Doctor and Holmes workflow to diagnose, apply a supported targeted repair, and validate the result." + proposal.Action = "./jeannie doctor cluster " + incident.Target + " --ai" + proposal.RiskLevel = "high" + proposal.Preconditions = []string{ + "Authenticate an authorized operator (not implemented in this slice).", + "Revalidate that the cited evidence execution is current.", + "Confirm Jeannie still advertises the exact Doctor command and arguments.", + "Establish a target-specific backup and rollback procedure.", + } + proposal.RiskNotes = []string{ + "The Doctor/Holmes workflow can change Kubernetes runtime state.", + "AI root-cause hypotheses are not proof and may be incomplete.", + "The affected application may be temporarily unavailable during repair.", + } + proposal.Rollback = "No target-specific rollback has been established automatically. Approval remains disabled until an operator supplies and validates one." + return proposal +} + func ValidDoctorTarget(scope string, target string) bool { return scope == "cluster" && kubernetesApplicationName.MatchString(target) } diff --git a/apps/opsproof/overlay/services/jeannie_test.go b/apps/opsproof/overlay/services/jeannie_test.go index 6216216..68e0dc8 100644 --- a/apps/opsproof/overlay/services/jeannie_test.go +++ b/apps/opsproof/overlay/services/jeannie_test.go @@ -102,6 +102,12 @@ func TestDoctorNormalizesEvidenceAndRejectsArbitraryTargets(t *testing.T) { if len(incident.Evidence) != 1 || incident.Evidence[0].ID != "C01" || incident.Evidence[0].Cause == "" { t.Fatalf("unexpected normalized evidence: %#v", incident.Evidence) } + if incident.Proposal.Status != "blocked" || incident.Proposal.ReadyForApproval || incident.Proposal.Action != "./jeannie doctor cluster n8n --ai" { + t.Fatalf("unexpected remediation proposal: %#v", incident.Proposal) + } + if len(incident.Proposal.EvidenceIDs) != 1 || incident.Proposal.EvidenceIDs[0] != "C01" { + t.Fatalf("proposal did not retain its evidence reference: %#v", incident.Proposal.EvidenceIDs) + } if _, err := client.Doctor(context.Background(), "cluster", "n8n;shutdown"); err == nil { t.Fatal("expected unsafe target to be rejected") } @@ -109,3 +115,15 @@ func TestDoctorNormalizesEvidenceAndRejectsArbitraryTargets(t *testing.T) { t.Fatal("only the cluster application drill-down is enabled in this slice") } } + +func TestProposalIsNotNeededWithoutProblemEvidence(t *testing.T) { + proposal := buildRemediationProposal(IncidentSnapshot{ + Target: "grafana", + ExecutionID: "doctor-ok", + NextCommand: "./jeannie doctor cluster grafana --details", + Evidence: []IncidentEvidence{{ID: "C01", Status: "ok"}}, + }) + if proposal.Status != "not-needed" || proposal.Action != "" || proposal.ReadyForApproval { + t.Fatalf("healthy evidence must not create an action: %#v", proposal) + } +} diff --git a/docs/opsproof-architecture.md b/docs/opsproof-architecture.md index 39daea2..18ac945 100644 --- a/docs/opsproof-architecture.md +++ b/docs/opsproof-architecture.md @@ -68,6 +68,10 @@ confirmed by deterministic validation. - Constrain incident routes to known target types, collect focused Doctor JSON server-side, and expose bounded evidence excerpts rather than executable commands or the complete private response. +- Bind every remediation proposal to one Doctor execution and its evidence IDs. + Keep the proposal blocked when identity, current-evidence validation, or a + target-specific rollback is absent; rendering a command never grants the + authority to execute it. ## Why not Laravel Rust now? diff --git a/tests/jeannie/test_privacy_services_pipeline.py b/tests/jeannie/test_privacy_services_pipeline.py index 85e738d..aab7f3b 100644 --- a/tests/jeannie/test_privacy_services_pipeline.py +++ b/tests/jeannie/test_privacy_services_pipeline.py @@ -125,9 +125,16 @@ class OpsProofPipelineTests(unittest.TestCase): ) self.assertIn("Command output excerpt", incident) self.assertIn("Root-cause hypothesis", incident) - self.assertIn("No mitigation in this slice", incident) + self.assertIn("Remediation proposal", incident) + self.assertIn("Risk review", incident) + self.assertIn("Deterministic validation", incident) + self.assertIn("Approval unavailable until identity", incident) self.assertNotIn("fetch('/v1/execute", incident) + self.assertIn("ReadyForApproval bool", client) + self.assertIn('proposal.Status = "blocked"', client) + self.assertIn('"./jeannie doctor cluster " + incident.Target + " --ai"', client) + if __name__ == "__main__": unittest.main()