Skip to content

[GCP] Extract tls_private_key resource from hashicorp/tls provider into an insecure module #222

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
28 changes: 14 additions & 14 deletions deployment/live/gcp/static-ct/cloudbuild/prod/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions deployment/live/gcp/static-ct/logs/ci/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions deployment/live/gcp/test/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deployment/modules/gcp/artifactregistry/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
google = {
source = "registry.terraform.io/hashicorp/google"
version = "6.12.0"
version = "6.28.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion deployment/modules/gcp/cloudbuild/conformance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
google = {
source = "registry.terraform.io/hashicorp/google"
version = "6.12.0"
version = "6.28.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion deployment/modules/gcp/cloudbuild/preloaded/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
google = {
source = "registry.terraform.io/hashicorp/google"
version = "6.12.0"
version = "6.28.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion deployment/modules/gcp/cloudrun/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
google = {
source = "registry.terraform.io/hashicorp/google"
version = "6.12.0"
version = "6.28.0"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions deployment/modules/gcp/insecuretlskey/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# [WARNING]
# This module will store unencrypted private keys in the Terraform state file.
# DO NOT use this for production logs.
21 changes: 21 additions & 0 deletions deployment/modules/gcp/insecuretlskey/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_providers {
tls = {
source = "hashicorp/tls"
version = "4.0.6"
}
}
}

# ECDSA key with P256 elliptic curve. Do NOT use this in production environment.
#
# Security Notice
# The private key generated by this resource will be stored unencrypted in your
# Terraform state file. Use of this resource for production deployments is not
# recommended.
#
# See https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key.
resource "tls_private_key" "ecdsa_p256" {
algorithm = "ECDSA"
ecdsa_curve = "P256"
}
9 changes: 9 additions & 0 deletions deployment/modules/gcp/insecuretlskey/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "tls_private_key_ecdsa_p256_public_key_pem" {
value = tls_private_key.ecdsa_p256.public_key_pem
sensitive = true
}

output "tls_private_key_ecdsa_p256_private_key_pem" {
value = tls_private_key.ecdsa_p256.private_key_pem
sensitive = true
}
23 changes: 5 additions & 18 deletions deployment/modules/gcp/secretmanager/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
google = {
source = "registry.terraform.io/hashicorp/google"
version = "6.12.0"
version = "6.28.0"
}
}
}
Expand All @@ -14,19 +14,6 @@ resource "google_project_service" "secretmanager_googleapis_com" {
disable_on_destroy = false
}

# ECDSA key with P256 elliptic curve. Do NOT use this in production environment.
#
# Security Notice
# The private key generated by this resource will be stored unencrypted in your
# Terraform state file. Use of this resource for production deployments is not
# recommended.
#
# See https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key.
resource "tls_private_key" "sctfe_ecdsa_p256" {
algorithm = "ECDSA"
ecdsa_curve = "P256"
}

resource "google_secret_manager_secret" "sctfe_ecdsa_p256_public_key" {
secret_id = "${var.base_name}-ecdsa-p256-public-key"

Expand All @@ -44,7 +31,7 @@ resource "google_secret_manager_secret" "sctfe_ecdsa_p256_public_key" {
resource "google_secret_manager_secret_version" "sctfe_ecdsa_p256_public_key" {
secret = google_secret_manager_secret.sctfe_ecdsa_p256_public_key.id

secret_data = tls_private_key.sctfe_ecdsa_p256.public_key_pem
secret_data = var.tls_private_key_ecdsa_p256_public_key_pem
}

resource "google_secret_manager_secret" "sctfe_ecdsa_p256_private_key" {
Expand All @@ -62,7 +49,7 @@ resource "google_secret_manager_secret" "sctfe_ecdsa_p256_private_key" {
}

resource "google_secret_manager_secret_version" "sctfe_ecdsa_p256_private_key" {
secret = google_secret_manager_secret.sctfe_ecdsa_p256_private_key.id

secret_data = tls_private_key.sctfe_ecdsa_p256.private_key_pem
secret = google_secret_manager_secret.sctfe_ecdsa_p256_private_key.id
secret_data_wo_version = 1
secret_data_wo = var.tls_private_key_ecdsa_p256_private_key_pem
}
12 changes: 12 additions & 0 deletions deployment/modules/gcp/secretmanager/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@ variable "base_name" {
description = "Base name to use when naming resources"
type = string
}

variable "tls_private_key_ecdsa_p256_public_key_pem" {
description = "Public ECDSA key with P256 elliptic curve in PEM format."
type = string
sensitive = true
}

variable "tls_private_key_ecdsa_p256_private_key_pem" {
description = "Private ECDSA key with P256 elliptic curve in PEM format."
type = string
sensitive = true
}
2 changes: 1 addition & 1 deletion deployment/modules/gcp/storage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
google = {
source = "registry.terraform.io/hashicorp/google"
version = "6.12.0"
version = "6.28.0"
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion deployment/modules/gcp/tesseract/conformance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ module "storage" {
module "secretmanager" {
source = "../../secretmanager"

base_name = var.base_name
base_name = var.base_name
tls_private_key_ecdsa_p256_public_key_pem = module.insecuretlskey.tls_private_key_ecdsa_p256_public_key_pem
tls_private_key_ecdsa_p256_private_key_pem = module.insecuretlskey.tls_private_key_ecdsa_p256_private_key_pem
}

# [WARNING]
# This module will store unencrypted private keys in the Terraform state file.
# DO NOT use this for production logs.
module "insecuretlskey" {
source = "../../insecuretlskey"
}

module "cloudrun" {
Expand Down
11 changes: 10 additions & 1 deletion deployment/modules/gcp/tesseract/test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,14 @@ module "storage" {
module "secretmanager" {
source = "../../secretmanager"

base_name = var.base_name
base_name = var.base_name
tls_private_key_ecdsa_p256_public_key_pem = module.insecuretlskey.tls_private_key_ecdsa_p256_public_key_pem
tls_private_key_ecdsa_p256_private_key_pem = module.insecuretlskey.tls_private_key_ecdsa_p256_private_key_pem
}

# [WARNING]
# This module will store unencrypted private keys in the Terraform state file.
# DO NOT use this for production logs.
module "insecuretlskey" {
source = "../../insecuretlskey"
}
Loading