From 485f48e6e13de34cea73bad7dd580cab481ea37b Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Sat, 5 Dec 2026 08:20:25 -0600 Subject: [PATCH] Separate OpsProof remediation approval --- apps/opsproof/README.md | 9 ++++----- .../overlay/handlers/proposal/proposal.go | 15 +-------------- .../overlay/resources/js/pages/Proposal.tsx | 18 +++++++++++++++--- .../overlay/tests/feature/proposal_test.go | 16 +++++++++------- .../jeannie/test_privacy_services_pipeline.py | 7 +++++++ 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/apps/opsproof/README.md b/apps/opsproof/README.md index b2de849..2fc66f4 100644 --- a/apps/opsproof/README.md +++ b/apps/opsproof/README.md @@ -85,11 +85,10 @@ landing page. An authenticated operator may convert current incident evidence into a durable proposal only after supplying a rollback procedure. PostgreSQL stores the proposal, its evidence hash, exact command and arguments, risk, creator, and a -separate one-time approval record. Approval reruns Doctor, requires an exact -evidence-hash match, checks Jeannie's advertised command allowlist, validates -the fixed argument shape, and then records the returned execution ID. The -execution page polls that ID and persists bounded progress output; it never -submits another command while refreshing. +separate one-time approval record. Approval requires a deliberate review +confirmation, reruns Doctor, requires an exact evidence-hash match, checks +Jeannie's advertised command allowlist, and validates the fixed argument shape. +Approval records the decision but does not execute it. After an execution reaches a terminal state, OpsProof automatically runs the same focused Doctor target again. It retains the before/after evidence and diff --git a/apps/opsproof/overlay/handlers/proposal/proposal.go b/apps/opsproof/overlay/handlers/proposal/proposal.go index 2a49deb..b1bcd21 100644 --- a/apps/opsproof/overlay/handlers/proposal/proposal.go +++ b/apps/opsproof/overlay/handlers/proposal/proposal.go @@ -137,18 +137,5 @@ func Approve(request *web.Request) *web.Response { if err != nil { return web.Fail(err) } - - remote, err := client.Submit(request.Context(), proposal.Command, arguments) - if err != nil { - _ = model.Update(request, &proposal, db.Values{"status": "submit_failed"}) - return web.Fail(err) - } - execution := models.OperationExecution{ - ProposalID: proposal.ID, JeannieExecutionID: remote.ID, Status: remote.Status, - } - if err := model.Create(request, &execution); err != nil { - return web.Fail(err) - } - _ = model.Update(request, &proposal, db.Values{"status": "executing"}) - return web.Redirect(fmt.Sprintf("/executions/%d", execution.ID)) + return web.Redirect(fmt.Sprintf("/proposals/%d", proposal.ID)) } diff --git a/apps/opsproof/overlay/resources/js/pages/Proposal.tsx b/apps/opsproof/overlay/resources/js/pages/Proposal.tsx index 74db310..c1f206f 100644 --- a/apps/opsproof/overlay/resources/js/pages/Proposal.tsx +++ b/apps/opsproof/overlay/resources/js/pages/Proposal.tsx @@ -18,6 +18,7 @@ interface Proposal { export default function ProposalPage({ proposal }: { proposal: Proposal }) { const [submitting, setSubmitting] = useState(false); + const [confirmed, setConfirmed] = useState(false); function approve() { setSubmitting(true); @@ -52,15 +53,26 @@ export default function ProposalPage({ proposal }: { proposal: Proposal }) {

- Approval re-runs Doctor, compares the evidence hash, checks the Jeannie allowlist, and validates the exact arguments before submission. + Approval re-runs Doctor, compares the evidence hash, checks the Jeannie allowlist, and validates the exact arguments. It records the decision but does not execute it.

+ {proposal.status === 'pending' && ( + + )}
diff --git a/apps/opsproof/overlay/tests/feature/proposal_test.go b/apps/opsproof/overlay/tests/feature/proposal_test.go index 92dc72e..c0c33ef 100644 --- a/apps/opsproof/overlay/tests/feature/proposal_test.go +++ b/apps/opsproof/overlay/tests/feature/proposal_test.go @@ -14,9 +14,10 @@ import ( "app/tests" ) -func TestProposalApprovalRevalidatesAndSubmitsExactDoctorAction(t *testing.T) { +func TestProposalApprovalRevalidatesWithoutExecuting(t *testing.T) { t.Setenv("OPSPROOF_OPERATOR_EMAILS", "operator@example.test") doctorRequests := 0 + remediationRequests := 0 server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) { switch request.URL.Path { case "/v1/commands": @@ -27,15 +28,14 @@ func TestProposalApprovalRevalidatesAndSubmitsExactDoctorAction(t *testing.T) { } _ = json.NewDecoder(request.Body).Decode(&payload) if len(payload.Args) == 3 && payload.Args[2] == "--ai" { - _, _ = response.Write([]byte(`{"id":"execution-approved","status":"queued"}`)) + remediationRequests++ + http.Error(response, "approval must not submit the remediation", http.StatusConflict) return } doctorRequests++ _, _ = response.Write([]byte(`{"id":"doctor-` + string(rune('0'+doctorRequests)) + `","status":"queued"}`)) case "/v1/executions/doctor-1", "/v1/executions/doctor-2", "/v1/executions/doctor-3": _, _ = response.Write([]byte(`{"id":"doctor","status":"failed","output":"{\"title\":\"Doctor\",\"rows\":[{\"status\":\"fail\",\"area\":\"Kubernetes apps\",\"check\":\"n8n\",\"summary\":\"CrashLoopBackOff\",\"detail\":\"container exits\",\"cause\":\"startup failure\"}]}"}`)) - case "/v1/executions/execution-approved": - _, _ = response.Write([]byte(`{"id":"execution-approved","status":"succeeded","output":"repair completed"}`)) default: http.NotFound(response, request) } @@ -51,7 +51,9 @@ func TestProposalApprovalRevalidatesAndSubmitsExactDoctorAction(t *testing.T) { "rollback": {"Restore the previous deployment revision and verify pod readiness."}, }).AssertRedirect("/proposals/1") client.Get("/proposals/1").AssertOK().AssertInertia("Proposal") - client.WithoutRedirects().Post("/proposals/1/approval", url.Values{}).AssertRedirect("/executions/1") - client.Get("/executions/1").AssertOK().AssertInertia("Execution").AssertProp("view.execution.status", "succeeded").AssertProp("view.execution.report_id", float64(1)) - client.Get("/reports/1").AssertOK().AssertInertia("Report").AssertProp("report.outcome", "needs-attention") + client.WithoutRedirects().Post("/proposals/1/approval", url.Values{}).AssertRedirect("/proposals/1") + client.Get("/proposals/1").AssertOK().AssertInertia("Proposal").AssertProp("proposal.status", "approved") + if remediationRequests != 0 { + t.Fatalf("approval submitted %d remediation request(s)", remediationRequests) + } } diff --git a/tests/jeannie/test_privacy_services_pipeline.py b/tests/jeannie/test_privacy_services_pipeline.py index 74b479d..3b0a731 100644 --- a/tests/jeannie/test_privacy_services_pipeline.py +++ b/tests/jeannie/test_privacy_services_pipeline.py @@ -175,6 +175,13 @@ class OpsProofPipelineTests(unittest.TestCase): self.assertIn("LockForUpdate", proposal_handler) self.assertIn('arguments[2] != "--ai"', proposal_handler) + proposal_page = ( + ROOT / "apps/opsproof/overlay/resources/js/pages/Proposal.tsx" + ).read_text(encoding="utf-8") + self.assertIn("Approve proposal", proposal_page) + self.assertIn("does not execute it", proposal_page) + self.assertNotIn("Approve once and execute", proposal_page) + migration = ( ROOT / "apps/opsproof/overlay/database/migrations/2026_12_04_000003_create_opsproof_workflow_tables.go"