Skip to content

Certificate replacement #19

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ credentials.json
*.pfx

terraform.tfvars
.certs
18 changes: 18 additions & 0 deletions docs/Cloudflare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Free https with cloudflare

CloudFlare can provide a forever free https certificate in front of your app.

The requirements are:
- Create a free cloudflare account
- Buy a domain random dotcom is ~$8 (you can buy it directly from coudflare or you buy it externally and then configure dns with cloudflare)
- Create and Download a cloudflare generated and trusted certificate and key. If you have multiple domains all of them need to be managed in cloudflare and you need to list them all when creating the certificate.
<img src="cloudflare/first.png">

- Use that certificate while setting up https with terraform
- Choose end-to end encryption in cloudflare
<img src="cloudflare/second.png">

- Choose force everything to https
<img src="cloudflare/third.png">

Enjoy free https
Binary file added docs/cloudflare/first.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/cloudflare/second.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/cloudflare/third.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 33 additions & 13 deletions terraform/gke.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ resource "google_compute_subnetwork" "default" {
ip_cidr_range = "10.0.0.0/24"
}

resource "google_container_cluster" "default" {
provider = google-beta
project = var.project_id
name = var.gke_cluster_name
location = var.zone
initial_node_count = var.num_nodes
# More info on the VPC native cluster: https://cloud.google.com/kubernetes-engine/docs/how-to/standalone-neg#create_a-native_cluster
networking_mode = "VPC_NATIVE"
network = google_compute_network.default.name
subnetwork = google_compute_subnetwork.default.name
# Disable the Google Cloud Logging service because you may overrun the Logging free tier allocation, and it may be expensive
logging_service = "none"
# Node pool configuration
resource "google_container_node_pool" "primary_pool" {
name = "primary-node-pool"
cluster = "${google_container_cluster.default.name}"
project = google_compute_network.default.project
location = var.zone
node_count = var.num_nodes

autoscaling {
min_node_count = var.num_nodes
max_node_count = 10
}

node_config {
# More info on Spot VMs with GKE https://cloud.google.com/kubernetes-engine/docs/how-to/spot-vms#create_a_cluster_with_enabled
Expand All @@ -47,7 +47,27 @@ resource "google_container_cluster" "default" {
"https://www.googleapis.com/auth/servicecontrol",
]
}

management {
auto_repair = true
auto_upgrade = true
}
}

resource "google_container_cluster" "default" {
provider = google-beta
project = var.project_id
name = var.gke_cluster_name
location = var.zone
# More info on the VPC native cluster: https://cloud.google.com/kubernetes-engine/docs/how-to/standalone-neg#create_a-native_cluster
networking_mode = "VPC_NATIVE"
network = google_compute_network.default.name
subnetwork = google_compute_subnetwork.default.name
# Disable the Google Cloud Logging service because you may overrun the Logging free tier allocation, and it may be expensive
logging_service = "none"

remove_default_node_pool = "true"
# initial_node_count = 1

addons_config {
http_load_balancing {
# This needs to be enabled for the NEG to be automatically created for the ingress gateway svc
Expand Down
22 changes: 19 additions & 3 deletions terraform/https.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
provider "random" {
# Configuration options
}
resource "google_compute_forwarding_rule" "redirect" {
depends_on = [google_compute_subnetwork.proxy]
count = var.https ? 1 : 0
Expand Down Expand Up @@ -47,17 +50,30 @@ resource "google_compute_region_url_map" "redirect" {
}
}

resource "random_string" "random_cert_suffix" {
length = 8
special = false
lower = true
upper = false
}

resource "google_compute_region_ssl_certificate" "default" {
depends_on = [random_string.random_cert_suffix]
project = google_compute_subnetwork.default.project
region = google_compute_subnetwork.default.region
name = var.ssl_cert_name
name = "${var.ssl_cert_name}-${random_string.random_cert_suffix.result}"
description = "SSL certificate for l7-xlb-proxy-https"
private_key = file(var.ssl_cert_key)
certificate = file(var.ssl_cert_crt)
private_key = file("${var.ssl_cert_path}/${var.ssl_cert_name}.key")
certificate = file("${var.ssl_cert_path}/${var.ssl_cert_name}.crt")

lifecycle {
create_before_destroy = true
}
}

# https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/compute_ssl_certificate#example-usage---ssl-certificate-target-https-proxies
resource "google_compute_region_target_https_proxy" "default" {
depends_on = [google_compute_region_ssl_certificate.default]
project = google_compute_subnetwork.default.project
region = google_compute_subnetwork.default.region
name = "l7-xlb-proxy-https"
Expand Down
12 changes: 4 additions & 8 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,16 @@ variable "ip_address_name" {
description = "The name of the static IP Address for the load balancer"
}

variable "ssl_cert_name" {
description = "The name of the SSL certificate for the load balancer"
}

variable "https" {
description = "Whether to set up the load balancer with HTTPS or not"
}

variable "ssl_cert_crt" {
description = "Path to the SSL certificate .crt"
variable "ssl_cert_name" {
description = "The name of the files .crt and .key files inside cert_path folder. This will be used as SSL certificate name for the load balancer"
}

variable "ssl_cert_key" {
description = "Path to the SSL certificate private .key"
variable "ssl_cert_path" {
description = "Path to the SSL certificate folder where your .crt and .key files are"
}

resource "google_compute_network" "default" {
Expand Down
2 changes: 2 additions & 0 deletions terraform/scripts/install-gloo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ helm install gloo gloo/gloo \
--create-namespace \
--namespace gloo-system \
-f "$DIR/values.yaml"

true
6 changes: 5 additions & 1 deletion terraform/terraform.tfvars.template
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ ssl_cert_crt = "certs/self-signed.crt"
ssl_cert_key = "certs/self-signed.key"

# Change to true to enable HTTPS and HTTP redirect for the load balancer
https = false
https = false
# You need to have the certificate and the key in the same folder.
# Example self-signed.crt and self-signed.key in certs directory
# ssl_cert_name = "self-signed"
# ssl_cert_path = "certs"
5 changes: 5 additions & 0 deletions terraform/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ terraform {
source = "hashicorp/google-beta"
version = "4.5.0"
}

random = {
source = "hashicorp/random"
version = "3.1.0"
}
}

required_version = ">= 1.0"
Expand Down