# kind cluster for the Part 05 audit and detection lab (chapter 05.08, tier A).
# The API server writes an audit log and reads the policy in
# examples/security-lab/audit/audit-policy.yaml. The configuration follows
# kind's Auditing page, with the kubeadm v1beta4 list form for extraArgs.
#
# Replace AUDIT_DIR with the absolute path of the directory that holds
# audit-policy.yaml on the machine that runs kind, then create the cluster:
#
#   kind create cluster --config audit-cluster.yaml
#
# Run the labs only against a cluster you own. The lab deletes its own
# namespaces, and deletes this whole cluster when it finishes.
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: p05-08
networking:
  # A fixed port, so a lab host can forward it. Pick a free port on that host.
  apiServerPort: 36081
nodes:
  - role: control-plane
    image: kindest/node:v1.37.0@sha256:a1ed56cfb0e7b93589bdf97c8cd566405a265939e3620fc4f5de89adff580ae5
    extraMounts:
      - hostPath: AUDIT_DIR/audit-policy.yaml
        containerPath: /etc/kubernetes/policies/audit-policy.yaml
        readOnly: true
    kubeadmConfigPatches:
      # A fresh node unpacks the control-plane images on first start. On a
      # loaded or slow disk the API server can take minutes to answer, and
      # kubeadm's one-minute default for its first API call gives up first.
      - |
        apiVersion: kubeadm.k8s.io/v1beta4
        kind: InitConfiguration
        timeouts:
          controlPlaneComponentHealthCheck: 10m
          kubernetesAPICall: 10m
      - |
        apiVersion: kubeadm.k8s.io/v1beta4
        kind: ClusterConfiguration
        apiServer:
          extraArgs:
            - name: audit-policy-file
              value: /etc/kubernetes/policies/audit-policy.yaml
            - name: audit-log-path
              value: /var/log/kubernetes/kube-apiserver-audit.log
          extraVolumes:
            - name: audit-policies
              hostPath: /etc/kubernetes/policies
              mountPath: /etc/kubernetes/policies
              readOnly: true
              pathType: DirectoryOrCreate
            - name: audit-logs
              hostPath: /var/log/kubernetes
              mountPath: /var/log/kubernetes
              readOnly: false
              pathType: DirectoryOrCreate
