feat(request): add service accounts and unified authorization

This commit is contained in:
2026-08-11 11:16:38 +03:00
parent 51f01300c3
commit 4e7dc451ac
22 changed files with 4947 additions and 19 deletions
@@ -0,0 +1,38 @@
"""ServiceAccountAuditEvent model — security audit trail.
Audit is accountability mechanism.
NEVER log plaintext credentials or sensitive token material.
"""
from sqlalchemy import Column, String, Integer, ForeignKey, Text
from sqlalchemy.orm import relationship
from request_app.models.base import Base, TimestampMixin
class ServiceAccountAuditEvent(Base, TimestampMixin):
"""Security audit events for Service Account lifecycle.
Audit is accountability, NOT a defense against SQL tampering.
"""
__tablename__ = "service_account_audit_events"
id = Column(Integer, primary_key=True, index=True)
service_account_id = Column(Integer, ForeignKey("service_accounts.id", ondelete="CASCADE"), nullable=False, index=True)
# Event type
event_type = Column(String(50), nullable=False, index=True)
# Types: created, activated, disabled, enabled, revoked,
# credential_issued, credential_rotated, credential_revoked,
# role_assigned, role_removed, authentication_success, authentication_failure
# Event details (NO secrets)
message = Column(Text, nullable=False)
performed_by = Column(String(200), nullable=True) # Who performed the action
extra_data = Column(Text, nullable=True) # JSON for additional context (NO secrets)
# Relationships
service_account = relationship("ServiceAccount", back_populates="audit_events")
def __repr__(self) -> str:
return f"<ServiceAccountAuditEvent(sa_id={self.service_account_id}, type='{self.event_type}')>"