Repository navigation
Conversation
|
|
a86fb30 to
f1a3ed5
Compare
|
Looks like #11767 beat me to it |
|
@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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
| } | ||
| } | ||
|
|
||
| func TestAdaptControlPlaneEndpoints(t *testing.T) { |
There was a problem hiding this comment.
Remove this test. With the true default, the cases in Test_Adapt cover it. The existing cases there expect IPEndpointsEnabled: iacTypes.BoolTest(true).
|
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
f1a3ed5 to
1d18ce8
Compare
Description
GCP-0061 (master authorized networks) fails for a GKE cluster whose IP-based control plane endpoints are disabled:
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:
ControlPlaneEndpoints.IPEndpoints.Enabledto the GKEClustermodel, mirroring the Terraform blocks;control_plane_endpoints_config.ip_endpoints_config.enabledin the Terraform adapter. The default istruewhen the attribute or its blocks are not set, as in the provider docs;pkg/iac/rego/schemas/cloud.jsonwithmage schema:generate.Tests: the existing
Test_Adaptcases expectEnabled: true, and a new case coversenabled = 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 Trivymain, 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/trivy0.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).ip_endpoints_config { enabled = false }ip_endpoints_config { enabled = true }, without authorized networksip_endpoints_config {}, without authorized networkscontrol_plane_endpoints_confignot set, without authorized networksenabled = var.x(no value), without authorized networksenabled = falseplus an emptymaster_authorized_networks_config {}go testforpkg/iac/adapters/terraform/...,pkg/iac/rego/...andpkg/iac/scanners/terraform/...,mage schema:verify,go vetand golangci-lint v2.14.0 (on the two changed packages) pass with Go 1.27.0.Related issues
Related PRs
Checklist