clusterrole-nonresource-urls
Wildcard or root non-resource paths grant every API server endpoint outside the resource model, so /logs serves node file contents and /debug/pprof heap dumps that carry in-flight credentials straight to the role holder.
!has(object.rules) || object.rules.all(r,
!(has(r.nonResourceURLs) && has(r.verbs) &&
r.nonResourceURLs.exists(u, u == "*" || u in ["/","/api","/api/*","/metrics","/logs","/debug","/debug/*"]) &&
r.verbs.exists(v, v in ["get","post","create","update","patch","delete"]))
)
ClusterRoles must not grant broad nonResourceURL access to API server endpoints (/, /api, /api/*, /metrics, /logs, /debug/*).
Replace the wildcard or root paths with the specific endpoints the caller needs, such as /healthz or /version, and limit the verbs to get. Fields: rules[*].nonResourceURLs, rules[*].verbs.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: clusterrole-nonresource-urls
annotations:
kubeapt.io/uuid: "38352a02-360d-47e3-91a5-1fa70e8ae41e"
security.kubeapt.io/displayName: "Grants Broad Non-Resource URL Access"
security.kubeapt.io/description: "Wildcard or root non-resource paths grant every API server endpoint outside the resource model, so /logs serves node file contents and /debug/pprof heap dumps that carry in-flight credentials straight to the role holder."
security.kubeapt.io/resource: "ClusterRoles"
security.kubeapt.io/severity: "Moderate"
security.kubeapt.io/remediation: "Replace the wildcard or root paths with the specific endpoints the caller needs, such as /healthz or /version, and limit the verbs to get. Fields: rules[*].nonResourceURLs, rules[*].verbs."
security.kubeapt.io/product: "Kubernetes"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- rbac.authorization.k8s.io
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- clusterroles
validations:
- expression: |
!has(object.rules) || object.rules.all(r,
!(has(r.nonResourceURLs) && has(r.verbs) &&
r.nonResourceURLs.exists(u, u == "*" || u in ["/","/api","/api/*","/metrics","/logs","/debug","/debug/*"]) &&
r.verbs.exists(v, v in ["get","post","create","update","patch","delete"]))
)
message: |
ClusterRoles must not grant broad nonResourceURL access to API server endpoints (/, /api, /api/*, /metrics, /logs, /debug/*).Save it as clusterrole-nonresource-urls.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./clusterrole-nonresource-urls.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name clusterrole-nonresource-urls -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name clusterrole-nonresource-urls -A