checkov icon indicating copy to clipboard operation
checkov copied to clipboard

Checkov fails on `CKV_AZURE_168` if ternary condition is compared to `null`

Open ppawlowski opened this issue 2 years ago • 10 comments

Describe the issue

In terraform, in ternary operation, if condition consists of null comparison, checkov fails. This particular check fails on both azurerm_kubernetes_cluster and azurerm_kubernetes_cluster_node_pool . If different value is used (tested on boolean, string and number) checkov is able to handle such comparison and check is marked as passed.

Examples

main.tf:

provider "azurerm" {
  features {}
}

variable "max_pods" {
  default = null
}

resource "azurerm_kubernetes_cluster" "example" {
    name = "checkovAksCluster"
    default_node_pool {
      name = "syspool"
      max_pods = var.max_pods == null ? 51 : 49
    }
}

checkov execution (irrelevant output omitted):

$ checkov -d . -c CKV_AZURE_168

terraform scan results:

Passed checks: 0, Failed checks: 1, Skipped checks: 0

Check: CKV_AZURE_168: "Ensure Azure Kubernetes Cluster (AKS) nodes should use a minimum number of 50 pods."
        FAILED for resource: azurerm_kubernetes_cluster.example
        File: /main.tf:9-15

                9  | resource "azurerm_kubernetes_cluster" "example" {
                10 |     name = "checkovAksCluster"
                11 |     default_node_pool {
                12 |       name = "syspool"
                13 |       max_pods = var.max_pods == null ? 51 : 49
                14 |     }
                15 | }

Expected checkov output (irrelevant output omitted):

$ checkov -d . -c CKV_AZURE_168

terraform scan results:

Passed checks: 1, Failed checks: 0, Skipped checks: 0

Check: CKV_AZURE_168: "Ensure Azure Kubernetes Cluster (AKS) nodes should use a minimum number of 50 pods."
        PASSED for resource: azurerm_kubernetes_cluster.example
        File: /main.tf:9-15

Version (please complete the following information):

2.3.200

ppawlowski avatar Apr 27 '23 09:04 ppawlowski

Thanks for contributing to Checkov! We've automatically marked this issue as stale to keep our issues list tidy, because it has not had any activity for 6 months. It will be closed in 14 days if no further activity occurs. Commenting on this issue will remove the stale tag. If you want to talk through the issue or help us understand the priority and context, feel free to add a comment or join us in the Checkov slack channel at https://slack.bridgecrew.io Thanks!

stale[bot] avatar Oct 29 '23 12:10 stale[bot]

Not stale.

ppawlowski avatar Nov 06 '23 07:11 ppawlowski

Thanks for contributing to Checkov! We've automatically marked this issue as stale to keep our issues list tidy, because it has not had any activity for 6 months. It will be closed in 14 days if no further activity occurs. Commenting on this issue will remove the stale tag. If you want to talk through the issue or help us understand the priority and context, feel free to add a comment or join us in the Checkov slack channel at codifiedsecurity.slack.com Thanks!

stale[bot] avatar May 16 '24 03:05 stale[bot]

Not stale.

ppawlowski avatar May 20 '24 10:05 ppawlowski

Hi @ppawlowski

Thanks for reaching us out and for reporting! @tsmithv11, @bo156 do you know if we supported such cases? seems that the resource azurerm_kubernetes_cluster.example are not recognizing the value of var.max_pods

itai1357 avatar Jul 18 '24 10:07 itai1357

Thanks for contributing to Checkov! We've automatically marked this issue as stale to keep our issues list tidy, because it has not had any activity for 6 months. It will be closed in 14 days if no further activity occurs. Commenting on this issue will remove the stale tag. If you want to talk through the issue or help us understand the priority and context, feel free to add a comment or join us in the Checkov slack channel at codifiedsecurity.slack.com Thanks!

stale[bot] avatar Jan 18 '25 07:01 stale[bot]

Not stale.

ppawlowski avatar Jan 19 '25 12:01 ppawlowski