Bind trusted task approval to exact producer facts and lifetime
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a140c4-354a-7823-8f0d-8f717397f786
This commit is contained in:
parent
4f6946bbb3
commit
2b064eee51
31 changed files with 2170 additions and 30 deletions
|
|
@ -112,7 +112,9 @@ func (o *Outbox) nextEntry() (entry, int64, error) {
|
|||
return entry{}, 0, err
|
||||
}
|
||||
var e entry
|
||||
if err := json.Unmarshal(line, &e); err != nil {
|
||||
decoder := json.NewDecoder(bytes.NewReader(line))
|
||||
decoder.UseNumber()
|
||||
if err := decoder.Decode(&e); err != nil {
|
||||
return entry{}, 0, err
|
||||
}
|
||||
if e.Seq != o.cursor.Seq+1 || e.Event.Source != o.source {
|
||||
|
|
|
|||
53
internal/emission/numeric_replay_test.go
Normal file
53
internal/emission/numeric_replay_test.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package emission
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/ed25519"
|
||||
"encoding/json"
|
||||
"github.com/netkingdom/access-engine/internal/sign"
|
||||
"github.com/netkingdom/access-engine/pkg/api"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOutboxReplayPreservesProducerNumericSignature(t *testing.T) {
|
||||
folder := t.TempDir()
|
||||
outbox, err := Open(folder, "synthetic-source")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
key := ed25519.NewKeyFromSeed(bytes.Repeat([]byte{21}, 32))
|
||||
envelope := api.DecisionEnvelope{ID: "decision:synthetic-numeric", Effect: api.DecisionEffectDeny, Resource: api.ResourceRef{ID: "synthetic", Type: "tenant", System: "tenant-engine"}}
|
||||
envelope.Binding = &api.DecisionBinding{Context: map[string]any{"float": json.Number("1.0"), "negative_zero": json.Number("-0.0"), "integer": json.Number("9007199254740993"), "exponent": json.Number("1e-07")}}
|
||||
if err := sign.Sign(&envelope, key, "synthetic-numeric"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := outbox.Append(envelope); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
outbox.Close()
|
||||
outbox, err = Open(folder, "synthetic-source")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer outbox.Close()
|
||||
entry, _, err := outbox.nextEntry()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wire, err := json.Marshal(entry.Event.Data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
replayed, err := sign.DecodeEnvelope(wire)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := sign.Verify(replayed, map[string]ed25519.PublicKey{"synthetic-numeric": key.Public().(ed25519.PublicKey)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, _ := sign.CanonicalBytes(envelope)
|
||||
after, _ := sign.CanonicalBytes(replayed)
|
||||
if !bytes.Equal(before, after) {
|
||||
t.Fatal("replayed signed bytes changed")
|
||||
}
|
||||
}
|
||||
|
|
@ -136,7 +136,9 @@ func (o *Outbox) load() error {
|
|||
return os.Truncate(o.path, o.size)
|
||||
}
|
||||
var e entry
|
||||
if err := json.Unmarshal(data[good:good+end], &e); err != nil {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data[good : good+end]))
|
||||
decoder.UseNumber()
|
||||
if err := decoder.Decode(&e); err != nil {
|
||||
return fmt.Errorf("outbox line %d is corrupt: %w", line, err)
|
||||
}
|
||||
if e.Seq != o.seq+1 || e.Event.Source != o.source {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue