feat: apply sealed installation plans without interactive setup

This commit is contained in:
Codex
2026-10-06 15:45:18 +02:00
parent c3c9f509bf
commit 8b9a086fd6
31 changed files with 1542 additions and 45 deletions
+27 -10
View File
@@ -28,6 +28,8 @@ type Plan struct {
Platform string `json:"platform"`
WorkspaceDirectory string `json:"workspace_directory"`
WorkspaceRevision string `json:"workspace_revision"`
ManifestPath string `json:"manifest_path,omitempty"`
BootstrapPath string `json:"bootstrap_path,omitempty"`
Inputs []string `json:"inputs"`
AbsentInputs []string `json:"absent_inputs"`
InputSeal string `json:"input_seal"`
@@ -62,10 +64,16 @@ func CaptureInputs(paths []string, workspace string, absent ...string) (func() b
// A separate owner-only random key prevents public/offline guessing of low-entropy secrets.
// Live prerequisites must still be rechecked immediately before any execution or resumption.
func seal(plan Plan, key []byte) (string, error) {
func seal(plan Plan, key []byte, materialized ...bool) (string, error) {
for _, path := range plan.AbsentInputs {
if _, err := os.Lstat(path); !errors.Is(err, os.ErrNotExist) {
return "", invalidPlan()
name := "deploy/" + filepath.Base(path)
allowed := len(materialized) > 0 && materialized[0] && (name == "deploy/compose.git-https.yaml" || name == "deploy/compose.git-ssh.yaml") && path == filepath.Join(plan.Installation.ProjectDirectory, filepath.FromSlash(name))
data, readErr := safeio.ReadCanonicalRegular(path, 32<<20)
sum := sha256.Sum256(data)
if !allowed || readErr != nil || hex.EncodeToString(sum[:]) != plan.Release.Files[name] {
return "", invalidPlan()
}
}
}
mac := hmac.New(sha256.New, key)
@@ -138,35 +146,44 @@ func WritePlan(path string, plan *Plan, guards ...func() bool) error {
return nil
}
func VerifyPlanInputs(path string) error {
_, err := readPlan(path, false)
return err
}
// ReadExecutionPlan permits only exact release-owned overlays installed by a prior attempt.
// The authored documents, credentials, bundle and private seal must otherwise remain unchanged.
func ReadExecutionPlan(path string) (Plan, error) { return readPlan(path, true) }
func readPlan(path string, materialized bool) (Plan, error) {
data, err := safeio.ReadCanonicalPrivateRegular(path, 4<<20)
if err != nil {
return invalidPlan()
return Plan{}, invalidPlan()
}
key, err := safeio.ReadCanonicalPrivateRegular(path+".key", 32)
if err != nil || len(key) != 32 {
return invalidPlan()
return Plan{}, invalidPlan()
}
var plan Plan
if json.Unmarshal(data, &plan) != nil || plan.SchemaVersion != 1 || plan.ValidatorProtocol != Protocol || !plan.Report.OK || len(plan.Inputs) == 0 || len(plan.Inputs) > 10000 {
return invalidPlan()
return Plan{}, invalidPlan()
}
actual, err := seal(plan, key)
actual, err := seal(plan, key, materialized)
if err != nil || !hmac.Equal([]byte(actual), []byte(plan.InputSeal)) {
return invalidPlan()
return Plan{}, invalidPlan()
}
// Detect added or removed workspace files as well as changes to known file bytes.
if plan.WorkspaceDirectory != "" {
files, err := treeFiles(plan.WorkspaceDirectory, true)
if err != nil {
return invalidPlan()
return Plan{}, invalidPlan()
}
for _, file := range files {
if !slices.Contains(plan.Inputs, file) {
return invalidPlan()
return Plan{}, invalidPlan()
}
}
}
return nil
return plan, nil
}
func treeFiles(root string, skipGit bool) ([]string, error) {
paths := []string{}