← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Grants Broad Non-Resource URL Access

clusterrole-nonresource-urls

severityModerate resourceClusterRoles productKubernetes bundles1

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.

Rejects unless

!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/*).

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.

Applies to

  • clusterroles · rbac.authorization.k8s.io/v1 · CREATE, UPDATE

Manifest

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.

Validate with kubeapt

Check a workload against this one policy, before anything is installed on a cluster.

$ kubeapt validate -p ./clusterrole-nonresource-urls.yaml -r ./workload.yaml

Or without the file, from the published policy set — -r takes a directory too:

$ kubeapt policies download && kubeapt validate --policy-name clusterrole-nonresource-urls -r ./manifests

Or against every namespace in the cluster your kubeconfig points at:

$ kubeapt validate --policy-name clusterrole-nonresource-urls -A