5eef13b615
方案A:所有对象写入经 loopback 网关,持久计划/grant/intent/逐版本 receipt 与 attempt→grant delivery 落在治理 PG;scope 由 provider+endpoint+bucket 决定, 同一物理桶只允许一个写域。版本 append 不等于 CAS,未锚定计划在首笔业务写前拒绝。 本提交只含网关与其适配层接线、协议文档;生产独占、凭据切换与桶设置未改动。
60 lines
2.2 KiB
Go
60 lines
2.2 KiB
Go
package objectgateway_test
|
|
|
|
import (
|
|
"context"
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"encoding/json"
|
|
g "knowledge-governance/internal/objectgateway"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestGatewayAuditCannotBeConfigurationBoolean(t *testing.T) {
|
|
pub, priv, e := ed25519.GenerateKey(rand.Reader)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "audit.json")
|
|
verifier := g.AuditVerifier{Path: path, PublicKey: pub, Scope: "target", GatewayID: "gateway"}
|
|
if verifier.Verify(context.Background()) == nil {
|
|
t.Fatal("missing audit accepted")
|
|
}
|
|
if os.WriteFile(path, []byte(`{"isolated":true,"ready":true}`), 0600) != nil {
|
|
t.Fatal("fixture")
|
|
}
|
|
if verifier.Verify(context.Background()) == nil {
|
|
t.Fatal("boolean accepted as isolation proof")
|
|
}
|
|
a := g.Attestation{Protocol: g.Protocol, Scope: "target", GatewayID: "gateway", IssuedAt: time.Now().Add(-time.Minute), ExpiresAt: time.Now().Add(30 * time.Minute), WriterInventory: g.Digest([]byte("inventory")), PolicyEvidence: g.Digest([]byte("policy")), DenialEvidence: g.Digest([]byte("denials")), DrainEvidence: g.Digest([]byte("drain"))}
|
|
write := func(v g.Attestation) {
|
|
t.Helper()
|
|
raw, _ := json.Marshal(v)
|
|
signed, _ := json.Marshal(g.SignedAttestation{Payload: raw, Signature: ed25519.Sign(priv, raw)})
|
|
if os.WriteFile(path, signed, 0600) != nil {
|
|
t.Fatal("fixture")
|
|
}
|
|
}
|
|
write(a)
|
|
if verifier.Verify(context.Background()) != nil {
|
|
t.Fatal("valid test auditor signature rejected")
|
|
}
|
|
for _, mutate := range []func(*g.Attestation){func(v *g.Attestation) { v.Scope = "other" }, func(v *g.Attestation) { v.GatewayID = "other" }, func(v *g.Attestation) { v.ExpiresAt = time.Now().Add(-time.Second) }, func(v *g.Attestation) { v.DenialEvidence = "" }, func(v *g.Attestation) { v.IssuedAt = time.Now().Add(time.Hour) }, func(v *g.Attestation) { v.ExpiresAt = time.Now().Add(24 * time.Hour) }} {
|
|
bad := a
|
|
mutate(&bad)
|
|
write(bad)
|
|
if verifier.Verify(context.Background()) == nil {
|
|
t.Fatal("invalid isolation audit accepted")
|
|
}
|
|
}
|
|
write(a)
|
|
other, _, _ := ed25519.GenerateKey(rand.Reader)
|
|
verifier.PublicKey = other
|
|
if verifier.Verify(context.Background()) == nil {
|
|
t.Fatal("untrusted signer accepted")
|
|
}
|
|
}
|