architect/_archive/2025-11-cleanup/platform-v2-cifra/06_SECURITY.md

CIFRA — Безопасность

Версия: 2.0.0
Дата: 2025-11-10


Содержание

  1. Authentication (Email/Password, OAuth, 2FA)
  2. Authorization (RBAC, ABAC, RLS)
  3. Encryption
  4. OWASP Top 10
  5. Compliance

1. Authentication

Email/Password

from cifra.auth import register, login

# Registration
user = await register(
    email='user@example.com',
    password='SecurePass123!',
    name='John Doe'
)

# Login
token = await login(
    email='user@example.com',
    password='SecurePass123!'
)
# → JWT token

OAuth 2.0

integrations:
  google_oauth:
    enabled: true
    client_id: ${GOOGLE_CLIENT_ID}
    client_secret: ${GOOGLE_CLIENT_SECRET}

  github_oauth:
    enabled: true
    client_id: ${GITHUB_CLIENT_ID}

Two-Factor Authentication

# Enable 2FA
qr_code = await enable_2fa(user_id)

# Verify 2FA
await verify_2fa(user_id, code='123456')

2. Authorization

RBAC (Role-Based Access Control)

permissions:
  roles:
    admin:
      - "*"

    manager:
      - contact:view
      - contact:create
      - contact:update
      - deal:*

    user:
      - contact:view_own

ABAC (Attribute-Based Access Control)

permissions:
  rules:
    - name: Can edit own contacts
      effect: allow
      actions: [contact:update]
      conditions:
        contact.owner_id: "{{user.id}}"

RLS (Row-Level Security)

-- PostgreSQL RLS
CREATE POLICY contact_isolation ON contacts
  USING (owner_id = current_setting('app.user_id')::uuid);

3. Encryption

In Transit: TLS 1.3
At Rest: AES-256
Passwords: Argon2

from cifra.crypto import hash_password, verify_password

# Hash password
hashed = hash_password('SecurePass123!')

# Verify
is_valid = verify_password('SecurePass123!', hashed)

4. OWASP Top 10

Угроза Защита Статус
A01: Broken Access Control RBAC + ABAC + RLS
A02: Cryptographic Failures TLS 1.3, AES-256
A03: Injection Parameterized queries
A07: Auth Failures OAuth2, 2FA

5. Compliance


Следующий документ: API_AND_INTEGRATION.md →