Separate OpsProof remediation approval
This commit is contained in:
parent
0941304a25
commit
485f48e6e1
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 }) {
|
|||
</div>
|
||||
<div className="p-6">
|
||||
<p className="text-sm text-amber-200">
|
||||
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.
|
||||
</p>
|
||||
{proposal.status === 'pending' && (
|
||||
<label className="mt-5 flex cursor-pointer items-start gap-3 rounded-xl border border-white/10 bg-white/[0.025] p-4 text-sm text-slate-300">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={confirmed}
|
||||
onChange={(event) => setConfirmed(event.target.checked)}
|
||||
className="mt-0.5 size-4 accent-cyan-300"
|
||||
/>
|
||||
<span>I reviewed the evidence, exact action, risk, and rollback procedure.</span>
|
||||
</label>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={approve}
|
||||
disabled={submitting || proposal.status !== 'pending'}
|
||||
disabled={submitting || proposal.status !== 'pending' || !confirmed}
|
||||
className="mt-5 w-full rounded-lg bg-violet-300 px-4 py-3 font-semibold text-slate-950 disabled:cursor-not-allowed disabled:bg-white/8 disabled:text-slate-500"
|
||||
>
|
||||
{submitting ? 'Revalidating…' : proposal.status === 'pending' ? 'Approve once and execute' : `Proposal ${proposal.status}`}
|
||||
{submitting ? 'Revalidating…' : proposal.status === 'pending' ? 'Approve proposal' : `Proposal ${proposal.status}`}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue