a55319d972
build / build (push) Failing after 2m29s
现象:共享桶部署下网关启动即报 gateway_auditor_key_required,残留过期 审计文件则每次 Execute 报 gateway_exclusive_writer_evidence_unverified; 用户已改为“停目标写入容器→更新→启动”的维护式更新。 根因:Gateway.Ready 强制 Isolation.Verify,main 强制 Ed25519 公钥,等于 把整桶独占证明当作发布前置;这与共享桶、沿用原 AK 的实际部署矛盾。 取舍:删除审计校验与相关 env 依赖,保留 journal、治理 PG 只读 authority、 plan/owner/attempt/epoch 绑定、intent-before-send、单次写与精确版本回滚。 create 仅在精确版本读回且仍为 current 时提交;发现外部 latest 只返回冲突, 不在 confirm 阶段删除(journal create intent 已提交,删除会变成无 delete intent/receipt 的未记账副作用并让 intent 永久 held)。同 key 不自动合并。 证据:真实二进制无审计/残留审计两环境通过;kg-pgtest-writeset 一次性库 + 随机 MinIO 桶跑 14 个网关用例(含共享桶共存写者、同 key 既有对象拒绝、 精确回滚)全过;umask 022 下 make verify 本地必需项全 success。
115 lines
4.8 KiB
Go
115 lines
4.8 KiB
Go
package objectgateway_test
|
|
|
|
import (
|
|
"bytes"
|
|
"net"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
g "knowledge-governance/internal/objectgateway"
|
|
)
|
|
|
|
// A maintenance update of the target KB runs while the same bucket still
|
|
// serves other writers. Publishing planned objects must neither require a
|
|
// whole-bucket exclusivity attestation nor disturb an unrelated key or a
|
|
// pre-existing object at a planned key. External writes here are made before
|
|
// execute (coexistence), not interleaved concurrently with the PUT.
|
|
func TestGatewaySharedBucketCoexistenceWithOtherWriters(t *testing.T) {
|
|
ctx, pool, backend := fixture(t)
|
|
endpoint := os.Getenv("KG_GATEWAY_TEST_ENDPOINT")
|
|
scope := g.Digest([]byte("minio\x00" + endpoint + "\x00" + backend.Bucket))
|
|
listener, e := net.Listen("tcp", "127.0.0.1:0")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
addr := listener.Addr().String()
|
|
listener.Close()
|
|
data, control := g.Digest([]byte("data "+scope)), g.Digest([]byte("control "+scope))
|
|
client, e := g.NewClient("http://"+addr, data, scope)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
admin, _ := g.NewClient("http://"+addr, control, scope)
|
|
// Deliberately no OBJECT_GATEWAY_AUDIT_FILE / OBJECT_GATEWAY_AUDIT_PUBLIC_KEY:
|
|
// the default shared-bucket path must start without whole-bucket evidence.
|
|
env := []string{
|
|
"PATH=" + os.Getenv("PATH"),
|
|
"HOME=" + os.Getenv("HOME"),
|
|
"OBJECT_GATEWAY_LISTEN=" + addr,
|
|
"OBJECT_GATEWAY_DATABASE_URL=" + os.Getenv("KG_GATEWAY_TEST_DATABASE_URL"),
|
|
"OBJECT_GATEWAY_PROVIDER=minio",
|
|
"OBJECT_GATEWAY_ENDPOINT=" + endpoint,
|
|
"OBJECT_GATEWAY_BUCKET=" + backend.Bucket,
|
|
"OBJECT_GATEWAY_REGION=us-east-1",
|
|
"OBJECT_GATEWAY_ACCESS_KEY=" + os.Getenv("KG_GATEWAY_TEST_ACCESS_KEY"),
|
|
"OBJECT_GATEWAY_SECRET_KEY=" + os.Getenv("KG_GATEWAY_TEST_SECRET_KEY"),
|
|
"OBJECT_GATEWAY_DATA_TOKEN=" + data,
|
|
"OBJECT_GATEWAY_CONTROL_TOKEN=" + control,
|
|
}
|
|
startGateway(t, env, client)
|
|
if e = client.ReadyForAcquisition(ctx); e == nil {
|
|
t.Fatal("gateway without control authority advertised automatic grants")
|
|
}
|
|
|
|
// Another service keeps writing unrelated keys during the maintenance window.
|
|
externalOwner := g.Digest([]byte("other-service"))
|
|
unrelatedKey := "other-service/unrelated-" + g.Digest([]byte(backend.Bucket))[:8]
|
|
unrelatedBody := []byte("unrelated service body")
|
|
if _, e = backend.Client.PutObject(ctx, &s3.PutObjectInput{Bucket: aws.String(backend.Bucket), Key: aws.String(unrelatedKey), Body: bytes.NewReader(unrelatedBody), Metadata: map[string]string{"kg-release-owner": externalOwner}}); e != nil {
|
|
t.Fatalf("external unrelated write failed: %v", e)
|
|
}
|
|
unrelated, _, e := backend.Observe(ctx, unrelatedKey, "")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
|
|
// A planned key already holds a foreign object: the plan must refuse it and
|
|
// leave that object byte-identical.
|
|
existingKey := "unchanged/existing-object"
|
|
existingBody := []byte("pre-existing production content")
|
|
if _, e = backend.Client.PutObject(ctx, &s3.PutObjectInput{Bucket: aws.String(backend.Bucket), Key: aws.String(existingKey), Body: bytes.NewReader(existingBody), Metadata: map[string]string{"kg-release-owner": externalOwner}}); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
existing, _, e := backend.Observe(ctx, existingKey, "")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
|
|
grant := g.Grant{Epoch: 1, Owner: g.Digest([]byte("maintenance-owner")), Plan: g.Digest([]byte("maintenance-plan"))}
|
|
fresh := request("shared-fresh", grant)
|
|
clash := request("shared-clash", grant)
|
|
clash.Key = existingKey
|
|
if e = admin.InstallPlan(ctx, planFor(grant, fresh, clash)); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if e = admin.Advance(ctx, 0, grant); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
receipt, e := client.Execute(ctx, fresh, []byte("gateway fixture shared-fresh"))
|
|
if e != nil || receipt.State != "committed" {
|
|
t.Fatalf("planned create blocked by unrelated writers: %v %s", e, receipt.State)
|
|
}
|
|
rejected, e := client.Execute(ctx, clash, []byte("gateway fixture shared-clash"))
|
|
if e != nil || rejected.State != "rejected" {
|
|
t.Fatalf("pre-existing planned key not rejected: %v %s", e, rejected.State)
|
|
}
|
|
after, exists, e := backend.Observe(ctx, existingKey, "")
|
|
if e != nil || !exists || after.ID != existing.ID || after.SHA256 != g.Digest(existingBody) {
|
|
t.Fatalf("pre-existing object modified: %v %+v", e, after)
|
|
}
|
|
still, exists, e := backend.Observe(ctx, unrelatedKey, "")
|
|
if e != nil || !exists || still.ID != unrelated.ID {
|
|
t.Fatalf("unrelated object disturbed: %v %+v", e, still)
|
|
}
|
|
|
|
// Precise rollback removes only the version this gateway created.
|
|
cleanup(t, ctx, &g.Gateway{Pool: pool, Scope: scope, Backend: backend, MaxBytes: 1 << 20}, receipt)
|
|
for key, keep := range map[string]g.Version{existingKey: existing, unrelatedKey: unrelated} {
|
|
if e = backend.Delete(ctx, key, keep); e != nil {
|
|
t.Fatalf("external fixture cleanup %s: %v", key, e)
|
|
}
|
|
}
|
|
}
|