Skip to content

Harden the rest server with authenticated - #108

Open
gloskull wants to merge 3 commits into
StellarChainproof:masterfrom
gloskull:Harden-the-REST-Server-with-Authenticated
Open

Harden the rest server with authenticated#108
gloskull wants to merge 3 commits into
StellarChainproof:masterfrom
gloskull:Harden-the-REST-Server-with-Authenticated

Conversation

@gloskull

Copy link
Copy Markdown

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:

  1. Authentication & Scope-Based RBAC (@chainproof/core/src/auth)
    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).
  2. Durable Priority Job Queue & Worker Engine (@chainproof/core/src/queue)
    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).
  3. Tenant Isolation & Resource Safeguards (@chainproof/core/src/isolation)
    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).
  4. Quotas & Audit Events (@chainproof/core/src/quota & @chainproof/core/src/audit)
    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.
  5. Server Endpoints & Operations (@chainproof/server)
    /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

google-labs-jules Bot and others added 2 commits August 28, 2026 21:58
…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
@Nanle-code

Copy link
Copy Markdown
Contributor

@gloskull Fix conflicts

@gloskull

Copy link
Copy Markdown
Author

Hello @Nanle-code , all conflicts FIXED. Please merge and give a high review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden the REST Server with Authenticated Queues, Isolation, and Multi-Tenant Controls

2 participants