service-nodeport
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.
!has(object.spec.type) || object.spec.type != "NodePort"
Service type NodePort is disallowed; use ClusterIP/LoadBalancer with proper controls.
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.
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.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./service-nodeport.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-nodeport -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name service-nodeport -A