Spaces:
Sleeping
Sleeping
Download app/models/security.py from yabeskn/briga-core-api: direct link, hf CLI and curl.
- Browser
- Download file 2.44 kB
-
https://huggingface.co/spaces/yabeskn/briga-core-api/resolve/main/app/models/security.py
- Command line
-
hf download hf://spaces/yabeskn/briga-core-api/app/models/security.py
-
curl -L -o security.py https://huggingface.co/spaces/yabeskn/briga-core-api/resolve/main/app/models/security.py
2.44 kB
| """Security & Cryptographic Audit Trail models.""" | |
| import uuid | |
| from datetime import datetime | |
| from sqlalchemy import Column, String, Integer, Text, Boolean, DateTime, ForeignKey, BigInteger | |
| from app.models.base import JSONB | |
| from sqlalchemy.dialects.postgresql import UUID | |
| from sqlalchemy.orm import relationship | |
| from app.models.base import Base | |
| class ProfileKey(Base): | |
| """Stores profile-specific AES-256 Data Encryption Keys (DEK). | |
| DEKs are encrypted by the KMS Master Key (Envelope Encryption). | |
| """ | |
| __tablename__ = "profile_keys" | |
| __table_args__ = {"schema": "security"} | |
| profile_id = Column(UUID(as_uuid=True), ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True) | |
| encrypted_symmetric_key = Column(Text, nullable=False) | |
| created_at = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow) | |
| # Relationships | |
| profile = relationship("Profile", back_populates="key") | |
| class AuditTrail(Base): | |
| """Cryptographic Append-Only Hash-Chained Audit Trail.""" | |
| __tablename__ = "audit_trail" | |
| __table_args__ = {"schema": "audit"} | |
| id = Column(BigInteger, primary_key=True, autoincrement=True) | |
| timestamp = Column(DateTime(timezone=True), default=datetime.utcnow) | |
| record_table = Column(String(100), nullable=False) | |
| record_id = Column(UUID(as_uuid=True), nullable=False) | |
| action_type = Column(String(10), nullable=False) # INSERT, UPDATE, DELETE | |
| ciphertext_hash = Column(String(64), nullable=False) | |
| signature_hash = Column(String(64), nullable=True) | |
| previous_hash = Column(String(64), nullable=False, index=True) | |
| current_hash = Column(String(64), nullable=False, index=True) | |
| class AuditAnchor(Base): | |
| """Anchors for pruned/archived audit logs to ensure chain continuity.""" | |
| __tablename__ = "audit_anchors" | |
| __table_args__ = {"schema": "audit"} | |
| id = Column(BigInteger, primary_key=True, autoincrement=True) | |
| archive_run_id = Column(UUID(as_uuid=True), default=uuid.uuid4) | |
| max_audit_id = Column(BigInteger, nullable=False) | |
| anchor_hash = Column(String(64), nullable=False, index=True) | |
| cold_storage_uri = Column(Text, nullable=False) | |
| archive_file_hash = Column(String(64), nullable=False) | |
| created_at = Column(DateTime(timezone=True), default=datetime.utcnow) | |