How richardoc/kube-audit-rest works
Major Components
• Kubernetes API Server (external) – Sends AdmissionReview requests via a ValidatingWebhook configuration.
• kube-audit-rest Service – Represented as a containerized service deployed on Kubernetes.
• HTTP Listener Module – Within the service, this component listens for webhook requests over HTTPS (using TLS certificates specified through flags).
• Event Processor – Responsible for processing and filtering the incoming AdmissionReview requests.
• Audit Writer Subsystem – Contains different writers (e.g., disk_writer, stderr_writer, and common_writer) that handle how and where audit events are written.
• Metrics Exporter – Exposes application-level metrics (using the prometheus client) and Go runtime metrics.
• Logging – Uses structured logging (with zap) that is integrated into many system modules.
Interactions and Relationships
• The HTTP Listener forwards inbound requests to the Event Processor.
• The Event Processor then directs processed audit events to the Audit Writer.
• Simultaneously, metrics are recorded and exposed through the Metrics Exporter, and logging is carried out throughout the components.
• Optionally, include configuration and management flows (e.g., container images – “-distroless” or “-alpine” variants – are built with Dockerfiles and deployed via Kubernetes manifests).
Architectural Patterns and Design Principles
• Modular Design: The system is clearly broken into discrete internal packages (each having well-defined interfaces such as iaudit_writer.go, ievent_processor.go, etc.) making it easier to understand, test, and maintain.
• Interface-driven Development: Interfaces for audit writing, metrics, HTTP listening, and event processing allow swapping or extending functionality (e.g., choosing between disk or stderr logging).
• Containerization and Kubernetes-Native Deployment: Dockerfiles, Kubernetes YAML in the k8s directory, and examples for integration with Elastic Stack detail how the service should be built and deployed.
• Observability: Integrated Prometheus metrics and structured logging emphasize monitoring and observability as core design principles.
• TLS and Security: With certificate management (and associated examples), the design ensures secure communication between the Kubernetes API server and the service.
Detail Relevant Technologies, Frameworks, and Libraries
• Programming Language: Go (with dependencies managed via go.mod and go.sum).
• Logging: zap for structured logging.
• Metrics and Instrumentation: Prometheus client for metrics collection.
• Containerization: Docker (with both distroless and alpine Dockerfiles).
• Kubernetes Webhook Integration: Use of ValidatingWebhookConfiguration to capture mutating/creation events from Kubernetes.