Skip to content
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

fix: Implement workaround to make HSM keys work #21

Merged
merged 1 commit into from
Sep 20, 2023
Merged
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
4 changes: 2 additions & 2 deletions bootstrap.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ resource "google_cloud_run_v2_job" "bootstrap" {

env {
name = "ACTIVE_ID_KEY_REF"
value = google_kms_crypto_key_version.identity_key.id
value = data.google_kms_crypto_key_version.initial_identity_key.id
}
env {
name = "ACTIVE_ID_PUBLIC_KEY"
value = data.google_kms_crypto_key_version.identity_key.public_key[0].pem
value = data.google_kms_crypto_key_version.initial_identity_key.public_key[0].pem
}

env {
Expand Down
18 changes: 9 additions & 9 deletions kms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ resource "google_kms_crypto_key" "identity_key" {
key_ring = google_kms_key_ring.keystores.id
purpose = "ASYMMETRIC_SIGN"

skip_initial_version_creation = true

version_template {
algorithm = "RSA_SIGN_PSS_2048_SHA256"
protection_level = var.kms_protection_level
Expand All @@ -35,7 +33,11 @@ resource "google_kms_crypto_key" "identity_key" {
}
}

resource "google_kms_crypto_key_version" "identity_key" {
// Ideally, we'd just manage the key version explicitly, but we can't due to two limitations
// in the Google provider:
// 1.- This bug with HSM keys: https://github.com/hashicorp/terraform-provider-google/issues/13924
// 2.- The lack of support for reading the public key as soon as the key is created.
data "google_kms_crypto_key_version" "initial_identity_key" {
crypto_key = google_kms_crypto_key.identity_key.id

depends_on = [time_sleep.wait_for_id_key_creation]
Expand All @@ -57,15 +59,13 @@ resource "google_kms_crypto_key" "session_keys" {
}
}

data "google_kms_crypto_key_version" "identity_key" {
crypto_key = google_kms_crypto_key.identity_key.id

depends_on = [time_sleep.wait_for_id_key_creation]
}

resource "time_sleep" "wait_for_id_key_creation" {
depends_on = [google_kms_crypto_key.identity_key]
create_duration = "30s"

triggers = {
kms_protection_level = var.kms_protection_level
}
}

// IAM
Expand Down
4 changes: 2 additions & 2 deletions pohttp_client.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ resource "google_cloud_run_v2_service" "pohttp_client" {

env {
name = "ACTIVE_ID_KEY_REF"
value = google_kms_crypto_key_version.identity_key.id
value = data.google_kms_crypto_key_version.initial_identity_key.id
}
env {
name = "ACTIVE_ID_PUBLIC_KEY"
value = data.google_kms_crypto_key_version.identity_key.public_key[0].pem
value = data.google_kms_crypto_key_version.initial_identity_key.public_key[0].pem
}

env {
Expand Down
4 changes: 2 additions & 2 deletions pohttp_server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ resource "google_cloud_run_v2_service" "pohttp_server" {

env {
name = "ACTIVE_ID_KEY_REF"
value = google_kms_crypto_key_version.identity_key.id
value = data.google_kms_crypto_key_version.initial_identity_key.id
}
env {
name = "ACTIVE_ID_PUBLIC_KEY"
value = data.google_kms_crypto_key_version.identity_key.public_key[0].pem
value = data.google_kms_crypto_key_version.initial_identity_key.public_key[0].pem
}

env {
Expand Down
Loading