459 lines
15 KiB
Markdown
459 lines
15 KiB
Markdown
# TT-008 Final Evidence Review
|
|
# TT-008 Финальная проверка доказательств
|
|
|
|
## 1. Executive Summary / Резюме
|
|
|
|
| Пункт / Item | Значение / Value |
|
|
|--------------|------------------|
|
|
| Дата / Date | 2026-08-06 |
|
|
| Тип / Type | Evidence-only verification |
|
|
| Код изменён / Code modified | НЕТ / NO |
|
|
|
|
**Final Verdict: READY FOR HUMAN CODE REVIEW**
|
|
|
|
Все критические требования подтверждены source/test/migration evidence.
|
|
|
|
All critical requirements confirmed by source/test/migration evidence.
|
|
|
|
---
|
|
|
|
## 2. Principal & Authentication
|
|
|
|
### get_current_principal()
|
|
|
|
| Property | Evidence |
|
|
|----------|----------|
|
|
| File | `request_app/core/auth.py:110-141` |
|
|
| Returns | `Union[User, ServiceAccount]` |
|
|
| User detection | JWT decode via `get_user_id_from_token()` |
|
|
| SA detection | `identifier:secret` format in Authorization header |
|
|
| Invalid | Raises HTTPException 401 |
|
|
|
|
### Flow
|
|
|
|
```text
|
|
Credential/Session
|
|
↓
|
|
get_current_principal() [auth.py:110]
|
|
↓
|
|
Principal (User or ServiceAccount)
|
|
↓
|
|
compute_effective_policy() [permissions.py:24]
|
|
↓
|
|
require_permission() [auth.py:186]
|
|
```
|
|
|
|
### Absence of second security entry point
|
|
|
|
| Check | Status | Evidence |
|
|
|-------|--------|----------|
|
|
| `require_sa_permission` | ✅ ABSENT | Not in auth.py |
|
|
| `require_service_account_permission` | ✅ ABSENT | Not in auth.py |
|
|
| Separate SA authorization engine | ✅ ABSENT | Single `compute_effective_policy()` |
|
|
| Bypass `require_permission()` | ✅ ABSENT | SA uses same function |
|
|
|
|
---
|
|
|
|
## 3. Unified Authorization
|
|
|
|
### Single require_permission()
|
|
|
|
| Property | Evidence |
|
|
|----------|----------|
|
|
| File | `request_app/core/auth.py:186-209` |
|
|
| Accepts | `Union[User, ServiceAccount]` via `get_current_principal()` |
|
|
| Uses | `compute_effective_policy(principal, db)` |
|
|
|
|
### isinstance() usage
|
|
|
|
| Location | Purpose | Creates separate path? |
|
|
|----------|---------|------------------------|
|
|
| `permissions.py:36-43` | Role resolution adapter | NO — same authorization engine |
|
|
|
|
This is a local adapter for type-specific role resolution, NOT a separate authorization path.
|
|
|
|
---
|
|
|
|
## 4. ServiceAccount → Role → Permission
|
|
|
|
### Chain
|
|
|
|
```text
|
|
ServiceAccount
|
|
↓
|
|
ServiceAccountRole (service_account_roles table)
|
|
↓
|
|
Role (roles table)
|
|
↓
|
|
RolePermission (role_permissions table)
|
|
↓
|
|
Permission (permissions table)
|
|
```
|
|
|
|
### Evidence
|
|
|
|
| Component | File | Verified |
|
|
|-----------|------|----------|
|
|
| ServiceAccountRole model | `models/service_account_role.py` | ✅ |
|
|
| FK → roles.id | `service_account_role.py:15` | ✅ CASCADE |
|
|
| FK → service_accounts.id | `service_account_role.py:14` | ✅ CASCADE |
|
|
| Unique constraint | `service_account_role.py:20` | ✅ |
|
|
| No SA → Permission bypass | `permissions.py:36-43` | ✅ |
|
|
|
|
---
|
|
|
|
## 5. Management API
|
|
|
|
### Endpoints
|
|
|
|
| Operation | Method | Path | File:Line | Auth |
|
|
|-----------|--------|------|-----------|------|
|
|
| Create | POST | `/service-accounts` | `service_accounts.py:56` | `get_current_user` |
|
|
| List | GET | `/service-accounts` | `service_accounts.py:113` | `get_current_user` |
|
|
| Get | GET | `/service-accounts/{id}` | `service_accounts.py:125` | `get_current_user` |
|
|
| Disable | POST | `/service-accounts/{id}/disable` | `service_accounts.py:138` | `get_current_user` |
|
|
| Enable | POST | `/service-accounts/{id}/enable` | `service_accounts.py:159` | `get_current_user` |
|
|
| Revoke | POST | `/service-accounts/{id}/revoke` | `service_accounts.py:180` | `get_current_user` |
|
|
| Rotate | POST | `/service-accounts/{id}/rotate-credential` | `service_accounts.py:201` | `get_current_user` |
|
|
| Roles | PUT | `/service-accounts/{id}/roles` | `service_accounts.py:223` | `get_current_user` |
|
|
|
|
### Secret exposure
|
|
|
|
| Endpoint | Returns secret? | Evidence |
|
|
|----------|-----------------|----------|
|
|
| Create | YES (once) | `service_accounts.py:108` |
|
|
| List | NO | `service_accounts.py:121` — `_sa_to_dict()` |
|
|
| Get | NO | `service_accounts.py:135` — `_sa_to_dict()` |
|
|
| Disable/Enable/Revoke | NO | Returns `_sa_to_dict()` |
|
|
| Rotate | YES (once) | `service_accounts.py:219` |
|
|
|
|
---
|
|
|
|
## 6. Credential Security
|
|
|
|
### Generation
|
|
|
|
| Property | Evidence |
|
|
|----------|----------|
|
|
| Source | `secrets.token_urlsafe(48)` — `service_account_auth.py:20` |
|
|
| Length | 48 bytes (~64 chars base64) |
|
|
| Algorithm | Cryptographically random |
|
|
|
|
### Storage
|
|
|
|
| Property | Evidence |
|
|
|----------|----------|
|
|
| Hash only | `service_account_auth.py:48` — `hash_secret(secret)` |
|
|
| Algorithm | bcrypt — `service_account_auth.py:24` |
|
|
| Plaintext stored? | NO — only `secret_hash` in DB |
|
|
|
|
### Authentication
|
|
|
|
| Step | Evidence |
|
|
|------|----------|
|
|
| Identifier lookup | `service_account_auth.py:89` |
|
|
| Lifecycle check | `service_account_auth.py:94` |
|
|
| Credential state check | `service_account_auth.py:110-113` |
|
|
| Secret verification | `service_account_auth.py:127` — bcrypt |
|
|
|
|
### Rotation evidence
|
|
|
|
| Requirement | Test | Status |
|
|
|-------------|------|--------|
|
|
| Old credential → DENY | `test_credential_rotation:324` | ✅ PASS |
|
|
| New credential → ALLOW | `test_credential_rotation:328` | ✅ PASS |
|
|
|
|
---
|
|
|
|
## 7. Lifecycle
|
|
|
|
### State machine
|
|
|
|
| State | Can authenticate? | Allowed transitions |
|
|
|-------|-------------------|---------------------|
|
|
| CREATED | NO | ACTIVE, REVOKED |
|
|
| ACTIVE | YES | DISABLED, REVOKED |
|
|
| DISABLED | NO | ACTIVE, REVOKED |
|
|
| REVOKED | NO | (terminal) |
|
|
|
|
### Evidence
|
|
|
|
| Requirement | Test | Status |
|
|
|-------------|------|--------|
|
|
| CREATED cannot authenticate | `service_account_auth.py:94` | ✅ |
|
|
| ACTIVE can authenticate | `test_credential_validation:238` | ✅ |
|
|
| DISABLED cannot authenticate | `test_disabled_account_cannot_authenticate:271` | ✅ |
|
|
| REVOKED cannot authenticate | `test_revoked_account_cannot_authenticate:286` | ✅ |
|
|
| REVOKED is terminal | `test_revoked_is_terminal:186` | ✅ |
|
|
| Lifecycle transitions | `test_service_account_lifecycle_transitions:159` | ✅ |
|
|
|
|
---
|
|
|
|
## 8. Audit
|
|
|
|
### Model
|
|
|
|
| Property | Evidence |
|
|
|----------|----------|
|
|
| File | `models/service_account_audit.py` |
|
|
| Table | `service_account_audit_events` |
|
|
| Fields | id, service_account_id, event_type, message, performed_by, extra_data |
|
|
|
|
### Events tracked
|
|
|
|
| Event | Evidence |
|
|
|-------|----------|
|
|
| created | `service_accounts.py:98` |
|
|
| activated | `service_accounts.py:99` |
|
|
| disabled | `service_accounts.py:153` |
|
|
| enabled | `service_accounts.py:174` |
|
|
| revoked | `service_accounts.py:195` |
|
|
| credential_issued | `service_account_auth.py:64-69` |
|
|
| credential_rotated | `service_account_auth.py:177-182` |
|
|
| credential_revoked | `service_account_auth.py:199-204` |
|
|
| role_assigned | `service_accounts.py:245` |
|
|
| authentication_success | `service_account_auth.py:142-146` |
|
|
| authentication_failure | `service_account_auth.py:96-102` |
|
|
|
|
### Secret in audit?
|
|
|
|
| Check | Evidence |
|
|
|-------|----------|
|
|
| No plaintext secret | Audit messages contain only `credential_id`, not secret |
|
|
| No password | Not in audit model |
|
|
| No token material | Not in audit model |
|
|
|
|
---
|
|
|
|
## 9. Platform Independence
|
|
|
|
### Authentication path
|
|
|
|
```text
|
|
ServiceAccount credential
|
|
↓
|
|
validate_credential() [service_account_auth.py:78]
|
|
↓
|
|
DB lookup (local)
|
|
↓
|
|
bcrypt verification (local)
|
|
↓
|
|
ALLOW / DENY
|
|
```
|
|
|
|
### Evidence
|
|
|
|
| Check | Status | Evidence |
|
|
|-------|--------|----------|
|
|
| Platform API call | ✅ ABSENT | `service_account_auth.py` — no HTTP calls |
|
|
| Remote user lookup | ✅ ABSENT | Only local DB queries |
|
|
| Platform JWT validation | ✅ ABSENT | Uses bcrypt, not JWT |
|
|
| Platform sync | ✅ ABSENT | No sync mechanism |
|
|
|
|
### Test
|
|
|
|
| Test | File | Status |
|
|
|------|------|--------|
|
|
| Platform outage | `test_service_account_auth_no_platform_dependency:425` | ✅ PASS |
|
|
|
|
---
|
|
|
|
## 10. Platform Boundary
|
|
|
|
### Ownership
|
|
|
|
| Component | Owner | Evidence |
|
|
|-----------|-------|----------|
|
|
| ServiceAccount | Module | `models/service_account.py` |
|
|
| Credentials | Module | `models/service_account_credential.py` |
|
|
| Roles | Module | `models/service_account_role.py` |
|
|
| Audit | Module | `models/service_account_audit.py` |
|
|
|
|
### Direct DB access
|
|
|
|
| Check | Status | Evidence |
|
|
|-------|--------|----------|
|
|
| Platform → Module DB | ✅ ABSENT | No direct DB access mechanism |
|
|
|
|
---
|
|
|
|
## 11. Migration
|
|
|
|
### Revision chain
|
|
|
|
| Property | Value |
|
|
|----------|-------|
|
|
| Revision | `002_add_service_accounts` |
|
|
| Down revision | `001_add_permissions` |
|
|
| File | `migrations/alembic/versions/002_add_service_accounts.py` |
|
|
|
|
### Tables created
|
|
|
|
| Table | Columns | Verified |
|
|
|-------|---------|----------|
|
|
| service_accounts | id, identifier, display_name, description, state, module_id, created_by, last_authenticated_at, created_at, updated_at | ✅ |
|
|
| service_account_credentials | id, service_account_id, credential_id, secret_hash, state, issued_at, expires_at, revoked_at, rotated_at, issued_by, created_at, updated_at | ✅ |
|
|
| service_account_roles | id, service_account_id, role_id, created_at, updated_at | ✅ |
|
|
| service_account_audit_events | id, service_account_id, event_type, message, performed_by, extra_data, created_at, updated_at | ✅ |
|
|
|
|
### Constraints
|
|
|
|
| Table | PK | FK | Unique |
|
|
|-------|----|----|--------|
|
|
| service_accounts | id | - | identifier (index) |
|
|
| service_account_credentials | id | service_account_id → service_accounts.id CASCADE | credential_id (index) |
|
|
| service_account_roles | id | service_account_id → service_accounts.id CASCADE, role_id → roles.id CASCADE | (service_account_id, role_id) |
|
|
| service_account_audit_events | id | service_account_id → service_accounts.id CASCADE | - |
|
|
|
|
### Upgrade/Downgrade
|
|
|
|
| Operation | Status | Evidence |
|
|
|-----------|--------|----------|
|
|
| Upgrade | ✅ VERIFIED | 4 tables created |
|
|
| Schema | ✅ VERIFIED | All columns match models |
|
|
| Downgrade | ✅ VERIFIED | 4 tables removed |
|
|
| Prerequisite integrity | ✅ VERIFIED | users, roles, permissions intact |
|
|
|
|
---
|
|
|
|
## 12. Test Evidence
|
|
|
|
### Concrete test matrix
|
|
|
|
| Requirement | Test file | Test name | Status |
|
|
|-------------|-----------|-----------|--------|
|
|
| Model exists | test_service_accounts.py | test_service_account_model_exists | PASS |
|
|
| Credential model | test_service_accounts.py | test_service_account_credential_model_exists | PASS |
|
|
| Role model | test_service_accounts.py | test_service_account_role_model_exists | PASS |
|
|
| Audit model | test_service_accounts.py | test_service_account_audit_model_exists | PASS |
|
|
| Lifecycle states | test_service_accounts.py | test_service_account_lifecycle_states | PASS |
|
|
| Create | test_service_accounts.py | test_service_account_creation | PASS |
|
|
| Unique identifier | test_service_accounts.py | test_service_account_unique_identifier | PASS |
|
|
| Lifecycle transitions | test_service_accounts.py | test_service_account_lifecycle_transitions | PASS |
|
|
| REVOKED terminal | test_service_accounts.py | test_revoked_is_terminal | PASS |
|
|
| Credential creation | test_service_accounts.py | test_credential_creation | PASS |
|
|
| Secret once | test_service_accounts.py | test_credential_one_time_secret | PASS |
|
|
| Valid auth | test_service_accounts.py | test_credential_validation | PASS |
|
|
| Invalid secret | test_service_accounts.py | test_credential_invalid_secret | PASS |
|
|
| Disabled deny | test_service_accounts.py | test_disabled_account_cannot_authenticate | PASS |
|
|
| Revoked deny | test_service_accounts.py | test_revoked_account_cannot_authenticate | PASS |
|
|
| Rotation | test_service_accounts.py | test_credential_rotation | PASS |
|
|
| Old credential denied | test_service_accounts.py | test_credential_rotation:324 | PASS |
|
|
| New credential accepted | test_service_accounts.py | test_credential_rotation:328 | PASS |
|
|
| Plaintext absent | test_service_accounts.py | test_plaintext_not_stored | PASS |
|
|
| SA with role | test_service_accounts.py | test_service_account_with_role | PASS |
|
|
| SA no role | test_service_accounts.py | test_service_account_without_role | PASS |
|
|
| SA multiple roles | test_service_accounts.py | test_service_account_multiple_roles | PASS |
|
|
| Same engine | test_service_accounts.py | test_same_authorization_engine | PASS |
|
|
| Platform outage | test_service_accounts.py | test_service_account_auth_no_platform_dependency | PASS |
|
|
|
|
### Missing tests (EVIDENCE GAP)
|
|
|
|
| Requirement | Status |
|
|
|-------------|--------|
|
|
| Management API create authorization | EVIDENCE GAP |
|
|
| Management API list no secret | EVIDENCE GAP |
|
|
| Management API get no secret | EVIDENCE GAP |
|
|
| Management API disable | EVIDENCE GAP |
|
|
| Management API enable | EVIDENCE GAP |
|
|
| Management API revoke | EVIDENCE GAP |
|
|
| Management API rotate | EVIDENCE GAP |
|
|
| Management API role assignment | EVIDENCE GAP |
|
|
| Management API unauthorized access | EVIDENCE GAP |
|
|
| User require_permission | EVIDENCE GAP |
|
|
| SA require_permission | EVIDENCE GAP |
|
|
|
|
---
|
|
|
|
## 13. Break-Glass Negative Verification
|
|
|
|
| Check | Status | Evidence |
|
|
|-------|--------|----------|
|
|
| emergency_admin | ✅ ABSENT | Not in codebase |
|
|
| Vendor root | ✅ ABSENT | Not in codebase |
|
|
| Break-Glass endpoint | ✅ ABSENT | Not in codebase |
|
|
| Emergency Authority | ✅ ABSENT | Not in codebase |
|
|
| Recovery Grant | ✅ ABSENT | Not in codebase |
|
|
| Vendor authorization artifact | ✅ ABSENT | Not in codebase |
|
|
| Emergency credential | ✅ ABSENT | Not in codebase |
|
|
| Licensing gate | ✅ ABSENT | Not in codebase |
|
|
|
|
---
|
|
|
|
## 14. Security Boundary
|
|
|
|
### Security-sensitive mutable fields
|
|
|
|
| Field | Table | Risk |
|
|
|-------|-------|------|
|
|
| state | service_accounts | Lifecycle bypass |
|
|
| state | service_account_credentials | Credential theft |
|
|
| secret_hash | service_account_credentials | Credential theft |
|
|
| service_account_id + role_id | service_account_roles | Permission escalation |
|
|
|
|
### Limitation
|
|
|
|
```text
|
|
Database stores state and audit
|
|
≠
|
|
Database alone establishes Vendor authority
|
|
```
|
|
|
|
SQL tampering is NOT fully prevented. This is a documented limitation for future authorization artifact work.
|
|
|
|
---
|
|
|
|
## 15. Evidence Gaps
|
|
|
|
| Gap | Severity | Description |
|
|
|-----|----------|-------------|
|
|
| Management API tests | MEDIUM | No tests for management API endpoints |
|
|
| User require_permission test | MEDIUM | No test proving User uses require_permission() |
|
|
| SA require_permission test | MEDIUM | No test proving SA uses require_permission() |
|
|
|
|
---
|
|
|
|
## 16. Findings
|
|
|
|
### Positive
|
|
|
|
1. Single `require_permission()` for User and ServiceAccount
|
|
2. `get_current_principal()` as unified auth entry point
|
|
3. No `require_sa_permission()` or equivalent
|
|
4. Credential security: bcrypt, one-time secret, no plaintext storage
|
|
5. Lifecycle: CREATED/ACTIVE/DISABLED/REVOKED with terminal REVOKED
|
|
6. Audit: comprehensive event tracking
|
|
7. Platform independence: no runtime dependency
|
|
8. Migration: upgrade/downgrade verified
|
|
|
|
### Gaps
|
|
|
|
1. Management API not tested (endpoints exist but no test coverage)
|
|
2. `require_permission()` not tested with SA through API (only through `compute_effective_policy()`)
|
|
|
|
---
|
|
|
|
## 17. Final Verdict
|
|
|
|
**READY FOR HUMAN CODE REVIEW**
|
|
|
|
Критические архитектурные требования подтверждены:
|
|
- Единый authorization pipeline ✅
|
|
- Service Account ≠ User subtype ✅
|
|
- Credential security ✅
|
|
- Lifecycle ✅
|
|
- Platform independence ✅
|
|
- Migration ✅
|
|
- Break-Glass deferred ✅
|
|
|
|
Gaps are non-blocking for human code review (management API tests can be added during review).
|
|
|
|
Critical architectural requirements confirmed:
|
|
- Unified authorization pipeline ✅
|
|
- Service Account ≠ User subtype ✅
|
|
- Credential security ✅
|
|
- Lifecycle ✅
|
|
- Platform independence ✅
|
|
- Migration ✅
|
|
- Break-Glass deferred ✅
|