Resolve complete Home identity within note ingestion
4 files changed,
+14
−20
go.mod+1 −1go.sum+2 −0internal/memoria/agent_boundary.go+8 −18internal/memoria/agent_hardening_test.go+3 −1
CI passed — run details
diff --git a/go.mod b/go.mod| index 5556564..6b151b7 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -7,7 +7,7 @@ toolchain go1.26.5 |
| require ( |
| amadan.net/oficina/agent-access.git v0.0.0-20261024232549-8ed8ba826000 |
| amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768 |
| - amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c |
| + amadan.net/oficina/home/connect v0.0.0-20261025004522-7430dd23a847 |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 |
| amadan.net/oficina/suite v0.0.0-20260905215529-60b01a8a0d6d |
| amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 |
diff --git a/go.sum b/go.sum| index 2428be8..1d92687 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -4,6 +4,8 @@ amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768 h1:bVscoa9fH5Ld |
| amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw= |
| amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c h1:3yxO2D8BxDLMGfFV2o6Sp9Z91yLnjDCIuRKHVWORa8A= |
| amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c/go.mod h1:YroavXe43Wietec+po8mtSk4a9Bir2h31Q3iAf4MWxI= |
| +amadan.net/oficina/home/connect v0.0.0-20261025004522-7430dd23a847 h1:pJYp3kEWLUXXoi4UtRH8SIX+HyAyQUQOaFNE7XuY20Y= |
| +amadan.net/oficina/home/connect v0.0.0-20261025004522-7430dd23a847/go.mod h1:YroavXe43Wietec+po8mtSk4a9Bir2h31Q3iAf4MWxI= |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 h1:RPKtyry/71i06o8L+gjAaUyexbmG56kO1YPs601URAM= |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k= |
| amadan.net/oficina/suite v0.0.0-20260905215529-60b01a8a0d6d h1:x6Bq9+QzpFYAyV+zRzgyHwD/RmZ4Hy4biwtxK7CdaSs= |
diff --git a/internal/memoria/agent_boundary.go b/internal/memoria/agent_boundary.go| index e12dee9..76f39e2 100644 |
| --- a/internal/memoria/agent_boundary.go |
| +++ b/internal/memoria/agent_boundary.go |
| @@ -3,13 +3,13 @@ package memoria |
| import ( |
| "context" |
| "crypto/hmac" |
| - "database/sql" |
| "encoding/json" |
| "errors" |
| "net/http" |
| "strings" |
| access "amadan.net/oficina/agent-access.git" |
| + "amadan.net/oficina/home/connect/linkstore" |
| "gorm.io/gorm" |
| ) |
| @@ -65,27 +65,17 @@ func (a *app) checkAgentWriter(ctx context.Context, tx *gorm.DB, p access.Princi |
| if e := state.verify(ctx, p, "notes:write"); e != nil { |
| return e |
| } |
| - var id int64 |
| - if e := tx.Raw("SELECT person_id FROM home_identity_links WHERE issuer=? AND subject=?", a.home.issuer, p.Subject).Row().Scan(&id); e != nil { |
| - if errors.Is(e, sql.ErrNoRows) { |
| - return access.Fail("forbidden", "The linked identity is unavailable.") |
| - } |
| - return e |
| - } |
| - if id != state.personID { |
| - return access.Fail("forbidden", "The linked identity changed.") |
| + person, e := a.home.bridge.ResolveOn(ctx, tx.Statement.ConnPool, p.Subject) |
| + if errors.Is(e, linkstore.ErrRefused) { |
| + return access.Fail("forbidden", "The linked identity is unavailable.") |
| } |
| - q, ok := tx.Statement.ConnPool.(homeIdentityQueryer) |
| - if !ok { |
| - return errors.New("memoria: transaction identity unavailable") |
| - } |
| - current, e := a.lookupHomeLocalIdentity(ctx, q, id) |
| - if e != nil && !errors.Is(e, sql.ErrNoRows) { |
| + if e != nil { |
| return e |
| } |
| - if e != nil || current != address { |
| - return access.Fail("forbidden", "This account is no longer admitted.") |
| + if person.ID != state.personID || person.Label != address { |
| + return access.Fail("forbidden", "The linked identity changed.") |
| } |
| + |
| return nil |
| } |
diff --git a/internal/memoria/agent_hardening_test.go b/internal/memoria/agent_hardening_test.go| index 7525458..3464754 100644 |
| --- a/internal/memoria/agent_hardening_test.go |
| +++ b/internal/memoria/agent_hardening_test.go |
| @@ -33,7 +33,7 @@ func assertAgentNoteEmpty(t *testing.T, a *app) { |
| } |
| } |
| func TestAgentNoteAtomicReceiptAndAuthority(t *testing.T) { |
| - for _, mode := range []string{"receipt-failure", "chunk-failure", "unlink", "revoke-reserved", "revoke-final"} { |
| + for _, mode := range []string{"receipt-failure", "chunk-failure", "binding", "unlink", "revoke-reserved", "revoke-final"} { |
| t.Run(mode, func(t *testing.T) { |
| f, p := linkedAgentFixture(t) |
| var checks atomic.Int64 |
| @@ -53,6 +53,8 @@ func TestAgentNoteAtomicReceiptAndAuthority(t *testing.T) { |
| trigger = "CREATE TRIGGER fail_receipt BEFORE UPDATE OF document_id ON memoria_agent_notes BEGIN SELECT RAISE(ABORT,'injected'); END" |
| case "chunk-failure": |
| trigger = "CREATE TRIGGER fail_chunk AFTER INSERT ON chunks BEGIN SELECT RAISE(ABORT,'injected'); END" |
| + case "binding": |
| + trigger = "CREATE TRIGGER lose_binding AFTER INSERT ON chunks BEGIN UPDATE home_identity_links SET person_binding='broken'; END" |
| case "unlink": |
| trigger = "CREATE TRIGGER unlink_after_body AFTER INSERT ON chunks BEGIN DELETE FROM home_identity_links; END" |
| } |