Add OpsProof remediation proposals
Homelab Main / validate (push) Failing after 1m40s Details
Homelab Main / running-update (push) Has been skipped Details
Homelab Main / debian-ops (push) Has been skipped Details

This commit is contained in:
juvenal.diaz 2026-12-04 16:06:07 -06:00
parent 193f07b044
commit 5a49552694
6 changed files with 189 additions and 14 deletions

View File

@ -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;

View File

@ -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) {
<code className="mt-3 block overflow-x-auto rounded-lg bg-black/20 p-3 text-xs text-cyan-100">
{incident.nextCommand}
</code>
<button type="button" disabled className="mt-4 w-full cursor-not-allowed rounded-lg bg-white/8 px-4 py-2.5 text-sm text-slate-500">
No mitigation in this slice
</div>
</section>
<section className="mt-6 overflow-hidden rounded-3xl border border-violet-300/20 bg-violet-300/[0.04]">
<div className="flex flex-col gap-4 border-b border-white/10 p-6 sm:flex-row sm:items-start sm:justify-between">
<div>
<p className="text-xs uppercase tracking-[0.18em] text-violet-200">Remediation proposal</p>
<h2 className="mt-2 text-xl font-semibold text-white">{incident.proposal.summary}</h2>
<p className="mt-2 font-mono text-[11px] text-slate-500">
{incident.proposal.id} · evidence {incident.proposal.evidenceIds.join(', ') || 'none'}
</p>
</div>
<div className="flex gap-2">
<span className="rounded-md border border-white/10 bg-white/[0.04] px-2 py-1 text-[10px] uppercase text-slate-300">
{incident.proposal.status}
</span>
<span className="rounded-md border border-rose-300/20 bg-rose-300/10 px-2 py-1 text-[10px] uppercase text-rose-200">
risk {incident.proposal.riskLevel}
</span>
</div>
</div>
<div className="grid gap-px bg-white/10 lg:grid-cols-2">
<div className="space-y-6 bg-[#0b1621] p-6">
<div>
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Proposed Jeannie action</p>
<code className="mt-3 block overflow-x-auto rounded-lg bg-black/20 p-3 text-xs text-violet-100">
{incident.proposal.action || 'No state-changing action proposed.'}
</code>
</div>
<div>
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Preconditions</p>
<ul className="mt-3 space-y-2 text-sm text-slate-400">
{incident.proposal.preconditions.map((item) => (
<li key={item}>• {item}</li>
))}
{incident.proposal.preconditions.length === 0 && <li>• No change is proposed.</li>}
</ul>
</div>
</div>
<div className="space-y-6 bg-[#0b1621] p-6">
<div>
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Risk review</p>
<ul className="mt-3 space-y-2 text-sm text-slate-400">
{incident.proposal.riskNotes.map((item) => (
<li key={item}>• {item}</li>
))}
{incident.proposal.riskNotes.length === 0 && <li>• No state-changing risk was introduced.</li>}
</ul>
</div>
<div>
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Rollback</p>
<p className="mt-3 text-sm leading-6 text-slate-400">{incident.proposal.rollback}</p>
</div>
</div>
</div>
<div className="border-t border-white/10 p-6">
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Deterministic validation</p>
<div className="mt-3 grid gap-2 sm:grid-cols-2">
{incident.proposal.validation.map((command) => (
<code key={command} className="overflow-x-auto rounded-lg bg-black/20 p-3 text-xs text-cyan-100">
{command}
</code>
))}
</div>
<button
type="button"
disabled={!incident.proposal.readyForApproval}
className="mt-5 w-full cursor-not-allowed rounded-lg bg-white/8 px-4 py-3 text-sm text-slate-500"
>
Approval unavailable until identity, authorization, and rollback controls exist
</button>
</div>
</section>

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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?

View File

@ -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()