Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terrascan wrongly reports a accurics.gcp.NS.130 (checkIpForward) violation #320

Closed
ferrarimarco opened this issue Sep 14, 2020 · 1 comment · Fixed by #321
Closed

Terrascan wrongly reports a accurics.gcp.NS.130 (checkIpForward) violation #320

ferrarimarco opened this issue Sep 14, 2020 · 1 comment · Fixed by #321

Comments

@ferrarimarco
Copy link

  • terrascan version: 1.0.0
  • Operating System: Ubuntu 20.04

Description

Terrascan reports a violation of the accurics.gcp.NS.130 rule (rule code is in checkIpForward.rego), and it should not.

What I Did

Here's my google_compute_instance. Adding a can_ip_forward = false doesn't make any difference.

resource "google_compute_instance" "development-workstation" {
  name             = var.development_workstation_name
  machine_type     = var.development_workstation_machine_type
  min_cpu_platform = var.development_workstation_min_cpu_platform

  boot_disk {
    initialize_params {
      image = "${google_compute_image.dev-workstation-image-ubuntu-2004.family}/${google_compute_image.dev-workstation-image-ubuntu-2004.name}"
      type  = "pd-ssd"
    }
  }

  network_interface {
    network = "default"

    access_config {
      // Ephemeral IP
    }
  }
}

What am I doing wrong?

@williepaul
Copy link
Contributor

williepaul commented Sep 14, 2020

Hi @ferrarimarco, appreciate the bug report. I verified the issue on my dev box, and it's definitely a policy bug.

Basically, it looks like the intention for the checkIpForward rule was to check if !(.can_ip_forward == true), but due to syntax, "not api.config.can_ip_forward" actually checks if a key does not exist, which in this case is true (it's not in the test file).
Since the can_ip_forward rule defaults to false, removing the "not" and just checking for can_ip_forward == true should suffice.

pkg/policies/opa/rego/gcp/google_compute_instance/checkIpForward.rego:

checkIpForward[api.id]
{
api := input.google_compute_instance[_]
not api.config.can_ip_forward == true
}

Fixed:
checkIpForward[api.id]
{
api := input.google_compute_instance[_]
api.config.can_ip_forward == true
}

I'll check in the fix shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants