feat(object-gateway): 统一对象写网关与不可变治理日志
方案A:所有对象写入经 loopback 网关,持久计划/grant/intent/逐版本 receipt 与 attempt→grant delivery 落在治理 PG;scope 由 provider+endpoint+bucket 决定, 同一物理桶只允许一个写域。版本 append 不等于 CAS,未锚定计划在首笔业务写前拒绝。 本提交只含网关与其适配层接线、协议文档;生产独占、凭据切换与桶设置未改动。
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package objectgateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Attestation is issued by an independent deployment auditor, never by a worker.
|
||||
// Its signature authenticates an audit, not the truth of self-reported config.
|
||||
// Runtime cutover must invalidate/replace the audit whenever writer rights change.
|
||||
type Attestation struct {
|
||||
Protocol string `json:"protocol"`
|
||||
Scope string `json:"scope"`
|
||||
GatewayID string `json:"gateway_id"`
|
||||
IssuedAt time.Time `json:"issued_at"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
WriterInventory string `json:"writer_inventory_sha256"`
|
||||
PolicyEvidence string `json:"policy_evidence_sha256"`
|
||||
DenialEvidence string `json:"denial_evidence_sha256"`
|
||||
DrainEvidence string `json:"drain_evidence_sha256"`
|
||||
}
|
||||
type SignedAttestation struct {
|
||||
Payload json.RawMessage `json:"payload"`
|
||||
Signature []byte `json:"signature"`
|
||||
}
|
||||
type AuditVerifier struct {
|
||||
Path string
|
||||
PublicKey ed25519.PublicKey
|
||||
Scope, GatewayID string
|
||||
}
|
||||
|
||||
func (v AuditVerifier) Verify(ctx context.Context) error {
|
||||
if ctx.Err() != nil {
|
||||
return ErrIsolation
|
||||
}
|
||||
st, e := os.Lstat(v.Path)
|
||||
if e != nil || !st.Mode().IsRegular() || st.Size() > 16384 || st.Mode().Perm()&0022 != 0 {
|
||||
return ErrIsolation
|
||||
}
|
||||
raw, e := os.ReadFile(v.Path)
|
||||
if e != nil {
|
||||
return ErrIsolation
|
||||
}
|
||||
var signed SignedAttestation
|
||||
var a Attestation
|
||||
if json.Unmarshal(raw, &signed) != nil || len(v.PublicKey) != ed25519.PublicKeySize || !ed25519.Verify(v.PublicKey, signed.Payload, signed.Signature) || json.Unmarshal(signed.Payload, &a) != nil {
|
||||
return ErrIsolation
|
||||
}
|
||||
now := time.Now()
|
||||
if a.Protocol != Protocol || a.Scope != v.Scope || a.GatewayID != v.GatewayID || a.GatewayID == "" || a.IssuedAt.After(now) || !a.ExpiresAt.After(now) || a.ExpiresAt.Sub(a.IssuedAt) > time.Hour || !validHash(a.WriterInventory) || !validHash(a.PolicyEvidence) || !validHash(a.DenialEvidence) || !validHash(a.DrainEvidence) {
|
||||
return ErrIsolation
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user