github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/kubernetes/policies/pss/baseline/1_host_network.rego (about)

     1  # METADATA
     2  # title: "Access to host network"
     3  # description: "Sharing the host’s network namespace permits processes in the pod to communicate with processes bound to the host’s loopback adapter."
     4  # scope: package
     5  # schemas:
     6  # - input: schema["kubernetes"]
     7  # related_resources:
     8  # - https://kubernetes.io/docs/concepts/security/pod-security-standards/#baseline
     9  # custom:
    10  #   id: KSV009
    11  #   avd_id: AVD-KSV-0009
    12  #   severity: HIGH
    13  #   short_code: no-host-network
    14  #   recommended_action: "Do not set 'spec.template.spec.hostNetwork' to true."
    15  #   input:
    16  #     selector:
    17  #     - type: kubernetes
    18  package builtin.kubernetes.KSV009
    19  
    20  import data.lib.kubernetes
    21  
    22  default failHostNetwork = false
    23  
    24  # failHostNetwork is true if spec.hostNetwork is set to true (on all controllers)
    25  failHostNetwork {
    26  	kubernetes.host_networks[_] == true
    27  }
    28  
    29  deny[res] {
    30  	failHostNetwork
    31  	msg := kubernetes.format(sprintf("%s '%s' should not set 'spec.template.spec.hostNetwork' to true", [kubernetes.kind, kubernetes.name]))
    32  	res := result.new(msg, input.spec)
    33  }