← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Claims Arbitrary External IP Addresses

service-external-ips

severityModerate resourceServices productKubernetes bundles1

externalIPs make every node claim the listed addresses and steer matching traffic into the selected pods, so any namespace able to create a Service can hijack and man-in-the-middle traffic destined for those IPs.

Rejects unless

!has(object.spec.externalIPs) || size(object.spec.externalIPs) == 0

spec.externalIPs must not be set.

Remediation

Remove spec.externalIPs and publish the Service through an Ingress or a LoadBalancer address assigned by the platform. Field: spec.externalIPs.

Applies to

  • services · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: service-external-ips
  annotations:
    kubeapt.io/uuid: "67c6d14c-e374-4cfc-87aa-94f214f1e104"
    security.kubeapt.io/displayName: "Claims Arbitrary External IP Addresses"
    security.kubeapt.io/description: "externalIPs make every node claim the listed addresses and steer matching traffic into the selected pods, so any namespace able to create a Service can hijack and man-in-the-middle traffic destined for those IPs."
    security.kubeapt.io/resource: "Services"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Remove spec.externalIPs and publish the Service through an Ingress or a LoadBalancer address assigned by the platform. Field: spec.externalIPs."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - services
  validations:
  - expression: |
      !has(object.spec.externalIPs) || size(object.spec.externalIPs) == 0
    message: |
      spec.externalIPs must not be set.

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

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

$ kubeapt validate --policy-name service-external-ips -A