Harden the rest server with authenticated - #108
Open
gloskull wants to merge 3 commits into
Open
Conversation
…lti-tenant controls Add production-grade multi-tenancy, API key and OIDC principal authentication, scope-based RBAC, key rotation and revocation, durable priority job queueing, worker lease and heartbeat tracking, crash recovery, cancellation, tenant sandbox file isolation, safe zip archive extraction with zip bomb defense, error sanitization, multi-tenant quota controls, audit logging, status streaming, health/readiness probes, and operational metrics. Co-authored-by: gloskull <189399494+gloskull@users.noreply.github.com>
…on-quotas-530920321138634004 Harden REST Server with Authenticated Queues, Isolation, and Multi-Tenant Controls
Contributor
|
@gloskull Fix conflicts |
Author
|
Hello @Nanle-code , all conflicts FIXED. Please merge and give a high review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Harden REST Server with Authenticated Queues, Isolation, and Multi-Tenant Controls (#98)
Architecture Overview
This PR hardens @chainproof/server and @chainproof/core to deliver a production-grade multi-tenant scanning platform. Key features include:
Principals: Principal model supporting roles (admin, tenant-admin, operator, viewer) and fine-grained scopes (scan:create, scan:read, scan:cancel, scan:delete, jobs:manage, metrics:read, audit:read, keys:manage, tenant:manage).
API Key Management: ApiKeyManager featuring SHA-256 hashed storage, cp_live_ prefixing, scope authorization, key rotation with configurable grace period, and instant key revocation.
OIDC Claims: OIDCVerifier for JWT claim validation (sub, iss, aud, tenant_id, roles, scopes).
Durable Storage: DurableJobStore providing atomic snapshot disk persistence and state recovery across server restarts.
Queue Scheduler: JobQueueManager handling priority scheduling (0=critical first), idempotencyKey deduplication within active retention windows, status transitions (queued, running, completed, failed, cancelled, timed_out), job filtering/pagination, and retention purging.
Worker & Leases: QueueWorker and LeaseManager managing timed leases, 5s heartbeats, AbortSignal timeout enforcement, user job cancellation, auto-retries, and automatic stale lease crash recovery sweeps.
SSE Status Streaming: Real-time progress and completion streaming via Server-Sent Events (GET /jobs/:id/stream).
Sandbox Workspaces: TenantSandbox isolating files in per-job directories (chainproof-sandboxes/tenant-/job-), scrubbing environment variables, restricting subprocesses, and guaranteeing temp directory cleanup.
Safe Archive Extraction: SafeArchiveExtractor providing zip bomb protection (max 100:1 compression ratio, max 50MB total uncompressed size, max 10MB single file size, max 500 files) and path traversal prevention (.., absolute paths, symlink targets).
Error Sanitizer: ErrorSanitizer scrubbing local host filesystem paths, credentials, and API keys from error messages, stack traces, and audit logs.
Tenant Policy Enforcer: TenantPolicyEnforcer enforcing tenant policies (e.g. allowLLM: false default).
Quota Manager: Enforces max concurrent active jobs, job submission rate limit per window, storage limits, and compute time limits with structured JSON error responses (429 / 413).
Audit Logger: AuditLogger recording structured, sanitized audit events for auth, job submissions, cancellations, deletions, quota violations, and key rotation/revocation.
/jobs: Submit (POST), List (GET), Status & SSE Stream (GET /jobs/:id, GET /jobs/:id/stream), Cancel (POST /jobs/:id/cancel), Delete (DELETE /jobs/:id).
/auth/keys: Key generation, list, rotation, revocation (POST, GET, DELETE).
/audit: Query audit log events (GET /audit).
/health: Liveness (/health/live) and Readiness (/health/ready).
/metrics: Tenant queue stats, quota usage, process metrics (GET /metrics).
Verification & Test Evidence
Created comprehensive unit and integration test suites:
packages/core/src/tests/auth.test.ts
packages/core/src/tests/queue.test.ts
packages/core/src/tests/isolation.test.ts
packages/core/src/tests/quota.test.ts
packages/core/src/tests/audit.test.ts
packages/server/src/tests/server-hardening.test.ts
Automated checks executed and passing:
npm run build (All workspaces pass)
npm run lint (Zero errors)
npm test (All 42 test suites pass)
npm run test:ci --workspace=packages/core (100% test pass rate)
Complete architecture and operational guide written in docs/server-hardening.md.
Closes #98