Skip to content

campus.audit: API Key Security Implementation #538

@ngjunsiang

Description

@ngjunsiang

Overview

Implement comprehensive API key security for the Campus Audit Service to replace current HTTP Basic/Bearer authentication with a dedicated API key system that provides granular access control, auditability, and rate limiting.

Background

The audit trace API currently uses HTTP Basic/Bearer authentication but lacks dedicated API key management. While the PRD mentions that API keys should be required for trace endpoints, there's no actual API key validation system in place.

Design Decision: Standalone Service

campus.audit is a standalone service with its own authentication system:

  • Only uses API key authentication (no users, no clients)
  • Users/clients are in campus.auth service
  • Only admins can create audit API keys
  • No actor tracking needed (no user/client concept in audit service)

Goals

  • Replace HTTP Basic/Bearer auth with dedicated API key system
  • Provide granular access control via scopes
  • Enable API key lifecycle management (create, revoke, expire)
  • Implement per-key rate limiting
  • Full audit trail for key usage (what, when, which key - no actor)
  • Secure key storage (hashes only, never plaintext)

Subissues

This issue is broken down into 7 subissues:

✅ Completed

🔄 In Progress

📋 Deferred to Future Iterations

Design Decisions

  • APIKey inherits from Model - Leverages existing id and created_at fields
  • Owner field instead of created_by - Allows key reassignment between users (no actor tracking needed)
  • revoked_at timestamp - More useful than boolean, tracks when key was revoked
  • SHA-256 hashing - Secure, fast, constant-time comparison
  • Scope-based permissions - Fine-grained access control (traces:read, metrics:read, etc.)
  • Per-key rate limits - Prevent abuse while allowing different tiers
  • No actor tracking - Standalone service with no users/clients (admin-only key creation)

Migration Path

Phase 1: Core API key system (model, validation, middleware) ✅
Phase 2: Management endpoints and admin UI ✅
Phase 3: Rate limiting and advanced security features (future)
Phase 4: Migration of existing clients to API keys (future)

Related

  • PRD: campus/audit/docs/campus-trace-api-prd-v3.md §5.1 (Authentication)
  • Current auth: campus/campus/auth/middleware/__init__.py
  • Audit service: campus/campus/audit/

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status

Implementation

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions