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 }