Skip to content

fix(misconf): adapt ip_endpoints_config of google_container_cluster - #11769

Open
les2 wants to merge 1 commit into
aquasecurity:mainfrom
les2:fix/gke-dns-endpoint-authorized-networks
Open

les2 wants to merge 1 commit into
aquasecurity:mainfrom
les2:fix/gke-dns-endpoint-authorized-networks

Conversation

@les2

@les2 les2 commented Nov 26, 2026 •

Copy link
Copy Markdown

Description

GCP-0061 (master authorized networks) fails for a GKE cluster whose IP-based control plane endpoints are disabled:

control_plane_endpoints_config {
  dns_endpoint_config { allow_external_traffic = true }
  ip_endpoints_config { enabled = false }
}

Authorized networks apply only to the IP-based endpoints. The GKE model does not record this setting, so the check cannot skip such a cluster.

This PR:

  • adds ControlPlaneEndpoints.IPEndpoints.Enabled to the GKE Cluster model, mirroring the Terraform blocks;
  • reads control_plane_endpoints_config.ip_endpoints_config.enabled in the Terraform adapter. The default is true when the attribute or its blocks are not set, as in the provider docs;
  • regenerates pkg/iac/rego/schemas/cloud.json with mage schema:generate.

Tests: the existing Test_Adapt cases expect Enabled: true, and a new case covers enabled = false.

The check change is aquasecurity/trivy-checks#674: GCP-0061 reports a cluster only when value.is_true(cluster.controlplaneendpoints.ipendpoints.enabled), so a disabled or unresolvable value gives no finding. Its schema test reads the schema from Trivy main, so this PR needs to merge first.

Before and after, with the two folders from https://github.com/les2/trivy-gcp-0061-repro plus four more configurations. "Before" is the aquasec/trivy 0.76.2 image with the published checks bundle. "After" is a build of this branch with a checks bundle built from the trivy-checks branch and served from a local registry (--checks-bundle-repository).

Configuration Before After
ip_endpoints_config { enabled = false } GCP-0061 passes
ip_endpoints_config { enabled = true }, without authorized networks GCP-0061 GCP-0061
ip_endpoints_config {}, without authorized networks GCP-0061 GCP-0061
control_plane_endpoints_config not set, without authorized networks GCP-0061 GCP-0061
enabled = var.x (no value), without authorized networks GCP-0061 passes
enabled = false plus an empty master_authorized_networks_config {} passes passes

go test for pkg/iac/adapters/terraform/..., pkg/iac/rego/... and pkg/iac/scanners/terraform/..., mage schema:verify, go vet and golangci-lint v2.14.0 (on the two changed packages) pass with Go 1.27.0.

Related issues

Related PRs

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@CLAassistant

CLAassistant commented Nov 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@les2
les2 force-pushed the fix/gke-dns-endpoint-authorized-networks branch from a86fb30 to f1a3ed5 Compare November 26, 2026 22:45
@les2
les2 marked this pull request as ready for review November 26, 2026 22:47
@les2
les2 requested a review from nikpivkin as a code owner November 26, 2026 22:47
@les2 les2 closed this Nov 26, 2026
@les2

les2 commented Nov 26, 2026

Copy link
Copy Markdown
Author

Looks like #11767 beat me to it

@les2 les2 reopened this Nov 27, 2026
@les2 les2 closed this Nov 27, 2026
@les2 les2 reopened this Nov 27, 2026
@les2

les2 commented Nov 27, 2026

Copy link
Copy Markdown
Author

@adityagupta26 i think need to regenerate the schema / update cloud.json like in this PR -- i can close this one. there's a change to trivy-checks required to fix the issue that goes along with this one.

EnablePrivateNodes iacTypes.BoolValue
}

type ControlPlaneEndpoints struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flat IPEndpointsEnabled field cannot be extended. If another property of ip_endpoints_config or dns_endpoint_config is needed later, this struct has no place for it. Mirror the Terraform blocks instead:

type ControlPlaneEndpoints struct {
	Metadata    iacTypes.Metadata
	IPEndpoints IPEndpoints
}

type IPEndpoints struct {
	Metadata iacTypes.Metadata
	Enabled  iacTypes.BoolValue
}

The check then reads cluster.controlplaneendpoints.ipendpoints.enabled.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. note that I haven't modeled (added) the DNS endpoint config as it wasn't used in trivy-checks

}
}

func adaptControlPlaneEndpoints(block *terraform.Block) gke.ControlPlaneEndpoints {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use true as the default. The provider docs linked in the description say "Defaults to true", and released provider versions, up to v8.12.0, send Enabled: true when ip_endpoints_config is not set. The next release will stop sending the field (hashicorp/terraform-provider-google@1395780), and then GKE picks the value, which is enabled by default (https://docs.cloud.google.com/kubernetes-engine/docs/concepts/configuration-overview).

func adaptControlPlaneEndpoints(block *terraform.Block) gke.ControlPlaneEndpoints {
	endpoints := gke.ControlPlaneEndpoints{
		Metadata:           block.GetMetadata(),
		IPEndpointsEnabled: iacTypes.BoolDefault(true, block.GetMetadata()),
	}

	if ipBlock := block.GetBlock("ip_endpoints_config"); ipBlock.IsNotNil() {
		enabledAttr := ipBlock.GetAttribute("enabled")
		endpoints.IPEndpointsEnabled = enabledAttr.AsBoolValueOrDefault(true, ipBlock)
	}

	return endpoints
}

adaptCluster and adaptNodePool need the same default.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}

func TestAdaptControlPlaneEndpoints(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this test. With the true default, the cases in Test_Adapt cover it. The existing cases there expect IPEndpointsEnabled: iacTypes.BoolTest(true).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@les2

les2 commented Nov 28, 2026

Copy link
Copy Markdown
Author

addressing feedback now

Add ControlPlaneEndpoints.IPEndpoints.Enabled to the GKE cluster model
and read control_plane_endpoints_config.ip_endpoints_config.enabled in
the Terraform adapter, defaulting to true. Regenerate the cloud schema.

Refs: aquasecurity#11753
@les2
les2 force-pushed the fix/gke-dns-endpoint-authorized-networks branch from f1a3ed5 to 1d18ce8 Compare November 28, 2026 02:18
@les2
les2 requested a review from nikpivkin November 28, 2026 02:55

This branch has not been deployed

No deployments
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 this pull request may close these issues.

bug(misconf): GCP-0061 fails for GKE clusters with disabled IP-based endpoints

3 participants