Skip to content

feat(t8s-cluster/management-cluster): allow auditing of kcp clusters (opt-in)#2039

Merged
cwrau merged 1 commit intomainfrom
feat/t8s-cluster/allow-auditing-kcp-clusters
Apr 14, 2026
Merged

feat(t8s-cluster/management-cluster): allow auditing of kcp clusters (opt-in)#2039
cwrau merged 1 commit intomainfrom
feat/t8s-cluster/allow-auditing-kcp-clusters

Conversation

@cwrau
Copy link
Copy Markdown
Member

@cwrau cwrau commented Apr 8, 2026

This is to be used for management clusters

Summary by CodeRabbit

  • New Features
    • Configurable API server audit logging via a new controlPlane.audit setting (default: false). Opt-in for kubeadm control planes; hosted control planes remain audit-enabled.
    • Audit policy and webhook support added, including optional webhook token sourced from cluster secrets and dynamic inclusion of audit-related files.

Copilot AI review requested due to automatic review settings April 8, 2026 09:04
@cwrau cwrau enabled auto-merge April 8, 2026 09:04
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d55acc53-8df8-4a76-83e8-b4b3c561f647

📥 Commits

Reviewing files that changed from the base of the PR and between b3cad26 and 0e7c808.

📒 Files selected for processing (5)
  • charts/t8s-cluster/templates/management-cluster/clusterClass/_helpers.tpl
  • charts/t8s-cluster/templates/management-cluster/clusterClass/hostedControlPlaneTemplate/_hostedControlPlaneTemplateSpec.yaml
  • charts/t8s-cluster/templates/management-cluster/clusterClass/kubeadmControlPlaneTemplate/_helpers.tpl
  • charts/t8s-cluster/values.schema.json
  • charts/t8s-cluster/values.yaml
✅ Files skipped from review due to trivial changes (2)
  • charts/t8s-cluster/values.yaml
  • charts/t8s-cluster/values.schema.json

📝 Walkthrough

Walkthrough

Adds optional control-plane audit support to the t8s-cluster Helm chart: new helper templates and files for audit policy/webhook, conditional API server args and dynamic file emission, a kubeadmControlPlaneTemplate change to accept contentFrom files, and a new controlPlane.audit schema/value toggle.

Changes

Cohort / File(s) Summary
API Server Audit Helpers
charts/t8s-cluster/templates/management-cluster/clusterClass/_helpers.tpl
Added multiple audit-related helper templates (filenames, absolute paths, auditPolicyRules, audit-webhook.kubeconfig) and conditional logic that injects API server args for audit-policy-file and audit-webhook-config-file when .Values.controlPlane.audit / .context.Values.controlPlane.audit is enabled.
Hosted Control Plane Template
charts/t8s-cluster/templates/management-cluster/clusterClass/hostedControlPlaneTemplate/_hostedControlPlaneTemplateSpec.yaml
Replaced inline API server audit policy YAML with a call to the centralized t8s-cluster.clusterClass.apiServer.auditPolicyRules helper to render policy rules.
Kubeadm ControlPlane dynamic files
charts/t8s-cluster/templates/management-cluster/clusterClass/kubeadmControlPlaneTemplate/_helpers.tpl
Updated files helper to accept dynamic apiServer.dynamicFiles entries that may provide contentFrom (secret-sourced) or content, changing emitted files structure accordingly.
Values and Schema
charts/t8s-cluster/values.schema.json, charts/t8s-cluster/values.yaml
Added controlPlane.audit boolean (default: false) to values and JSON schema to opt in audit logging for kubeadm control planes.
Dynamic file emission
charts/t8s-cluster/templates/management-cluster/clusterClass/_helpers.tpl (same file as helpers)
Changed apiServer.dynamicFiles handling to build a $files map and conditionally append audit policy/webhook/token entries; webhook token file can be populated via contentFrom from wazuh-audit-webhook secret.`

Sequence Diagram(s)

sequenceDiagram
  participant Helm as Helm renderer
  participant KubeAPIServer as kube-apiserver (control plane)
  participant AuditWebhook as Audit Webhook
  participant SecretStore as Secret (wazuh-audit-webhook)

  Helm->>Helm: Render templates (helpers produce audit files & kubeconfig) 
  Helm->>KubeAPIServer: Deploy control plane with --audit-policy-file and --audit-webhook-config-file args and mounted files
  KubeAPIServer->>AuditWebhook: Send audit events (per policy)
  AuditWebhook->>SecretStore: Read token from mounted token file (populated via secret)
  AuditWebhook-->>KubeAPIServer: Acknowledge / accept audit payloads
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • tasches
  • marvinWolff
  • teutonet-bot

Poem

🐰 I hopped through templates, neat and spry,
Wove policies where secrets lie.
Args now point where audits play,
A webhook listens—hooray, hooray! 🐇

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing optional audit logging for KCP (kubeadm control plane) clusters. It matches the core functionality across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/t8s-cluster/allow-auditing-kcp-clusters

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces audit logging for the control plane, adding several helper templates to manage audit policies and webhook configurations while refactoring the hosted control plane template to use these shared definitions. The review feedback identifies a bug in the mustMerge function usage that will likely cause template failures, points out that using lookup with required will break helm template and dry-run operations, recommends making the hardcoded Wazuh webhook URL configurable, and warns of potential argument conflicts for hosted control planes.

Comment thread charts/t8s-cluster/templates/management-cluster/clusterClass/_helpers.tpl Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in switch to enable Kubernetes API server audit logging for kubeadm control planes in the t8s-cluster management-cluster ClusterClass, while keeping hosted control planes audited by default.

Changes:

  • Introduces controlPlane.audit (default false) in chart values and schema.
  • Refactors hosted control plane audit policy rules into a shared helper template.
  • Adds templated generation of audit policy + webhook kubeconfig files and corresponding kube-apiserver flags when auditing is enabled.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
charts/t8s-cluster/values.yaml Adds controlPlane.audit value (default off).
charts/t8s-cluster/values.schema.json Adds schema for controlPlane.audit with behavior description.
charts/t8s-cluster/templates/management-cluster/clusterClass/hostedControlPlaneTemplate/_hostedControlPlaneTemplateSpec.yaml Replaces inline audit policy rules with shared helper include.
charts/t8s-cluster/templates/management-cluster/clusterClass/_helpers.tpl Adds audit policy/webhook helpers, dynamically injects audit files and kube-apiserver args when enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread charts/t8s-cluster/templates/management-cluster/clusterClass/_helpers.tpl Outdated
Comment thread charts/t8s-cluster/templates/management-cluster/clusterClass/_helpers.tpl Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@charts/t8s-cluster/templates/management-cluster/clusterClass/_helpers.tpl`:
- Around line 221-224: The audit args block currently runs for all control
planes when .context.Values.controlPlane.audit is true; wrap the existing
conditional to also check that the control plane is not hosted by gating with
not .context.Values.controlPlane.hosted so the audit-policy-file and
audit-webhook-config-file assignments (the lines setting $args with include
"t8s-cluster.clusterClass.apiServer.auditPolicyPath" and include
"t8s-cluster.clusterClass.apiServer.auditWebhookConfigPath") only execute for
kubeadm control planes; apply the same not-hosted guard to the other audit
branch around the include calls at the second location (the block spanning the
include calls at the later lines) so hosted control planes don’t get duplicate
audit paths or ConfigMap token injection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f8af4685-26bc-42c8-b118-e422bd022aa2

📥 Commits

Reviewing files that changed from the base of the PR and between c2f224a and b3cad26.

📒 Files selected for processing (4)
  • charts/t8s-cluster/templates/management-cluster/clusterClass/_helpers.tpl
  • charts/t8s-cluster/templates/management-cluster/clusterClass/hostedControlPlaneTemplate/_hostedControlPlaneTemplateSpec.yaml
  • charts/t8s-cluster/values.schema.json
  • charts/t8s-cluster/values.yaml

…(opt-in)

This is to be used for management clusters
@cwrau cwrau force-pushed the feat/t8s-cluster/allow-auditing-kcp-clusters branch from b3cad26 to 0e7c808 Compare April 9, 2026 11:31
@cwrau cwrau added this pull request to the merge queue Apr 14, 2026
Merged via the queue into main with commit 3387520 Apr 14, 2026
32 checks passed
@cwrau cwrau deleted the feat/t8s-cluster/allow-auditing-kcp-clusters branch April 14, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants