service-admin-ports
Admin, debug, metrics and management listeners are usually unauthenticated, so publishing them on a LoadBalancer or NodePort hands outside callers internal telemetry, profiling and heap dumps, and sometimes live control over the workload.
!(
(object.spec.type == 'LoadBalancer' || object.spec.type == 'NodePort')
&&
object.spec.ports.exists(p,
has(p.name) &&
p.name.matches('(?i).*(admin|debug|metrics|mgmt|management).*')
)
)
Externally reachable Services (type LoadBalancer/NodePort) must not expose admin/debug/metrics ports. Split these endpoints into a separate internal-only Service.
Move the admin, debug, metrics and management ports to a separate ClusterIP Service and leave only application ports on the externally reachable one. Fields: spec.type, spec.ports[*].name.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: service-admin-ports
annotations:
kubeapt.io/uuid: "4bb23409-36e0-41b0-8511-c6511ac6b211"
security.kubeapt.io/displayName: "Exposes an Admin or Metrics Port Externally"
security.kubeapt.io/description: "Admin, debug, metrics and management listeners are usually unauthenticated, so publishing them on a LoadBalancer or NodePort hands outside callers internal telemetry, profiling and heap dumps, and sometimes live control over the workload."
security.kubeapt.io/resource: "Services"
security.kubeapt.io/severity: "Moderate"
security.kubeapt.io/remediation: "Move the admin, debug, metrics and management ports to a separate ClusterIP Service and leave only application ports on the externally reachable one. Fields: spec.type, spec.ports[*].name."
security.kubeapt.io/product: "Kubernetes"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- ''
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- services
validations:
- expression: |
!(
(object.spec.type == 'LoadBalancer' || object.spec.type == 'NodePort')
&&
object.spec.ports.exists(p,
has(p.name) &&
p.name.matches('(?i).*(admin|debug|metrics|mgmt|management).*')
)
)
message: Externally reachable Services (type LoadBalancer/NodePort) must not expose admin/debug/metrics ports. Split these endpoints into a separate internal-only Service.Save it as service-admin-ports.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./service-admin-ports.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name service-admin-ports -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name service-admin-ports -A