Skip to content

Commit

Permalink
Azure and GCP support client_cidrs, plus fixed https over wireguard o…
Browse files Browse the repository at this point in the history
…utput link
  • Loading branch information
chadgeary committed Nov 17, 2020
1 parent 6090fd3 commit 1195ce6
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aws/aws-output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ output "pihole-web-msg" {
}

output "pihole-web-vpn-msg" {
value = "pihole webUI also available (when on Wireguard VPN) @ https://${var.docker_pihole}/admin/"
value = "pihole webUI also available (when on Wireguard VPN) @ https://${var.docker_webproxy}/admin/"
}

output "ph-wireguard-msg" {
Expand Down
5 changes: 5 additions & 0 deletions azure/az-generic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ variable "mgmt_cidr" {
description = "A subnet (in CIDR notation) granted SSH, WebUI, and (if dns_novpn = 1) DNS access to virtual machine instance. Deploying from home? This is your public ip with a /32, e.g. 1.2.3.4/32"
}

variable "client_cidrs" {
type = list
description = "List of subnets (in CIDR notation) granted access to DNS without VPN"
}

variable "ph_password" {
type = string
description = "Password for Pihole WebUI access"
Expand Down
30 changes: 30 additions & 0 deletions azure/az-network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,33 @@ resource "azurerm_network_security_rule" "ph-net-rule-dnsudp" {
source_address_prefix = var.mgmt_cidr
destination_address_prefixes = [var.az_subnet_cidr]
}

resource "azurerm_network_security_rule" "ph-net-rule-clients-dnstcp" {
count = length(var.client_cidrs) == 0 ? 0 : 1
name = "${var.ph_prefix}-net-rule-clients-dnstcp"
resource_group_name = azurerm_resource_group.ph-resourcegroup.name
network_security_group_name = azurerm_network_security_group.ph-net-sec.name
priority = 202
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "53"
source_address_prefixes = var.client_cidrs
destination_address_prefixes = [var.az_subnet_cidr]
}

resource "azurerm_network_security_rule" "ph-net-rule-clients-dnsudp" {
count = length(var.client_cidrs) == 0 ? 0 : 1
name = "${var.ph_prefix}-net-rule-clients-dnsudp"
resource_group_name = azurerm_resource_group.ph-resourcegroup.name
network_security_group_name = azurerm_network_security_group.ph-net-sec.name
priority = 203
direction = "Inbound"
access = "Allow"
protocol = "Udp"
source_port_range = "*"
destination_port_range = "53"
source_address_prefixes = var.client_cidrs
destination_address_prefixes = [var.az_subnet_cidr]
}
2 changes: 1 addition & 1 deletion azure/az-output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ output "wireguard-msg" {
}

output "pihole-web-vpn-msg" {
value = "pihole webUI also available (when on Wireguard VPN) @ https://${var.docker_pihole}/admin/"
value = "pihole webUI also available (when on Wireguard VPN) @ https://${var.docker_webproxy}/admin/"
}

output "pihole-web-msg" {
Expand Down
4 changes: 4 additions & 0 deletions azure/az.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ vpn_traffic = "dns"
# a value of 1 permits mgmt_cidr access to DNS without the VPN
dns_novpn = 1

# additional client networks granted access pihole DNS without the VPN, example format:
# client_cidrs = ["127.0.0.1/32","8.8.8.8/32"]
client_cidrs = []

## UNCOMMON ##
# An azure region (and zone), use the following command for a list of region names (use the varsfile value):
# az account list-locations --query "[?metadata.regionType=='Physical'].{varsfile:displayName, cli:name}" --output table
Expand Down
5 changes: 5 additions & 0 deletions gcp/gcp-generic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ variable "mgmt_cidr" {
description = "The subnet in CIDR notation able to reach the instance via SSH, HTTPS, and (if dns_novpn = 1) DNS."
}

variable "client_cidrs" {
type = list
description = "List of subnets (in CIDR notation) granted access to DNS without VPN"
}

variable "vpn_cidr" {
type = string
description = "The subnet in CIDR notation able to reach the instance via Wireguard VPN."
Expand Down
25 changes: 25 additions & 0 deletions gcp/gcp-network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,28 @@ resource "google_compute_firewall" "ph-firewall-mgmt-dnsudp" {
ports = ["53"]
}
}

# client_cidrs
resource "google_compute_firewall" "ph-firewall-client-dnstcp" {
count = length(var.client_cidrs) == 0 ? 0 : 1
name = "${var.ph_prefix}-firewall-client-dnstcp"
project = google_project.ph-project.project_id
network = google_compute_network.ph-network.self_link
source_ranges = var.client_cidrs
allow {
protocol = "tcp"
ports = ["53"]
}
}

resource "google_compute_firewall" "ph-firewall-client-dnsudp" {
count = length(var.client_cidrs) == 0 ? 0 : 1
name = "${var.ph_prefix}-firewall-client-dnsudp"
project = google_project.ph-project.project_id
network = google_compute_network.ph-network.self_link
source_ranges = var.client_cidrs
allow {
protocol = "udp"
ports = ["53"]
}
}
2 changes: 1 addition & 1 deletion gcp/gcp-output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ output "pihole-web-msg" {
}

output "pihole-web-vpn-msg" {
value = "pihole webUI also available (when on Wireguard VPN) @ https://${var.docker_pihole}/admin/"
value = "pihole webUI also available (when on Wireguard VPN) @ https://${var.docker_webproxy}/admin/"
}

output "wireguard-msg" {
Expand Down
4 changes: 4 additions & 0 deletions gcp/gcp.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ vpn_traffic = "dns"
# a value of 1 permits mgmt_cidr access to DNS without the VPN
dns_novpn = 1

# additional client networks granted access pihole DNS without the VPN, example format:
# client_cidrs = ["127.0.0.1/32","8.8.8.8/32"]
client_cidrs = []

## UNCOMMON ##
gcp_region = "us-east1"
gcp_zone = "b"
Expand Down
2 changes: 1 addition & 1 deletion oci/oci-output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ output "pihole-web-msg" {
}

output "pihole-web-vpn-msg" {
value = "pihole webUI also available (when on Wireguard VPN) @ https://${var.docker_pihole}/admin/"
value = "pihole webUI also available (when on Wireguard VPN) @ https://${var.docker_webproxy}/admin/"
}

0 comments on commit 1195ce6

Please sign in to comment.