NET_RAW Capabilities Not Being Dropped

  • Query id: e5587d53-a673-4a6b-b3f2-ba07ec274def
  • Query name: NET_RAW Capabilities Not Being Dropped
  • Platform: Terraform
  • Severity: Medium
  • Category: Insecure Configurations
  • CWE: 269
  • Risk score: 6.2
  • URL: Github

Description

Containers should drop 'ALL' or at least 'NET_RAW' capabilities
Documentation

Code samples

Code samples with security vulnerabilities

Positive test num. 1 - tf file
resource "kubernetes_pod" "positive1" {
  metadata {
    name = "terraform-example"
  }

  spec {
   container {
    image = "nginx:1.7.9"
    name  = "example1"

    security_context {
      capabilities {
      }
    }

    env {
      name  = "environment"
      value = "test"
    }

    port {
      container_port = 8080
    }

    liveness_probe {
      http_get {
        path = "/nginx_status"
        port = 80

        http_header {
          name  = "X-Custom-Header"
          value = "Awesome"
        }
      }

      initial_delay_seconds = 3
      period_seconds        = 3
    }
   }

   container {
    image = "nginx:1.7.9"
    name  = "example11"

    security_context {
      capabilities {
      }
    }

    env {
      name  = "environment"
      value = "test"
    }

    port {
      container_port = 8080
    }

    liveness_probe {
      http_get {
        path = "/nginx_status"
        port = 80

        http_header {
          name  = "X-Custom-Header"
          value = "Awesome"
        }
      }

      initial_delay_seconds = 3
      period_seconds        = 3
    }
   }

   container {
    image = "nginx:1.7.9"
    name  = "example2"

    security_context {
      capabilities {
        drop = ["NET_BIND_SERVICE"]
      }
    }

    env {
      name  = "environment"
      value = "test"
    }

    port {
      container_port = 8080
    }

    liveness_probe {
      http_get {
        path = "/nginx_status"
        port = 80

        http_header {
          name  = "X-Custom-Header"
          value = "Awesome"
        }
      }

      initial_delay_seconds = 3
      period_seconds        = 3
    }
   }

   container {
    image = "nginx:1.7.9"
    name  = "example22"

    security_context {
      capabilities {
        drop = ["NET_BIND_SERVICE"]
      }
    }

    env {
      name  = "environment"
      value = "test"
    }

    port {
      container_port = 8080
    }

    liveness_probe {
      http_get {
        path = "/nginx_status"
        port = 80

        http_header {
          name  = "X-Custom-Header"
          value = "Awesome"
        }
      }

      initial_delay_seconds = 3
      period_seconds        = 3
    }
   }

   container {
    image = "nginx:1.7.9"
    name  = "example3"

    security_context {
      read_only_root_filesystem = true
    }

    env {
      name  = "environment"
      value = "test"
    }

    port {
      container_port = 8080
    }

    liveness_probe {
      http_get {
        path = "/nginx_status"
        port = 80

        http_header {
          name  = "X-Custom-Header"
          value = "Awesome"
        }
      }

      initial_delay_seconds = 3
      period_seconds        = 3
    }
   }

   container {
    image = "nginx:1.7.9"
    name  = "example33"

    security_context {
      read_only_root_filesystem = true
    }

    env {
      name  = "environment"
      value = "test"
    }

    port {
      container_port = 8080
    }

    liveness_probe {
      http_get {
        path = "/nginx_status"
        port = 80

        http_header {
          name  = "X-Custom-Header"
          value = "Awesome"
        }
      }

      initial_delay_seconds = 3
      period_seconds        = 3
    }
   }

   container {
    image = "nginx:1.7.9"
    name  = "example4"

    env {
      name  = "environment"
      value = "test"
    }

    port {
      container_port = 8080
    }

    liveness_probe {
      http_get {
        path = "/nginx_status"
        port = 80

        http_header {
          name  = "X-Custom-Header"
          value = "Awesome"
        }
      }

      initial_delay_seconds = 3
      period_seconds        = 3
    }
   }

   container {
    image = "nginx:1.7.9"
    name  = "example44"

    env {
      name  = "environment"
      value = "test"
    }

    port {
      container_port = 8080
    }

    liveness_probe {
      http_get {
        path = "/nginx_status"
        port = 80

        http_header {
          name  = "X-Custom-Header"
          value = "Awesome"
        }
      }

      initial_delay_seconds = 3
      period_seconds        = 3
    }
   }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}

resource "kubernetes_pod" "positive2" {
  metadata {
    name = "terraform-example"
  }

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"

      security_context {
        capabilities {
        }
      }

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }

      liveness_probe {
        http_get {
          path = "/nginx_status"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}

resource "kubernetes_pod" "positive3" {
  metadata {
    name = "terraform-example"
  }

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"

      security_context {
        capabilities {
          drop = ["NET_BIND_SERVICE"]
        }
      }

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }

      liveness_probe {
        http_get {
          path = "/nginx_status"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}

resource "kubernetes_pod" "positive4" {
  metadata {
    name = "terraform-example"
  }

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"

      security_context {
      }

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }

      liveness_probe {
        http_get {
          path = "/nginx_status"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}

resource "kubernetes_pod" "positive5" {
  metadata {
    name = "terraform-example"
  }

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }

      liveness_probe {
        http_get {
          path = "/nginx_status"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}

Code samples without security vulnerabilities

Negative test num. 1 - tf file
resource "kubernetes_pod" "negative3" {
  metadata {
    name = "terraform-example"
  }

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"

      security_context {
        capabilities {
          drop = ["ALL"]
        }
      }

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }

      liveness_probe {
        http_get {
          path = "/nginx_status"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    container {
      image = "nginx:1.7.9"
      name  = "example2"

      security_context {
        capabilities {
          drop = ["ALL"]
        }
      }

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }

      liveness_probe {
        http_get {
          path = "/nginx_status"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}

resource "kubernetes_pod" "negative4" {
  metadata {
    name = "terraform-example"
  }

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"

      security_context {
          capabilities {
            drop = ["ALL"]
          }
      }

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 8080
      }

      liveness_probe {
        http_get {
          path = "/nginx_status"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}