homek8s/apps/base/secops/clusterrole.yaml
Lance Walters 2e52bfad24 apps(secops): scoped read-only auditor ServiceAccount + ClusterRole (F8)
Security runs had no read-only identity: every audit ran as kubernetes-admin
(system:masters), the identity that can delete the cluster, so the auditor was
the largest privilege holder in the environment.

New ns secops with SA secops-auditor bound to a from-scratch ClusterRole:

  get,list,watch  pods services endpoints events configmaps namespaces nodes
  get,list,watch  * in apps, batch, networking.k8s.io,
                    gateway.networking.k8s.io, cilium.io
  get             pods/log

Deliberately absent: secrets (all verbs), pods/exec, pods/attach, every write
verb, impersonate/escalate/bind. Not bound to view/edit/admin (all three carry
Secrets; edit reads Secret data).

The bearer token is a credential and is generated out of band into
~/.kube/secops.yaml (mode 600) — see the SA manifest comment for the one-liner.
2026-11-27 00:08:14 -05:00

48 lines
1.8 KiB
YAML

# Deliberately built from scratch: do NOT swap this for the built-in `view`,
# `edit` or `admin` ClusterRoles. All three include Secrets (`view` can read
# Secret metadata and `edit` can read Secret data), which defeats the purpose of
# a read-only audit identity. `edit` is effectively read-all + write.
#
# Deliberately absent, and must stay absent:
# - secrets (would expose every credential in the cluster)
# - pods/exec, pods/attach (would be arbitrary code execution in any pod,
# and the flow collector pattern — socket mount —
# exists precisely so hubble needs no exec)
# - events create/patch (only get/list/watch)
# - any write verb on any resource
#
# kubectl auth can-i / kubectl logs still work: SelfSubjectAccessReview and API
# discovery come from the default `system:basic-user` / `system:discovery`
# bindings to system:authenticated, not from this role.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: secops-auditor
labels:
app.kubernetes.io/part-of: secops
rules:
- apiGroups: [""]
resources:
- pods
- services
- endpoints
- events
- configmaps
- namespaces
- nodes
verbs: ["get", "list", "watch"]
# Pod logs, read only. No `pods/exec`, no `pods/attach`.
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get"]
# Workload / policy / ingress / CNI object models, read only. Group-scoped
# wildcard so the identity follows CRD additions in these groups without
# another RBAC change (none of them carry Secret data).
- apiGroups:
- apps
- batch
- networking.k8s.io
- gateway.networking.k8s.io
- cilium.io
resources: ["*"]
verbs: ["get", "list", "watch"]