-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for setting firewall rules (#470)
* Squash Commits Signed-off-by: Dev <[email protected]> * Fix example Signed-off-by: Dev <[email protected]> * Rename var + update README Signed-off-by: Dev <[email protected]> * Set to false as default Signed-off-by: Dev <[email protected]> * Enable firewall support in shared_vpc example Signed-off-by: Dev <[email protected]> * Remove network datasource and make subnetwork conditional on firewall Signed-off-by: Dev <[email protected]> * Fix attribute error Signed-off-by: Dev <[email protected]>
- Loading branch information
Showing
46 changed files
with
1,010 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
{{ autogeneration_note }} | ||
|
||
|
||
/****************************************** | ||
Match the gke-<CLUSTER>-<ID>-all INGRESS | ||
firewall rule created by GKE but for EGRESS | ||
|
||
Required for clusters when VPCs enforce | ||
a default-deny egress rule | ||
*****************************************/ | ||
resource "google_compute_firewall" "intra_egress" { | ||
count = var.add_cluster_firewall_rules ? 1 : 0 | ||
name = "gke-${substr(var.name, 0, min(25, length(var.name)))}-intra-cluster-egress" | ||
description = "Managed by terraform gke module: Allow pods to communicate with each other and the master" | ||
project = local.network_project_id | ||
network = var.network | ||
priority = var.firewall_priority | ||
direction = "EGRESS" | ||
|
||
target_tags = [local.cluster_network_tag] | ||
destination_ranges = [ | ||
local.cluster_endpoint_for_nodes, | ||
local.cluster_subnet_cidr, | ||
local.cluster_alias_ranges_cidr[var.ip_range_pods], | ||
] | ||
|
||
# Allow all possible protocols | ||
allow { protocol = "tcp" } | ||
allow { protocol = "udp" } | ||
allow { protocol = "icmp" } | ||
allow { protocol = "sctp" } | ||
allow { protocol = "esp" } | ||
allow { protocol = "ah" } | ||
|
||
depends_on = [ | ||
google_container_cluster.primary, | ||
] | ||
} | ||
|
||
|
||
/****************************************** | ||
Allow GKE master to hit non 443 ports for | ||
Webhooks/Admission Controllers | ||
|
||
https://github.com/kubernetes/kubernetes/issues/79739 | ||
*****************************************/ | ||
resource "google_compute_firewall" "master_webhooks" { | ||
count = var.add_cluster_firewall_rules ? 1 : 0 | ||
name = "gke-${substr(var.name, 0, min(25, length(var.name)))}-webhooks" | ||
description = "Managed by terraform gke module: Allow master to hit pods for admission controllers/webhooks" | ||
project = local.network_project_id | ||
network = var.network | ||
priority = var.firewall_priority | ||
direction = "INGRESS" | ||
|
||
source_ranges = [local.cluster_endpoint_for_nodes] | ||
target_tags = [local.cluster_network_tag] | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = var.firewall_inbound_ports | ||
} | ||
|
||
depends_on = [ | ||
google_container_cluster.primary, | ||
] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
{{ autogeneration_note }} | ||
|
||
data "google_compute_subnetwork" "gke_subnetwork" { | ||
provider = google | ||
|
||
count = var.add_cluster_firewall_rules ? 1 : 0 | ||
name = var.subnetwork | ||
region = local.region | ||
project = local.network_project_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.