diff --git a/apps/opsproof/README.md b/apps/opsproof/README.md index 12eb320..80a3807 100644 --- a/apps/opsproof/README.md +++ b/apps/opsproof/README.md @@ -79,6 +79,15 @@ user identity. Incident and future mutation routes require both authentication and current membership in that allowlist. The overview remains a read-only 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. + ## Security boundary OpsProof is not a shell console. @@ -106,7 +115,7 @@ Each slice should be a small, independently testable commit: 5. remediation proposal with risk and rollback details (implemented as a blocked, non-executable proposal); 6. Dex login and operator authorization (implemented); -7. approval-gated execution and live progress; +7. approval-gated execution and live progress (implemented); 8. post-change validation and incident report; 9. sanitized public demo mode and portfolio link. diff --git a/apps/opsproof/overlay/database/migrations/2026_12_04_000003_create_opsproof_workflow_tables.go b/apps/opsproof/overlay/database/migrations/2026_12_04_000003_create_opsproof_workflow_tables.go new file mode 100644 index 0000000..7b8b88d --- /dev/null +++ b/apps/opsproof/overlay/database/migrations/2026_12_04_000003_create_opsproof_workflow_tables.go @@ -0,0 +1,46 @@ +package migrations + +import ( + "context" + + "go.laravel.com/schema" +) + +func createOpsProofWorkflowTables(ctx context.Context) error { + if err := schema.Create(ctx, "remediation_proposals", func(table *schema.Blueprint) { + table.ID() + table.String("scope") + table.String("target") + table.String("doctor_execution_id") + table.String("evidence_hash") + table.LongText("evidence_json") + table.String("command") + table.Text("arguments_json") + table.String("risk_level") + table.LongText("rollback") + table.String("status") + table.String("created_by") + table.Timestamps() + }); err != nil { + return err + } + if err := schema.Create(ctx, "remediation_approvals", func(table *schema.Blueprint) { + table.ID() + table.BigInteger("proposal_id") + table.String("operator_email") + table.String("evidence_hash") + table.Timestamp("approved_at") + table.Timestamps() + }); err != nil { + return err + } + return schema.Create(ctx, "operation_executions", func(table *schema.Blueprint) { + table.ID() + table.BigInteger("proposal_id") + table.String("jeannie_execution_id") + table.String("status") + table.LongText("output") + table.Text("error") + table.Timestamps() + }) +} diff --git a/apps/opsproof/overlay/database/migrations/migrations.go b/apps/opsproof/overlay/database/migrations/migrations.go new file mode 100644 index 0000000..a49b58c --- /dev/null +++ b/apps/opsproof/overlay/database/migrations/migrations.go @@ -0,0 +1,10 @@ +package migrations + +import "go.laravel.com/db" + +var All = []db.Migration{ + {Name: "0001_01_01_000000_create_users_table", Run: createUsersTable}, + {Name: "0001_01_01_000001_create_cache_table", Run: createCacheTable}, + {Name: "0001_01_01_000002_create_jobs_table", Run: createJobsTable}, + {Name: "2026_12_04_000003_create_opsproof_workflow_tables", Run: createOpsProofWorkflowTables}, +} diff --git a/apps/opsproof/overlay/handlers/execution/show.go b/apps/opsproof/overlay/handlers/execution/show.go new file mode 100644 index 0000000..42dbb29 --- /dev/null +++ b/apps/opsproof/overlay/handlers/execution/show.go @@ -0,0 +1,43 @@ +package execution + +import ( + "go.laravel.com/db" + "go.laravel.com/inertia" + "go.laravel.com/model" + "go.laravel.com/web" + + "app/models" + "app/services" +) + +func Show(request *web.Request) *web.Response { + id, err := request.PathInt("execution") + if err != nil { + return web.Fail(err) + } + execution, err := model.Query[models.OperationExecution]().Find(request, id) + if err != nil { + return web.Fail(err) + } + proposal, err := model.Query[models.RemediationProposal]().Find(request, execution.ProposalID) + if err != nil { + return web.Fail(err) + } + remote, err := services.From(request.Context()).Jeannie.Execution(request.Context(), execution.JeannieExecutionID) + if err != nil { + return web.Fail(err) + } + if err := model.Update(request, &execution, db.Values{ + "status": remote.Status, "output": remote.Output, "error": remote.Error, + }); err != nil { + return web.Fail(err) + } + if remote.Status == "succeeded" || remote.Status == "failed" { + if err := model.Update(request, &proposal, db.Values{"status": remote.Status}); err != nil { + return web.Fail(err) + } + } + return inertia.Render("Execution", inertia.Props{ + "view": inertia.Props{"execution": execution, "proposal": proposal}, + }) +} diff --git a/apps/opsproof/overlay/handlers/proposal/proposal.go b/apps/opsproof/overlay/handlers/proposal/proposal.go new file mode 100644 index 0000000..2a49deb --- /dev/null +++ b/apps/opsproof/overlay/handlers/proposal/proposal.go @@ -0,0 +1,154 @@ +package proposal + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "time" + + "go.laravel.com/db" + "go.laravel.com/inertia" + "go.laravel.com/model" + "go.laravel.com/validation" + "go.laravel.com/validation/rule" + "go.laravel.com/web" + + "app/models" + "app/services" +) + +type StoreProposal struct { + Rollback string `json:"rollback"` +} + +func (form *StoreProposal) Rules() validation.Rules { + return validation.For(form, rule.Field(&form.Rollback, rule.Required, rule.Min(20), rule.Max(2000))) +} + +func Store(request *web.Request) *web.Response { + scope, target := request.PathValue("scope"), request.PathValue("target") + if !services.ValidDoctorTarget(scope, target) { + return web.Abort(http.StatusNotFound) + } + form, err := request.Validate[StoreProposal]() + if err != nil { + return web.Fail(err) + } + incident, err := services.From(request.Context()).Jeannie.Doctor(request.Context(), scope, target) + if err != nil { + return web.Fail(err) + } + if incident.Proposal.Action == "" || len(incident.Proposal.EvidenceIDs) == 0 { + return web.Abort(http.StatusConflict) + } + evidenceHash, err := services.EvidenceFingerprint(incident) + if err != nil { + return web.Fail(err) + } + evidenceJSON, err := json.Marshal(incident.Evidence) + if err != nil { + return web.Fail(err) + } + argumentsJSON, _ := json.Marshal([]string{scope, target, "--ai"}) + operator := models.CurrentUser(request) + proposal := models.RemediationProposal{ + Scope: scope, Target: target, DoctorExecutionID: incident.ExecutionID, + EvidenceHash: evidenceHash, EvidenceJSON: string(evidenceJSON), Command: "doctor", + ArgumentsJSON: string(argumentsJSON), RiskLevel: incident.Proposal.RiskLevel, + Rollback: form.Rollback, Status: "pending", CreatedBy: operator.Email, + } + if err := model.Create(request, &proposal); err != nil { + return web.Fail(err) + } + return web.Redirect(fmt.Sprintf("/proposals/%d", proposal.ID)) +} + +func Show(request *web.Request) *web.Response { + id, err := request.PathInt("proposal") + if err != nil { + return web.Fail(err) + } + proposal, err := model.Query[models.RemediationProposal]().Find(request, id) + if err != nil { + return web.Fail(err) + } + return inertia.Render("Proposal", inertia.Props{"proposal": proposal}) +} + +func Approve(request *web.Request) *web.Response { + id, err := request.PathInt("proposal") + if err != nil { + return web.Fail(err) + } + proposal, err := model.Query[models.RemediationProposal]().Find(request, id) + if err != nil { + return web.Fail(err) + } + if proposal.Status != "pending" { + return web.Abort(http.StatusConflict) + } + client := services.From(request.Context()).Jeannie + current, err := client.Doctor(request.Context(), proposal.Scope, proposal.Target) + if err != nil { + return web.Fail(err) + } + fingerprint, err := services.EvidenceFingerprint(current) + if err != nil { + return web.Fail(err) + } + if fingerprint != proposal.EvidenceHash { + _ = model.Update(request, &proposal, db.Values{"status": "stale"}) + return web.Abort(http.StatusConflict) + } + allowed, err := client.CommandAllowed(request.Context(), proposal.Command) + if err != nil { + return web.Fail(err) + } + if !allowed { + return web.Abort(http.StatusForbidden) + } + var arguments []string + if err := json.Unmarshal([]byte(proposal.ArgumentsJSON), &arguments); err != nil { + return web.Fail(err) + } + if len(arguments) != 3 || arguments[0] != proposal.Scope || arguments[1] != proposal.Target || arguments[2] != "--ai" { + return web.Abort(http.StatusForbidden) + } + + operator := models.CurrentUser(request) + err = db.Transaction(request, func(ctx context.Context) error { + locked, err := model.Query[models.RemediationProposal]().LockForUpdate().Find(ctx, proposal.ID) + if err != nil { + return err + } + if locked.Status != "pending" { + return fmt.Errorf("proposal is no longer pending") + } + approval := models.RemediationApproval{ + ProposalID: proposal.ID, OperatorEmail: operator.Email, + EvidenceHash: proposal.EvidenceHash, ApprovedAt: time.Now().UTC(), + } + if err := model.Create(ctx, &approval); err != nil { + return err + } + return model.Update(ctx, &locked, db.Values{"status": "approved"}) + }) + 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)) +} diff --git a/apps/opsproof/overlay/models/remediation.go b/apps/opsproof/overlay/models/remediation.go new file mode 100644 index 0000000..288c52a --- /dev/null +++ b/apps/opsproof/overlay/models/remediation.go @@ -0,0 +1,41 @@ +package models + +import "time" + +type RemediationProposal struct { + ID int64 `json:"id"` + Scope string `json:"scope"` + Target string `json:"target"` + DoctorExecutionID string `json:"doctor_execution_id"` + EvidenceHash string `json:"evidence_hash"` + EvidenceJSON string `json:"evidence_json"` + Command string `json:"command"` + ArgumentsJSON string `json:"arguments_json"` + RiskLevel string `json:"risk_level"` + Rollback string `json:"rollback"` + Status string `json:"status"` + CreatedBy string `json:"created_by"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + +type RemediationApproval struct { + ID int64 `json:"id"` + ProposalID int64 `json:"proposal_id"` + OperatorEmail string `json:"operator_email"` + EvidenceHash string `json:"evidence_hash"` + ApprovedAt time.Time `json:"approved_at"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + +type OperationExecution struct { + ID int64 `json:"id"` + ProposalID int64 `json:"proposal_id"` + JeannieExecutionID string `json:"jeannie_execution_id"` + Status string `json:"status"` + Output string `json:"output"` + Error string `json:"error"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} diff --git a/apps/opsproof/overlay/resources/js/pages/Execution.tsx b/apps/opsproof/overlay/resources/js/pages/Execution.tsx new file mode 100644 index 0000000..1fca85c --- /dev/null +++ b/apps/opsproof/overlay/resources/js/pages/Execution.tsx @@ -0,0 +1,48 @@ +import { router } from '@inertiajs/react'; +import { useEffect } from 'react'; + +interface ExecutionView { + execution: { + id: number; + jeannie_execution_id: string; + status: string; + output: string; + error: string; + }; + proposal: { + id: number; + scope: string; + target: string; + evidence_hash: string; + }; +} + +export default function ExecutionPage({ view }: { view: ExecutionView }) { + const active = view.execution.status === 'queued' || view.execution.status === 'running'; + useEffect(() => { + if (!active) return; + const timer = window.setInterval(() => router.reload({ only: ['view'] }), 2000); + return () => window.clearInterval(timer); + }, [active]); + + return ( +
+
+

Approval-gated execution

+

{view.proposal.scope} / {view.proposal.target}

+
+
+ {view.execution.jeannie_execution_id} + + {view.execution.status} + +
+
+                        {view.execution.output || (active ? 'Waiting for Jeannie output…' : view.execution.error || 'No output returned.')}
+                    
+ {active &&

Refreshing every two seconds.

} +
+
+
+ ); +} diff --git a/apps/opsproof/overlay/resources/js/pages/Incident.tsx b/apps/opsproof/overlay/resources/js/pages/Incident.tsx index 47e529a..05a94e3 100644 --- a/apps/opsproof/overlay/resources/js/pages/Incident.tsx +++ b/apps/opsproof/overlay/resources/js/pages/Incident.tsx @@ -1,3 +1,6 @@ +import { router } from '@inertiajs/react'; +import { useState } from 'react'; + interface Evidence { id: string; status: string; @@ -56,6 +59,13 @@ const tone: Record = { export default function IncidentPage({ laravelVersion, view, operator }: Props) { const incident = view.incident; + const [rollback, setRollback] = useState(''); + const [submitting, setSubmitting] = useState(false); + + function storeProposal() { + setSubmitting(true); + router.post(`/incidents/${incident.scope}/${incident.target}/proposals`, { rollback }, { onFinish: () => setSubmitting(false) }); + } return (
@@ -227,13 +237,30 @@ export default function IncidentPage({ laravelVersion, view, operator }: Props) ))} - + {incident.proposal.status === 'blocked' && ( +
+ +