fix: accept isolation supersets in evidence and publication
7 files changed,
+85
−19
internal/equipo/final_isolation_test.go+25 −0internal/equipo/runner_report_validation.go+3 −17internal/equipo/team/actions.go+2 −2internal/equipo/team/final_isolation_test.go+26 −0internal/equipo/team/git_evidence.go+3 −0internal/equipo/team/publication.go+20 −0internal/equipo/team/publication_no_effect_test.go+6 −0
diff --git a/internal/equipo/final_isolation_test.go b/internal/equipo/final_isolation_test.go| new file mode 100644 |
| index 00000000..7409e337 |
| --- /dev/null |
| +++ b/internal/equipo/final_isolation_test.go |
| @@ -0,0 +1,25 @@ |
| +package equipo |
| + |
| +import ( |
| + "amadan.net/oficina/equipo/internal/equipo/team" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestExecutorReportIsolationContains(t *testing.T) { |
| + need := team.IsolationSnapshot{Status: "unconfined", RunnerTainted: true, AcknowledgementIDs: []string{"current"}, ObservedTuples: []team.IsolationTuple{{Provider: "codex", ProviderVersion: "1", PaseoVersion: "1", IsolationConfigHash: strings.Repeat("a", 64)}}} |
| + have := need |
| + have.AcknowledgementIDs = []string{"current", "extra"} |
| + if !executorReportIsolation(have, need) { |
| + t.Fatal("extra taint refused") |
| + } |
| + have.RunnerTainted = false |
| + if executorReportIsolation(have, need) { |
| + t.Fatal("stripped taint accepted") |
| + } |
| + have = need |
| + have.AcknowledgementIDs = nil |
| + if executorReportIsolation(have, need) { |
| + t.Fatal("missing acknowledgement accepted") |
| + } |
| +} |
diff --git a/internal/equipo/runner_report_validation.go b/internal/equipo/runner_report_validation.go| index 21b3fb1e..893b630d 100644 |
| --- a/internal/equipo/runner_report_validation.go |
| +++ b/internal/equipo/runner_report_validation.go |
| @@ -6,7 +6,6 @@ import ( |
| "database/sql" |
| "encoding/json" |
| "gorm.io/gorm" |
| - "slices" |
| "amadan.net/oficina/equipo/internal/equipo/team" |
| "amadan.net/oficina/equipo/internal/runnerproto" |
| @@ -172,25 +171,12 @@ func (s *Store) supervisedExecutorEvidence(ctx context.Context, raw *sql.Tx, sco |
| if expectedIsolation.RunnerTainted { |
| expectedIsolation.Status = "unconfined" |
| } |
| - reported := canonicalReportIsolation(iso) |
| - expected := canonicalReportIsolation(expectedIsolation) |
| - if !bytes.Equal(reported, expected) { |
| + if !executorReportIsolation(iso, expectedIsolation) { |
| return team.Provenance{}, ErrForbidden |
| } |
| return team.Provenance{Producer: "equipo-checks", Provider: "executor", Context: h.Runner, ConnectionID: value.Selection.ConnectionID, Isolation: value.Selection.Isolation}, nil |
| } |
| -func canonicalReportIsolation(iso team.IsolationSnapshot) []byte { |
| - iso.AcknowledgementIDs = slices.Clone(iso.AcknowledgementIDs) |
| - slices.Sort(iso.AcknowledgementIDs) |
| - iso.AcknowledgementIDs = slices.Compact(iso.AcknowledgementIDs) |
| - iso.ObservedTuples = slices.Clone(iso.ObservedTuples) |
| - slices.SortFunc(iso.ObservedTuples, func(a, b team.IsolationTuple) int { |
| - x, _ := json.Marshal(a) |
| - y, _ := json.Marshal(b) |
| - return bytes.Compare(x, y) |
| - }) |
| - iso.ObservedTuples = slices.Compact(iso.ObservedTuples) |
| - raw, _ := json.Marshal(iso) |
| - return raw |
| +func executorReportIsolation(have, need team.IsolationSnapshot) bool { |
| + return team.IsolationContains(have, need) |
| } |
diff --git a/internal/equipo/team/actions.go b/internal/equipo/team/actions.go| index c37a50fa..52acb4b6 100644 |
| --- a/internal/equipo/team/actions.go |
| +++ b/internal/equipo/team/actions.go |
| @@ -189,7 +189,7 @@ func (s *Store) Intend(ctx context.Context, scope Scope, h Handle, in IntentSpec |
| if err != nil { |
| return err |
| } |
| - if (p.Description != "" && p.Description != description) || (p.DescriptionHash != "" && p.DescriptionHash != hashBytes([]byte(description))) { |
| + if (p.Description != "" && !publicationDescriptionContains(p.Description, description)) || (p.DescriptionHash != "" && p.DescriptionHash != hashBytes([]byte(p.Description))) { |
| return ErrEvidence |
| } |
| p.Description = description |
| @@ -301,7 +301,7 @@ func checkPublication(ctx context.Context, tx *sql.Tx, j jobRow, payload []byte) |
| if err != nil { |
| return err |
| } |
| - if p.Description != description || p.DescriptionHash != hashBytes([]byte(description)) { |
| + if !publicationDescriptionContains(p.Description, description) || p.DescriptionHash != hashBytes([]byte(p.Description)) { |
| return ErrEvidence |
| } |
| if !rep.Satisfied || !isolationContains(p.Isolation, rep.Isolation) { |
diff --git a/internal/equipo/team/final_isolation_test.go b/internal/equipo/team/final_isolation_test.go| new file mode 100644 |
| index 00000000..4ea2c663 |
| --- /dev/null |
| +++ b/internal/equipo/team/final_isolation_test.go |
| @@ -0,0 +1,26 @@ |
| +package team |
| + |
| +import ( |
| + "encoding/json" |
| + "testing" |
| +) |
| + |
| +func TestPublicationAcceptsContainedIsolation(t *testing.T) { |
| + g := newGitEnv(t) |
| + g.build() |
| + g.review() |
| + g.verify(true) |
| + h := g.claimStep("publish") |
| + p, err := g.store.Publication(g.ctx, g.scope, h) |
| + must(t, err) |
| + var d PublicationDescription |
| + must(t, json.Unmarshal([]byte(p.Description), &d)) |
| + d.Isolation.AcknowledgementIDs = append(d.Isolation.AcknowledgementIDs, "extra") |
| + for i := range d.Evidence { |
| + d.Evidence[i].Provenance.Isolation.AcknowledgementIDs = append(d.Evidence[i].Provenance.Isolation.AcknowledgementIDs, "extra") |
| + } |
| + p.Description = string(mustJSON(d)) |
| + p.DescriptionHash = hashBytes([]byte(p.Description)) |
| + _, err = g.store.Intend(g.ctx, g.scope, h, IntentSpec{Key: "superset", Operation: OpForgePublish, Payload: mustJSON(p), Reserve: Usage{Calls: 1}}) |
| + must(t, err) |
| +} |
diff --git a/internal/equipo/team/git_evidence.go b/internal/equipo/team/git_evidence.go| index 1076fde1..2c335f79 100644 |
| --- a/internal/equipo/team/git_evidence.go |
| +++ b/internal/equipo/team/git_evidence.go |
| @@ -281,3 +281,6 @@ func gitCandidateFields(raw []byte) bool { |
| token, err = dec.Token() |
| return err == nil && token == json.Delim('}') && len(seen) == 4 && jsonEnd(dec) == nil |
| } |
| + |
| +// IsolationContains checks that reported provenance retains the current exposure. |
| +func IsolationContains(have, need IsolationSnapshot) bool { return isolationContains(have, need) } |
diff --git a/internal/equipo/team/publication.go b/internal/equipo/team/publication.go| index 1bd202df..35ab77a0 100644 |
| --- a/internal/equipo/team/publication.go |
| +++ b/internal/equipo/team/publication.go |
| @@ -4,6 +4,7 @@ import ( |
| "context" |
| "database/sql" |
| "encoding/json" |
| + "reflect" |
| "regexp" |
| ) |
| @@ -183,3 +184,22 @@ func (s *Store) AuthorizePublication(ctx context.Context, scope Scope, h Handle, |
| }) |
| return a, err |
| } |
| + |
| +func publicationDescriptionContains(have, need string) bool { |
| + var a, b PublicationDescription |
| + if strictJSON([]byte(have), &a) != nil || strictJSON([]byte(need), &b) != nil || len(a.Evidence) != len(b.Evidence) { |
| + return false |
| + } |
| + if !isolationContains(a.Isolation, b.Isolation) || (b.Label == "unconfined" && a.Label != "unconfined") { |
| + return false |
| + } |
| + a.Isolation, a.Label = b.Isolation, b.Label |
| + for i := range a.Evidence { |
| + if !isolationContains(a.Evidence[i].Provenance.Isolation, b.Evidence[i].Provenance.Isolation) || (b.Evidence[i].Label == "unconfined" && a.Evidence[i].Label != "unconfined") { |
| + return false |
| + } |
| + a.Evidence[i].Provenance.Isolation = b.Evidence[i].Provenance.Isolation |
| + a.Evidence[i].Label = b.Evidence[i].Label |
| + } |
| + return reflect.DeepEqual(a, b) |
| +} |
diff --git a/internal/equipo/team/publication_no_effect_test.go b/internal/equipo/team/publication_no_effect_test.go| index 40d2cb55..9e9b8f8a 100644 |
| --- a/internal/equipo/team/publication_no_effect_test.go |
| +++ b/internal/equipo/team/publication_no_effect_test.go |
| @@ -48,6 +48,12 @@ func TestPublishNoEffectSettlement(t *testing.T) { |
| rows, err := g.store.Reservations(g.ctx, g.scope) |
| must(t, err) |
| for _, r := range rows { |
| + if r.ID == a.Reservation && recover { |
| + if r.State != ReservationSettled || r.Settled != r.Reserved { |
| + t.Fatal("unknown charge refunded", r) |
| + } |
| + continue |
| + } |
| if r.ID == a.Reservation && (r.State != ReservationReleased || r.Settled.Calls != 0 || r.Settled.CostMicros != 0) { |
| t.Fatalf("no dispatch retained charge: %+v", r) |
| } |