← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Is Exposed on Every Node via NodePort

service-nodeport

severityModerate resourceServices productKubernetes bundles1

A NodePort opens the same port on every node address, bypassing the ingress path with its TLS termination and authentication and leaving node-level firewalling as the only control between the workload and the wider network.

Rejects unless

!has(object.spec.type) || object.spec.type != "NodePort"

Service type NodePort is disallowed; use ClusterIP/LoadBalancer with proper controls.

Remediation

Set spec.type to ClusterIP and expose the workload through an Ingress, or use a LoadBalancer Service that the platform fronts with its own controls. Field: spec.type.

Applies to

  • services · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: service-nodeport
  annotations:
    kubeapt.io/uuid: "3c5f4471-4c69-4659-8fe0-f4a7a5036ab3"
    security.kubeapt.io/displayName: "Is Exposed on Every Node via NodePort"
    security.kubeapt.io/description: "A NodePort opens the same port on every node address, bypassing the ingress path with its TLS termination and authentication and leaving node-level firewalling as the only control between the workload and the wider network."
    security.kubeapt.io/resource: "Services"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Set spec.type to ClusterIP and expose the workload through an Ingress, or use a LoadBalancer Service that the platform fronts with its own controls. Field: spec.type."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - services
  validations:
  - expression: |
      !has(object.spec.type) || object.spec.type != "NodePort"
    message: |
      Service type NodePort is disallowed; use ClusterIP/LoadBalancer with proper controls.

Save it as service-nodeport.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 ./service-nodeport.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 service-nodeport -r ./manifests

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

$ kubeapt validate --policy-name service-nodeport -A